aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-07-30 23:25:59 +0000
committerterminaldweller <devi@terminaldweller.com>2024-07-30 23:25:59 +0000
commit81469bbb1745a835676c3664e75a4a951223da9d (patch)
tree70a53b118c406d5958a8fb8c72e391fb6439f729 /main.go
parentwe can now add new commands from lua plugins (diff)
downloadmilla-81469bbb1745a835676c3664e75a4a951223da9d.tar.gz
milla-81469bbb1745a835676c3664e75a4a951223da9d.zip
* fixed a crash when unloading a lua script
* added event types, foreground and background color for watchlists * added a url_encode function to lua to encode urls. Underneath, it just calls the standard library function from golang * updated the README * the urban plugin now can take in the number of entries to return * reverted a bug where setting the http proxy for the lua http module was not working * fixed the url for the ip script so it is actually working. the current provider does not support ipv6 though
Diffstat (limited to 'main.go')
-rw-r--r--main.go53
1 files changed, 43 insertions, 10 deletions
diff --git a/main.go b/main.go
index 619ea63..05133c0 100644
--- a/main.go
+++ b/main.go
@@ -554,7 +554,12 @@ func runCommand(
break
}
- result := RunLuaFunc(args[0], args[1], client, appConfig)
+ luaArgs := strings.TrimPrefix(event.Last(), appConfig.IrcNick+": ")
+ luaArgs = strings.TrimSpace(luaArgs)
+ luaArgs = strings.TrimPrefix(luaArgs, "/")
+ luaArgs = strings.TrimPrefix(luaArgs, args[0])
+
+ result := RunLuaFunc(args[0], luaArgs, client, appConfig)
client.Cmd.Reply(event, result)
}
}
@@ -640,11 +645,6 @@ func DoOllamaRequest(
return "", err
}
- if err != nil {
-
- return "", err
- }
-
defer response.Body.Close()
log.Println("response body:", response.Body)
@@ -1086,17 +1086,50 @@ func populateWatchListWords(appConfig *TomlConfig) {
}
func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {
- irc.Handlers.AddBg(girc.PRIVMSG, func(_ *girc.Client, event girc.Event) {
+ irc.Handlers.AddBg(girc.ALL_EVENTS, func(_ *girc.Client, event girc.Event) {
+ var isRightEventType bool
+
sarray := suffixarray.New([]byte(event.Last()))
+ if len(event.Params) == 0 {
+ return
+ }
+
for watchname, watchlist := range appConfig.WatchLists {
for _, channel := range watchlist.WatchList {
+ isRightEventType = false
+
if channel == event.Params[0] {
+
+ for _, eventType := range watchlist.EventTypes {
+ if eventType == event.Command {
+ isRightEventType = true
+
+ break
+ }
+ }
+
+ if !isRightEventType {
+ continue
+ }
+
for _, word := range watchlist.Words {
- indexes := sarray.Lookup([]byte(word), -1)
+ indexes := sarray.Lookup([]byte(" "+word+" "), 1)
if len(indexes) > 0 {
- irc.Cmd.Message(watchlist.AlertChannel, fmt.Sprintf("%s: %s", watchname, event.Last()))
- log.Printf("%s: %s", watchname, event.Last())
+ nextWhitespaceIndex := strings.Index(event.Last()[indexes[0]+1:], " ")
+
+ rewrittenMessage :=
+ event.Last()[:indexes[0]+1] +
+ fmt.Sprintf("\x1b[48;5;%dm", watchlist.BGColor) +
+ fmt.Sprintf("\x1b[38;5;%dm", watchlist.FGColor) +
+ event.Last()[indexes[0]+1:indexes[0]+1+nextWhitespaceIndex] +
+ "\x1b[0m" + event.Last()[indexes[0]+1+nextWhitespaceIndex:]
+
+ irc.Cmd.Message(
+ watchlist.AlertChannel,
+ fmt.Sprintf("%s: %s", watchname, rewrittenMessage))
+
+ log.Printf("matched from watchlist -- %s: %s", watchname, event.Last())
break
}