qwtf_discord_bot 5.5.11 → 5.5.16

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: d80c495a035630d38507c5cb5f1d523a40b92f6e0bb7be6703e60124657d9eaf
4
- data.tar.gz: d56c1c31f43fee69628d0ad10a631213a35f854a1109d0148c8b32486253254d
3
+ metadata.gz: bb00493577fe32e4a2f0a73fd049bec1c195d08f710d559d3bc61f3c399f8e9a
4
+ data.tar.gz: b9fe1647ba8814b8f2d25c5dbcaacd8c52c930f891f27fdded26028dae2ee392
5
5
  SHA512:
6
- metadata.gz: 9c99d3227ae01315b829469e9cb14c28041917506e331a75de7773ec48241ae40ba8985ae3a12eb8437e57e944c6561b2d26373bcb7cecc584798842337cc3ab
7
- data.tar.gz: 35dde220e2248935dd8e0f96bff722a35d9aecfc7b93f3c72dbba6bb0cd5fbfa3afb2943c36f18975c416fd763c505aa54903118ce60a372e6d5b67bd80d2053
6
+ metadata.gz: 03be912e0aa6aa8a46f9edad585bb4512aa1f22cf78689faabb4be646ba99bffe50cc03cddaf88e308c4fb40893d3d8107431dc2da3c7b59a809cec500d68381
7
+ data.tar.gz: 73bd5b3b894f3e422d983f1295959cb6cd12f165d47f5ce9f86481e6ff6731226fdc9b909051d0d00df67c6b586fa124bd880d72d992ca2406a00c7e91a2bc40
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.5.11
1
+ 5.5.16
data/lib/pug.rb CHANGED
@@ -147,6 +147,14 @@ class Pug
147
147
  redis.get(last_result_time_key).to_i
148
148
  end
149
149
 
150
+ def equal_number_of_players_on_each_team?
151
+ team_player_counts = actual_teams.map do |_name, players|
152
+ players.size
153
+ end
154
+
155
+ team_player_counts.uniq.size == 1
156
+ end
157
+
150
158
  private
151
159
 
152
160
  def leave_teams(player_id)
@@ -8,7 +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
+ TEN_MINUTES = 10 * 60
12
12
 
13
13
  def run
14
14
  bot = Discordrb::Commands::CommandBot.new(
@@ -46,6 +46,13 @@ class QwtfDiscordBotPug # :nodoc:
46
46
 
47
47
  bot.command :choose do |event, *args|
48
48
  setup_pug(event) do |e, pug|
49
+ if pug.joined_players.count > pug.maxplayers
50
+ return send_embedded_message(
51
+ description: "Too many players, increase `!teamsize` or `!kick` extras",
52
+ channel: event.channel
53
+ )
54
+ end
55
+
49
56
  if pug.joined_players.count.odd?
50
57
  return send_embedded_message(
51
58
  description: "Can't choose teams with odd number of players",
@@ -240,7 +247,13 @@ class QwtfDiscordBotPug # :nodoc:
240
247
  )
241
248
  end
242
249
 
243
- join_pug(e, pug) unless pug.joined?(user_id)
250
+ if pug.team(team_no).size >= pug.teamsize
251
+ return send_embedded_message(
252
+ description: "Team is full",
253
+ channel: e.channel
254
+ )
255
+ end
256
+
244
257
  pug.join_team(team_no: team_no, player_id: user_id)
245
258
 
246
259
  send_embedded_message(
@@ -252,6 +265,13 @@ class QwtfDiscordBotPug # :nodoc:
252
265
  )
253
266
  else
254
267
  args[1..-1].each do |mention|
268
+ if pug.team(team_no).size >= pug.teamsize
269
+ return send_embedded_message(
270
+ description: "Team is full",
271
+ channel: e.channel
272
+ )
273
+ end
274
+
255
275
  unless mention.match(/<@!\d+>/)
256
276
  send_embedded_message(
257
277
  description: "#{arg} isn't a valid mention",
@@ -356,6 +376,13 @@ class QwtfDiscordBotPug # :nodoc:
356
376
  )
357
377
  end
358
378
 
379
+ if !pug.equal_number_of_players_on_each_team?
380
+ return send_embedded_message(
381
+ description: "Can't report unless teams have same number of players",
382
+ channel: event.channel
383
+ )
384
+ end
385
+
359
386
  unless ["1", "2"].any?(args.first)
360
387
  return send_embedded_message(
361
388
  description: "Invalid team number",
@@ -363,11 +390,9 @@ class QwtfDiscordBotPug # :nodoc:
363
390
  )
364
391
  end
365
392
 
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
-
393
+ if pug.last_result_time && pug.last_result_time > ten_minutes_ago
369
394
  return send_embedded_message(
370
- description: "Please wait #{ONE_MINUTE - time_ago} more seconds before reporting",
395
+ description: "A match was reported less than 10 minutes ago",
371
396
  channel: event.channel
372
397
  )
373
398
  end
@@ -404,8 +429,6 @@ class QwtfDiscordBotPug # :nodoc:
404
429
  }.to_json
405
430
  ).body
406
431
 
407
- pug.unteam_all_players
408
-
409
432
  send_embedded_message(
410
433
  description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Ratings](http://ratings.fortressone.org)",
411
434
  channel: e.channel
@@ -429,6 +452,13 @@ class QwtfDiscordBotPug # :nodoc:
429
452
  )
430
453
  end
431
454
 
455
+ if !pug.equal_number_of_players_on_each_team?
456
+ return send_embedded_message(
457
+ description: "Can't report unless teams have same number of players",
458
+ channel: event.channel
459
+ )
460
+ end
461
+
432
462
  if pug.actual_teams.count < 2
433
463
  return send_embedded_message(
434
464
  description: "There must be at least two teams with players to submit a result",
@@ -436,11 +466,11 @@ class QwtfDiscordBotPug # :nodoc:
436
466
  )
437
467
  end
438
468
 
439
- if pug.last_result_time && pug.last_result_time > one_minute_ago
469
+ if pug.last_result_time && pug.last_result_time > ten_minutes_ago
440
470
  time_ago = Time.now.to_i - pug.last_result_time
441
471
 
442
472
  return send_embedded_message(
443
- description: "Please wait #{ONE_MINUTE - time_ago} more seconds before reporting",
473
+ description: "A match was reported less than 10 minutes ago",
444
474
  channel: event.channel
445
475
  )
446
476
  end
@@ -467,8 +497,6 @@ class QwtfDiscordBotPug # :nodoc:
467
497
  }.to_json
468
498
  ).body
469
499
 
470
- pug.unteam_all_players
471
-
472
500
  send_embedded_message(
473
501
  description: "Match ##{id} drawn. `!choose` again. [Ratings](http://ratings.fortressone.org)",
474
502
  channel: e.channel
@@ -816,7 +844,7 @@ class QwtfDiscordBotPug # :nodoc:
816
844
  JSON.parse(res.body).map(&:to_h)
817
845
  end
818
846
 
819
- def one_minute_ago
820
- Time.now.to_i - ONE_MINUTE
847
+ def ten_minutes_ago
848
+ Time.now.to_i - TEN_MINUTES
821
849
  end
822
850
  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.11
4
+ version: 5.5.16
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-12-03 00:00:00.000000000 Z
11
+ date: 2020-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb