-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (60 loc) · 1.39 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
package main
import (
"log"
"os"
"time"
"github.com/bwmarrin/discordgo"
)
func main() {
file, err := os.Open("config.json")
if err != nil {
log.Fatalln("Error opening config file: ", err)
}
// Parse the config file
config, err := ParseConfig(file)
if err != nil {
log.Fatalln("Error parsing config file: ", err)
}
file.Close()
// Create a new Discord session using the provided bot token.
session, err := discordgo.New("Bot " + config.DiscordToken)
if err != nil {
log.Fatalln("Error creating Discord session: ", err)
}
// Create a new bot
bot := NewBot(session, config.SessionCookie)
// Start the bot
err = bot.Start()
if err != nil {
log.Fatalln("Error starting bot: ", err)
}
// Add guilds
for guildID, guildConfig := range config.Guilds {
err = bot.AddGuild(guildID, guildConfig)
if err != nil {
log.Fatalln("Error adding guild: ", err)
}
}
// Register commands
err = bot.RegisterCommands()
if err != nil {
log.Fatalln("Error registering commands: ", err)
}
// Register handlers
bot.AddHandlers()
// Add roles
for _, guild := range bot.session.State.Guilds {
err = bot.CreateRoles(guild)
if err != nil {
log.Fatalln("Error creating roles: ", err)
}
}
log.Println("Press CTRL-C to exit.")
// Every 15 minutes, sync the bot with the Advent of Code API
bot.Sync()
ticker := time.NewTicker(15 * time.Minute)
for {
<-ticker.C
bot.Sync()
}
}