all repos — paprika @ e0be121a9aae75ae30392da6e48156116d781ca4

go rewrite of taigabot

main.go (view raw)

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