Some initial work towards having actual plugins.

main
Robert Gerus 2022-01-08 16:18:32 +01:00
parent 28adce4345
commit 0f51bfba4f
3 changed files with 27 additions and 6 deletions

2
at.go
View File

@ -3,8 +3,8 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"time" "time"
"log"
"gopkg.in/irc.v3" "gopkg.in/irc.v3"
) )

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"time"
"io" "io"
"net/http" "net/http"
"time"
) )
func listSubstract(a, b []string) (ret []string) { func listSubstract(a, b []string) (ret []string) {

View File

@ -7,16 +7,37 @@ import (
"gopkg.in/irc.v3" "gopkg.in/irc.v3"
) )
func genericHandler(c *irc.Client, m *irc.Message) { type dispatchFunc func(*irc.Client, *irc.Message)
func handlerFactory(dispatchers []dispatchFunc) func(*irc.Client, *irc.Message) {
return func(c *irc.Client, m *irc.Message) {
for _, f := range dispatchers {
go f(c, m.Copy())
}
}
}
func logger(_ *irc.Client, m *irc.Message) {
log.Println(m) log.Println(m)
if m.Command == "001" { }
c.Write("JOIN #hswaw-members")
func joinerFactory(channels []string) func(*irc.Client, *irc.Message) {
return func(c *irc.Client, m *irc.Message) {
if m.Command == "001" {
for _, ch := range channels {
c.Write("JOIN " + ch)
}
}
} }
} }
func main() { func main() {
done := make(chan bool) done := make(chan bool)
var a atMonitor var a atMonitor
var dispatchers = []dispatchFunc{
logger,
joinerFactory([]string{"#hswaw-members"}),
}
conn, err := net.Dial("tcp", "irc.libera.chat:6667") conn, err := net.Dial("tcp", "irc.libera.chat:6667")
if err != nil { if err != nil {
@ -28,7 +49,7 @@ func main() {
Pass: "***", Pass: "***",
User: "bot", User: "bot",
Name: "notbot", Name: "notbot",
Handler: irc.HandlerFunc(genericHandler), Handler: irc.HandlerFunc(handlerFactory(dispatchers)),
} }
client := irc.NewClient(conn, config) client := irc.NewClient(conn, config)