qwtf_discord_bot 6.1.5 → 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: b502dce9e5188d2ac6cb3695ff9f9af13953fc8ad97b3d7aaafaa8802df788c1
4
- data.tar.gz: 0fa775500df5d9cf58f05600a89a82ff09a6764d1cdf9f9bbd5a0f22a3486dbd
3
+ metadata.gz: 1bfa9a0b1f5ad3c3206d216e1e266d2749e081c6dc3c58e77994ec997f64fe2f
4
+ data.tar.gz: 215a86a21d79da634525e031ad7408ad0f1c2b3ee2eced49ec2dc9f7dfffd8f1
5
5
  SHA512:
6
- metadata.gz: 4e4e48deace1b6f3565de55f1da7ccc611198bfe1ed231161948c801a6d4b9b592ffa0163a523b473dcb10199b6f34fab74b022fe3898ffdad7c6b4c1a42da4f
7
- data.tar.gz: eedf346d74132c50aa36b37caa40f82e140e6bcaa28e5dac980a07312d56f9c20d5fd937fb95db2ea8218a74702585bdeb30ce141e11d0f67e3ebbae8d106128
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.4)
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!
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.5
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
@@ -11,6 +12,28 @@ class QwtfDiscordBotPug # :nodoc:
11
12
  TEN_MINUTES = 10 * 60
12
13
  VALID_MENTION = /<@!?\d+>/
13
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]" }
36
+
14
37
  def run
15
38
  bot = Discordrb::Commands::CommandBot.new(
16
39
  token: QwtfDiscordBot.config.token,
@@ -28,19 +51,80 @@ class QwtfDiscordBotPug # :nodoc:
28
51
  )
29
52
 
30
53
  bot.command :help do |event, *args|
31
- "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
32
62
  end
33
63
 
34
64
  bot.command :join do |event, *args|
35
65
  setup_pug(event) do |e, pug|
36
- if pug.joined?(e.user_id)
37
- return send_embedded_message(
38
- 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"),
39
124
  channel: e.channel
40
125
  )
41
126
  end
42
127
 
43
- join_pug(e, pug)
44
128
  start_pug(pug, e) if pug.has_exactly_maxplayers?
45
129
  end
46
130
  end
@@ -67,7 +151,21 @@ class QwtfDiscordBotPug # :nodoc:
67
151
  0
68
152
  end
69
153
 
70
- 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)
71
169
  status(pug: pug, event: e, message_obj: message_obj) if message_obj
72
170
  end
73
171
  end
@@ -171,12 +269,12 @@ class QwtfDiscordBotPug # :nodoc:
171
269
  )
172
270
  end
173
271
 
272
+ errors = []
273
+ kickees = []
274
+
174
275
  args.each do |mention|
175
- unless mention.match(VALID_MENTION)
176
- send_embedded_message(
177
- description: "#{mention} isn't a valid mention",
178
- channel: e.channel
179
- )
276
+ if !mention.match(VALID_MENTION)
277
+ errors << "#{mention} isn't a valid mention"
180
278
  next
181
279
  end
182
280
 
@@ -184,43 +282,57 @@ class QwtfDiscordBotPug # :nodoc:
184
282
  display_name = e.display_name_for(user_id) || mention
185
283
 
186
284
  unless pug.joined?(user_id)
187
- send_embedded_message(
188
- description: "#{display_name} isn't in the PUG",
189
- channel: e.channel
190
- )
285
+ errors << "#{display_name} isn't in the PUG"
191
286
  next
192
287
  end
193
288
 
194
289
  pug.leave(user_id)
195
290
 
196
- snippets = [
197
- "#{display_name} is kicked from the PUG",
198
- "#{pug.player_slots} remain"
199
- ]
291
+ kickees << display_name
292
+ end
200
293
 
201
- message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
294
+ message = ""
295
+ description = []
202
296
 
203
- send_embedded_message(
204
- message: message,
205
- description: snippets.join(MSG_SNIPPET_DELIMITER),
206
- channel: e.channel
207
- )
297
+ if pug.slots_left == 1
298
+ message = "#{pug.slots_left} more #{pug.notify_roles}"
299
+ end
208
300
 
209
- 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(" ")
210
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?
211
323
  end
212
324
  end
213
325
 
214
326
  bot.command :team do |event, *args|
215
327
  setup_pug(event) do |e, pug|
216
- unless args.any?
328
+ if args.empty?
217
329
  return send_embedded_message(
218
330
  description: "Which team? E.G. `!team 1`",
219
331
  channel: e.channel
220
332
  )
221
333
  end
222
334
 
223
- unless ["1", "2"].any?(args.first)
335
+ if ["1", "2"].none?(args.first)
224
336
  return send_embedded_message(
225
337
  description: "Choose `!team 1`, `!team 2`, or `!unteam` to leave team",
226
338
  channel: e.channel
@@ -250,12 +362,12 @@ class QwtfDiscordBotPug # :nodoc:
250
362
  channel: e.channel
251
363
  )
252
364
  else
365
+ errors = []
366
+ teamers = []
367
+
253
368
  args[1..-1].each do |mention|
254
- unless mention.match(VALID_MENTION)
255
- send_embedded_message(
256
- description: "#{mention} isn't a valid mention",
257
- channel: e.channel
258
- )
369
+ if !mention.match(VALID_MENTION)
370
+ errors << "#{mention} isn't a valid mention"
259
371
  next
260
372
  end
261
373
 
@@ -263,14 +375,25 @@ class QwtfDiscordBotPug # :nodoc:
263
375
  display_name = e.display_name_for(user_id) || mention
264
376
  pug.join_team(team_no: team_no, player_id: user_id)
265
377
 
266
- send_embedded_message(
267
- description: [
268
- "#{display_name} joins #{TEAM_NAMES[team_no]}",
269
- "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
270
- ].join(MSG_SNIPPET_DELIMITER),
271
- channel: e.channel
272
- )
378
+ teamers << display_name
273
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
+ )
274
397
  end
275
398
 
276
399
  start_pug(pug, e) if !pug_already_full && pug.has_exactly_maxplayers?
@@ -281,7 +404,7 @@ class QwtfDiscordBotPug # :nodoc:
281
404
  setup_pug(event) do |e, pug|
282
405
  user_id = e.user_id
283
406
 
284
- unless pug.active?
407
+ if !pug.active?
285
408
  return send_embedded_message(
286
409
  description: 'No PUG has been started. `!join` to create',
287
410
  channel: e.channel
@@ -289,7 +412,7 @@ class QwtfDiscordBotPug # :nodoc:
289
412
  end
290
413
 
291
414
  if args.empty?
292
- unless pug.joined?(user_id)
415
+ if !pug.joined?(user_id)
293
416
  return send_embedded_message(
294
417
  description: "You aren't in this PUG",
295
418
  channel: e.channel
@@ -310,32 +433,38 @@ class QwtfDiscordBotPug # :nodoc:
310
433
  channel: e.channel
311
434
  )
312
435
  else
436
+ errors = []
437
+ unteamers = []
438
+
313
439
  args.each do |mention|
314
- unless mention.match(VALID_MENTION)
315
- send_embedded_message(
316
- description: "#{mention} isn't a valid mention",
317
- channel: e.channel
318
- )
440
+ if !mention.match(VALID_MENTION)
441
+ errors << "#{mention} isn't a valid mention"
319
442
  next
320
443
  end
321
444
 
322
445
  user_id = mention_to_user_id(mention)
323
446
  display_name = e.display_name_for(user_id) || mention
324
447
 
325
- unless pug.joined?(user_id)
326
- return send_embedded_message(
327
- description: "#{display_name} isn't in this PUG",
328
- channel: e.channel
329
- )
448
+ if !pug.joined?(user_id)
449
+ errors << "#{display_name} isn't in this PUG"
450
+ next
330
451
  end
331
452
 
332
453
  pug.unteam(user_id)
333
454
 
334
- send_embedded_message(
335
- description: "#{display_name} leaves team",
336
- channel: e.channel
337
- )
455
+ unteamers << display_name
338
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
+ )
339
468
  end
340
469
  end
341
470
  end
@@ -417,7 +546,7 @@ class QwtfDiscordBotPug # :nodoc:
417
546
  ).body
418
547
 
419
548
  send_embedded_message(
420
- 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)})",
421
550
  channel: e.channel
422
551
  )
423
552
  end
@@ -485,7 +614,7 @@ class QwtfDiscordBotPug # :nodoc:
485
614
  ).body
486
615
 
487
616
  send_embedded_message(
488
- 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)})",
489
618
  channel: e.channel
490
619
  )
491
620
  end
@@ -640,7 +769,7 @@ class QwtfDiscordBotPug # :nodoc:
640
769
  end
641
770
 
642
771
  def mention_to_user_id(mention)
643
- mention[3..-2].to_i
772
+ mention[/\d+/].to_i
644
773
  end
645
774
 
646
775
  def join_pug(e, pug)
@@ -648,7 +777,7 @@ class QwtfDiscordBotPug # :nodoc:
648
777
 
649
778
  if pug.total_player_count == 1
650
779
  snippets = ["#{e.display_name} creates a PUG", "#{pug.player_slots} joined"]
651
- message = pug.notify_roles
780
+ message = "#{pug.notify_roles} PUG started"
652
781
  else
653
782
  snippets = ["#{e.display_name} joins the PUG", "#{pug.player_slots} joined"]
654
783
  message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left.between?(1, 3)
@@ -668,7 +797,7 @@ class QwtfDiscordBotPug # :nodoc:
668
797
  nil # stop discordrb printing return value
669
798
  end
670
799
 
671
- def choose_fair_teams(pug:, event:, iteration: 0)
800
+ def choose_teams(pug:, event:, iteration: nil)
672
801
  if !pug.full?
673
802
  return send_embedded_message(
674
803
  description: "Not enough players, reduce !teamsize",
@@ -677,7 +806,7 @@ class QwtfDiscordBotPug # :nodoc:
677
806
  end
678
807
 
679
808
  message_obj = send_embedded_message(
680
- description: "Choosing fair teams...",
809
+ description: "Choosing teams...",
681
810
  channel: event.channel
682
811
  )
683
812
 
@@ -685,14 +814,18 @@ class QwtfDiscordBotPug # :nodoc:
685
814
  channel_id: event.channel.id, players: pug.up_now_players
686
815
  )
687
816
 
688
- teams = combinations[iteration]
817
+ if iteration
818
+ teams = combinations[iteration]
689
819
 
690
- if !teams
691
- return send_embedded_message(
692
- description: "There are only #{combinations.count} possible combinations",
693
- channel: event.channel,
694
- message_obj: message_obj
695
- ) && 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
696
829
  end
697
830
 
698
831
  pug.destroy_teams
@@ -748,8 +881,6 @@ class QwtfDiscordBotPug # :nodoc:
748
881
  end
749
882
 
750
883
  def start_pug(pug, event)
751
- choose_fair_teams(pug: pug, event: event) unless pug.teams.any?
752
-
753
884
  footer = [
754
885
  pug.game_map,
755
886
  "#{pug.player_slots} joined",
@@ -759,7 +890,7 @@ class QwtfDiscordBotPug # :nodoc:
759
890
  event.mention_for(player_id)
760
891
  end
761
892
 
762
- mention_line = "Time to play! #{mentions.join(" ")}"
893
+ mention_line = "`!choose`, `!shuffle` or `!team` up. #{mentions.join(" ")}"
763
894
 
764
895
  send_embedded_message(
765
896
  message: mention_line,
@@ -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.5
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-07-24 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