aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: bbe995e93d4e1112fccc124175d9f69d84d56d2d (plain)
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
package main

import (
	"flag"
	"github.com/anhgelus/gokord"
	"github.com/anhgelus/les-copaings-bot/commands"
	"github.com/anhgelus/les-copaings-bot/xp"
	"github.com/bwmarrin/discordgo"
)

var token string

func init() {
	flag.StringVar(&token, "token", "", "token of the bot")
	flag.Parse()
}

func main() {
	err := gokord.SetupConfigs([]*gokord.ConfigInfo{})
	if err != nil {
		panic(err)
	}

	err = gokord.DB.AutoMigrate(&xp.Copaing{})
	if err != nil {
		panic(err)
	}

	rankCmd := gokord.NewCommand("rank", "Affiche le niveau d'une personne").
		HasOption().
		AddOption(gokord.NewOption(
			discordgo.ApplicationCommandOptionUser,
			"copaing",
			"Le niveau du Copaing que vous souhaitez obtenir",
		)).
		SetHandler(commands.Rank).
		ToCmd()

	bot := gokord.Bot{
		Token: token,
		Status: []*gokord.Status{
			{
				Type:    gokord.GameStatus,
				Content: "Les Copaings Bot 2.0",
				Url:     "",
			},
		},
		Commands: []*gokord.Cmd{
			rankCmd,
		},
		AfterInit: afterInit,
	}
	bot.Start()
}

func afterInit(dg *discordgo.Session) {
	dg.AddHandler(xp.OnMessage)
	dg.AddHandler(xp.OnVoiceUpdate)
}