-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (66 loc) · 1.97 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
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
88
89
90
package main
import (
"flag"
"fmt"
"github.com/zaibon/ircbot"
"github.com/zaibon/ircbot/actions"
)
// needed for the flag "channel"
type channels []string
func (c *channels) String() string {
return fmt.Sprintf("%s", *c)
}
func (c *channels) Set(value string) error {
*c = append(*c, value)
return nil
}
var (
flagServer string
flagPort uint
flagSsl bool
flagChannels channels
flagNick string
flagPassword string
flagWebEnable bool
flagWebPort string
flagDBPath string
)
func init() {
flag.StringVar(&flagServer, "server", "irc.freenode.net", "ip adresse of the server you want to connect to")
flag.StringVar(&flagServer, "s", "irc.freenode.net", "ip adresse of the server you want to connect to")
flag.UintVar(&flagPort, "port", 6667, "port")
flag.UintVar(&flagPort, "p", 6667, "port")
flag.BoolVar(&flagSsl, "ssl", false, "true|false")
flag.StringVar(&flagNick, "nick", "ZbiBot", "nickname")
flag.StringVar(&flagNick, "n", "ZbiBot", "nickname")
flag.StringVar(&flagPassword, "password", "", "password")
flag.BoolVar(&flagWebEnable, "web", false, "enable or not the web interface true|false")
flag.StringVar(&flagWebPort, "wport", "3000", "port on wich to bind web interface")
flag.StringVar(&flagDBPath, "db", "irc.db", "path to the sqlite3 database")
}
func main() {
flag.Var(&flagChannels, "c", "channels")
flag.Parse()
if flagSsl {
flagPort = 6697
}
ch := channels{}
if flag.NFlag() != 0 {
for i := 0; i < len(flagChannels); i++ {
ch = append(ch, flagChannels[i])
}
}
//create new bot
b := ircbot.NewIrcBot(flagNick, flagNick, flagPassword, flagServer, flagPort, ch, flagDBPath)
b.AddInternAction(&actions.Greet{})
b.AddInternAction(&actions.TitleExtract{})
b.AddInternAction(actions.NewLogger(b))
//command fire by users
b.AddUserAction(&actions.Help{})
//connectin to server, listen and serve
b.Connect()
// //TODO handle signal system to throw something in b.Exit
<-b.Exit
//and then disconenct
b.Disconnect()
}