summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtzfr.eu>2020-08-19 22:28:17 +0200
committerHubert Hirtz <hubert@hirtzfr.eu>2020-08-19 22:28:17 +0200
commitc3e6c2796694bb9d09f4b6baa02021d065361c23 (patch)
tree17a0c876a5e746bb6d2e1306e947a5468244d0f1
parentFix highlight not following new nick on registration (diff)
ui: Notify on highlight (or execute any command)
-rw-r--r--app.go22
-rw-r--r--config.go3
2 files changed, 23 insertions, 2 deletions
diff --git a/app.go b/app.go
index e718fc6..5d3d085 100644
--- a/app.go
+++ b/app.go
@@ -4,6 +4,7 @@ import (
"crypto/tls"
"fmt"
"log"
+ "os/exec"
"strings"
"time"
@@ -23,7 +24,9 @@ type App struct {
}
func NewApp(cfg Config) (app *App, err error) {
- app = &App{}
+ app = &App{
+ cfg: cfg,
+ }
if cfg.Highlights != nil {
app.highlights = make([]string, len(cfg.Highlights))
@@ -132,6 +135,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
app.win.AddLine(ui.Home, l)
app.win.TypingStop(ui.Home, ev.Nick)
app.lastQuery = ev.Nick
+ app.notifyHighlight("", ev.Nick, ev.Content)
} else if ev.Command == "NOTICE" {
l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, true, false)
app.win.AddLine("", l)
@@ -144,6 +148,9 @@ func (app *App) handleIRCEvent(ev irc.Event) {
l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, ev.Command == "NOTICE", isHighlight)
app.win.AddLine(ev.Channel, l)
app.win.TypingStop(ev.Channel, ev.Nick)
+ if isHighlight {
+ app.notifyHighlight(ev.Channel, ev.Nick, ev.Content)
+ }
case irc.QueryTagEvent:
if ev.Typing == irc.TypingActive || ev.Typing == irc.TypingPaused {
app.win.TypingStart(ui.Home, ev.Nick)
@@ -259,6 +266,19 @@ func (app *App) isHighlight(nick, content string) bool {
return false
}
+func (app *App) notifyHighlight(context, nick, content string) {
+ sh, err := exec.LookPath("sh")
+ if err != nil {
+ return
+ }
+ command := app.cfg.OnHighlight
+ command = strings.Replace(command, "%%", "%", -1)
+ command = strings.Replace(command, "%c", context, -1)
+ command = strings.Replace(command, "%n", nick, -1)
+ command = strings.Replace(command, "%m", content, -1)
+ exec.Command(sh, "-c", command).Run()
+}
+
func (app *App) requestHistory() {
if app.s == nil {
return
diff --git a/config.go b/config.go
index 09f4b39..65ca203 100644
--- a/config.go
+++ b/config.go
@@ -14,7 +14,8 @@ type Config struct {
Password *string
Highlights []string
- NickColWidth int `yaml:"nick-column-width"`
+ OnHighlight string `yaml:"on-highlight"`
+ NickColWidth int `yaml:"nick-column-width"`
Debug bool
}