-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
executable file
·90 lines (73 loc) · 2.26 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 (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
"github.com/digitalungdom-se/dub/commands/admin"
"github.com/digitalungdom-se/dub/commands/digitalungdom"
"github.com/digitalungdom-se/dub/commands/misc"
"github.com/digitalungdom-se/dub/commands/music"
"github.com/digitalungdom-se/dub/events"
"github.com/digitalungdom-se/dub/internal"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
botToken := os.Getenv("BOT_TOKEN")
discord, err := discordgo.New("Bot " + botToken)
if err != nil {
log.Fatal("Error creating Discord session,", err)
}
config := internal.LoadConfig()
server := internal.NewServer(config, discord)
if err != nil {
log.Fatal("Error creating server,", err)
}
registerCommands(&server.CommandHandler)
discord.AddHandler(events.GuildMemberAddHandler(server))
discord.AddHandler(events.MessageHandler(server))
discord.AddHandler(events.AddReactionHandler(server))
discord.AddHandler(events.RemoveReactionHandler(server))
discord.AddHandlerOnce(events.StartHandler(server))
err = discord.Open()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v | STARTED ANNA IN DISCORD\n", time.Now().Format("2006-01-02 15:04:05"))
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM)
<-sc
err = discord.Close()
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}
func registerCommands(commandHandler *internal.CommandHandler) {
commandHandler.Register(admin.DubStatus)
commandHandler.Register(admin.Join)
commandHandler.Register(admin.SendGuild)
commandHandler.Register(admin.SendDM)
commandHandler.Register(digitalungdom.Bug)
commandHandler.Register(digitalungdom.Idea)
commandHandler.Register(digitalungdom.Report)
commandHandler.Register(digitalungdom.Status)
commandHandler.Register(digitalungdom.Verify)
commandHandler.Register(digitalungdom.Whois)
commandHandler.Register(misc.Ping)
commandHandler.Register(misc.Slap)
commandHandler.Register(misc.Help)
commandHandler.Register(misc.Info)
commandHandler.Register(music.Play)
commandHandler.Register(music.Skip)
commandHandler.Register(music.Stop)
commandHandler.Register(music.PauseResume)
commandHandler.Register(music.Controller)
}