-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (63 loc) · 1.33 KB
/
Copy pathmain.go
File metadata and controls
76 lines (63 loc) · 1.33 KB
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
package main
import (
"gobot/commands/airhorn"
"gobot/commands/ping"
"gobot/listeners/interactionCreate"
"gobot/listeners/ready"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/FedorLap2006/disgolf"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal(err)
}
token, exists := os.LookupEnv("DISCORD_TOKEN")
if !exists {
log.Fatal("missing DISCORD_TOKEN env")
}
applicationId, exists := os.LookupEnv("APPLICATION_ID")
if !exists {
log.Fatal("missing APPLICATION_ID env")
}
err = airhorn.LoadSound()
if err != nil {
log.Fatal(err)
}
bot, err := disgolf.New(token)
if err != nil {
log.Fatal(err)
}
bot.Identify.Intents = discordgo.IntentsGuilds | discordgo.IntentsGuildVoiceStates
bot.Router.Register(ping.Data)
bot.Router.Register(airhorn.Data)
bot.AddHandler(bot.Router.HandleInteraction)
bot.AddHandler(interactionCreate.Handler)
bot.AddHandler(ready.Handler)
err = bot.Router.Sync(bot.Session, applicationId, "")
if err != nil {
log.Fatal(err)
}
err = bot.Open()
if err != nil {
log.Fatal(err)
}
defer bot.Close()
stchan := make(chan os.Signal, 1)
signal.Notify(stchan, syscall.SIGTERM, os.Interrupt, syscall.SIGSEGV)
end:
for {
select {
case <-stchan:
break end
default:
}
time.Sleep(time.Second)
}
}