-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
113 lines (103 loc) · 3.42 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"context"
"os"
"os/signal"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/json"
"github.com/disgoorg/log"
"github.com/mandriota/gatewarden-bot/pkg/config"
"github.com/mandriota/gatewarden-bot/pkg/listener"
)
func newCommandCreate(cfg *config.Config) []discord.ApplicationCommandCreate {
return []discord.ApplicationCommandCreate{
discord.SlashCommandCreate{
Name: cfg.Commands.Config.Name,
Description: cfg.Commands.Config.Description,
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionString{
Name: "driver",
Description: "set captcha driver",
Choices: []discord.ApplicationCommandOptionChoiceString{
{
Name: "Default",
},
{
Name: "Mathematical",
Value: "mathematical",
},
{
Name: "Alphanumerical",
Value: "alphanumerical",
},
{
Name: "Simplified Alphanumerical",
Value: "simplified",
},
{
Name: "Alphabetical",
Value: "alphabetical",
},
{
Name: "Numerical",
Value: "numerical",
},
},
},
discord.ApplicationCommandOptionRole{
Name: cfg.Commands.Config.Options.Bypass.Name,
Description: cfg.Commands.Config.Options.Bypass.Description,
DescriptionLocalizations: cfg.Commands.Config.Options.Bypass.DescriptionLocalizations,
},
discord.ApplicationCommandOptionBool{
Name: cfg.Commands.Config.Options.Ephemeral.Name,
Description: cfg.Commands.Config.Options.Ephemeral.Description,
DescriptionLocalizations: cfg.Commands.Config.Options.Ephemeral.DescriptionLocalizations,
},
},
DescriptionLocalizations: cfg.Commands.Config.DescriptionLocalizations,
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionAdministrator),
},
discord.SlashCommandCreate{
Name: cfg.Commands.Captcha.Name,
Description: cfg.Commands.Captcha.Description,
DescriptionLocalizations: cfg.Commands.Captcha.DescriptionLocalizations,
},
discord.SlashCommandCreate{
Name: cfg.Commands.Submit.Name,
Description: cfg.Commands.Submit.Description,
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionString{
Name: cfg.Commands.Submit.Options.Answer.Name,
Description: cfg.Commands.Submit.Options.Answer.Description,
Required: true,
DescriptionLocalizations: cfg.Commands.Submit.Options.Answer.DescriptionLocalizations,
},
},
DescriptionLocalizations: cfg.Commands.Submit.DescriptionLocalizations,
},
}
}
func main() {
log.SetLevel(log.LevelDebug)
ctx := context.Background()
cfg := config.FromStdin(&config.Config{})
client, err := disgo.New(cfg.Token,
bot.WithDefaultGateway(),
bot.WithEventListenerFunc(listener.New(ctx, cfg)),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
}
defer client.Close(ctx)
if _, err := client.Rest().SetGlobalCommands(client.ApplicationID(), newCommandCreate(cfg)); err != nil {
log.Fatal("error while registering commands: ", err)
}
if err := client.OpenGateway(ctx); err != nil {
log.Fatal("error while connecting to gateway: ", err)
}
ctx, _ = signal.NotifyContext(ctx, os.Interrupt)
<-ctx.Done()
}