qwtf_discord_bot 5.5.2 → 5.5.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/VERSION +1 -1
- data/lib/dashboard.rb +14 -18
- data/lib/pug.rb +19 -2
- data/lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb +4 -2
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +43 -9
- 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: 0a8c6eefd8588a9acd888fb745e2237883b750360db00b7bf5bc729eb9b548dd
|
4
|
+
data.tar.gz: 18e9d938af51b6131335adf47a94a2f1fa2ed59cba783f958351388163c970a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c530cc4676e80e3d75806e542192f3711f5eebd59255a59207243bf6e3a5903b83359f4139ebb99d26b46cbbc53a822fdd92108b45020e307d420a0b1532be0
|
7
|
+
data.tar.gz: 9dd8e00b8ab94b3215e73688908ec75bdac1aca71e71b5380e65b46a3833b317b8f632964f2f013de851a52af9f5bf3c5955bd606b539c702f0c72d96fa61854
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.5.
|
1
|
+
5.5.7
|
data/lib/dashboard.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
class Dashboard
|
2
|
-
def initialize(
|
3
|
-
@
|
4
|
-
@endpoints =
|
5
|
-
@bot = bot
|
2
|
+
def initialize(dashboard_config, bot)
|
3
|
+
@server = bot.server(dashboard_config["server_id"])
|
4
|
+
@endpoints = dashboard_config["endpoints"]
|
6
5
|
@messages = {}
|
6
|
+
|
7
|
+
old_dashboard_channel = @server.channels.find do |chan|
|
8
|
+
chan.name == "dashboard" && chan.topic = "QWTF Bot Dashboard"
|
9
|
+
end
|
10
|
+
|
11
|
+
old_dashboard_channel && old_dashboard_channel.delete
|
12
|
+
|
13
|
+
@channel = @server.create_channel("dashboard")
|
14
|
+
@channel.topic = "QWTF Bot Dashboard"
|
15
|
+
@channel.position = dashboard_config["position"]
|
7
16
|
end
|
8
17
|
|
9
18
|
def update
|
@@ -24,21 +33,8 @@ class Dashboard
|
|
24
33
|
@messages[endpoint] = if @messages[endpoint]
|
25
34
|
@messages[endpoint].edit(nil, embed)
|
26
35
|
else
|
27
|
-
channel.send_embed(nil, embed)
|
36
|
+
@channel.send_embed(nil, embed)
|
28
37
|
end
|
29
38
|
end
|
30
39
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def channel
|
35
|
-
data = Discordrb::API::Channel.resolve(
|
36
|
-
"Bot #{QwtfDiscordBot.config.token}",
|
37
|
-
@channel_id
|
38
|
-
)
|
39
|
-
|
40
|
-
puts JSON.parse(data)
|
41
|
-
|
42
|
-
Discordrb::Channel.new(JSON.parse(data), @bot)
|
43
|
-
end
|
44
40
|
end
|
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
|
|
@@ -133,6 +132,20 @@ class Pug
|
|
133
132
|
teams.tap { |team| team.delete(0) }
|
134
133
|
end
|
135
134
|
|
135
|
+
def unteam_all_players
|
136
|
+
joined_players.each do |player_id|
|
137
|
+
join_team(team_no: 0, player_id: player_id)
|
138
|
+
end
|
139
|
+
end
|
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
|
+
|
136
149
|
private
|
137
150
|
|
138
151
|
def leave_teams(player_id)
|
@@ -149,6 +162,10 @@ class Pug
|
|
149
162
|
[pug_key, 'teams', team_no].join(':')
|
150
163
|
end
|
151
164
|
|
165
|
+
def last_result_time_key
|
166
|
+
[channel_key, 'last_result_time'].join(':')
|
167
|
+
end
|
168
|
+
|
152
169
|
def pug_key
|
153
170
|
[channel_key, 'pug'].join(':')
|
154
171
|
end
|
@@ -17,8 +17,10 @@ class QwtfDiscordBotDashboard
|
|
17
17
|
end
|
18
18
|
)
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
bot.run(true) && sleep(5)
|
21
|
+
|
22
|
+
@dashboards ||= QwtfDiscordBot.config.dashboards.map do |dashboard_config|
|
23
|
+
Dashboard.new(dashboard_config, bot)
|
22
24
|
end
|
23
25
|
|
24
26
|
every(THIRTY_SECONDS) do
|
@@ -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,
|
@@ -393,8 +404,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
393
404
|
}.to_json
|
394
405
|
).body
|
395
406
|
|
407
|
+
pug.unteam_all_players
|
408
|
+
|
396
409
|
send_embedded_message(
|
397
|
-
description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. [Ratings](http://ratings.fortressone.org)",
|
410
|
+
description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Ratings](http://ratings.fortressone.org)",
|
398
411
|
channel: e.channel
|
399
412
|
)
|
400
413
|
end
|
@@ -423,6 +436,15 @@ class QwtfDiscordBotPug # :nodoc:
|
|
423
436
|
)
|
424
437
|
end
|
425
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
|
+
|
426
448
|
team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
|
427
449
|
players = player_ids.inject({}) do |memo, id|
|
428
450
|
memo.merge({ id => e.display_name_for(id) })
|
@@ -431,7 +453,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
431
453
|
teams.merge({ name => { players: players, result: 0 } })
|
432
454
|
end
|
433
455
|
|
434
|
-
id =
|
456
|
+
id = report(
|
457
|
+
pug,
|
435
458
|
{
|
436
459
|
match: {
|
437
460
|
map: pug.game_map,
|
@@ -444,8 +467,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
444
467
|
}.to_json
|
445
468
|
).body
|
446
469
|
|
470
|
+
pug.unteam_all_players
|
471
|
+
|
447
472
|
send_embedded_message(
|
448
|
-
description: "Match ##{id} drawn. [Ratings](http://ratings.fortressone.org)",
|
473
|
+
description: "Match ##{id} drawn. `!choose` again. [Ratings](http://ratings.fortressone.org)",
|
449
474
|
channel: e.channel
|
450
475
|
)
|
451
476
|
end
|
@@ -763,6 +788,11 @@ class QwtfDiscordBotPug # :nodoc:
|
|
763
788
|
end
|
764
789
|
end
|
765
790
|
|
791
|
+
def report(pug, json)
|
792
|
+
pug.update_last_result_time
|
793
|
+
post_results(json)
|
794
|
+
end
|
795
|
+
|
766
796
|
def post_results(json)
|
767
797
|
uri = URI("#{ENV['RATINGS_API_URL']}matches/")
|
768
798
|
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
@@ -785,4 +815,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
785
815
|
|
786
816
|
JSON.parse(res.body).map(&:to_h)
|
787
817
|
end
|
818
|
+
|
819
|
+
def one_minute_ago
|
820
|
+
Time.now.to_i - ONE_MINUTE
|
821
|
+
end
|
788
822
|
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.5.
|
4
|
+
version: 5.5.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-11-
|
11
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|