qwtf_discord_bot 5.4.3 → 5.4.4

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: bb40c561739b201a25554221a3b07ff74da6ef621121a8032cf7ff0638e8040d
4
- data.tar.gz: 3215cfed66032d0e0f96689b885d427f9529b55cf07934dc9c8606ba76d467b4
3
+ metadata.gz: 81a6cd600bd16f113cbfd1a44b05a5d362428c5f31e3bc3a1310fc243cbb14d7
4
+ data.tar.gz: 0da538524b5ad76d74ce7eaf380331769759e540ffc80719d784abea9d0789eb
5
5
  SHA512:
6
- metadata.gz: 2cc6e47321572b0459ef66a518631df912ac96726b4a62c7f508c174236a756c65b8c6898757a61b0c5854b145907e6d9b9e525db8df972ddd520b492512bed2
7
- data.tar.gz: f8a5aff8a87cb70a32438199e5b85aa0388f5ef3918ed7f5b578d3241f199e354e799eac6cadb7a81075a799f9a42ac724152d3e783fc98a5dee0924c32b3866
6
+ metadata.gz: 2c349a08aaeb38a0dee3448fe0f57307dd20d17b71ff6dbae4e6a1da2d4c6198c13ed04ca560386013fcc89cafa7d584a5f5388b965594d6e8879c71d86efdc4
7
+ data.tar.gz: 73e8b9482f07568f16fc3c1100103aa2679e84f4cf656d163bb0f5dc7d51259b8d422498b7dfcef2c62fca5f093b8a6981814dae956da0d5bd49eae044e076b1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.4.3
1
+ 5.4.4
data/lib/pug.rb CHANGED
@@ -122,13 +122,15 @@ class Pug
122
122
  end
123
123
 
124
124
  def teams
125
- teams_keys.inject({}) do |teams, team|
126
- teams.merge({ team.split(':').last => redis.smembers(team).map(&:to_i) })
125
+ all_teams = teams_keys.inject({}) do |teams, team|
126
+ teams.merge({ team.split(':').last.to_i => redis.smembers(team).map(&:to_i) })
127
127
  end
128
+
129
+ all_teams.sort.to_h
128
130
  end
129
131
 
130
132
  def actual_teams
131
- teams.tap { |team| team.delete("0") }
133
+ teams.tap { |team| team.delete(0) }
132
134
  end
133
135
 
134
136
  private
@@ -7,6 +7,7 @@ class QwtfDiscordBotPug # :nodoc:
7
7
  include QwtfDiscordBot
8
8
 
9
9
  MSG_SNIPPET_DELIMITER = ' · '
10
+ TEAM_NAMES = { 0 => "No team", 1 => "Blue", 2 => "Red" }
10
11
 
11
12
  def run
12
13
  bot = Discordrb::Commands::CommandBot.new(
@@ -41,14 +42,32 @@ class QwtfDiscordBotPug # :nodoc:
41
42
  setup_pug(event) do |e, pug|
42
43
  return send_embedded_message('No PUG has been started. `!join` to create', e.channel) unless pug.active?
43
44
 
44
- send_embedded_message(
45
- [
46
- "#{pug.player_slots} joined",
47
- "Map: #{pug.game_map}",
48
- pug_teams_message(pug, e).join("\n")
49
- ].join("\n"),
50
- e.channel
51
- )
45
+ footer = [
46
+ pug.game_map,
47
+ "#{pug.player_slots} joined",
48
+ ].compact.join(MSG_SNIPPET_DELIMITER)
49
+
50
+ send_embedded_message(nil, e.channel) do |embed|
51
+ embed.footer = Discordrb::Webhooks::EmbedFooter.new(
52
+ text: footer
53
+ )
54
+
55
+ pug.teams.each do |team_no, player_ids|
56
+ team_display_names = player_ids.map do |player_id|
57
+ e.display_name_for(player_id)
58
+ end
59
+
60
+ embed.add_field(
61
+ Discordrb::Webhooks::EmbedField.new(
62
+ {
63
+ inline: true,
64
+ name: team_name(team_no),
65
+ value: team_display_names.join("\n")
66
+ }
67
+ )
68
+ )
69
+ end
70
+ end
52
71
  end
53
72
  end
54
73
 
@@ -154,14 +173,14 @@ class QwtfDiscordBotPug # :nodoc:
154
173
 
155
174
  if args.count == 1
156
175
  user_id = e.user_id
157
- return send_embedded_message("You're already in team #{team_no}", e.channel) if pug.team(team_no).include?(user_id)
176
+ return send_embedded_message("You're already in #{TEAM_NAMES[team_no]}", e.channel) if pug.team(team_no).include?(user_id)
158
177
 
159
178
  join_pug(e, pug) unless pug.joined?(user_id)
160
179
  pug.join_team(team_no: team_no, player_id: user_id)
161
180
 
162
181
  send_embedded_message(
163
182
  [
164
- "#{e.display_name} joins team #{team_no}",
183
+ "#{e.display_name} joins #{TEAM_NAMES[team_no]}",
165
184
  "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
166
185
  ].join(MSG_SNIPPET_DELIMITER), e.channel
167
186
  )
@@ -184,7 +203,7 @@ class QwtfDiscordBotPug # :nodoc:
184
203
 
185
204
  send_embedded_message(
186
205
  [
187
- "#{display_name} joins team #{team_no}",
206
+ "#{display_name} joins #{TEAM_NAMES[team_no]}",
188
207
  "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
189
208
  ].join(MSG_SNIPPET_DELIMITER), e.channel
190
209
  )
@@ -210,10 +229,10 @@ class QwtfDiscordBotPug # :nodoc:
210
229
  bot.command :win do |event, *args|
211
230
  setup_pug(event) do |e, pug|
212
231
  return send_embedded_message(no_active_pug_message, e.channel) unless pug.active?
232
+ return send_embedded_message("Specify winning team; e.g. `!win 1`", e.channel) unless args.any?
233
+ return send_embedded_message("Invalid team number", e.channel) unless ["1", "2"].any?(args.first)
213
234
 
214
- winning_team_no = args[0]
215
-
216
- return send_embedded_message("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
235
+ winning_team_no = args.first.to_i
217
236
 
218
237
  if pug.actual_teams.count < 2
219
238
  return send_embedded_message(
@@ -243,7 +262,7 @@ class QwtfDiscordBotPug # :nodoc:
243
262
  }.to_json
244
263
  )
245
264
 
246
- send_embedded_message("Team #{winning_team_no} wins. [Ratings](http://ratings.fortressone.org)", e.channel)
265
+ send_embedded_message("#{TEAM_NAMES[winning_team_no]} wins. [Ratings](http://ratings.fortressone.org)", e.channel)
247
266
  end
248
267
  end
249
268
 
@@ -358,6 +377,10 @@ class QwtfDiscordBotPug # :nodoc:
358
377
 
359
378
  private
360
379
 
380
+ def team_name(team_no)
381
+ [team_no, TEAM_NAMES[team_no]].join(" ")
382
+ end
383
+
361
384
  def mention_to_user_id(mention)
362
385
  mention[3..-2].to_i
363
386
  end
@@ -384,6 +407,7 @@ class QwtfDiscordBotPug # :nodoc:
384
407
 
385
408
  def start_pug(pug, event)
386
409
  if !pug.actual_teams.any?
410
+ send_embedded_message("Choosing fair teams...", event.channel)
387
411
  teams = get_fair_teams(pug.joined_players)
388
412
 
389
413
  teams.each do |team_no, player_ids|
@@ -393,48 +417,31 @@ class QwtfDiscordBotPug # :nodoc:
393
417
  end
394
418
  end
395
419
 
396
- pug_teams = pug.teams.map do |team_no, player_ids|
397
- team_mentions = player_ids.map do |player_id|
398
- event.mention_for(player_id)
399
- end
420
+ footer = [
421
+ pug.game_map,
422
+ "#{pug.player_slots} joined",
423
+ ].compact.join(MSG_SNIPPET_DELIMITER)
400
424
 
401
- team_status_line(
402
- team_no: team_no.to_i,
403
- names: team_mentions,
404
- teamsize: pug.teamsize
425
+ send_embedded_message("Time to play!", event.channel) do |embed|
426
+ embed.footer = Discordrb::Webhooks::EmbedFooter.new(
427
+ text: footer
405
428
  )
406
- end
407
429
 
408
- msg = [
409
- 'Time to play!',
410
- pug_teams
411
- ].join("\n")
412
-
413
- send_embedded_message(msg, event.channel)
414
- end
430
+ pug.teams.each do |team_no, player_ids|
431
+ team_mentions = player_ids.map do |player_id|
432
+ event.mention_for(player_id)
433
+ end
415
434
 
416
- def pug_teams_message(pug, event)
417
- pug.teams.map do |team_no, player_ids|
418
- team_display_names = player_ids.map do |player_id|
419
- event.display_name_for(player_id)
435
+ embed.add_field(
436
+ Discordrb::Webhooks::EmbedField.new(
437
+ {
438
+ inline: true,
439
+ name: team_name(team_no),
440
+ value: team_mentions.join("\n")
441
+ }
442
+ )
443
+ )
420
444
  end
421
-
422
- team_status_line(
423
- team_no: team_no.to_i,
424
- names: team_display_names,
425
- teamsize: pug.teamsize
426
- )
427
- end
428
- end
429
-
430
- def team_status_line(team_no:, names:, teamsize:)
431
- if team_no.to_i.zero?
432
- ["No team: #{names.join(', ')}"]
433
- else
434
- [
435
- "Team #{team_no}: #{names.join(', ')}",
436
- "#{names.count}/#{teamsize}"
437
- ].join(MSG_SNIPPET_DELIMITER)
438
445
  end
439
446
  end
440
447
 
@@ -450,6 +457,7 @@ class QwtfDiscordBotPug # :nodoc:
450
457
  def send_embedded_message(message, channel)
451
458
  embed = Discordrb::Webhooks::Embed.new
452
459
  embed.description = message
460
+ yield(embed) if block_given?
453
461
  channel.send_embed(nil, embed) && puts(message)
454
462
  end
455
463
 
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.3
4
+ version: 5.4.4
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-25 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb