-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_guild.go
243 lines (200 loc) · 5.56 KB
/
command_guild.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package diswordle
import (
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog/log"
)
var guildWordleApplicationCommands = []*discordgo.ApplicationCommand{
{
Name: "guild",
Description: "Play a guild wordle",
Type: discordgo.ChatApplicationCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Name: "start",
Description: "Start a new guild wordle",
Type: discordgo.ApplicationCommandOptionSubCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Name: "word_length",
Description: "The length of the word to be used",
Type: discordgo.ApplicationCommandOptionInteger,
},
},
},
{
Name: "guess",
Description: "Guess a word in the guild wordle",
Type: discordgo.ApplicationCommandOptionSubCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Name: "word",
Description: "The word to guess",
Type: discordgo.ApplicationCommandOptionString,
Required: true,
},
},
},
{
Name: "show",
Description: "Show the guild wordle again",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
{
Name: "cancel",
Description: "Vote to cancel the current guild wordle",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
{
Name: "votes",
Description: "Show the cancel votes for the current guild wordle",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
{
Name: "letters",
Description: "Show the letters used in the current guild wordle",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
},
},
}
func (wb *WordleBot) handleGuildWordle(s *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.Type {
case discordgo.InteractionApplicationCommand:
d := i.ApplicationCommandData()
if d.Name == "guild" {
switch d.Options[0].Name {
case "start":
wb.handleGuildWordleStart(s, i)
case "guess":
wb.handleGuildWordleGuess(s, i)
case "cancel":
wb.handleGuildWordleCancel(s, i)
case "show":
wb.handleGuildWordleShow(s, i)
case "votes":
wb.handleGuildWordleVotes(s, i)
case "letters":
wb.handleGuildWordleLetters(s, i)
}
}
case discordgo.InteractionMessageComponent:
d := i.MessageComponentData()
switch d.CustomID {
}
}
}
func (wb *WordleBot) handleGuildWordleStart(s *discordgo.Session, i *discordgo.InteractionCreate) {
_, ok := wb.guildWordleGame(i)
if ok {
warningRespond(s, i, "A guild wordle is already in progress. Use `/guild cancel` to vote to cancel it.")
return
}
wordLength := 7
if len(i.ApplicationCommandData().Options[0].Options) > 0 {
wordLength = int(i.ApplicationCommandData().Options[0].Options[0].IntValue())
}
wg, err := wb.newGuildWordleGame(i, wordLength)
if err != nil {
log.Error().
Err(err).
Msg("Failed to create guild wordle game")
errorRespond(s, i, err)
return
}
err = wg.responseCreate()
if err != nil {
log.Error().
Err(err).
Msg("Failed to create response")
errorRespond(s, i, err)
return
}
}
func (wb *WordleBot) handleGuildWordleGuess(s *discordgo.Session, i *discordgo.InteractionCreate) {
wg, ok := wb.guildWordleGame(i)
if !ok {
warningRespond(s, i, "No guild wordle in progress. Use `/guild start` to start a new game.")
return
}
guess := i.ApplicationCommandData().Options[0].Options[0].StringValue()
_, err := wg.Guess(guess)
if err != nil {
errorRespond(s, i, err)
return
}
err = wg.responseUpdate()
if err != nil {
log.Error().
Err(err).
Msg("Failed to edit interaction")
errorRespond(s, i, err)
return
}
wg.addPlayer(i.Member.User.ID)
successRespond(s, i, "Guess accepted")
if wg.Done() {
delete(wb.guildWordles, wg.interaction.GuildID)
}
}
func (wb *WordleBot) handleGuildWordleCancel(s *discordgo.Session, i *discordgo.InteractionCreate) {
wg, ok := wb.guildWordleGame(i)
if !ok {
warningRespond(s, i, "No guild wordle in progress. Use `/guild start` to start a new game.")
return
}
err := wg.voteCancel(i.Member.User.ID)
if err != nil {
errorRespond(s, i, err)
return
}
respond(s, i, ephemeralify(embedResponse(wg.voteEmbed())))
if wg.Done() {
err = wg.responseUpdate()
if err != nil {
log.Error().
Err(err).
Msg("Failed to update response")
errorRespond(s, i, err)
}
delete(wb.guildWordles, wg.interaction.GuildID)
}
}
func (wb *WordleBot) handleGuildWordleShow(s *discordgo.Session, i *discordgo.InteractionCreate) {
wg, ok := wb.guildWordleGame(i)
if !ok {
warningRespond(s, i, "No wordle in progress. Use `/guild start` to start a new game.")
return
}
err := wg.responseDelete()
if err != nil {
log.Error().
Err(err).
Msg("Failed to delete response")
errorRespond(s, i, err)
}
wg.setInteraction(i)
err = wg.responseCreate()
if err != nil {
log.Error().
Err(err).
Msg("Failed to create response")
errorRespond(s, i, err)
return
}
}
func (wb *WordleBot) handleGuildWordleVotes(s *discordgo.Session, i *discordgo.InteractionCreate) {
wg, ok := wb.guildWordleGame(i)
if !ok {
warningRespond(s, i, "No guild wordle in progress. Use `/guild start` to start a new game.")
return
}
respond(s, i, ephemeralify(embedResponse(wg.voteEmbed())))
}
func (wb *WordleBot) handleGuildWordleLetters(s *discordgo.Session, i *discordgo.InteractionCreate) {
wg, ok := wb.guildWordleGame(i)
if !ok {
warningRespond(s, i, "No wordle in progress. Use `/start` to start a new game.")
return
}
respond(s, i, ephemeralify(embedResponse(wg.lettersEmbed())))
}