qwtf_discord_bot 5.5.1 → 5.5.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1d76ac11d350eb38fbb60579e3ce26d561066f17e1bcda29029791afd98d36f
4
- data.tar.gz: 1e75a7c3cecf17134bd41e2a9370bce29f82260319cd4d78bd9e9638e1c8e3af
3
+ metadata.gz: 3b23056513d2164179b74059da9679cad97749b7b541a72c3cfc5dd5f4cf7f8e
4
+ data.tar.gz: cdea90ab6a7539a83aa4cb80a8c3766d0931c78ece2d197905b351b53b0a3540
5
5
  SHA512:
6
- metadata.gz: d13de4098fde37b346b4a668befed0c59ba73cae7a7640b69356064d1446c081af3b0552ef651896bd4c08b2548882a1386508992f12022717e9519eb5317dd2
7
- data.tar.gz: c0868734a288588818370904904a407789857c74164d4b4ef42e27bafc68724238dcd4235bd7c625d79f72949109eef08ead1f03e2dea5a9ab39472132d2e1be
6
+ metadata.gz: 0ae5e3ab1a227bfe61805e53ffdcdb5ceeb90b541eb693a7bb17f45cf510185a0efc004f3f8b6aabc11192aaf413ed5e0510d1720992efcf62d456baeda00169
7
+ data.tar.gz: 9c012e37ca4c35697513e5ff082d7ab5d6060b05280f9daa01e8aa156848a8cebb3594130e86b1fc3bfcdf148096c3c39ea024b1f01461e6d034aa618a79fb3f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.5.1
1
+ 5.5.6
@@ -1,9 +1,18 @@
1
1
  class Dashboard
2
- def initialize(channel, bot)
3
- @channel_id = channel["id"]
4
- @endpoints = channel["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,19 +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
- Discordrb::Channel.new(JSON.parse(data), @bot)
41
- end
42
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
- @dashboards ||= QwtfDiscordBot.config.dashboards.map do |channel|
21
- Dashboard.new(channel, bot)
20
+ bot.run(true)
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 args.any?
359
+ unless ["1", "2"].any?(args.first)
352
360
  return send_embedded_message(
353
- description: "Specify winning team; e.g. `!win 1`",
361
+ description: "Invalid team number",
354
362
  channel: e.channel
355
363
  )
356
364
  end
357
365
 
358
- unless ["1", "2"].any?(args.first)
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: "Invalid team number",
361
- channel: e.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 = post_results(
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 = post_results(
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.1
4
+ version: 5.5.6
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-15 00:00:00.000000000 Z
11
+ date: 2020-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb