-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
159 lines (151 loc) · 3.48 KB
/
commands.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// Commands list / helpers module
//
package main
import (
"log"
"github.com/bwmarrin/discordgo"
)
// Establish available commands
var (
commands = []*discordgo.ApplicationCommand{
// Misc
{
Name: "cara",
Description: "About Cara",
},
{
Name: "guild",
Description: "About current guild",
},
{
Name: "help",
Description: "Command help",
},
{
Name: "sticks",
Description: "Pick random members",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionInteger,
Name: "count",
Description: "Amount of members to pick at once",
Required: false,
},
},
},
{
Name: "avatar",
Description: "Get a member's avatar",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "member",
Description: "Member to steal from",
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionInteger,
Name: "size",
Description: "Size in px",
Required: false,
},
},
},
// Admin
{
Name: "restore",
Description: "Restore user role (Admin)",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionRole,
Name: "package",
Description: "Package to restore",
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "target",
Description: "Select restore target",
Required: false,
},
},
},
{
Name: "kick",
Description: "Kick user (Admin)",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionRole,
Name: "user",
Description: "User to kick",
Required: true,
},
},
},
{
Name: "status",
Description: "Change bot status",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "status",
Description: "Write a status",
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionInteger,
Name: "type",
Description: "type",
Required: true,
},
},
},
// Tweet
{
Name: "tweet",
Description: "Generate a fake tweet",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "content",
Description: "Tweet content",
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "user",
Description: "Select tweet author",
Required: false,
},
},
},
}
)
func registerCmd(s *discordgo.Session) {
// Register commands
for _, v := range commands {
log.Println("[Info] Registering:", v.Name)
_, err := s.ApplicationCommandCreate(s.State.User.ID, config.ID.Guild, v)
if err != nil {
log.Println("[Error] Cannot create '%v' command: %v", v.Name, err)
}
}
}
func unregisterCmd(s *discordgo.Session) {
// Get command list
pubCommands, err := s.ApplicationCommands(s.State.User.ID, config.ID.Guild)
if err != nil {
log.Println("[Error] Cannot get application commands: %v", err)
return
}
// Unregister commands by ID
for _, v := range pubCommands {
log.Println("[Info] Unregistering:", v.Name)
err := s.ApplicationCommandDelete(s.State.User.ID, config.ID.Guild, v.ID)
if err != nil {
log.Println("[Error] Cannot delete '%v' command: %v", v.Name, err)
}
}
log.Println("[Info] Commands unregistered")
}