qwtf_discord_bot 5.3.4 → 5.4.1
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/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +49 -9
- 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: a1d4b0223feae05745b7050dc8dc25193136bac78bee3fca74818559dad0dd7c
|
4
|
+
data.tar.gz: 8a7b7a27d72b759ffa4111bdf85f73c0effae38c4db7c8164f5abca357912dd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b621a49eefc9ab5c83c93e771a00d609aa72be3b675e627aa9f502cd1646832e4cd892e67b0864bdea9a9dbcaf9f0b691a6f3df71f852179d21a28d760312c28
|
7
|
+
data.tar.gz: 91ce0148eeb1a80d127bb722204153031087eb88b8460b64fab9004d834e0f96615bf605f35d3ef06a8df17ed23fdf4d863c1cbd0b2231070beb23e9b2b52dd7
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.4.1
|
@@ -16,6 +16,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
16
16
|
prefix: '!'
|
17
17
|
)
|
18
18
|
|
19
|
+
bot.command :help do |event, *args|
|
20
|
+
"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>`"
|
21
|
+
end
|
22
|
+
|
19
23
|
bot.command :join do |event, *args|
|
20
24
|
setup_pug(event) do |e, pug|
|
21
25
|
return send_msg("You've already joined", e.channel) if pug.joined?(e.user_id)
|
@@ -135,10 +139,9 @@ class QwtfDiscordBotPug # :nodoc:
|
|
135
139
|
bot.command :team do |event, *args|
|
136
140
|
setup_pug(event) do |e, pug|
|
137
141
|
return send_msg("Which team? E.G. `!team 1`", e.channel) unless args.any?
|
142
|
+
return send_msg("Choose a team between 0 and 2", e.channel) unless ["0", "1", "2"].any?(args.first)
|
138
143
|
|
139
|
-
team_no = args
|
140
|
-
return send_msg("Choose a team between 0 and 4", e.channel) unless team_no.between?(0, 4)
|
141
|
-
|
144
|
+
team_no = args.first.to_i
|
142
145
|
pug_already_full = pug.full?
|
143
146
|
|
144
147
|
if args.count == 1
|
@@ -204,9 +207,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
204
207
|
|
205
208
|
return send_msg("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
|
206
209
|
|
207
|
-
|
210
|
+
if pug.actual_teams.count < 2
|
211
|
+
return send_msg(
|
212
|
+
"There must be at least two teams with players to submit a result", e.channel
|
213
|
+
)
|
214
|
+
end
|
208
215
|
|
209
|
-
team_results = actual_teams.inject({}) do |teams, (name, player_ids)|
|
216
|
+
team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
|
210
217
|
players = player_ids.inject({}) do |memo, id|
|
211
218
|
memo.merge({ id => e.display_name_for(id) })
|
212
219
|
end
|
@@ -219,7 +226,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
219
226
|
{
|
220
227
|
match: {
|
221
228
|
map: pug.game_map,
|
222
|
-
teams: team_results
|
229
|
+
teams: team_results,
|
230
|
+
discord_channel: {
|
231
|
+
channel_id: e.channel_id,
|
232
|
+
name: "#{e.channel.server.name} ##{e.channel.name}"
|
233
|
+
}
|
223
234
|
}
|
224
235
|
}.to_json
|
225
236
|
)
|
@@ -242,9 +253,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
242
253
|
setup_pug(event) do |e, pug|
|
243
254
|
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
244
255
|
|
245
|
-
|
256
|
+
if pug.actual_teams.count < 2
|
257
|
+
return send_msg(
|
258
|
+
"There must be at least two teams with players to submit a result", e.channel
|
259
|
+
)
|
260
|
+
end
|
246
261
|
|
247
|
-
team_results = actual_teams.inject({}) do |teams, (name, player_ids)|
|
262
|
+
team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
|
248
263
|
players = player_ids.inject({}) do |memo, id|
|
249
264
|
memo.merge({ id => e.display_name_for(id) })
|
250
265
|
end
|
@@ -256,7 +271,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
256
271
|
{
|
257
272
|
match: {
|
258
273
|
map: pug.game_map,
|
259
|
-
teams: team_results
|
274
|
+
teams: team_results,
|
275
|
+
discord_channel: {
|
276
|
+
channel_id: e.channel_id,
|
277
|
+
name: "#{e.channel.server.name} ##{e.channel.name}"
|
278
|
+
}
|
260
279
|
}
|
261
280
|
}.to_json
|
262
281
|
)
|
@@ -366,6 +385,16 @@ class QwtfDiscordBotPug # :nodoc:
|
|
366
385
|
end
|
367
386
|
|
368
387
|
def start_pug(pug, event)
|
388
|
+
if !pug.actual_teams.any?
|
389
|
+
teams = get_fair_teams(pug.joined_players)
|
390
|
+
|
391
|
+
teams.each do |team_no, player_ids|
|
392
|
+
player_ids.each do |player_id|
|
393
|
+
pug.join_team(team_no: team_no, player_id: player_id)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
369
398
|
pug_teams = pug.teams.map do |team_no, player_ids|
|
370
399
|
team_mentions = player_ids.map do |player_id|
|
371
400
|
event.mention_for(player_id)
|
@@ -432,4 +461,15 @@ class QwtfDiscordBotPug # :nodoc:
|
|
432
461
|
http.request(req)
|
433
462
|
end
|
434
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
|
435
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.
|
4
|
+
version: 5.4.1
|
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
|