all repos — paprika @ bdaefbdeb1674762cd448b2b7288d1db2fb9c055

go rewrite of taigabot

main.go (view raw)

 1package main
 2
 3import (
 4	"log"
 5	"net"
 6
 7	"git.icyphox.sh/taigobot/db"
 8	"git.icyphox.sh/taigobot/plugins"
 9	"github.com/dgraph-io/badger/v3"
10	"gopkg.in/irc.v3"
11)
12
13func ircHandler(c *irc.Client, m *irc.Message) {
14	switch m.Command {
15	case "001":
16		// TODO: load this from config
17		c.Write("JOIN #taigobot-test")
18	case "PRIVMSG":
19		response, err := plugins.ProcessTrigger(m)
20		if err != nil {
21			c.Writef("error: %v", err)
22		}
23		c.WriteMessage(&irc.Message{
24			Command: "PRIVMSG",
25			Params: []string{
26				m.Params[0],
27				response,
28			},
29		})
30	}
31}
32
33func main() {
34	// TODO: load this from config
35	conn, err := net.Dial("tcp", "irc.rizon.net:6667")
36	if err != nil {
37		log.Fatal(err)
38	}
39
40	config := irc.ClientConfig{
41		Nick:    "taigobot",
42		Pass:    "",
43		User:    "taigobot",
44		Name:    "taigobot",
45		Handler: irc.HandlerFunc(ircHandler),
46	}
47
48	db.DB, err = badger.Open(badger.DefaultOptions("./badger"))
49	if err != nil {
50		log.Fatal(err)
51	}
52	defer db.DB.Close()
53
54	client := irc.NewClient(conn, config)
55	err = client.Run()
56	if err != nil {
57		log.Fatal(err)
58	}
59}