-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (63 loc) · 1.5 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
package main
import (
"fmt"
"go-seu-astral-bot/commands"
"go-seu-astral-bot/sounds"
"go-seu-astral-bot/translate"
"log"
"os"
"os/signal"
"strings"
"syscall"
"github.com/bwmarrin/discordgo"
)
var (
buffer = make([][]byte, 0)
configs Configs
loopCount = 0
_translate translate.Translate
)
const (
CMDStart = "!sa start"
CMDStop = "!sa stop"
CMDCount = "!sa count"
)
func main() {
configs = LoadConfigs()
_translate = translate.Load(configs["APP_LANGUAGE"])
sess, err := discordgo.New("Bot " + configs["DISCORD_BOT_TOKEN"])
if err != nil {
fmt.Println("Error creating Discord Session: ", err)
return
}
err = sounds.Load(&buffer, configs)
if err != nil {
fmt.Println("Error loading sound: ", err)
return
}
sess.AddHandler(handleCommands)
sess.Identify.Intents = discordgo.IntentsAllWithoutPrivileged
err = sess.Open()
if err != nil {
log.Fatal(err)
}
defer sess.Close()
fmt.Println(_translate["START_MESSAGE"])
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}
func handleCommands(session *discordgo.Session, message *discordgo.MessageCreate) {
if message.Author.ID == session.State.SessionID {
return
}
if strings.HasPrefix(message.Content, CMDStart) {
commands.Start(session, message, buffer, &loopCount)
}
if strings.HasPrefix(message.Content, CMDCount) {
commands.Count(session, message, &loopCount)
}
if strings.HasPrefix(message.Content, CMDStop) {
commands.Stop(session, message, configs)
}
}