-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (71 loc) · 1.72 KB
/
main.go
File metadata and controls
87 lines (71 loc) · 1.72 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"log"
"os"
"os/signal"
"github.com/caiofilipini/got/bot"
"github.com/caiofilipini/got/command"
"github.com/caiofilipini/got/irc"
)
var (
server *string
port *int
channel *string
user *string
passwd *string
logFilePath *string
)
func init() {
server = flag.String("s", "irc.freenode.org", "IRC server host")
port = flag.Int("p", 6667, "IRC server port")
user = flag.String("u", "gotgotgot", "bot username")
channel = flag.String("c", "", "channel to connect")
passwd = flag.String("k", "", "channel secret key")
logFilePath = flag.String("l", "", "log file location; if empty, stdout will be used")
flag.Parse()
if *channel == "" {
log.Println("No channel specified, aborting!")
flag.PrintDefaults()
os.Exit(1)
}
}
func setupLogging() *os.File {
if *logFilePath != "" {
file, err := os.OpenFile(*logFilePath, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
log.Fatal(err)
}
log.SetOutput(file)
return file
}
return nil
}
func main() {
logFile := setupLogging()
if logFile != nil {
defer logFile.Close()
}
conn := irc.NewIRC(*server, *port, *channel)
defer conn.Close()
bot := bot.NewBot(conn, *user, *passwd)
defer bot.Shutdown()
// Register commands
bot.Register(command.Swear())
bot.Register(command.Greet())
bot.Register(command.Image())
bot.Register(command.GIF())
bot.Register(command.Video())
bot.Register(command.XKCD())
bot.Register(command.BeerOClock())
bot.Register(command.Weather())
bot.Register(command.Luca()) // tribute to lucapette
bot.Start()
go bot.Listen()
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
for _ = range signals {
log.Println("KTHXBAI.")
os.Exit(0)
}
}