-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (74 loc) · 2.05 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
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/Im-Beast/Gophelper/commands"
gophelper "github.com/Im-Beast/Gophelper/internal"
middleware "github.com/Im-Beast/Gophelper/middleware"
"github.com/bwmarrin/discordgo"
)
var (
router = gophelper.Router{
Prefixes: []string{"go"},
CaseSensitive: false,
Config: gophelper.LoadConfig("configs/bot.json", "configs/languages/english.json"),
}
)
func main() {
discord, err := discordgo.New("Bot " + os.Getenv("BOT_TOKEN"))
if err != nil {
fmt.Println("Some error happened while launching bot:", err)
return
}
discord.StateEnabled = true
err = discord.Open()
if err != nil {
fmt.Println("Failed opening connection", err)
return
}
fmt.Printf("Bot %s is up and running\n", discord.State.User.Username)
registerCategories()
registerMiddleware()
registerCommands()
router.Init(discord)
defer func() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, syscall.SIGTERM)
<-sc
fmt.Println("\rDisabling bot")
discord.Close()
}()
}
func registerCategories() {
router.Categories = []*gophelper.Category{
gophelper.CATEGORY_FUN,
gophelper.CATEGORY_MISC,
gophelper.CATEGORY_MOD,
gophelper.CATEGORY_GAMES,
gophelper.CATEGORY_CONFIG,
}
router.RefreshCategories()
}
func registerMiddleware() {
router.AddRouterMiddleware("RefreshCommand", middleware.HelpInitMiddlware)
router.AddMiddleware(middleware.RateLimiterMiddleware)
router.AddMiddleware(middleware.PermissionCheckMiddleware)
}
func registerCommands() {
router.AddCommand(commands.Pet)
router.AddCommand(commands.Hug)
router.AddCommand(commands.Ping)
router.AddCommand(commands.Kiss)
router.AddCommand(commands.Help)
router.AddCommand(commands.Kitty)
router.AddCommand(commands.Stats)
router.AddCommand(commands.Waifu)
router.AddCommand(commands.Hentai)
router.AddCommand(commands.Doggie)
router.AddCommand(commands.PingPong)
router.AddCommand(commands.Pinterest)
router.AddCommand(commands.EightBall)
router.AddCommand(commands.LanguageSwitcher)
}