-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
70 lines (57 loc) · 1.56 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
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
"log"
"lumos-discord-bot/cmd"
del "lumos-discord-bot/cmd/delete"
"lumos-discord-bot/cmd/nox"
"lumos-discord-bot/handler"
"os"
"os/signal"
)
const (
EnvDiscordToken = "DISCORD_TOKEN"
EnvTargetServer = "TARGET_SERVER"
EnvWelcomeChannel = "WELCOME_CHANNEL"
EnvMemberRoleID = "MEMBER_ROLE_ID"
EnvTestUserID = "TEST_USER_ID"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Printf(".env file not found")
}
discordToken := os.Getenv(EnvDiscordToken)
welcomeChannel := os.Getenv(EnvWelcomeChannel)
targetServer := os.Getenv(EnvTargetServer)
memberRoleID := os.Getenv(EnvMemberRoleID)
testUserID := os.Getenv(EnvTestUserID)
bot, err := discordgo.New(fmt.Sprintf("Bot %s", discordToken))
if err != nil {
panic(err)
}
bot.Identify.Intents = discordgo.IntentsAll
bot.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
log.Printf("Logged in as: %v#%v", s.State.User.Username, s.State.User.Discriminator)
})
if err = bot.Open(); err != nil {
panic(err)
}
// setup commands...
cmds := cmd.NewExec()
noxCmd := nox.NewNoxCmd()
cmds.Add(noxCmd)
deleteCmd := del.NewDeleteCmd()
cmds.Add(deleteCmd)
cmdHandler := cmds.Activate(bot)
defer cmdHandler.Deactivate()
// setup commands end
welcome := handler.NewWelcomeHandler(targetServer, welcomeChannel, memberRoleID, testUserID)
bot.AddHandler(welcome.Handle)
defer bot.Close()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
log.Println("Press Ctrl+C to exit")
<-stop
}