qwtf_discord_bot 5.3.3 → 5.4.0
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 +52 -7
- 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: 483a4220fb3dd783224fad769534ecb77812428dfb75dd070ce5a2299d50a6c0
|
4
|
+
data.tar.gz: 7fb143e346b0afa23f0af56d1282309d560855c41d302016514e434f01839445
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75f5981bfa1c28dea2d79011de86ac2bf5610ae7791e147b85fb1f1819d2a332098b06695d689944d400880ac8d54469f2a153508310613d5a1ea1125b790d6e
|
7
|
+
data.tar.gz: def0724c06d819f0ffcdf49f2447562c261d48b0d2875c091df9b4f47500af28411b9aa62e62f924d1a57f1f71d3345b8634ba65d8935f64a5ca591335f60383
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.4.0
|
@@ -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)
|
@@ -137,7 +141,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
137
141
|
return send_msg("Which team? E.G. `!team 1`", e.channel) unless args.any?
|
138
142
|
|
139
143
|
team_no = args[0].to_i
|
140
|
-
return send_msg("Choose a team between
|
144
|
+
return send_msg("Choose a team between 0 and 4", e.channel) unless team_no.between?(0, 4)
|
141
145
|
|
142
146
|
pug_already_full = pug.full?
|
143
147
|
|
@@ -204,20 +208,30 @@ class QwtfDiscordBotPug # :nodoc:
|
|
204
208
|
|
205
209
|
return send_msg("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
|
206
210
|
|
207
|
-
|
211
|
+
if pug.actual_teams.count < 2
|
212
|
+
return send_msg(
|
213
|
+
"There must be at least two teams with players to submit a result", e.channel
|
214
|
+
)
|
215
|
+
end
|
216
|
+
|
217
|
+
team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
|
208
218
|
players = player_ids.inject({}) do |memo, id|
|
209
219
|
memo.merge({ id => e.display_name_for(id) })
|
210
220
|
end
|
211
221
|
|
212
|
-
|
213
|
-
|
222
|
+
result = winning_team_no.to_i == name.to_i ? 1 : -1
|
223
|
+
teams.merge({ name => { players: players, result: result } })
|
214
224
|
end
|
215
225
|
|
216
226
|
post_results(
|
217
227
|
{
|
218
228
|
match: {
|
219
229
|
map: pug.game_map,
|
220
|
-
teams: team_results
|
230
|
+
teams: team_results,
|
231
|
+
discord_channel: {
|
232
|
+
channel_id: e.channel_id,
|
233
|
+
name: "#{e.channel.server.name} ##{e.channel.name}"
|
234
|
+
}
|
221
235
|
}
|
222
236
|
}.to_json
|
223
237
|
)
|
@@ -240,7 +254,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
240
254
|
setup_pug(event) do |e, pug|
|
241
255
|
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
242
256
|
|
243
|
-
|
257
|
+
if pug.actual_teams.count < 2
|
258
|
+
return send_msg(
|
259
|
+
"There must be at least two teams with players to submit a result", e.channel
|
260
|
+
)
|
261
|
+
end
|
262
|
+
|
263
|
+
team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
|
244
264
|
players = player_ids.inject({}) do |memo, id|
|
245
265
|
memo.merge({ id => e.display_name_for(id) })
|
246
266
|
end
|
@@ -252,7 +272,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
252
272
|
{
|
253
273
|
match: {
|
254
274
|
map: pug.game_map,
|
255
|
-
teams: team_results
|
275
|
+
teams: team_results,
|
276
|
+
discord_channel: {
|
277
|
+
channel_id: e.channel_id,
|
278
|
+
name: "#{e.channel.server.name} ##{e.channel.name}"
|
279
|
+
}
|
256
280
|
}
|
257
281
|
}.to_json
|
258
282
|
)
|
@@ -362,6 +386,16 @@ class QwtfDiscordBotPug # :nodoc:
|
|
362
386
|
end
|
363
387
|
|
364
388
|
def start_pug(pug, event)
|
389
|
+
if !pug.actual_teams.any?
|
390
|
+
teams = get_fair_teams(pug.joined_players)
|
391
|
+
|
392
|
+
teams.each do |team_no, player_ids|
|
393
|
+
player_ids.each do |player_id|
|
394
|
+
pug.join_team(team_no: team_no, player_id: player_id)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
365
399
|
pug_teams = pug.teams.map do |team_no, player_ids|
|
366
400
|
team_mentions = player_ids.map do |player_id|
|
367
401
|
event.mention_for(player_id)
|
@@ -428,4 +462,15 @@ class QwtfDiscordBotPug # :nodoc:
|
|
428
462
|
http.request(req)
|
429
463
|
end
|
430
464
|
end
|
465
|
+
|
466
|
+
def get_fair_teams(players)
|
467
|
+
uri = URI("#{ENV['RATINGS_API_URL']}fair_teams/new")
|
468
|
+
params = { 'players[]' => players }
|
469
|
+
uri.query = URI.encode_www_form(params)
|
470
|
+
req = Net::HTTP::Get.new(uri)
|
471
|
+
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
472
|
+
http.request(req)
|
473
|
+
end
|
474
|
+
JSON.parse(res.body).first.to_h
|
475
|
+
end
|
431
476
|
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.0
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|