qwtf_discord_bot 5.4.8 → 5.4.13

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: aa0cd4500b420de235f08b79fb20ae3ce42740811ee6a75a780d1c4a1b44125e
4
- data.tar.gz: c3d6bd3347b2661d6db8672bc659dab1a4efe78f13da96cc89e7339b6d21c02d
3
+ metadata.gz: 256bc5dd2a321a2e9495764c946142a36bdc4cec6f4871a70c3d8b2b6e0d1357
4
+ data.tar.gz: 16d3964888b04bdb1580ef62b1541375876dfdd2a24847ff60bc2927871f8ab3
5
5
  SHA512:
6
- metadata.gz: fb897f2b93c97bab3cb3d6fb391eb5b929b47afaf103998c3df41547385369dea49f99b8fdef59e28a4cb09c056088c57ef98fc54a1b5d9aae13e71f3a973106
7
- data.tar.gz: f4ffee4a777a3a4538d35d27c30068a3b3f2171aa087ec66f056885a6b5c93ef305faf088ae2736313dbb4acf7569402cb520fe9f1e2c88b8b052400965c0394
6
+ metadata.gz: c153a53da144bd6af78ea5013dd080d1f7da909ec532da2fa3787aa872ef03d778aaf30857d63ed204934cdfe5be3ff23aab166f6a747291ccb67f94ea23f10e
7
+ data.tar.gz: 986cc092056e071b8dcd877a4869d98911e9366253842f48e75df0f333445bfab71da2a6bab20e8242127a38a4fa187c930279497a3b632bc81ad63327972b65
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.4.8
1
+ 5.4.13
@@ -65,8 +65,9 @@ class QwtfDiscordBotPug # :nodoc:
65
65
  0
66
66
  end
67
67
 
68
- choose_fair_teams(pug: pug, event: e, iteration: iteration)
69
- status(pug: pug, event: e)
68
+
69
+ message_obj = choose_fair_teams(pug: pug, event: e, iteration: iteration)
70
+ status(pug: pug, event: e, message_obj: message_obj) if message_obj
70
71
  end
71
72
  end
72
73
 
@@ -260,15 +261,6 @@ class QwtfDiscordBotPug # :nodoc:
260
261
 
261
262
  user_id = mention_to_user_id(mention)
262
263
  display_name = e.display_name_for(user_id) || arg
263
-
264
- unless pug.joined?(user_id)
265
- send_embedded_message(
266
- description: "#{display_name} isn't in the PUG",
267
- channel: e.channel
268
- )
269
- next
270
- end
271
-
272
264
  pug.join_team(team_no: team_no, player_id: user_id)
273
265
 
274
266
  send_embedded_message(
@@ -296,26 +288,47 @@ class QwtfDiscordBotPug # :nodoc:
296
288
  )
297
289
  end
298
290
 
299
- unless pug.joined?(user_id)
300
- return send_embedded_message(
301
- description: "You aren't in this PUG",
302
- channel: e.channel
303
- )
304
- end
291
+ if args.empty?
292
+ unless pug.joined?(user_id)
293
+ return send_embedded_message(
294
+ description: "You aren't in this PUG",
295
+ channel: e.channel
296
+ )
297
+ end
305
298
 
306
- if pug.team(0).include?(user_id)
307
- return send_embedded_message(
308
- description: "You aren't in a team",
299
+ if pug.team(0).include?(user_id)
300
+ return send_embedded_message(
301
+ description: "You aren't in a team",
302
+ channel: e.channel
303
+ )
304
+ end
305
+
306
+ pug.join_team(team_no: 0, player_id: user_id)
307
+
308
+ send_embedded_message(
309
+ description: "#{e.display_name} leaves team",
309
310
  channel: e.channel
310
311
  )
311
- end
312
+ else
313
+ args.each do |mention|
314
+ unless mention.match(/<@!\d+>/)
315
+ send_embedded_message(
316
+ description: "#{arg} isn't a valid mention",
317
+ channel: e.channel
318
+ )
319
+ next
320
+ end
312
321
 
313
- pug.join_team(team_no: 0, player_id: user_id)
322
+ user_id = mention_to_user_id(mention)
323
+ display_name = e.display_name_for(user_id) || arg
324
+ pug.join_team(team_no: 0, player_id: user_id)
314
325
 
315
- send_embedded_message(
316
- description: "#{e.display_name} leaves team",
317
- channel: e.channel
318
- )
326
+ send_embedded_message(
327
+ description: "#{display_name} leaves team",
328
+ channel: e.channel
329
+ )
330
+ end
331
+ end
319
332
  end
320
333
  end
321
334
 
@@ -328,6 +341,13 @@ class QwtfDiscordBotPug # :nodoc:
328
341
  )
329
342
  end
330
343
 
344
+ if !pug.full?
345
+ return send_embedded_message(
346
+ description: "Can't report unless PUG is full",
347
+ channel: event.channel
348
+ )
349
+ end
350
+
331
351
  unless args.any?
332
352
  return send_embedded_message(
333
353
  description: "Specify winning team; e.g. `!win 1`",
@@ -360,7 +380,7 @@ class QwtfDiscordBotPug # :nodoc:
360
380
  teams.merge({ name => { players: players, result: result } })
361
381
  end
362
382
 
363
- post_results(
383
+ id = post_results(
364
384
  {
365
385
  match: {
366
386
  map: pug.game_map,
@@ -371,10 +391,10 @@ class QwtfDiscordBotPug # :nodoc:
371
391
  }
372
392
  }
373
393
  }.to_json
374
- )
394
+ ).body
375
395
 
376
396
  send_embedded_message(
377
- description: "#{TEAM_NAMES[winning_team_no]} wins. [Ratings](http://ratings.fortressone.org)",
397
+ description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. [Ratings](http://ratings.fortressone.org)",
378
398
  channel: e.channel
379
399
  )
380
400
  end
@@ -389,6 +409,13 @@ class QwtfDiscordBotPug # :nodoc:
389
409
  )
390
410
  end
391
411
 
412
+ if !pug.full?
413
+ return send_embedded_message(
414
+ description: "Can't report unless PUG is full",
415
+ channel: event.channel
416
+ )
417
+ end
418
+
392
419
  if pug.actual_teams.count < 2
393
420
  return send_embedded_message(
394
421
  description: "There must be at least two teams with players to submit a result",
@@ -404,7 +431,7 @@ class QwtfDiscordBotPug # :nodoc:
404
431
  teams.merge({ name => { players: players, result: 0 } })
405
432
  end
406
433
 
407
- post_results(
434
+ id = post_results(
408
435
  {
409
436
  match: {
410
437
  map: pug.game_map,
@@ -415,10 +442,10 @@ class QwtfDiscordBotPug # :nodoc:
415
442
  }
416
443
  }
417
444
  }.to_json
418
- )
445
+ ).body
419
446
 
420
447
  send_embedded_message(
421
- description: "Match drawn. [Ratings](http://ratings.fortressone.org)",
448
+ description: "Match ##{id} drawn. [Ratings](http://ratings.fortressone.org)",
422
449
  channel: e.channel
423
450
  )
424
451
  end
@@ -606,10 +633,10 @@ class QwtfDiscordBotPug # :nodoc:
606
633
  return send_embedded_message(
607
634
  description: "Can't choose teams until PUG is full",
608
635
  channel: event.channel
609
- )
636
+ ) && nil
610
637
  end
611
638
 
612
- send_embedded_message(
639
+ message_obj = send_embedded_message(
613
640
  description: "Choosing fair teams...",
614
641
  channel: event.channel
615
642
  )
@@ -620,8 +647,9 @@ class QwtfDiscordBotPug # :nodoc:
620
647
  if !teams
621
648
  return send_embedded_message(
622
649
  description: "There are only #{combinations.count} possible combinations",
623
- channel: event.channel
624
- )
650
+ channel: event.channel,
651
+ message_obj: message_obj
652
+ ) && nil
625
653
  end
626
654
 
627
655
  teams.each do |team_no, player_ids|
@@ -629,17 +657,20 @@ class QwtfDiscordBotPug # :nodoc:
629
657
  pug.join_team(team_no: team_no, player_id: player_id)
630
658
  end
631
659
  end
660
+
661
+ message_obj
632
662
  end
633
663
 
634
- def status(pug:, event:)
664
+ def status(pug:, event:, message_obj: nil)
635
665
  footer = [
636
- pug.game_map,
637
- "#{pug.player_slots} joined"
666
+ pug.game_map || "No map selected",
667
+ "#{pug.player_slots} joined",
638
668
  ].compact.join(MSG_SNIPPET_DELIMITER)
639
669
 
640
670
  send_embedded_message(
641
671
  description: nil,
642
- channel: event.channel
672
+ channel: event.channel,
673
+ message_obj: message_obj
643
674
  ) do |embed|
644
675
  embed.footer = Discordrb::Webhooks::EmbedFooter.new(
645
676
  text: footer
@@ -716,11 +747,20 @@ class QwtfDiscordBotPug # :nodoc:
716
747
  "There's no active PUG"
717
748
  end
718
749
 
719
- def send_embedded_message(message: nil, description: nil, channel:)
750
+ def send_embedded_message(message: nil, description: nil, channel:, message_obj: nil)
720
751
  embed = Discordrb::Webhooks::Embed.new
721
752
  embed.description = description
722
753
  yield(embed) if block_given?
723
- channel.send_embed(message, embed) && puts(message)
754
+
755
+ if message_obj
756
+ message_obj.edit(message, embed).tap do
757
+ puts(message)
758
+ end
759
+ else
760
+ channel.send_embed(message, embed).tap do
761
+ puts(message)
762
+ end
763
+ end
724
764
  end
725
765
 
726
766
  def post_results(json)
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.8
4
+ version: 5.4.13
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-28 00:00:00.000000000 Z
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb