-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (45 loc) · 1.15 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"flag"
"fmt"
"github.com/jdiez17/go-irc"
"os"
"strings"
"time"
)
func main() {
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
configFile := fs.String("config", "", "The config.json.")
fs.Parse(os.Args[1:])
err := loadConfig(*configFile)
if err != nil {
fmt.Println("Error reading the configuration: " + err.Error())
return
}
conn, err := irc.NewConnection(Config.IRC.Server, int(Config.IRC.Port))
if err != nil {
fmt.Println("error: ", err)
return
}
defer conn.Close()
conn.LogIn(irc.Identity{Nick: Config.Nick})
conn.AddHandler(irc.MOTD_END, func(c *irc.Connection, e *irc.Event) {
if Config.NickServPassword != "" {
c.Privmsg("NickServ", "identify "+Config.NickServPassword)
}
for _, channel := range Config.Channels {
c.Join(channel)
}
})
conn.AddHandler(irc.PRIVMSG, expandGithubIssue)
bot := irc.NewBot(conn)
bot.AddCommand("echo", func(c *irc.Connection, e *irc.Event) {
message := strings.Join(e.Params, " ")
e.React(c, message)
})
bot.AddCommand("portal", portalCommandHandler)
bot.AddCommand("compliment", complimentCommandHandler)
for {
<-time.After(1 * time.Second)
}
}