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