aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-06-15 13:43:57 +0000
committerterminaldweller <devi@terminaldweller.com>2024-06-15 13:43:57 +0000
commit20f83572448187f806095ee0a8cc5b30bff72a93 (patch)
tree4c36696a6629b8dc6615fc6e98a67872923ce86d /main.go
parentadded a shell.nix for pgformatter, and a wip trigger for db size maintenance (diff)
downloadmilla-20f83572448187f806095ee0a8cc5b30bff72a93.tar.gz
milla-20f83572448187f806095ee0a8cc5b30bff72a93.zip
added watchlists
Diffstat (limited to 'main.go')
-rw-r--r--main.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/main.go b/main.go
index f8dd3bb..3962a9b 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"errors"
"flag"
"fmt"
+ "index/suffixarray"
"log"
"net"
"net/http"
@@ -1044,6 +1045,50 @@ func scrapeChannel(irc *girc.Client, poolChan chan *pgxpool.Pool, appConfig Toml
})
}
+func populateWatchListWords(appConfig *TomlConfig) {
+ for watchlistName, watchlist := range appConfig.WatchLists {
+ for _, filepath := range watchlist.WatchFiles {
+ filebytes, err := os.ReadFile(filepath)
+ if err != nil {
+ log.Println(err.Error())
+
+ continue
+ }
+
+ filestring := string(filebytes)
+
+ words := strings.Split(filestring, "\n")
+
+ watchlist.Words = append(watchlist.Words, words...)
+ appConfig.WatchLists[watchlistName] = watchlist
+ }
+ }
+
+ log.Print(appConfig.WatchLists["security"].Words)
+}
+
+func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {
+ irc.Handlers.AddBg(girc.PRIVMSG, func(_ *girc.Client, event girc.Event) {
+ sarray := suffixarray.New([]byte(event.Last()))
+
+ for watchname, watchlist := range appConfig.WatchLists {
+ for _, channel := range watchlist.WatchList {
+ if channel == event.Params[0] {
+ for _, word := range watchlist.Words {
+ 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())
+
+ break
+ }
+ }
+ }
+ }
+ }
+ })
+}
+
func runIRC(appConfig TomlConfig) {
var OllamaMemory []MemoryElement
@@ -1148,6 +1193,23 @@ func runIRC(appConfig TomlConfig) {
go scrapeChannel(irc, poolChan, appConfig)
}
+ if len(appConfig.WatchLists) > 0 {
+ irc.Handlers.AddBg(girc.CONNECTED, func(client *girc.Client, _ girc.Event) {
+ for _, watchlist := range appConfig.WatchLists {
+ log.Print("joining ", watchlist.AlertChannel)
+ client.Cmd.Join(watchlist.AlertChannel)
+
+ for _, channel := range watchlist.WatchList {
+ client.Cmd.Join(channel)
+ }
+ }
+ })
+
+ populateWatchListWords(&appConfig)
+
+ go WatchListHandler(irc, appConfig)
+ }
+
for {
var dialer proxy.Dialer