-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (36 loc) · 1.1 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
package main
import (
"flag"
"log"
"os"
"os/signal"
"github.com/discordcalorietracker/command"
"github.com/discordcalorietracker/component"
"github.com/discordcalorietracker/database"
"github.com/discordcalorietracker/discord"
)
// Bot parameters
var (
GuildID = flag.String("guild", "", "Test guild ID. If not passed - bot registers commands globally")
BotToken = flag.String("token", "", "Bot access token")
RemoveCommands = flag.Bool("rmcmd", true, "Remove all commands after shutting down or not")
)
func main() {
flag.Parse()
database.InitDatabase()
discord.InitDiscordSession(*BotToken)
discord.OpenDiscordSession()
discord.InitDiscordCommands(command.CommandDefinitions, command.CommandHandlers)
discord.InitDiscordComponentHandlers(component.ComponentHandlers)
discord.AddCommandsDiscord(*GuildID)
defer database.DB.Close()
defer discord.S.Close()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
log.Println("Press Ctrl+C to exit")
<-stop
if *RemoveCommands {
discord.RemoveCommandsDiscord(*GuildID)
}
log.Println("Gracefully shutting down.")
}