qwtf_discord_bot 6.1.2 → 6.2.0

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: 6ac5cd6d9034e9742121d3a1f73e2b7b4dcfdd88f6d38ac4092857b1c73a1cb2
4
- data.tar.gz: af41c6aa3d43e94a8e9834d087716df7f7913dea4e5366c416673ed995a53571
3
+ metadata.gz: 1bfa9a0b1f5ad3c3206d216e1e266d2749e081c6dc3c58e77994ec997f64fe2f
4
+ data.tar.gz: 215a86a21d79da634525e031ad7408ad0f1c2b3ee2eced49ec2dc9f7dfffd8f1
5
5
  SHA512:
6
- metadata.gz: edc080da2401d91e932fe1a0afc338503e58773fafbaff1290827829e3c30006c529a9cc0f0d9ae0b460feb6d1ef440e12fd8cdebcda74fca941ffa6361c690d
7
- data.tar.gz: 3864eddf20434aa1e22baf84848b76a871f51453eb95979b5738b275d9438252596eb3ab08c171caa2f2824d77dfcb5e26ef15cf5a9a4f83081b6b4c0f2031b6
6
+ metadata.gz: b206b70ee1b67653022619909db86705c05f08006cc712179d00ec30b556fb64ea901f164395c7f8ad35649bf5c67a082f858d46b50fae4c4ee690be5b194ae6
7
+ data.tar.gz: 8174cd63f0589c839a2a47509d8de220d7ef8b96c82fec9b38501a4bdac56000767c0425a8b55c10d858e8c5b0d919f8a7763a680775316ae1ef286818b6380a
data/Gemfile CHANGED
@@ -6,9 +6,11 @@ gem 'bundler'
6
6
  gem 'discordrb', '3.4.0'
7
7
  gem 'redis'
8
8
  gem 'thor'
9
+ gem 'activesupport'
9
10
 
10
11
  group :development do
11
12
  gem 'pry'
13
+ gem 'dotenv'
12
14
  end
13
15
 
14
16
  group :test do
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qwtf_discord_bot (6.1.2)
4
+ qwtf_discord_bot (6.2.0)
5
+ activesupport (~> 6.1)
5
6
  discordrb (= 3.4.0)
6
7
  redis (~> 4.2)
7
8
  thor (~> 1.1)
@@ -28,6 +29,7 @@ GEM
28
29
  rest-client (>= 2.1.0.rc1)
29
30
  domain_name (0.5.20190701)
30
31
  unf (>= 0.0.5, < 1.0.0)
32
+ dotenv (2.7.6)
31
33
  event_emitter (0.2.6)
32
34
  factory_bot (6.1.0)
33
35
  activesupport (>= 5.0.0)
@@ -83,8 +85,10 @@ PLATFORMS
83
85
  x86_64-linux
84
86
 
85
87
  DEPENDENCIES
88
+ activesupport
86
89
  bundler
87
90
  discordrb (= 3.4.0)
91
+ dotenv
88
92
  factory_bot
89
93
  pry
90
94
  qwtf_discord_bot!
@@ -93,4 +97,4 @@ DEPENDENCIES
93
97
  thor
94
98
 
95
99
  BUNDLED WITH
96
- 2.2.8
100
+ 2.2.21
data/README.md CHANGED
@@ -105,6 +105,7 @@ This responds to discord messages:
105
105
  - `!maps`
106
106
  - `!map [map_name]`
107
107
  - `!choose [n]`
108
+ - `!shuffle`
108
109
  - `!win <team_no>`
109
110
  - `!draw`
110
111
  - `!notify <@role>`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.1.2
1
+ 6.2.0
data/exe/qwtf_discord_bot CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'dotenv/load'
3
4
  require 'qwtf_discord_bot'
4
5
  require 'thor'
5
6
  require 'pry'
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'pug'
4
4
  require 'event_decorator'
5
+ require 'active_support/core_ext/array/conversions'
5
6
 
6
7
  class QwtfDiscordBotPug # :nodoc:
7
8
  include QwtfDiscordBot
@@ -9,6 +10,29 @@ class QwtfDiscordBotPug # :nodoc:
9
10
  MSG_SNIPPET_DELIMITER = ' · '
10
11
  TEAM_NAMES = { 1 => "Blue", 2 => "Red" }
11
12
  TEN_MINUTES = 10 * 60
13
+ VALID_MENTION = /<@!?\d+>/
14
+
15
+ COMMANDS = <<~MESSAGE
16
+ `!status` Shows who has joined
17
+ `!join [@player1] [@player2]` Join PUG. Can also join other players
18
+ `!leave` Leave PUG
19
+ `!kick <@player> [@player2]` Kick one or more other players
20
+ `!team <team_no> [@player1] [@player2]` Join team
21
+ `!unteam [@player1] [@player2]` Leave team and go to front of queue
22
+ `!choose [n]` Choose fair teams. Pass number for nth fairest team
23
+ `!shuffle` Choose random teams.
24
+ `!win <team_no>` Report winning team
25
+ `!draw` Report draw
26
+ `!end` End PUG. Kicks all players
27
+ `!teamsize <no_of_players>` Set number of players in a team
28
+ `!addmap <map_name>` Add map to map list
29
+ `!removemap <map_name>` Remove map from map list
30
+ `!maps` Show map list
31
+ `!map [map_name]` Show or set map
32
+ `!notify <@role>` Set @role for alerts
33
+ MESSAGE
34
+
35
+ HELP = { commands: COMMANDS, footer: "!command <required> [optional]" }
12
36
 
13
37
  def run
14
38
  bot = Discordrb::Commands::CommandBot.new(
@@ -27,19 +51,80 @@ class QwtfDiscordBotPug # :nodoc:
27
51
  )
28
52
 
29
53
  bot.command :help do |event, *args|
30
- "Pug commands: `!status`, `!join`, `!team <team_no> [@player1] [@player2]`, `!unteam`, `!leave`, `!kick <@player>`, `!win <team_no>`, `!draw`, `!end`, `!teamsize <no_of_players>`, `!addmap <map_name>`, `!removemap <map_name>`, `!maps`, `!map [map_name]`, `!choose [n]`, `!notify <@role>`"
54
+ send_embedded_message(
55
+ description: HELP[:commands],
56
+ channel: event.channel
57
+ ) do |embed|
58
+ embed.footer = Discordrb::Webhooks::EmbedFooter.new(
59
+ text: HELP[:footer]
60
+ )
61
+ end
31
62
  end
32
63
 
33
64
  bot.command :join do |event, *args|
34
65
  setup_pug(event) do |e, pug|
35
- if pug.joined?(e.user_id)
36
- return send_embedded_message(
37
- description: "You've already joined",
66
+ if args.empty?
67
+ if pug.joined?(e.user_id)
68
+ return send_embedded_message(
69
+ description: "You've already joined",
70
+ channel: e.channel
71
+ )
72
+ end
73
+
74
+ join_pug(e, pug)
75
+ else
76
+ errors = []
77
+ joiners = []
78
+
79
+ args.each do |mention|
80
+ if !mention.match(VALID_MENTION)
81
+ errors << "#{mention} isn't a valid mention"
82
+ next
83
+ end
84
+
85
+ user_id = mention_to_user_id(mention)
86
+ display_name = e.display_name_for(user_id) || mention
87
+
88
+ if pug.joined?(user_id)
89
+ errors << "#{display_name} is already in this PUG"
90
+ next
91
+ end
92
+
93
+ pug.join(user_id)
94
+ joiners << display_name
95
+ end
96
+
97
+ message = ""
98
+ description = []
99
+
100
+ if pug.total_player_count == 0
101
+ message = "#{pug.notify_roles} PUG started"
102
+ description << "#{e.display_name} creates a PUG"
103
+ elsif pug.slots_left.between?(1, 3)
104
+ message = "#{pug.slots_left} more #{pug.notify_roles}"
105
+ end
106
+
107
+ if joiners.any?
108
+ description << [
109
+ joiners.to_sentence,
110
+ joiners.count == 1 ? "joins" : "join",
111
+ "the PUG"
112
+ ].join(" ")
113
+ end
114
+
115
+ description << [
116
+ pug.total_player_count,
117
+ pug.maxplayers
118
+ ].join("/")
119
+
120
+
121
+ send_embedded_message(
122
+ message: message,
123
+ description: [errors, description.join(MSG_SNIPPET_DELIMITER)].join("\n"),
38
124
  channel: e.channel
39
125
  )
40
126
  end
41
127
 
42
- join_pug(e, pug)
43
128
  start_pug(pug, e) if pug.has_exactly_maxplayers?
44
129
  end
45
130
  end
@@ -66,7 +151,21 @@ class QwtfDiscordBotPug # :nodoc:
66
151
  0
67
152
  end
68
153
 
69
- message_obj = choose_fair_teams(pug: pug, event: e, iteration: iteration)
154
+ message_obj = choose_teams(pug: pug, event: e, iteration: iteration)
155
+ status(pug: pug, event: e, message_obj: message_obj) if message_obj
156
+ end
157
+ end
158
+
159
+ bot.command :shuffle do |event|
160
+ setup_pug(event) do |e, pug|
161
+ if !pug.full?
162
+ return send_embedded_message(
163
+ description: "Not enough players, reduce !teamsize",
164
+ channel: event.channel
165
+ )
166
+ end
167
+
168
+ message_obj = choose_teams(pug: pug, event: e)
70
169
  status(pug: pug, event: e, message_obj: message_obj) if message_obj
71
170
  end
72
171
  end
@@ -170,56 +269,70 @@ class QwtfDiscordBotPug # :nodoc:
170
269
  )
171
270
  end
172
271
 
173
- args.each do |arg|
174
- unless arg.match(/<@!\d+>/)
175
- send_embedded_message(
176
- description: "#{arg} isn't a valid mention",
177
- channel: e.channel
178
- )
272
+ errors = []
273
+ kickees = []
274
+
275
+ args.each do |mention|
276
+ if !mention.match(VALID_MENTION)
277
+ errors << "#{mention} isn't a valid mention"
179
278
  next
180
279
  end
181
280
 
182
- user_id = mention_to_user_id(arg)
183
- display_name = e.display_name_for(user_id) || arg
281
+ user_id = mention_to_user_id(mention)
282
+ display_name = e.display_name_for(user_id) || mention
184
283
 
185
284
  unless pug.joined?(user_id)
186
- send_embedded_message(
187
- description: "#{display_name} isn't in the PUG",
188
- channel: e.channel
189
- )
285
+ errors << "#{display_name} isn't in the PUG"
190
286
  next
191
287
  end
192
288
 
193
289
  pug.leave(user_id)
194
290
 
195
- snippets = [
196
- "#{display_name} is kicked from the PUG",
197
- "#{pug.player_slots} remain"
198
- ]
291
+ kickees << display_name
292
+ end
199
293
 
200
- message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
294
+ message = ""
295
+ description = []
201
296
 
202
- send_embedded_message(
203
- message: message,
204
- description: snippets.join(MSG_SNIPPET_DELIMITER),
205
- channel: e.channel
206
- )
297
+ if pug.slots_left == 1
298
+ message = "#{pug.slots_left} more #{pug.notify_roles}"
299
+ end
207
300
 
208
- break end_pug(pug, e.channel) if pug.empty?
301
+ if kickees.any?
302
+ description << [
303
+ kickees.to_sentence,
304
+ kickees.count == 1 ? "is" : "are",
305
+ "kicked from the PUG"
306
+ ].join(" ")
209
307
  end
308
+
309
+ description << [
310
+ [pug.total_player_count, pug.maxplayers].join("/"),
311
+ "remain"
312
+ ].join(" ")
313
+
314
+ description = [errors, description.join(MSG_SNIPPET_DELIMITER)].join("\n")
315
+
316
+ send_embedded_message(
317
+ message: message,
318
+ description: description,
319
+ channel: e.channel
320
+ )
321
+
322
+ end_pug(pug, e.channel) if pug.empty?
210
323
  end
211
324
  end
212
325
 
213
326
  bot.command :team do |event, *args|
214
327
  setup_pug(event) do |e, pug|
215
- unless args.any?
328
+ if args.empty?
216
329
  return send_embedded_message(
217
330
  description: "Which team? E.G. `!team 1`",
218
331
  channel: e.channel
219
332
  )
220
333
  end
221
334
 
222
- unless ["1", "2"].any?(args.first)
335
+ if ["1", "2"].none?(args.first)
223
336
  return send_embedded_message(
224
337
  description: "Choose `!team 1`, `!team 2`, or `!unteam` to leave team",
225
338
  channel: e.channel
@@ -249,27 +362,38 @@ class QwtfDiscordBotPug # :nodoc:
249
362
  channel: e.channel
250
363
  )
251
364
  else
365
+ errors = []
366
+ teamers = []
367
+
252
368
  args[1..-1].each do |mention|
253
- unless mention.match(/<@!\d+>/)
254
- send_embedded_message(
255
- description: "#{arg} isn't a valid mention",
256
- channel: e.channel
257
- )
369
+ if !mention.match(VALID_MENTION)
370
+ errors << "#{mention} isn't a valid mention"
258
371
  next
259
372
  end
260
373
 
261
374
  user_id = mention_to_user_id(mention)
262
- display_name = e.display_name_for(user_id) || arg
375
+ display_name = e.display_name_for(user_id) || mention
263
376
  pug.join_team(team_no: team_no, player_id: user_id)
264
377
 
265
- send_embedded_message(
266
- description: [
267
- "#{display_name} joins #{TEAM_NAMES[team_no]}",
268
- "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
269
- ].join(MSG_SNIPPET_DELIMITER),
270
- channel: e.channel
271
- )
378
+ teamers << display_name
272
379
  end
380
+
381
+ description = errors << [
382
+ [
383
+ teamers.to_sentence,
384
+ teamers.count == 1 ? "joins" : "join",
385
+ TEAM_NAMES[team_no]
386
+ ].join(" "),
387
+ [
388
+ pug.team_player_count(team_no),
389
+ pug.teamsize
390
+ ].join("/")
391
+ ].join(MSG_SNIPPET_DELIMITER)
392
+
393
+ send_embedded_message(
394
+ description: description.join("\n"),
395
+ channel: e.channel
396
+ )
273
397
  end
274
398
 
275
399
  start_pug(pug, e) if !pug_already_full && pug.has_exactly_maxplayers?
@@ -280,7 +404,7 @@ class QwtfDiscordBotPug # :nodoc:
280
404
  setup_pug(event) do |e, pug|
281
405
  user_id = e.user_id
282
406
 
283
- unless pug.active?
407
+ if !pug.active?
284
408
  return send_embedded_message(
285
409
  description: 'No PUG has been started. `!join` to create',
286
410
  channel: e.channel
@@ -288,7 +412,7 @@ class QwtfDiscordBotPug # :nodoc:
288
412
  end
289
413
 
290
414
  if args.empty?
291
- unless pug.joined?(user_id)
415
+ if !pug.joined?(user_id)
292
416
  return send_embedded_message(
293
417
  description: "You aren't in this PUG",
294
418
  channel: e.channel
@@ -309,24 +433,38 @@ class QwtfDiscordBotPug # :nodoc:
309
433
  channel: e.channel
310
434
  )
311
435
  else
436
+ errors = []
437
+ unteamers = []
438
+
312
439
  args.each do |mention|
313
- unless mention.match(/<@!\d+>/)
314
- send_embedded_message(
315
- description: "#{arg} isn't a valid mention",
316
- channel: e.channel
317
- )
440
+ if !mention.match(VALID_MENTION)
441
+ errors << "#{mention} isn't a valid mention"
318
442
  next
319
443
  end
320
444
 
321
445
  user_id = mention_to_user_id(mention)
322
- display_name = e.display_name_for(user_id) || arg
446
+ display_name = e.display_name_for(user_id) || mention
447
+
448
+ if !pug.joined?(user_id)
449
+ errors << "#{display_name} isn't in this PUG"
450
+ next
451
+ end
452
+
323
453
  pug.unteam(user_id)
324
454
 
325
- send_embedded_message(
326
- description: "#{display_name} leaves team",
327
- channel: e.channel
328
- )
455
+ unteamers << display_name
329
456
  end
457
+
458
+ description = errors << [
459
+ unteamers.to_sentence,
460
+ unteamers.count == 1 ? "goes" : "go",
461
+ "into the queue"
462
+ ].join(" ")
463
+
464
+ send_embedded_message(
465
+ description: description.join("\n"),
466
+ channel: e.channel
467
+ )
330
468
  end
331
469
  end
332
470
  end
@@ -408,7 +546,7 @@ class QwtfDiscordBotPug # :nodoc:
408
546
  ).body
409
547
 
410
548
  send_embedded_message(
411
- description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Ratings](#{discord_channel_leaderboard_url(e.channel.id)})",
549
+ description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Results](#{discord_channel_leaderboard_url(e.channel.id)})",
412
550
  channel: e.channel
413
551
  )
414
552
  end
@@ -476,7 +614,7 @@ class QwtfDiscordBotPug # :nodoc:
476
614
  ).body
477
615
 
478
616
  send_embedded_message(
479
- description: "Match ##{id} drawn. `!choose` again. [Ratings](#{discord_channel_leaderboard_url(e.channel.id)})",
617
+ description: "Match ##{id} drawn. `!choose` again. [Results](#{discord_channel_leaderboard_url(e.channel.id)})",
480
618
  channel: e.channel
481
619
  )
482
620
  end
@@ -631,7 +769,7 @@ class QwtfDiscordBotPug # :nodoc:
631
769
  end
632
770
 
633
771
  def mention_to_user_id(mention)
634
- mention[3..-2].to_i
772
+ mention[/\d+/].to_i
635
773
  end
636
774
 
637
775
  def join_pug(e, pug)
@@ -639,7 +777,7 @@ class QwtfDiscordBotPug # :nodoc:
639
777
 
640
778
  if pug.total_player_count == 1
641
779
  snippets = ["#{e.display_name} creates a PUG", "#{pug.player_slots} joined"]
642
- message = pug.notify_roles
780
+ message = "#{pug.notify_roles} PUG started"
643
781
  else
644
782
  snippets = ["#{e.display_name} joins the PUG", "#{pug.player_slots} joined"]
645
783
  message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left.between?(1, 3)
@@ -659,7 +797,7 @@ class QwtfDiscordBotPug # :nodoc:
659
797
  nil # stop discordrb printing return value
660
798
  end
661
799
 
662
- def choose_fair_teams(pug:, event:, iteration: 0)
800
+ def choose_teams(pug:, event:, iteration: nil)
663
801
  if !pug.full?
664
802
  return send_embedded_message(
665
803
  description: "Not enough players, reduce !teamsize",
@@ -668,7 +806,7 @@ class QwtfDiscordBotPug # :nodoc:
668
806
  end
669
807
 
670
808
  message_obj = send_embedded_message(
671
- description: "Choosing fair teams...",
809
+ description: "Choosing teams...",
672
810
  channel: event.channel
673
811
  )
674
812
 
@@ -676,14 +814,18 @@ class QwtfDiscordBotPug # :nodoc:
676
814
  channel_id: event.channel.id, players: pug.up_now_players
677
815
  )
678
816
 
679
- teams = combinations[iteration]
817
+ if iteration
818
+ teams = combinations[iteration]
680
819
 
681
- if !teams
682
- return send_embedded_message(
683
- description: "There are only #{combinations.count} possible combinations",
684
- channel: event.channel,
685
- message_obj: message_obj
686
- ) && nil
820
+ if !teams
821
+ return send_embedded_message(
822
+ description: "There are only #{combinations.count} possible combinations",
823
+ channel: event.channel,
824
+ message_obj: message_obj
825
+ ) && nil
826
+ end
827
+ else
828
+ teams = combinations.sample
687
829
  end
688
830
 
689
831
  pug.destroy_teams
@@ -739,8 +881,6 @@ class QwtfDiscordBotPug # :nodoc:
739
881
  end
740
882
 
741
883
  def start_pug(pug, event)
742
- choose_fair_teams(pug: pug, event: event) unless pug.teams.any?
743
-
744
884
  footer = [
745
885
  pug.game_map,
746
886
  "#{pug.player_slots} joined",
@@ -750,7 +890,7 @@ class QwtfDiscordBotPug # :nodoc:
750
890
  event.mention_for(player_id)
751
891
  end
752
892
 
753
- mention_line = "Time to play! #{mentions.join(" ")}"
893
+ mention_line = "`!choose`, `!shuffle` or `!team` up. #{mentions.join(" ")}"
754
894
 
755
895
  send_embedded_message(
756
896
  message: mention_line,
@@ -47,7 +47,7 @@ class QwtfDiscordBotServer
47
47
  request = QstatRequest.new(endpoint.address)
48
48
 
49
49
  if !request.live_server?
50
- event.channel.send_message("#{endpoint} isn't responding")
50
+ event.channel.send_message("#{endpoint.address} isn't responding")
51
51
  else
52
52
  event.channel.send_embed(nil, request.to_full_embed)
53
53
  end
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency 'discordrb', '3.4.0'
31
31
  spec.add_runtime_dependency 'redis', '~> 4.2'
32
32
  spec.add_runtime_dependency 'thor', '~>1.1'
33
+ spec.add_runtime_dependency 'activesupport', '~>6.1'
33
34
  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: 6.1.2
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Johnson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-13 00:00:00.000000000 Z
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6.1'
55
69
  description: A Discord bot for reporting on QuakeWorld Team Fortress game servers
56
70
  email:
57
71
  - shayolden@hotmail.com
@@ -141,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
155
  - !ruby/object:Gem::Version
142
156
  version: '0'
143
157
  requirements: []
144
- rubygems_version: 3.2.3
158
+ rubygems_version: 3.2.15
145
159
  signing_key:
146
160
  specification_version: 4
147
161
  summary: Works by wrapping the excellent CLI server query tool qstat. Accepts !server,