-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (54 loc) · 1.28 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
package main
import (
"errors"
"flag"
"log"
"os"
"twtbot/discord"
"twtbot/handlers/getuserpoints"
"twtbot/handlers/givepoints"
"twtbot/handlers/incrementkarma"
"twtbot/handlers/rearrangerhandler"
"twtbot/interfaces"
"twtbot/services/points"
)
var AuthToken string
func init() {
AuthToken = os.Getenv("DISCORD_AUTH_TOKEN")
if AuthToken == "" {
flag.StringVar(&AuthToken, "t", "", "Bot Token")
flag.Parse()
}
if AuthToken == "" {
log.Fatal(errors.New("no discord auth token supplied"))
}
}
func main() {
client, clientError := discord.NewDiscordClient(AuthToken)
if clientError != nil {
log.Fatal(clientError)
}
// Run Services
pointsManager := &points.Service{}
client.AttachService(pointsManager)
// Handlers
client.AttachHandler(func() interfaces.MessageHandlerInterface {
return &givepoints.Handler{
PointsManager: pointsManager,
}
})
client.AttachHandler(func() interfaces.MessageHandlerInterface {
return &getuserpoints.Handler{
PointsManager: pointsManager,
}
})
client.AttachHandler(func() interfaces.MessageHandlerInterface {
return &rearrangerhandler.Handler{}
})
client.AttachHandler(func() interfaces.MessageHandlerInterface {
return &incrementkarma.Handler{}
})
if runError := client.Run(); runError != nil {
log.Fatal(runError)
}
}