qwtf_discord_bot 5.5.4 → 5.5.5
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/pug.rb +13 -2
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +37 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f51fa8d63ad6a2e6e0e08e3e83c851930694ba6208a70469d95f3322f3a5215
|
4
|
+
data.tar.gz: f0d9139fab06e85aae6fe4d563cff3a13acd7ae88e0ba680c2add202a7c541e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ac22beba9007bc30f809e3ab82ad382e078ba8036c71f91474ccad8b301b0b850a0b04dfa0529bfc4755aaa84bf82769846c72706dca4dcd7ca1c301f271457
|
7
|
+
data.tar.gz: 341a554d68f4680b09d22dcdc08f16c711c6d86271811e66810d61f6660d628a1cac7a656ba23724e593d1ec638dd7512484cc5af2007ce6d1897b58cba30e64
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.5.
|
1
|
+
5.5.5
|
data/lib/pug.rb
CHANGED
@@ -11,8 +11,7 @@ class Pug
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def join(player_id)
|
14
|
-
redis.setnx(pug_key, Time.now)
|
15
|
-
|
14
|
+
redis.setnx(pug_key, Time.now.to_i)
|
16
15
|
redis.sadd(team_key(0), player_id)
|
17
16
|
end
|
18
17
|
|
@@ -139,6 +138,14 @@ class Pug
|
|
139
138
|
end
|
140
139
|
end
|
141
140
|
|
141
|
+
def update_last_result_time
|
142
|
+
redis.set(last_result_time_key, Time.now.to_i)
|
143
|
+
end
|
144
|
+
|
145
|
+
def last_result_time
|
146
|
+
redis.get(last_result_time_key).to_i
|
147
|
+
end
|
148
|
+
|
142
149
|
private
|
143
150
|
|
144
151
|
def leave_teams(player_id)
|
@@ -155,6 +162,10 @@ class Pug
|
|
155
162
|
[pug_key, 'teams', team_no].join(':')
|
156
163
|
end
|
157
164
|
|
165
|
+
def last_result_time_key
|
166
|
+
[channel_key, 'last_result_time'].join(':')
|
167
|
+
end
|
168
|
+
|
158
169
|
def pug_key
|
159
170
|
[channel_key, 'pug'].join(':')
|
160
171
|
end
|
@@ -8,6 +8,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
8
8
|
|
9
9
|
MSG_SNIPPET_DELIMITER = ' · '
|
10
10
|
TEAM_NAMES = { 1 => "Blue", 2 => "Red" }
|
11
|
+
ONE_MINUTE = 60
|
11
12
|
|
12
13
|
def run
|
13
14
|
bot = Discordrb::Commands::CommandBot.new(
|
@@ -334,6 +335,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
334
335
|
|
335
336
|
bot.command :win do |event, *args|
|
336
337
|
setup_pug(event) do |e, pug|
|
338
|
+
unless args.any?
|
339
|
+
return send_embedded_message(
|
340
|
+
description: "Specify winning team; e.g. `!win 1`",
|
341
|
+
channel: e.channel
|
342
|
+
)
|
343
|
+
end
|
344
|
+
|
337
345
|
unless pug.active?
|
338
346
|
return send_embedded_message(
|
339
347
|
description: no_active_pug_message,
|
@@ -348,17 +356,19 @@ class QwtfDiscordBotPug # :nodoc:
|
|
348
356
|
)
|
349
357
|
end
|
350
358
|
|
351
|
-
unless
|
359
|
+
unless ["1", "2"].any?(args.first)
|
352
360
|
return send_embedded_message(
|
353
|
-
description: "
|
361
|
+
description: "Invalid team number",
|
354
362
|
channel: e.channel
|
355
363
|
)
|
356
364
|
end
|
357
365
|
|
358
|
-
|
366
|
+
if pug.last_result_time && pug.last_result_time > one_minute_ago
|
367
|
+
time_ago = Time.now.to_i - pug.last_result_time
|
368
|
+
|
359
369
|
return send_embedded_message(
|
360
|
-
description: "
|
361
|
-
channel:
|
370
|
+
description: "Please wait #{ONE_MINUTE - time_ago} more seconds before reporting",
|
371
|
+
channel: event.channel
|
362
372
|
)
|
363
373
|
end
|
364
374
|
|
@@ -380,7 +390,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
380
390
|
teams.merge({ name => { players: players, result: result } })
|
381
391
|
end
|
382
392
|
|
383
|
-
id =
|
393
|
+
id = report(
|
394
|
+
pug,
|
384
395
|
{
|
385
396
|
match: {
|
386
397
|
map: pug.game_map,
|
@@ -425,6 +436,15 @@ class QwtfDiscordBotPug # :nodoc:
|
|
425
436
|
)
|
426
437
|
end
|
427
438
|
|
439
|
+
if pug.last_result_time && pug.last_result_time > one_minute_ago
|
440
|
+
time_ago = Time.now.to_i - pug.last_result_time
|
441
|
+
|
442
|
+
return send_embedded_message(
|
443
|
+
description: "Please wait #{ONE_MINUTE - time_ago} more seconds before reporting",
|
444
|
+
channel: event.channel
|
445
|
+
)
|
446
|
+
end
|
447
|
+
|
428
448
|
team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
|
429
449
|
players = player_ids.inject({}) do |memo, id|
|
430
450
|
memo.merge({ id => e.display_name_for(id) })
|
@@ -433,7 +453,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
433
453
|
teams.merge({ name => { players: players, result: 0 } })
|
434
454
|
end
|
435
455
|
|
436
|
-
id =
|
456
|
+
id = report(
|
457
|
+
pug,
|
437
458
|
{
|
438
459
|
match: {
|
439
460
|
map: pug.game_map,
|
@@ -767,6 +788,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
767
788
|
end
|
768
789
|
end
|
769
790
|
|
791
|
+
def report(pug, json)
|
792
|
+
pug.update_last_result_time
|
793
|
+
post_results(json)
|
794
|
+
end
|
795
|
+
|
770
796
|
def post_results(json)
|
771
797
|
uri = URI("#{ENV['RATINGS_API_URL']}matches/")
|
772
798
|
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
@@ -789,4 +815,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
789
815
|
|
790
816
|
JSON.parse(res.body).map(&:to_h)
|
791
817
|
end
|
818
|
+
|
819
|
+
def one_minute_ago
|
820
|
+
Time.now.to_i - ONE_MINUTE
|
821
|
+
end
|
792
822
|
end
|