qwtf_discord_bot 5.4.5 → 5.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/VERSION +1 -1
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +381 -123
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5bfd247ff3e811ab845a1cef86f043b93f54a6f30769885547d0ba1601c15ef
|
4
|
+
data.tar.gz: 72aebecdfaa233cd62e4d36b25c474a319dae5a1fa12d8ea8711536f23cf9549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c358f811c6c0d17b31fb26e1a8d6234bf170f82bd5a820da5d8474052a42594f1adeafcd6fa387488147559370533a10d73bf50526bdfedb5b948325f78f7d
|
7
|
+
data.tar.gz: e2eb01bcd75ff2ab9251452c6cfac97b381d1199d5fddc5a146ee451def5e56747b4528e2977fd15e2d3d732a63cac03a1dcaa38a37cecaa6a75758075bdf770
|
data/README.md
CHANGED
@@ -90,14 +90,14 @@ This responds to discord messages:
|
|
90
90
|
- `!join`
|
91
91
|
- `!leave`
|
92
92
|
- `!teamsize <no_of_players>`
|
93
|
-
- `!kick <@player
|
93
|
+
- `!kick <@player> [@player2]`
|
94
94
|
- `!team <team_no>`
|
95
95
|
- `!unteam`
|
96
96
|
- `!addmap <map_name>`
|
97
97
|
- `!removemap <map_name>`
|
98
98
|
- `!maps`
|
99
|
-
- `!map
|
100
|
-
- `!choose`
|
99
|
+
- `!map [map_name]`
|
100
|
+
- `!choose [n]`
|
101
101
|
- `!win <team_no>`
|
102
102
|
- `!draw`
|
103
103
|
- `!notify <@role>`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.4.
|
1
|
+
5.4.10
|
@@ -7,7 +7,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
7
7
|
include QwtfDiscordBot
|
8
8
|
|
9
9
|
MSG_SNIPPET_DELIMITER = ' · '
|
10
|
-
TEAM_NAMES = {
|
10
|
+
TEAM_NAMES = { 1 => "Blue", 2 => "Red" }
|
11
11
|
|
12
12
|
def run
|
13
13
|
bot = Discordrb::Commands::CommandBot.new(
|
@@ -26,12 +26,17 @@ class QwtfDiscordBotPug # :nodoc:
|
|
26
26
|
)
|
27
27
|
|
28
28
|
bot.command :help do |event, *args|
|
29
|
-
"Pug commands: `!status`, `!join`, `!team <team_no
|
29
|
+
"Pug commands: `!status`, `!join`, `!team <team_no> [@player1] [@player2]`, `!unteam`, `!leave`, `!kick <@player>`, `!win <team_no>`, `!draw`, `!end`, `!teamsize <no_of_players>`, `!addmap <map_name>`, `!removemap <map_name>`, `!maps`, `!map [map_name]`, `!choose [n]`, `!notify <@role>`"
|
30
30
|
end
|
31
31
|
|
32
32
|
bot.command :join do |event, *args|
|
33
33
|
setup_pug(event) do |e, pug|
|
34
|
-
|
34
|
+
if pug.joined?(e.user_id)
|
35
|
+
return send_embedded_message(
|
36
|
+
description: "You've already joined",
|
37
|
+
channel: e.channel
|
38
|
+
)
|
39
|
+
end
|
35
40
|
|
36
41
|
join_pug(e, pug)
|
37
42
|
start_pug(pug, e) if pug.full?
|
@@ -40,84 +45,95 @@ class QwtfDiscordBotPug # :nodoc:
|
|
40
45
|
|
41
46
|
bot.command :choose do |event, *args|
|
42
47
|
setup_pug(event) do |e, pug|
|
43
|
-
|
48
|
+
if pug.joined_players.count.odd?
|
49
|
+
return send_embedded_message(
|
50
|
+
description: "Can't choose teams with odd number of players",
|
51
|
+
channel: event.channel
|
52
|
+
)
|
53
|
+
end
|
44
54
|
|
45
|
-
|
46
|
-
|
55
|
+
if args.any? && args.first.to_i < 1
|
56
|
+
return send_embedded_message(
|
57
|
+
description: "Choose a number higher than 0; e.g. `!choose 2`",
|
58
|
+
channel: e.channel
|
59
|
+
)
|
47
60
|
end
|
48
61
|
|
49
|
-
|
62
|
+
iteration = if args.any?
|
63
|
+
args.first.to_i - 1
|
64
|
+
else
|
65
|
+
0
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
message_obj = choose_fair_teams(pug: pug, event: e, iteration: iteration)
|
70
|
+
status(pug: pug, event: e, message_obj: message_obj) if message_obj
|
50
71
|
end
|
51
72
|
end
|
52
73
|
|
53
74
|
bot.command :status do |event, *args|
|
54
75
|
setup_pug(event) do |e, pug|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
"#{pug.player_slots} joined",
|
60
|
-
].compact.join(MSG_SNIPPET_DELIMITER)
|
61
|
-
|
62
|
-
send_embedded_message(nil, e.channel) do |embed|
|
63
|
-
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
|
64
|
-
text: footer
|
76
|
+
if !pug.active?
|
77
|
+
return send_embedded_message(
|
78
|
+
description: "No PUG has been started. `!join` to create",
|
79
|
+
channel: e.channel
|
65
80
|
)
|
66
|
-
|
67
|
-
pug.teams.each do |team_no, player_ids|
|
68
|
-
team_display_names = player_ids.map do |player_id|
|
69
|
-
e.display_name_for(player_id)
|
70
|
-
end
|
71
|
-
|
72
|
-
embed.add_field(
|
73
|
-
Discordrb::Webhooks::EmbedField.new(
|
74
|
-
{
|
75
|
-
inline: true,
|
76
|
-
name: team_name(team_no),
|
77
|
-
value: team_display_names.join("\n")
|
78
|
-
}
|
79
|
-
)
|
80
|
-
)
|
81
|
-
end
|
82
81
|
end
|
82
|
+
|
83
|
+
status(pug: pug, event: e)
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
86
87
|
bot.command :teamsize do |event, *args|
|
87
88
|
setup_pug(event) do |e, pug|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
if new_teamsize
|
94
|
-
pug.teamsize = new_teamsize
|
95
|
-
|
96
|
-
send_embedded_message(
|
97
|
-
[
|
98
|
-
"Team size set to #{pug.teamsize}",
|
89
|
+
unless args.any?
|
90
|
+
return send_embedded_message(
|
91
|
+
description: [
|
92
|
+
"Each team has #{pug.teamsize} players",
|
99
93
|
"#{pug.player_slots} joined"
|
100
94
|
].join(MSG_SNIPPET_DELIMITER),
|
101
|
-
e.channel
|
95
|
+
channel: e.channel
|
102
96
|
)
|
97
|
+
end
|
103
98
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
].join(MSG_SNIPPET_DELIMITER),
|
111
|
-
e.channel
|
99
|
+
new_teamsize = args[0].to_i
|
100
|
+
|
101
|
+
if new_teamsize < 1
|
102
|
+
return send_embedded_message(
|
103
|
+
description: "Team size should be 1 or more",
|
104
|
+
channel: e.channel
|
112
105
|
)
|
113
106
|
end
|
107
|
+
|
108
|
+
pug.teamsize = new_teamsize
|
109
|
+
|
110
|
+
send_embedded_message(
|
111
|
+
description: [
|
112
|
+
"Each team has #{pug.teamsize} players",
|
113
|
+
"#{pug.player_slots} joined"
|
114
|
+
].join(MSG_SNIPPET_DELIMITER),
|
115
|
+
channel: e.channel
|
116
|
+
)
|
117
|
+
|
118
|
+
start_pug(pug, e) if pug.full?
|
114
119
|
end
|
115
120
|
end
|
116
121
|
|
117
122
|
bot.command :leave do |event, *args|
|
118
123
|
setup_pug(event) do |e, pug|
|
119
|
-
|
120
|
-
|
124
|
+
unless pug.active?
|
125
|
+
return send_embedded_message(
|
126
|
+
description: no_active_pug_message,
|
127
|
+
channel: e.channel
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
unless pug.joined?(e.user_id)
|
132
|
+
return send_embedded_message(
|
133
|
+
description: "You're not in the PUG",
|
134
|
+
channel: e.channel
|
135
|
+
)
|
136
|
+
end
|
121
137
|
|
122
138
|
pug.leave(e.user_id)
|
123
139
|
|
@@ -126,11 +142,12 @@ class QwtfDiscordBotPug # :nodoc:
|
|
126
142
|
"#{pug.player_slots} remain"
|
127
143
|
]
|
128
144
|
|
129
|
-
|
145
|
+
message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
|
130
146
|
|
131
147
|
send_embedded_message(
|
132
|
-
|
133
|
-
|
148
|
+
message: message,
|
149
|
+
description: snippets.join(MSG_SNIPPET_DELIMITER),
|
150
|
+
channel: e.channel
|
134
151
|
)
|
135
152
|
|
136
153
|
end_pug(pug, e.channel) if pug.empty?
|
@@ -139,12 +156,26 @@ class QwtfDiscordBotPug # :nodoc:
|
|
139
156
|
|
140
157
|
bot.command :kick do |event, *args|
|
141
158
|
setup_pug(event) do |e, pug|
|
142
|
-
|
143
|
-
|
159
|
+
unless args.any?
|
160
|
+
return send_embedded_message(
|
161
|
+
description: "Kick who? e.g. `!kick @#{e.display_name}`",
|
162
|
+
channel: e.channel
|
163
|
+
)
|
164
|
+
end
|
165
|
+
|
166
|
+
unless pug.active?
|
167
|
+
return send_embedded_message(
|
168
|
+
description: no_active_pug_message,
|
169
|
+
channel: e.channel
|
170
|
+
)
|
171
|
+
end
|
144
172
|
|
145
173
|
args.each do |arg|
|
146
174
|
unless arg.match(/<@!\d+>/)
|
147
|
-
send_embedded_message(
|
175
|
+
send_embedded_message(
|
176
|
+
description: "#{arg} isn't a valid mention",
|
177
|
+
channel: e.channel
|
178
|
+
)
|
148
179
|
next
|
149
180
|
end
|
150
181
|
|
@@ -152,7 +183,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
152
183
|
display_name = e.display_name_for(user_id) || arg
|
153
184
|
|
154
185
|
unless pug.joined?(user_id)
|
155
|
-
send_embedded_message(
|
186
|
+
send_embedded_message(
|
187
|
+
description: "#{display_name} isn't in the PUG",
|
188
|
+
channel: e.channel
|
189
|
+
)
|
156
190
|
next
|
157
191
|
end
|
158
192
|
|
@@ -163,11 +197,12 @@ class QwtfDiscordBotPug # :nodoc:
|
|
163
197
|
"#{pug.player_slots} remain"
|
164
198
|
]
|
165
199
|
|
166
|
-
|
200
|
+
message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
|
167
201
|
|
168
202
|
send_embedded_message(
|
169
|
-
|
170
|
-
|
203
|
+
message: message,
|
204
|
+
description: snippets.join(MSG_SNIPPET_DELIMITER),
|
205
|
+
channel: e.channel
|
171
206
|
)
|
172
207
|
|
173
208
|
break end_pug(pug, e.channel) if pug.empty?
|
@@ -177,47 +212,63 @@ class QwtfDiscordBotPug # :nodoc:
|
|
177
212
|
|
178
213
|
bot.command :team do |event, *args|
|
179
214
|
setup_pug(event) do |e, pug|
|
180
|
-
|
181
|
-
|
215
|
+
unless args.any?
|
216
|
+
return send_embedded_message(
|
217
|
+
description: "Which team? E.G. `!team 1`",
|
218
|
+
channel: e.channel
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
unless ["1", "2"].any?(args.first)
|
223
|
+
return send_embedded_message(
|
224
|
+
description: "Choose `!team 1`, `!team 2`, or `!unteam` to leave team",
|
225
|
+
channel: e.channel
|
226
|
+
)
|
227
|
+
end
|
182
228
|
|
183
229
|
team_no = args.first.to_i
|
184
230
|
pug_already_full = pug.full?
|
185
231
|
|
186
232
|
if args.count == 1
|
187
233
|
user_id = e.user_id
|
188
|
-
|
234
|
+
|
235
|
+
if pug.team(team_no).include?(user_id)
|
236
|
+
return send_embedded_message(
|
237
|
+
description: "You're already in #{TEAM_NAMES[team_no]}",
|
238
|
+
channel: e.channel
|
239
|
+
)
|
240
|
+
end
|
189
241
|
|
190
242
|
join_pug(e, pug) unless pug.joined?(user_id)
|
191
243
|
pug.join_team(team_no: team_no, player_id: user_id)
|
192
244
|
|
193
245
|
send_embedded_message(
|
194
|
-
[
|
246
|
+
description: [
|
195
247
|
"#{e.display_name} joins #{TEAM_NAMES[team_no]}",
|
196
248
|
"#{pug.team_player_count(team_no)}/#{pug.teamsize}"
|
197
|
-
].join(MSG_SNIPPET_DELIMITER),
|
249
|
+
].join(MSG_SNIPPET_DELIMITER),
|
250
|
+
channel: e.channel
|
198
251
|
)
|
199
252
|
else
|
200
253
|
args[1..-1].each do |mention|
|
201
254
|
unless mention.match(/<@!\d+>/)
|
202
|
-
send_embedded_message(
|
255
|
+
send_embedded_message(
|
256
|
+
description: "#{arg} isn't a valid mention",
|
257
|
+
channel: e.channel
|
258
|
+
)
|
203
259
|
next
|
204
260
|
end
|
205
261
|
|
206
262
|
user_id = mention_to_user_id(mention)
|
207
263
|
display_name = e.display_name_for(user_id) || arg
|
208
|
-
|
209
|
-
unless pug.joined?(user_id)
|
210
|
-
send_embedded_message("#{display_name} isn't in the PUG", e.channel)
|
211
|
-
next
|
212
|
-
end
|
213
|
-
|
214
264
|
pug.join_team(team_no: team_no, player_id: user_id)
|
215
265
|
|
216
266
|
send_embedded_message(
|
217
|
-
[
|
267
|
+
description: [
|
218
268
|
"#{display_name} joins #{TEAM_NAMES[team_no]}",
|
219
269
|
"#{pug.team_player_count(team_no)}/#{pug.teamsize}"
|
220
|
-
].join(MSG_SNIPPET_DELIMITER),
|
270
|
+
].join(MSG_SNIPPET_DELIMITER),
|
271
|
+
channel: e.channel
|
221
272
|
)
|
222
273
|
end
|
223
274
|
end
|
@@ -229,26 +280,66 @@ class QwtfDiscordBotPug # :nodoc:
|
|
229
280
|
bot.command :unteam do |event, *args|
|
230
281
|
setup_pug(event) do |e, pug|
|
231
282
|
user_id = e.user_id
|
232
|
-
|
233
|
-
|
234
|
-
|
283
|
+
|
284
|
+
unless pug.active?
|
285
|
+
return send_embedded_message(
|
286
|
+
description: 'No PUG has been started. `!join` to create',
|
287
|
+
channel: e.channel
|
288
|
+
)
|
289
|
+
end
|
290
|
+
|
291
|
+
unless pug.joined?(user_id)
|
292
|
+
return send_embedded_message(
|
293
|
+
description: "You aren't in this PUG",
|
294
|
+
channel: e.channel
|
295
|
+
)
|
296
|
+
end
|
297
|
+
|
298
|
+
if pug.team(0).include?(user_id)
|
299
|
+
return send_embedded_message(
|
300
|
+
description: "You aren't in a team",
|
301
|
+
channel: e.channel
|
302
|
+
)
|
303
|
+
end
|
235
304
|
|
236
305
|
pug.join_team(team_no: 0, player_id: user_id)
|
237
|
-
|
306
|
+
|
307
|
+
send_embedded_message(
|
308
|
+
description: "#{e.display_name} leaves team",
|
309
|
+
channel: e.channel
|
310
|
+
)
|
238
311
|
end
|
239
312
|
end
|
240
313
|
|
241
314
|
bot.command :win do |event, *args|
|
242
315
|
setup_pug(event) do |e, pug|
|
243
|
-
|
244
|
-
|
245
|
-
|
316
|
+
unless pug.active?
|
317
|
+
return send_embedded_message(
|
318
|
+
description: no_active_pug_message,
|
319
|
+
channel: e.channel
|
320
|
+
)
|
321
|
+
end
|
322
|
+
|
323
|
+
unless args.any?
|
324
|
+
return send_embedded_message(
|
325
|
+
description: "Specify winning team; e.g. `!win 1`",
|
326
|
+
channel: e.channel
|
327
|
+
)
|
328
|
+
end
|
329
|
+
|
330
|
+
unless ["1", "2"].any?(args.first)
|
331
|
+
return send_embedded_message(
|
332
|
+
description: "Invalid team number",
|
333
|
+
channel: e.channel
|
334
|
+
)
|
335
|
+
end
|
246
336
|
|
247
337
|
winning_team_no = args.first.to_i
|
248
338
|
|
249
339
|
if pug.actual_teams.count < 2
|
250
340
|
return send_embedded_message(
|
251
|
-
"There must be at least two teams with players to submit a result",
|
341
|
+
description: "There must be at least two teams with players to submit a result",
|
342
|
+
channel: e.channel
|
252
343
|
)
|
253
344
|
end
|
254
345
|
|
@@ -274,17 +365,26 @@ class QwtfDiscordBotPug # :nodoc:
|
|
274
365
|
}.to_json
|
275
366
|
)
|
276
367
|
|
277
|
-
send_embedded_message(
|
368
|
+
send_embedded_message(
|
369
|
+
description: "#{TEAM_NAMES[winning_team_no]} wins. [Ratings](http://ratings.fortressone.org)",
|
370
|
+
channel: e.channel
|
371
|
+
)
|
278
372
|
end
|
279
373
|
end
|
280
374
|
|
281
375
|
bot.command :draw do |event, *args|
|
282
376
|
setup_pug(event) do |e, pug|
|
283
|
-
|
377
|
+
unless pug.active?
|
378
|
+
return send_embedded_message(
|
379
|
+
description: no_active_pug_message,
|
380
|
+
channel: e.channel
|
381
|
+
)
|
382
|
+
end
|
284
383
|
|
285
384
|
if pug.actual_teams.count < 2
|
286
385
|
return send_embedded_message(
|
287
|
-
"There must be at least two teams with players to submit a result",
|
386
|
+
description: "There must be at least two teams with players to submit a result",
|
387
|
+
channel: e.channel
|
288
388
|
)
|
289
389
|
end
|
290
390
|
|
@@ -309,13 +409,21 @@ class QwtfDiscordBotPug # :nodoc:
|
|
309
409
|
}.to_json
|
310
410
|
)
|
311
411
|
|
312
|
-
send_embedded_message(
|
412
|
+
send_embedded_message(
|
413
|
+
description: "Match drawn. [Ratings](http://ratings.fortressone.org)",
|
414
|
+
channel: e.channel
|
415
|
+
)
|
313
416
|
end
|
314
417
|
end
|
315
418
|
|
316
419
|
bot.command :end do |event, *args|
|
317
420
|
setup_pug(event) do |e, pug|
|
318
|
-
|
421
|
+
unless pug.active?
|
422
|
+
return send_embedded_message(
|
423
|
+
description: no_active_pug_message,
|
424
|
+
channel: e.channel
|
425
|
+
)
|
426
|
+
end
|
319
427
|
|
320
428
|
end_pug(pug, e.channel)
|
321
429
|
end
|
@@ -324,47 +432,105 @@ class QwtfDiscordBotPug # :nodoc:
|
|
324
432
|
bot.command :addmap do |event, *args|
|
325
433
|
setup_pug(event) do |e, pug|
|
326
434
|
maps = args
|
327
|
-
|
435
|
+
|
436
|
+
unless maps.any?
|
437
|
+
return send_embedded_message(
|
438
|
+
description: "What map? e.g. `!addmap 2fort5r`",
|
439
|
+
channel: e.channel
|
440
|
+
)
|
441
|
+
end
|
328
442
|
|
329
443
|
pug.add_maps(maps)
|
330
|
-
|
444
|
+
|
445
|
+
send_embedded_message(
|
446
|
+
description: "#{maps.join(', ')} added to maps",
|
447
|
+
channel: e.channel)
|
331
448
|
end
|
332
449
|
end
|
333
450
|
|
334
451
|
bot.command :removemap do |event, *args|
|
335
452
|
setup_pug(event) do |e, pug|
|
336
453
|
maps = args
|
337
|
-
|
454
|
+
|
455
|
+
unless maps.any?
|
456
|
+
return send_embedded_message(
|
457
|
+
description: "What map? e.g. `!removemap 2fort5r`",
|
458
|
+
channel: e.channel
|
459
|
+
)
|
460
|
+
end
|
338
461
|
|
339
462
|
pug.remove_maps(maps)
|
340
|
-
|
463
|
+
|
464
|
+
send_embedded_message(
|
465
|
+
description: "#{maps.join(', ')} removed from maps",
|
466
|
+
channel: e.channel
|
467
|
+
)
|
341
468
|
end
|
342
469
|
end
|
343
470
|
|
344
471
|
bot.command :maps do |event, *args|
|
345
472
|
setup_pug(event) do |e, pug|
|
346
473
|
maps = pug.maps
|
347
|
-
|
474
|
+
unless maps.any?
|
475
|
+
return send_embedded_message(
|
476
|
+
description: 'No maps have been added. `!addmap`',
|
477
|
+
channel: e.channel
|
478
|
+
)
|
479
|
+
end
|
348
480
|
|
349
|
-
send_embedded_message(
|
481
|
+
send_embedded_message(
|
482
|
+
description: maps.join(', '),
|
483
|
+
channel: e.channel
|
484
|
+
)
|
350
485
|
end
|
351
486
|
end
|
352
487
|
|
353
488
|
bot.command :map do |event, *args|
|
354
489
|
setup_pug(event) do |e, pug|
|
355
490
|
maps = pug.maps
|
356
|
-
|
357
|
-
|
491
|
+
|
492
|
+
unless maps.any?
|
493
|
+
return send_embedded_message(
|
494
|
+
description: 'No maps have been added. `!addmap`',
|
495
|
+
channel: e.channel
|
496
|
+
)
|
497
|
+
end
|
498
|
+
|
499
|
+
unless pug.active?
|
500
|
+
return send_embedded_message(
|
501
|
+
description: no_active_pug_message,
|
502
|
+
channel: e.channel
|
503
|
+
)
|
504
|
+
end
|
358
505
|
|
359
506
|
if args.empty?
|
360
|
-
|
361
|
-
|
507
|
+
unless pug.game_map
|
508
|
+
return send_embedded_message(
|
509
|
+
description: 'No map has been set for the current PUG',
|
510
|
+
channel: e.channel
|
511
|
+
)
|
512
|
+
end
|
513
|
+
|
514
|
+
send_embedded_message(
|
515
|
+
description: "Current map is #{pug.game_map}",
|
516
|
+
channel: e.channel
|
517
|
+
)
|
362
518
|
else
|
363
519
|
game_map = args.first
|
364
|
-
|
520
|
+
|
521
|
+
unless maps.include?(game_map)
|
522
|
+
return send_embedded_message(
|
523
|
+
description: "#{game_map} isn't in the map list. `!addmap` to add it.",
|
524
|
+
channel: e.channel
|
525
|
+
)
|
526
|
+
end
|
365
527
|
|
366
528
|
pug.game_map = game_map
|
367
|
-
|
529
|
+
|
530
|
+
send_embedded_message(
|
531
|
+
description: "Map set to #{game_map}",
|
532
|
+
channel: e.channel
|
533
|
+
)
|
368
534
|
end
|
369
535
|
end
|
370
536
|
end
|
@@ -380,7 +546,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
380
546
|
"Notification role set to #{roles}"
|
381
547
|
end
|
382
548
|
|
383
|
-
send_embedded_message(
|
549
|
+
send_embedded_message(
|
550
|
+
description: msg,
|
551
|
+
channel: e.channel
|
552
|
+
)
|
384
553
|
end
|
385
554
|
end
|
386
555
|
|
@@ -390,6 +559,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
390
559
|
private
|
391
560
|
|
392
561
|
def team_name(team_no)
|
562
|
+
return "No team" if team_no == 0
|
563
|
+
|
393
564
|
[team_no, TEAM_NAMES[team_no]].join(" ")
|
394
565
|
end
|
395
566
|
|
@@ -401,13 +572,18 @@ class QwtfDiscordBotPug # :nodoc:
|
|
401
572
|
pug.join(e.user_id)
|
402
573
|
|
403
574
|
if pug.joined_player_count == 1
|
404
|
-
snippets = ["#{e.display_name} creates a PUG", pug.player_slots
|
575
|
+
snippets = ["#{e.display_name} creates a PUG", "#{pug.player_slots} joined"]
|
576
|
+
message = pug.notify_roles
|
405
577
|
else
|
406
|
-
snippets = ["#{e.display_name} joins the PUG", pug.player_slots]
|
407
|
-
|
578
|
+
snippets = ["#{e.display_name} joins the PUG", "#{pug.player_slots} joined"]
|
579
|
+
message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left.between?(1, 3)
|
408
580
|
end
|
409
581
|
|
410
|
-
send_embedded_message(
|
582
|
+
send_embedded_message(
|
583
|
+
message: message,
|
584
|
+
description: snippets.join(MSG_SNIPPET_DELIMITER),
|
585
|
+
channel: e.channel
|
586
|
+
)
|
411
587
|
end
|
412
588
|
|
413
589
|
def setup_pug(event)
|
@@ -417,31 +593,97 @@ class QwtfDiscordBotPug # :nodoc:
|
|
417
593
|
nil # stop discordrb printing return value
|
418
594
|
end
|
419
595
|
|
420
|
-
def
|
421
|
-
if !pug.
|
422
|
-
send_embedded_message(
|
423
|
-
|
596
|
+
def choose_fair_teams(pug:, event:, iteration: 0)
|
597
|
+
if !pug.full?
|
598
|
+
return send_embedded_message(
|
599
|
+
description: "Can't choose teams until PUG is full",
|
600
|
+
channel: event.channel
|
601
|
+
) && nil
|
602
|
+
end
|
603
|
+
|
604
|
+
message_obj = send_embedded_message(
|
605
|
+
description: "Choosing fair teams...",
|
606
|
+
channel: event.channel
|
607
|
+
)
|
608
|
+
|
609
|
+
combinations = get_fair_teams(pug.joined_players)
|
610
|
+
teams = combinations[iteration]
|
611
|
+
|
612
|
+
if !teams
|
613
|
+
return send_embedded_message(
|
614
|
+
description: "There are only #{combinations.count} possible combinations",
|
615
|
+
channel: event.channel,
|
616
|
+
message_obj: message_obj
|
617
|
+
) && nil
|
618
|
+
end
|
619
|
+
|
620
|
+
teams.each do |team_no, player_ids|
|
621
|
+
player_ids.each do |player_id|
|
622
|
+
pug.join_team(team_no: team_no, player_id: player_id)
|
623
|
+
end
|
624
|
+
end
|
424
625
|
|
425
|
-
|
426
|
-
|
427
|
-
|
626
|
+
message_obj
|
627
|
+
end
|
628
|
+
|
629
|
+
def status(pug:, event:, message_obj: nil)
|
630
|
+
footer = [
|
631
|
+
pug.game_map,
|
632
|
+
"#{pug.player_slots} joined"
|
633
|
+
].compact.join(MSG_SNIPPET_DELIMITER)
|
634
|
+
|
635
|
+
send_embedded_message(
|
636
|
+
description: nil,
|
637
|
+
channel: event.channel,
|
638
|
+
message_obj: message_obj
|
639
|
+
) do |embed|
|
640
|
+
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
|
641
|
+
text: footer
|
642
|
+
)
|
643
|
+
|
644
|
+
pug.teams.each do |team_no, player_ids|
|
645
|
+
team_display_names = player_ids.map do |player_id|
|
646
|
+
event.display_name_for(player_id)
|
428
647
|
end
|
648
|
+
|
649
|
+
embed.add_field(
|
650
|
+
Discordrb::Webhooks::EmbedField.new(
|
651
|
+
{
|
652
|
+
inline: true,
|
653
|
+
name: team_name(team_no),
|
654
|
+
value: team_display_names.join("\n")
|
655
|
+
}
|
656
|
+
)
|
657
|
+
)
|
429
658
|
end
|
430
659
|
end
|
660
|
+
end
|
661
|
+
|
662
|
+
def start_pug(pug, event)
|
663
|
+
choose_fair_teams(pug: pug, event: event) unless pug.actual_teams.any?
|
431
664
|
|
432
665
|
footer = [
|
433
666
|
pug.game_map,
|
434
667
|
"#{pug.player_slots} joined",
|
435
668
|
].compact.join(MSG_SNIPPET_DELIMITER)
|
436
669
|
|
437
|
-
|
670
|
+
mentions = pug.joined_players.map do |player_id|
|
671
|
+
event.mention_for(player_id)
|
672
|
+
end
|
673
|
+
|
674
|
+
mention_line = "Time to play! #{mentions.join(" ")}"
|
675
|
+
|
676
|
+
send_embedded_message(
|
677
|
+
message: mention_line,
|
678
|
+
channel: event.channel
|
679
|
+
) do |embed|
|
438
680
|
embed.footer = Discordrb::Webhooks::EmbedFooter.new(
|
439
681
|
text: footer
|
440
682
|
)
|
441
683
|
|
442
684
|
pug.teams.each do |team_no, player_ids|
|
443
685
|
team_mentions = player_ids.map do |player_id|
|
444
|
-
event.
|
686
|
+
event.display_name_for(player_id)
|
445
687
|
end
|
446
688
|
|
447
689
|
embed.add_field(
|
@@ -459,24 +701,38 @@ class QwtfDiscordBotPug # :nodoc:
|
|
459
701
|
|
460
702
|
def end_pug(pug, channel_id)
|
461
703
|
pug.end_pug
|
462
|
-
|
704
|
+
|
705
|
+
send_embedded_message(
|
706
|
+
description: 'PUG ended',
|
707
|
+
channel: channel_id
|
708
|
+
)
|
463
709
|
end
|
464
710
|
|
465
711
|
def no_active_pug_message
|
466
712
|
"There's no active PUG"
|
467
713
|
end
|
468
714
|
|
469
|
-
def send_embedded_message(message, channel)
|
715
|
+
def send_embedded_message(message: nil, description: nil, channel:, message_obj: nil)
|
470
716
|
embed = Discordrb::Webhooks::Embed.new
|
471
|
-
embed.description =
|
717
|
+
embed.description = description
|
472
718
|
yield(embed) if block_given?
|
473
|
-
|
719
|
+
|
720
|
+
if message_obj
|
721
|
+
message_obj.edit(message, embed).tap do
|
722
|
+
puts(message)
|
723
|
+
end
|
724
|
+
else
|
725
|
+
channel.send_embed(message, embed).tap do
|
726
|
+
puts(message)
|
727
|
+
end
|
728
|
+
end
|
474
729
|
end
|
475
730
|
|
476
731
|
def post_results(json)
|
477
732
|
uri = URI("#{ENV['RATINGS_API_URL']}matches/")
|
478
733
|
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
479
734
|
req.body = json
|
735
|
+
|
480
736
|
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
481
737
|
http.request(req)
|
482
738
|
end
|
@@ -487,9 +743,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
487
743
|
params = { 'players[]' => players }
|
488
744
|
uri.query = URI.encode_www_form(params)
|
489
745
|
req = Net::HTTP::Get.new(uri)
|
746
|
+
|
490
747
|
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
491
748
|
http.request(req)
|
492
749
|
end
|
493
|
-
|
750
|
+
|
751
|
+
JSON.parse(res.body).map(&:to_h)
|
494
752
|
end
|
495
753
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qwtf_discord_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.4.
|
4
|
+
version: 5.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|