qwtf_discord_bot 5.3.6 → 5.4.3
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/VERSION +1 -1
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +89 -65
- data/lib/qwtf_discord_bot/qwtf_discord_bot_server.rb +4 -0
- 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: bb40c561739b201a25554221a3b07ff74da6ef621121a8032cf7ff0638e8040d
|
4
|
+
data.tar.gz: 3215cfed66032d0e0f96689b885d427f9529b55cf07934dc9c8606ba76d467b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cc6e47321572b0459ef66a518631df912ac96726b4a62c7f508c174236a756c65b8c6898757a61b0c5854b145907e6d9b9e525db8df972ddd520b492512bed2
|
7
|
+
data.tar.gz: f8a5aff8a87cb70a32438199e5b85aa0388f5ef3918ed7f5b578d3241f199e354e799eac6cadb7a81075a799f9a42ac724152d3e783fc98a5dee0924c32b3866
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.3
|
1
|
+
5.4.3
|
@@ -13,12 +13,24 @@ class QwtfDiscordBotPug # :nodoc:
|
|
13
13
|
token: QwtfDiscordBot.config.token,
|
14
14
|
client_id: QwtfDiscordBot.config.client_id,
|
15
15
|
help_command: false,
|
16
|
-
prefix:
|
16
|
+
prefix: proc do |message|
|
17
|
+
match = /^\!(\w+)(.*)/.match(message.content)
|
18
|
+
if match
|
19
|
+
first = match[1]
|
20
|
+
rest = match[2]
|
21
|
+
# Return the modified string with the first word lowercase:
|
22
|
+
"#{first.downcase}#{rest}"
|
23
|
+
end
|
24
|
+
end
|
17
25
|
)
|
18
26
|
|
27
|
+
bot.command :help do |event, *args|
|
28
|
+
"Pug commands: `!status`, `!join`, `!team <team_no>`, `!unteam`, `!leave`, `!kick <@player>`, `!win <team_no>`, `!draw`, `!end`, `!teamsize <no_of_players>`, `!addmap <map_name>`, `!removemap <map_name>`, `!maps`, `!map <map_name>`, `!notify <@role>`"
|
29
|
+
end
|
30
|
+
|
19
31
|
bot.command :join do |event, *args|
|
20
32
|
setup_pug(event) do |e, pug|
|
21
|
-
return
|
33
|
+
return send_embedded_message("You've already joined", e.channel) if pug.joined?(e.user_id)
|
22
34
|
|
23
35
|
join_pug(e, pug)
|
24
36
|
start_pug(pug, e) if pug.full?
|
@@ -27,9 +39,9 @@ class QwtfDiscordBotPug # :nodoc:
|
|
27
39
|
|
28
40
|
bot.command :status do |event, *args|
|
29
41
|
setup_pug(event) do |e, pug|
|
30
|
-
return
|
42
|
+
return send_embedded_message('No PUG has been started. `!join` to create', e.channel) unless pug.active?
|
31
43
|
|
32
|
-
|
44
|
+
send_embedded_message(
|
33
45
|
[
|
34
46
|
"#{pug.player_slots} joined",
|
35
47
|
"Map: #{pug.game_map}",
|
@@ -42,15 +54,15 @@ class QwtfDiscordBotPug # :nodoc:
|
|
42
54
|
|
43
55
|
bot.command :teamsize do |event, *args|
|
44
56
|
setup_pug(event) do |e, pug|
|
45
|
-
return
|
57
|
+
return send_embedded_message("Team size is #{pug.teamsize}", e.channel) unless args.any?
|
46
58
|
|
47
59
|
new_teamsize = args[0].to_i
|
48
|
-
return
|
60
|
+
return send_embedded_message('Team size should be a number higher than 0', e.channel) unless new_teamsize > 0
|
49
61
|
|
50
62
|
if new_teamsize
|
51
63
|
pug.teamsize = new_teamsize
|
52
64
|
|
53
|
-
|
65
|
+
send_embedded_message(
|
54
66
|
[
|
55
67
|
"Team size set to #{pug.teamsize}",
|
56
68
|
"#{pug.player_slots} joined"
|
@@ -60,7 +72,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
60
72
|
|
61
73
|
start_pug(pug, e) if pug.full?
|
62
74
|
else
|
63
|
-
|
75
|
+
send_embedded_message(
|
64
76
|
[
|
65
77
|
"Current team size is #{pug.teamsize}",
|
66
78
|
"#{pug.player_slots} joined"
|
@@ -73,8 +85,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
73
85
|
|
74
86
|
bot.command :leave do |event, *args|
|
75
87
|
setup_pug(event) do |e, pug|
|
76
|
-
return
|
77
|
-
return
|
88
|
+
return send_embedded_message(no_active_pug_message, e.channel) unless pug.active?
|
89
|
+
return send_embedded_message("You're not in the PUG", e.channel) unless pug.joined?(e.user_id)
|
78
90
|
|
79
91
|
pug.leave(e.user_id)
|
80
92
|
|
@@ -85,7 +97,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
85
97
|
|
86
98
|
snippets << "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
|
87
99
|
|
88
|
-
|
100
|
+
send_embedded_message(
|
89
101
|
snippets.join(MSG_SNIPPET_DELIMITER),
|
90
102
|
e.channel
|
91
103
|
)
|
@@ -96,12 +108,12 @@ class QwtfDiscordBotPug # :nodoc:
|
|
96
108
|
|
97
109
|
bot.command :kick do |event, *args|
|
98
110
|
setup_pug(event) do |e, pug|
|
99
|
-
return
|
100
|
-
return
|
111
|
+
return send_embedded_message("Kick who? e.g. `!kick @#{e.display_name}`", e.channel) unless args.any?
|
112
|
+
return send_embedded_message(no_active_pug_message, e.channel) unless pug.active?
|
101
113
|
|
102
114
|
args.each do |arg|
|
103
115
|
unless arg.match(/<@!\d+>/)
|
104
|
-
|
116
|
+
send_embedded_message("#{arg} isn't a valid mention", e.channel)
|
105
117
|
next
|
106
118
|
end
|
107
119
|
|
@@ -109,7 +121,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
109
121
|
display_name = e.display_name_for(user_id) || arg
|
110
122
|
|
111
123
|
unless pug.joined?(user_id)
|
112
|
-
|
124
|
+
send_embedded_message("#{display_name} isn't in the PUG", e.channel)
|
113
125
|
next
|
114
126
|
end
|
115
127
|
|
@@ -122,7 +134,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
122
134
|
|
123
135
|
snippets << "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
|
124
136
|
|
125
|
-
|
137
|
+
send_embedded_message(
|
126
138
|
snippets.join(MSG_SNIPPET_DELIMITER),
|
127
139
|
e.channel
|
128
140
|
)
|
@@ -134,21 +146,20 @@ class QwtfDiscordBotPug # :nodoc:
|
|
134
146
|
|
135
147
|
bot.command :team do |event, *args|
|
136
148
|
setup_pug(event) do |e, pug|
|
137
|
-
return
|
138
|
-
|
139
|
-
team_no = args[0].to_i
|
140
|
-
return send_msg("Choose a team between 0 and 4", e.channel) unless team_no.between?(0, 4)
|
149
|
+
return send_embedded_message("Which team? E.G. `!team 1`", e.channel) unless args.any?
|
150
|
+
return send_embedded_message("Choose a team between 0 and 2", e.channel) unless ["0", "1", "2"].any?(args.first)
|
141
151
|
|
152
|
+
team_no = args.first.to_i
|
142
153
|
pug_already_full = pug.full?
|
143
154
|
|
144
155
|
if args.count == 1
|
145
156
|
user_id = e.user_id
|
146
|
-
return
|
157
|
+
return send_embedded_message("You're already in team #{team_no}", e.channel) if pug.team(team_no).include?(user_id)
|
147
158
|
|
148
159
|
join_pug(e, pug) unless pug.joined?(user_id)
|
149
160
|
pug.join_team(team_no: team_no, player_id: user_id)
|
150
161
|
|
151
|
-
|
162
|
+
send_embedded_message(
|
152
163
|
[
|
153
164
|
"#{e.display_name} joins team #{team_no}",
|
154
165
|
"#{pug.team_player_count(team_no)}/#{pug.teamsize}"
|
@@ -157,7 +168,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
157
168
|
else
|
158
169
|
args[1..-1].each do |mention|
|
159
170
|
unless mention.match(/<@!\d+>/)
|
160
|
-
|
171
|
+
send_embedded_message("#{arg} isn't a valid mention", e.channel)
|
161
172
|
next
|
162
173
|
end
|
163
174
|
|
@@ -165,13 +176,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
165
176
|
display_name = e.display_name_for(user_id) || arg
|
166
177
|
|
167
178
|
unless pug.joined?(user_id)
|
168
|
-
|
179
|
+
send_embedded_message("#{display_name} isn't in the PUG", e.channel)
|
169
180
|
next
|
170
181
|
end
|
171
182
|
|
172
183
|
pug.join_team(team_no: team_no, player_id: user_id)
|
173
184
|
|
174
|
-
|
185
|
+
send_embedded_message(
|
175
186
|
[
|
176
187
|
"#{display_name} joins team #{team_no}",
|
177
188
|
"#{pug.team_player_count(team_no)}/#{pug.teamsize}"
|
@@ -187,25 +198,25 @@ class QwtfDiscordBotPug # :nodoc:
|
|
187
198
|
bot.command :unteam do |event, *args|
|
188
199
|
setup_pug(event) do |e, pug|
|
189
200
|
user_id = e.user_id
|
190
|
-
return
|
191
|
-
return
|
192
|
-
return
|
201
|
+
return send_embedded_message('No PUG has been started. `!join` to create', e.channel) unless pug.active?
|
202
|
+
return send_embedded_message("You aren't in this PUG", e.channel) unless pug.joined?(user_id)
|
203
|
+
return send_embedded_message("You aren't in a team", e.channel) if pug.team(0).include?(user_id)
|
193
204
|
|
194
205
|
pug.join_team(team_no: 0, player_id: user_id)
|
195
|
-
|
206
|
+
send_embedded_message("#{e.display_name} has no team", e.channel)
|
196
207
|
end
|
197
208
|
end
|
198
209
|
|
199
210
|
bot.command :win do |event, *args|
|
200
211
|
setup_pug(event) do |e, pug|
|
201
|
-
return
|
212
|
+
return send_embedded_message(no_active_pug_message, e.channel) unless pug.active?
|
202
213
|
|
203
214
|
winning_team_no = args[0]
|
204
215
|
|
205
|
-
return
|
216
|
+
return send_embedded_message("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
|
206
217
|
|
207
218
|
if pug.actual_teams.count < 2
|
208
|
-
return
|
219
|
+
return send_embedded_message(
|
209
220
|
"There must be at least two teams with players to submit a result", e.channel
|
210
221
|
)
|
211
222
|
end
|
@@ -232,26 +243,16 @@ class QwtfDiscordBotPug # :nodoc:
|
|
232
243
|
}.to_json
|
233
244
|
)
|
234
245
|
|
235
|
-
#
|
236
|
-
# e.display_name_for(player_id)
|
237
|
-
# end
|
238
|
-
|
239
|
-
# non_winning_teams = pug.actual_teams.tap { |team| team.delete(winning_team_no) }
|
240
|
-
|
241
|
-
# losing_players = non_winning_teams.values.flatten.map do |player_id|
|
242
|
-
# e.display_name_for(player_id)
|
243
|
-
# end
|
244
|
-
|
245
|
-
send_msg("Team #{winning_team_no} wins", e.channel)
|
246
|
+
send_embedded_message("Team #{winning_team_no} wins. [Ratings](http://ratings.fortressone.org)", e.channel)
|
246
247
|
end
|
247
248
|
end
|
248
249
|
|
249
250
|
bot.command :draw do |event, *args|
|
250
251
|
setup_pug(event) do |e, pug|
|
251
|
-
return
|
252
|
+
return send_embedded_message(no_active_pug_message, e.channel) unless pug.active?
|
252
253
|
|
253
254
|
if pug.actual_teams.count < 2
|
254
|
-
return
|
255
|
+
return send_embedded_message(
|
255
256
|
"There must be at least two teams with players to submit a result", e.channel
|
256
257
|
)
|
257
258
|
end
|
@@ -277,13 +278,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
277
278
|
}.to_json
|
278
279
|
)
|
279
280
|
|
280
|
-
|
281
|
+
send_embedded_message("Match drawn. [Ratings](http://ratings.fortressone.org)", e.channel)
|
281
282
|
end
|
282
283
|
end
|
283
284
|
|
284
285
|
bot.command :end do |event, *args|
|
285
286
|
setup_pug(event) do |e, pug|
|
286
|
-
return
|
287
|
+
return send_embedded_message(no_active_pug_message, e.channel) unless pug.active?
|
287
288
|
|
288
289
|
end_pug(pug, e.channel)
|
289
290
|
end
|
@@ -292,47 +293,47 @@ class QwtfDiscordBotPug # :nodoc:
|
|
292
293
|
bot.command :addmap do |event, *args|
|
293
294
|
setup_pug(event) do |e, pug|
|
294
295
|
maps = args
|
295
|
-
return
|
296
|
+
return send_embedded_message("What map? e.g. `!addmap 2fort5r`", e.channel) unless maps.any?
|
296
297
|
|
297
298
|
pug.add_maps(maps)
|
298
|
-
|
299
|
+
send_embedded_message("#{maps.join(', ')} added to maps", e.channel)
|
299
300
|
end
|
300
301
|
end
|
301
302
|
|
302
303
|
bot.command :removemap do |event, *args|
|
303
304
|
setup_pug(event) do |e, pug|
|
304
305
|
maps = args
|
305
|
-
return
|
306
|
+
return send_embedded_message("What map? e.g. `!removemap 2fort5r`", e.channel) unless maps.any?
|
306
307
|
|
307
308
|
pug.remove_maps(maps)
|
308
|
-
|
309
|
+
send_embedded_message("#{maps.join(', ')} removed from maps", e.channel)
|
309
310
|
end
|
310
311
|
end
|
311
312
|
|
312
313
|
bot.command :maps do |event, *args|
|
313
314
|
setup_pug(event) do |e, pug|
|
314
315
|
maps = pug.maps
|
315
|
-
return
|
316
|
+
return send_embedded_message('No maps have been added. `!addmap`', e.channel) unless maps.any?
|
316
317
|
|
317
|
-
|
318
|
+
send_embedded_message(maps.join(', '), e.channel)
|
318
319
|
end
|
319
320
|
end
|
320
321
|
|
321
322
|
bot.command :map do |event, *args|
|
322
323
|
setup_pug(event) do |e, pug|
|
323
324
|
maps = pug.maps
|
324
|
-
return
|
325
|
-
return
|
325
|
+
return send_embedded_message('No maps have been added. `!addmap`', e.channel) unless maps.any?
|
326
|
+
return send_embedded_message(no_active_pug_message, e.channel) unless pug.active?
|
326
327
|
|
327
328
|
if args.empty?
|
328
|
-
return
|
329
|
-
|
329
|
+
return send_embedded_message('No map has been set for the current PUG', e.channel) unless pug.game_map
|
330
|
+
send_embedded_message("Current map is #{pug.game_map}", e.channel)
|
330
331
|
else
|
331
332
|
game_map = args.first
|
332
|
-
return
|
333
|
+
return send_embedded_message("#{game_map} isn't in the map list. `!addmap` to add it.", e.channel) unless maps.include?(game_map)
|
333
334
|
|
334
335
|
pug.game_map = game_map
|
335
|
-
|
336
|
+
send_embedded_message("Map set to #{game_map}", e.channel)
|
336
337
|
end
|
337
338
|
end
|
338
339
|
end
|
@@ -348,7 +349,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
348
349
|
"Notification role set to #{roles}"
|
349
350
|
end
|
350
351
|
|
351
|
-
|
352
|
+
send_embedded_message(msg, e.channel)
|
352
353
|
end
|
353
354
|
end
|
354
355
|
|
@@ -371,7 +372,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
371
372
|
snippets << "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left.between?(1, 3)
|
372
373
|
end
|
373
374
|
|
374
|
-
|
375
|
+
send_embedded_message(snippets.join(MSG_SNIPPET_DELIMITER), e.channel)
|
375
376
|
end
|
376
377
|
|
377
378
|
def setup_pug(event)
|
@@ -382,6 +383,16 @@ class QwtfDiscordBotPug # :nodoc:
|
|
382
383
|
end
|
383
384
|
|
384
385
|
def start_pug(pug, event)
|
386
|
+
if !pug.actual_teams.any?
|
387
|
+
teams = get_fair_teams(pug.joined_players)
|
388
|
+
|
389
|
+
teams.each do |team_no, player_ids|
|
390
|
+
player_ids.each do |player_id|
|
391
|
+
pug.join_team(team_no: team_no, player_id: player_id)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
385
396
|
pug_teams = pug.teams.map do |team_no, player_ids|
|
386
397
|
team_mentions = player_ids.map do |player_id|
|
387
398
|
event.mention_for(player_id)
|
@@ -399,7 +410,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
399
410
|
pug_teams
|
400
411
|
].join("\n")
|
401
412
|
|
402
|
-
|
413
|
+
send_embedded_message(msg, event.channel)
|
403
414
|
end
|
404
415
|
|
405
416
|
def pug_teams_message(pug, event)
|
@@ -429,15 +440,17 @@ class QwtfDiscordBotPug # :nodoc:
|
|
429
440
|
|
430
441
|
def end_pug(pug, channel_id)
|
431
442
|
pug.end_pug
|
432
|
-
|
443
|
+
send_embedded_message('PUG ended', channel_id)
|
433
444
|
end
|
434
445
|
|
435
446
|
def no_active_pug_message
|
436
447
|
"There's no active PUG"
|
437
448
|
end
|
438
449
|
|
439
|
-
def
|
440
|
-
|
450
|
+
def send_embedded_message(message, channel)
|
451
|
+
embed = Discordrb::Webhooks::Embed.new
|
452
|
+
embed.description = message
|
453
|
+
channel.send_embed(nil, embed) && puts(message)
|
441
454
|
end
|
442
455
|
|
443
456
|
def post_results(json)
|
@@ -448,4 +461,15 @@ class QwtfDiscordBotPug # :nodoc:
|
|
448
461
|
http.request(req)
|
449
462
|
end
|
450
463
|
end
|
464
|
+
|
465
|
+
def get_fair_teams(players)
|
466
|
+
uri = URI("#{ENV['RATINGS_API_URL']}fair_teams/new")
|
467
|
+
params = { 'players[]' => players }
|
468
|
+
uri.query = URI.encode_www_form(params)
|
469
|
+
req = Net::HTTP::Get.new(uri)
|
470
|
+
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
471
|
+
http.request(req)
|
472
|
+
end
|
473
|
+
JSON.parse(res.body).first.to_h
|
474
|
+
end
|
451
475
|
end
|
@@ -7,6 +7,10 @@ class QwtfDiscordBotServer
|
|
7
7
|
prefix: '!'
|
8
8
|
)
|
9
9
|
|
10
|
+
bot.command :help do |event, *args|
|
11
|
+
"Server commands: `!active`, `!all`, `!server <address>`"
|
12
|
+
end
|
13
|
+
|
10
14
|
bot.command :server do |event, *args|
|
11
15
|
if args.empty?
|
12
16
|
message = 'Provide a server address e.g. `!server ' \
|
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.3
|
4
|
+
version: 5.4.3
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|