-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord_bot.go
47 lines (38 loc) · 982 Bytes
/
discord_bot.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
package main
import (
"fmt"
"github.com/QOLPlus/discord-bot/refs"
"github.com/bwmarrin/discordgo"
"os"
"os/signal"
"syscall"
"github.com/QOLPlus/discord-bot/handlers"
)
const gameTitle = "Quality of Life"
func main() {
authToken := os.Getenv("DISCORD_AUTHENTICATION_TOKEN")
bot, err := discordgo.New("Bot " + authToken)
if err != nil {
fmt.Println("error creating Discord session,", err)
return
}
store := refs.Store{
Asset: &refs.AssetStore{},
Ticker: &refs.TickerStore{},
}
// Add handler
bot.AddHandler(handlers.HandlerFactory(&store))
bot.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
_ = s.UpdateStatus(0, gameTitle)
})
err = bot.Open()
if err != nil {
fmt.Println("error opening connection,", err)
return
}
fmt.Println("Bot is running. To exit bot, press Ctrl-C.")
closeChan := make(chan os.Signal, 1)
signal.Notify(closeChan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<- closeChan
_ = bot.Close()
}