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 (
"encoding/json"
"fmt"
"log"
"time"
"log"
"gopkg.in/irc.v3"
)

View File

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

View File

@ -7,16 +7,37 @@ import (
"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)
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() {
done := make(chan bool)
var a atMonitor
var dispatchers = []dispatchFunc{
logger,
joinerFactory([]string{"#hswaw-members"}),
}
conn, err := net.Dial("tcp", "irc.libera.chat:6667")
if err != nil {
@ -28,7 +49,7 @@ func main() {
Pass: "***",
User: "bot",
Name: "notbot",
Handler: irc.HandlerFunc(genericHandler),
Handler: irc.HandlerFunc(handlerFactory(dispatchers)),
}
client := irc.NewClient(conn, config)