qwtf_discord_bot 5.4.1 → 5.4.6

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: a1d4b0223feae05745b7050dc8dc25193136bac78bee3fca74818559dad0dd7c
4
- data.tar.gz: 8a7b7a27d72b759ffa4111bdf85f73c0effae38c4db7c8164f5abca357912dd1
3
+ metadata.gz: 5f57dc18281f366be0004ffcf3ab6a35938b155c5897922c28cba7c6cf7e18b5
4
+ data.tar.gz: a27fcdd5f32203382595bc5b135af9940690fc0b45f7dbd6a5e019777de0ff5a
5
5
  SHA512:
6
- metadata.gz: b621a49eefc9ab5c83c93e771a00d609aa72be3b675e627aa9f502cd1646832e4cd892e67b0864bdea9a9dbcaf9f0b691a6f3df71f852179d21a28d760312c28
7
- data.tar.gz: 91ce0148eeb1a80d127bb722204153031087eb88b8460b64fab9004d834e0f96615bf605f35d3ef06a8df17ed23fdf4d863c1cbd0b2231070beb23e9b2b52dd7
6
+ metadata.gz: c3d452a44dd1506cad8d214089737a0f515edabd2fe189bb437a321d624346ecd1795fa0bcb79bd8734d9f56f952c41e7aec49126a563bda7fbb8d313676cc24
7
+ data.tar.gz: 0df2e2073331e1cec5332bf7d680bb9715c789d2bac18ccf9750d48d7b4df1eb7a46c515f38a14597aa99de206b58392a41e613f5060b4f2b82c4438797c298b
data/README.md CHANGED
@@ -97,6 +97,7 @@ This responds to discord messages:
97
97
  - `!removemap <map_name>`
98
98
  - `!maps`
99
99
  - `!map <map_name>`
100
+ - `!choose`
100
101
  - `!win <team_no>`
101
102
  - `!draw`
102
103
  - `!notify <@role>`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.4.1
1
+ 5.4.6
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,78 +7,150 @@ class QwtfDiscordBotPug # :nodoc:
7
7
  include QwtfDiscordBot
8
8
 
9
9
  MSG_SNIPPET_DELIMITER = ' · '
10
+ TEAM_NAMES = { 1 => "Blue", 2 => "Red" }
10
11
 
11
12
  def run
12
13
  bot = Discordrb::Commands::CommandBot.new(
13
14
  token: QwtfDiscordBot.config.token,
14
15
  client_id: QwtfDiscordBot.config.client_id,
15
16
  help_command: false,
16
- prefix: '!'
17
+ prefix: proc do |message|
18
+ match = /^\!(\w+)(.*)/.match(message.content)
19
+ if match
20
+ first = match[1]
21
+ rest = match[2]
22
+ # Return the modified string with the first word lowercase:
23
+ "#{first.downcase}#{rest}"
24
+ end
25
+ end
17
26
  )
18
27
 
19
28
  bot.command :help do |event, *args|
20
- "Pug commands: `!status`, `!join`, `!team <team_no>`, `!unteam`, `!leave`, `!kick <@player>`, `!win <team_no>`, `!draw`, `!end`, `!teamsize <no_of_players>`, `!addmap <map_name>`, `!removemap <map_name>`, `!maps`, `!map <map_name>`, `!notify <@role>`"
29
+ "Pug commands: `!status`, `!join`, `!team <team_no>`, `!unteam`, `!leave`, `!kick <@player>`, `!win <team_no>`, `!draw`, `!end`, `!teamsize <no_of_players>`, `!addmap <map_name>`, `!removemap <map_name>`, `!maps`, `!map <map_name>`, `!choose`, `!notify <@role>`"
21
30
  end
22
31
 
23
32
  bot.command :join do |event, *args|
24
33
  setup_pug(event) do |e, pug|
25
- return send_msg("You've already joined", e.channel) if pug.joined?(e.user_id)
34
+ if pug.joined?(e.user_id)
35
+ return send_embedded_message(
36
+ description: "You've already joined",
37
+ channel: e.channel
38
+ )
39
+ end
26
40
 
27
41
  join_pug(e, pug)
28
42
  start_pug(pug, e) if pug.full?
29
43
  end
30
44
  end
31
45
 
32
- bot.command :status do |event, *args|
46
+ bot.command :choose do |event, *args|
33
47
  setup_pug(event) do |e, pug|
34
- return send_msg('No PUG has been started. `!join` to create', e.channel) unless pug.active?
35
-
36
- send_msg(
37
- [
38
- "#{pug.player_slots} joined",
39
- "Map: #{pug.game_map}",
40
- pug_teams_message(pug, e).join("\n")
41
- ].join("\n"),
42
- e.channel
43
- )
48
+ if !pug.full?
49
+ return send_embedded_message(
50
+ description: "Can't choose teams until PUG is full",
51
+ channel: e.channel
52
+ )
53
+ end
54
+
55
+ pug.joined_players.each do |player_id|
56
+ pug.join_team(team_no: 0, player_id: player_id)
57
+ end
58
+
59
+ start_pug(pug, e)
44
60
  end
45
61
  end
46
62
 
47
- bot.command :teamsize do |event, *args|
63
+ bot.command :status do |event, *args|
48
64
  setup_pug(event) do |e, pug|
49
- return send_msg("Team size is #{pug.teamsize}", e.channel) unless args.any?
65
+ if !pug.active?
66
+ return send_embedded_message(
67
+ description: "No PUG has been started. `!join` to create",
68
+ channel: e.channel
69
+ )
70
+ end
50
71
 
51
- new_teamsize = args[0].to_i
52
- return send_msg('Team size should be a number higher than 0', e.channel) unless new_teamsize > 0
72
+ footer = [
73
+ pug.game_map,
74
+ "#{pug.player_slots} joined",
75
+ ].compact.join(MSG_SNIPPET_DELIMITER)
76
+
77
+ send_embedded_message(
78
+ description: nil,
79
+ channel: e.channel
80
+ ) do |embed|
81
+ embed.footer = Discordrb::Webhooks::EmbedFooter.new(
82
+ text: footer
83
+ )
53
84
 
54
- if new_teamsize
55
- pug.teamsize = new_teamsize
85
+ pug.teams.each do |team_no, player_ids|
86
+ team_display_names = player_ids.map do |player_id|
87
+ e.display_name_for(player_id)
88
+ end
56
89
 
57
- send_msg(
58
- [
59
- "Team size set to #{pug.teamsize}",
90
+ embed.add_field(
91
+ Discordrb::Webhooks::EmbedField.new(
92
+ {
93
+ inline: true,
94
+ name: team_name(team_no),
95
+ value: team_display_names.join("\n")
96
+ }
97
+ )
98
+ )
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ bot.command :teamsize do |event, *args|
105
+ setup_pug(event) do |e, pug|
106
+ unless args.any?
107
+ return send_embedded_message(
108
+ description: [
109
+ "Each team has #{pug.teamsize} players",
60
110
  "#{pug.player_slots} joined"
61
111
  ].join(MSG_SNIPPET_DELIMITER),
62
- e.channel
112
+ channel: e.channel
63
113
  )
114
+ end
64
115
 
65
- start_pug(pug, e) if pug.full?
66
- else
67
- send_msg(
68
- [
69
- "Current team size is #{pug.teamsize}",
70
- "#{pug.player_slots} joined"
71
- ].join(MSG_SNIPPET_DELIMITER),
72
- e.channel
116
+ new_teamsize = args[0].to_i
117
+
118
+ if new_teamsize < 1
119
+ return send_embedded_message(
120
+ description: "Team size should be 1 or more",
121
+ channel: e.channel
73
122
  )
74
123
  end
124
+
125
+ pug.teamsize = new_teamsize
126
+
127
+ send_embedded_message(
128
+ description: [
129
+ "Each team has #{pug.teamsize} players",
130
+ "#{pug.player_slots} joined"
131
+ ].join(MSG_SNIPPET_DELIMITER),
132
+ channel: e.channel
133
+ )
134
+
135
+ start_pug(pug, e) if pug.full?
75
136
  end
76
137
  end
77
138
 
78
139
  bot.command :leave do |event, *args|
79
140
  setup_pug(event) do |e, pug|
80
- return send_msg(no_active_pug_message, e.channel) unless pug.active?
81
- return send_msg("You're not in the PUG", e.channel) unless pug.joined?(e.user_id)
141
+ unless pug.active?
142
+ return send_embedded_message(
143
+ description: no_active_pug_message,
144
+ channel: e.channel
145
+ )
146
+ end
147
+
148
+ unless pug.joined?(e.user_id)
149
+ return send_embedded_message(
150
+ description: "You're not in the PUG",
151
+ channel: e.channel
152
+ )
153
+ end
82
154
 
83
155
  pug.leave(e.user_id)
84
156
 
@@ -87,11 +159,12 @@ class QwtfDiscordBotPug # :nodoc:
87
159
  "#{pug.player_slots} remain"
88
160
  ]
89
161
 
90
- snippets << "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
162
+ message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
91
163
 
92
- send_msg(
93
- snippets.join(MSG_SNIPPET_DELIMITER),
94
- e.channel
164
+ send_embedded_message(
165
+ message: message,
166
+ description: snippets.join(MSG_SNIPPET_DELIMITER),
167
+ channel: e.channel
95
168
  )
96
169
 
97
170
  end_pug(pug, e.channel) if pug.empty?
@@ -100,12 +173,26 @@ class QwtfDiscordBotPug # :nodoc:
100
173
 
101
174
  bot.command :kick do |event, *args|
102
175
  setup_pug(event) do |e, pug|
103
- return send_msg("Kick who? e.g. `!kick @#{e.display_name}`", e.channel) unless args.any?
104
- return send_msg(no_active_pug_message, e.channel) unless pug.active?
176
+ unless args.any?
177
+ return send_embedded_message(
178
+ description: "Kick who? e.g. `!kick @#{e.display_name}`",
179
+ channel: e.channel
180
+ )
181
+ end
182
+
183
+ unless pug.active?
184
+ return send_embedded_message(
185
+ description: no_active_pug_message,
186
+ channel: e.channel
187
+ )
188
+ end
105
189
 
106
190
  args.each do |arg|
107
191
  unless arg.match(/<@!\d+>/)
108
- send_msg("#{arg} isn't a valid mention", e.channel)
192
+ send_embedded_message(
193
+ description: "#{arg} isn't a valid mention",
194
+ channel: e.channel
195
+ )
109
196
  next
110
197
  end
111
198
 
@@ -113,7 +200,10 @@ class QwtfDiscordBotPug # :nodoc:
113
200
  display_name = e.display_name_for(user_id) || arg
114
201
 
115
202
  unless pug.joined?(user_id)
116
- send_msg("#{display_name} isn't in the PUG", e.channel)
203
+ send_embedded_message(
204
+ description: "#{display_name} isn't in the PUG",
205
+ channel: e.channel
206
+ )
117
207
  next
118
208
  end
119
209
 
@@ -124,11 +214,12 @@ class QwtfDiscordBotPug # :nodoc:
124
214
  "#{pug.player_slots} remain"
125
215
  ]
126
216
 
127
- snippets << "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
217
+ message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left == 1
128
218
 
129
- send_msg(
130
- snippets.join(MSG_SNIPPET_DELIMITER),
131
- e.channel
219
+ send_embedded_message(
220
+ message: message,
221
+ description: snippets.join(MSG_SNIPPET_DELIMITER),
222
+ channel: e.channel
132
223
  )
133
224
 
134
225
  break end_pug(pug, e.channel) if pug.empty?
@@ -138,29 +229,50 @@ class QwtfDiscordBotPug # :nodoc:
138
229
 
139
230
  bot.command :team do |event, *args|
140
231
  setup_pug(event) do |e, pug|
141
- return send_msg("Which team? E.G. `!team 1`", e.channel) unless args.any?
142
- return send_msg("Choose a team between 0 and 2", e.channel) unless ["0", "1", "2"].any?(args.first)
232
+ unless args.any?
233
+ return send_embedded_message(
234
+ description: "Which team? E.G. `!team 1`",
235
+ channel: e.channel
236
+ )
237
+ end
238
+
239
+ unless ["1", "2"].any?(args.first)
240
+ return send_embedded_message(
241
+ description: "Choose `!team 1`, `!team 2`, or `!unteam` to leave team",
242
+ channel: e.channel
243
+ )
244
+ end
143
245
 
144
246
  team_no = args.first.to_i
145
247
  pug_already_full = pug.full?
146
248
 
147
249
  if args.count == 1
148
250
  user_id = e.user_id
149
- return send_msg("You're already in team #{team_no}", e.channel) if pug.team(team_no).include?(user_id)
251
+
252
+ if pug.team(team_no).include?(user_id)
253
+ return send_embedded_message(
254
+ description: "You're already in #{TEAM_NAMES[team_no]}",
255
+ channel: e.channel
256
+ )
257
+ end
150
258
 
151
259
  join_pug(e, pug) unless pug.joined?(user_id)
152
260
  pug.join_team(team_no: team_no, player_id: user_id)
153
261
 
154
- send_msg(
155
- [
156
- "#{e.display_name} joins team #{team_no}",
262
+ send_embedded_message(
263
+ description: [
264
+ "#{e.display_name} joins #{TEAM_NAMES[team_no]}",
157
265
  "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
158
- ].join(MSG_SNIPPET_DELIMITER), e.channel
266
+ ].join(MSG_SNIPPET_DELIMITER),
267
+ channel: e.channel
159
268
  )
160
269
  else
161
270
  args[1..-1].each do |mention|
162
271
  unless mention.match(/<@!\d+>/)
163
- send_msg("#{arg} isn't a valid mention", e.channel)
272
+ send_embedded_message(
273
+ description: "#{arg} isn't a valid mention",
274
+ channel: e.channel
275
+ )
164
276
  next
165
277
  end
166
278
 
@@ -168,17 +280,21 @@ class QwtfDiscordBotPug # :nodoc:
168
280
  display_name = e.display_name_for(user_id) || arg
169
281
 
170
282
  unless pug.joined?(user_id)
171
- send_msg("#{display_name} isn't in the PUG", e.channel)
283
+ send_embedded_message(
284
+ description: "#{display_name} isn't in the PUG",
285
+ channel: e.channel
286
+ )
172
287
  next
173
288
  end
174
289
 
175
290
  pug.join_team(team_no: team_no, player_id: user_id)
176
291
 
177
- send_msg(
178
- [
179
- "#{display_name} joins team #{team_no}",
292
+ send_embedded_message(
293
+ description: [
294
+ "#{display_name} joins #{TEAM_NAMES[team_no]}",
180
295
  "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
181
- ].join(MSG_SNIPPET_DELIMITER), e.channel
296
+ ].join(MSG_SNIPPET_DELIMITER),
297
+ channel: e.channel
182
298
  )
183
299
  end
184
300
  end
@@ -190,26 +306,66 @@ class QwtfDiscordBotPug # :nodoc:
190
306
  bot.command :unteam do |event, *args|
191
307
  setup_pug(event) do |e, pug|
192
308
  user_id = e.user_id
193
- return send_msg('No PUG has been started. `!join` to create', e.channel) unless pug.active?
194
- return send_msg("You aren't in this PUG", e.channel) unless pug.joined?(user_id)
195
- return send_msg("You aren't in a team", e.channel) if pug.team(0).include?(user_id)
309
+
310
+ unless pug.active?
311
+ return send_embedded_message(
312
+ description: 'No PUG has been started. `!join` to create',
313
+ channel: e.channel
314
+ )
315
+ end
316
+
317
+ unless pug.joined?(user_id)
318
+ return send_embedded_message(
319
+ description: "You aren't in this PUG",
320
+ channel: e.channel
321
+ )
322
+ end
323
+
324
+ if pug.team(0).include?(user_id)
325
+ return send_embedded_message(
326
+ description: "You aren't in a team",
327
+ channel: e.channel
328
+ )
329
+ end
196
330
 
197
331
  pug.join_team(team_no: 0, player_id: user_id)
198
- send_msg("#{e.display_name} has no team", e.channel)
332
+
333
+ send_embedded_message(
334
+ description: "#{e.display_name} leaves team",
335
+ channel: e.channel
336
+ )
199
337
  end
200
338
  end
201
339
 
202
340
  bot.command :win do |event, *args|
203
341
  setup_pug(event) do |e, pug|
204
- return send_msg(no_active_pug_message, e.channel) unless pug.active?
342
+ unless pug.active?
343
+ return send_embedded_message(
344
+ description: no_active_pug_message,
345
+ channel: e.channel
346
+ )
347
+ end
205
348
 
206
- winning_team_no = args[0]
349
+ unless args.any?
350
+ return send_embedded_message(
351
+ description: "Specify winning team; e.g. `!win 1`",
352
+ channel: e.channel
353
+ )
354
+ end
207
355
 
208
- return send_msg("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
356
+ unless ["1", "2"].any?(args.first)
357
+ return send_embedded_message(
358
+ description: "Invalid team number",
359
+ channel: e.channel
360
+ )
361
+ end
362
+
363
+ winning_team_no = args.first.to_i
209
364
 
210
365
  if pug.actual_teams.count < 2
211
- return send_msg(
212
- "There must be at least two teams with players to submit a result", e.channel
366
+ return send_embedded_message(
367
+ description: "There must be at least two teams with players to submit a result",
368
+ channel: e.channel
213
369
  )
214
370
  end
215
371
 
@@ -235,27 +391,26 @@ class QwtfDiscordBotPug # :nodoc:
235
391
  }.to_json
236
392
  )
237
393
 
238
- # winning_team = pug.team(winning_team_no).map do |player_id|
239
- # e.display_name_for(player_id)
240
- # end
241
-
242
- # non_winning_teams = pug.actual_teams.tap { |team| team.delete(winning_team_no) }
243
-
244
- # losing_players = non_winning_teams.values.flatten.map do |player_id|
245
- # e.display_name_for(player_id)
246
- # end
247
-
248
- send_msg("Team #{winning_team_no} wins", e.channel)
394
+ send_embedded_message(
395
+ description: "#{TEAM_NAMES[winning_team_no]} wins. [Ratings](http://ratings.fortressone.org)",
396
+ channel: e.channel
397
+ )
249
398
  end
250
399
  end
251
400
 
252
401
  bot.command :draw do |event, *args|
253
402
  setup_pug(event) do |e, pug|
254
- return send_msg(no_active_pug_message, e.channel) unless pug.active?
403
+ unless pug.active?
404
+ return send_embedded_message(
405
+ description: no_active_pug_message,
406
+ channel: e.channel
407
+ )
408
+ end
255
409
 
256
410
  if pug.actual_teams.count < 2
257
- return send_msg(
258
- "There must be at least two teams with players to submit a result", e.channel
411
+ return send_embedded_message(
412
+ description: "There must be at least two teams with players to submit a result",
413
+ channel: e.channel
259
414
  )
260
415
  end
261
416
 
@@ -280,13 +435,21 @@ class QwtfDiscordBotPug # :nodoc:
280
435
  }.to_json
281
436
  )
282
437
 
283
- send_msg("Match drawn", e.channel)
438
+ send_embedded_message(
439
+ description: "Match drawn. [Ratings](http://ratings.fortressone.org)",
440
+ channel: e.channel
441
+ )
284
442
  end
285
443
  end
286
444
 
287
445
  bot.command :end do |event, *args|
288
446
  setup_pug(event) do |e, pug|
289
- return send_msg(no_active_pug_message, e.channel) unless pug.active?
447
+ unless pug.active?
448
+ return send_embedded_message(
449
+ description: no_active_pug_message,
450
+ channel: e.channel
451
+ )
452
+ end
290
453
 
291
454
  end_pug(pug, e.channel)
292
455
  end
@@ -295,47 +458,105 @@ class QwtfDiscordBotPug # :nodoc:
295
458
  bot.command :addmap do |event, *args|
296
459
  setup_pug(event) do |e, pug|
297
460
  maps = args
298
- return send_msg("What map? e.g. `!addmap 2fort5r`", e.channel) unless maps.any?
461
+
462
+ unless maps.any?
463
+ return send_embedded_message(
464
+ description: "What map? e.g. `!addmap 2fort5r`",
465
+ channel: e.channel
466
+ )
467
+ end
299
468
 
300
469
  pug.add_maps(maps)
301
- send_msg("#{maps.join(', ')} added to maps", e.channel)
470
+
471
+ send_embedded_message(
472
+ description: "#{maps.join(', ')} added to maps",
473
+ channel: e.channel)
302
474
  end
303
475
  end
304
476
 
305
477
  bot.command :removemap do |event, *args|
306
478
  setup_pug(event) do |e, pug|
307
479
  maps = args
308
- return send_msg("What map? e.g. `!removemap 2fort5r`", e.channel) unless maps.any?
480
+
481
+ unless maps.any?
482
+ return send_embedded_message(
483
+ description: "What map? e.g. `!removemap 2fort5r`",
484
+ channel: e.channel
485
+ )
486
+ end
309
487
 
310
488
  pug.remove_maps(maps)
311
- send_msg("#{maps.join(', ')} removed from maps", e.channel)
489
+
490
+ send_embedded_message(
491
+ description: "#{maps.join(', ')} removed from maps",
492
+ channel: e.channel
493
+ )
312
494
  end
313
495
  end
314
496
 
315
497
  bot.command :maps do |event, *args|
316
498
  setup_pug(event) do |e, pug|
317
499
  maps = pug.maps
318
- return send_msg('No maps have been added. `!addmap`', e.channel) unless maps.any?
500
+ unless maps.any?
501
+ return send_embedded_message(
502
+ description: 'No maps have been added. `!addmap`',
503
+ channel: e.channel
504
+ )
505
+ end
319
506
 
320
- send_msg(maps.join(', '), e.channel)
507
+ send_embedded_message(
508
+ description: maps.join(', '),
509
+ channel: e.channel
510
+ )
321
511
  end
322
512
  end
323
513
 
324
514
  bot.command :map do |event, *args|
325
515
  setup_pug(event) do |e, pug|
326
516
  maps = pug.maps
327
- return send_msg('No maps have been added. `!addmap`', e.channel) unless maps.any?
328
- return send_msg(no_active_pug_message, e.channel) unless pug.active?
517
+
518
+ unless maps.any?
519
+ return send_embedded_message(
520
+ description: 'No maps have been added. `!addmap`',
521
+ channel: e.channel
522
+ )
523
+ end
524
+
525
+ unless pug.active?
526
+ return send_embedded_message(
527
+ description: no_active_pug_message,
528
+ channel: e.channel
529
+ )
530
+ end
329
531
 
330
532
  if args.empty?
331
- return send_msg('No map has been set for the current PUG', e.channel) unless pug.game_map
332
- send_msg("Current map is #{pug.game_map}", e.channel)
533
+ unless pug.game_map
534
+ return send_embedded_message(
535
+ description: 'No map has been set for the current PUG',
536
+ channel: e.channel
537
+ )
538
+ end
539
+
540
+ send_embedded_message(
541
+ description: "Current map is #{pug.game_map}",
542
+ channel: e.channel
543
+ )
333
544
  else
334
545
  game_map = args.first
335
- return send_msg("#{game_map} isn't in the map list. `!addmap` to add it.", e.channel) unless maps.include?(game_map)
546
+
547
+ unless maps.include?(game_map)
548
+ return send_embedded_message(
549
+ description: "#{game_map} isn't in the map list. `!addmap` to add it.",
550
+ channel: e.channel
551
+ )
552
+ end
336
553
 
337
554
  pug.game_map = game_map
338
- send_msg("Map set to #{game_map}", e.channel)
555
+
556
+ send_embedded_message(
557
+ description: "Map set to #{game_map}",
558
+ channel: e.channel
559
+ )
339
560
  end
340
561
  end
341
562
  end
@@ -351,7 +572,10 @@ class QwtfDiscordBotPug # :nodoc:
351
572
  "Notification role set to #{roles}"
352
573
  end
353
574
 
354
- send_msg(msg, e.channel)
575
+ send_embedded_message(
576
+ description: msg,
577
+ channel: e.channel
578
+ )
355
579
  end
356
580
  end
357
581
 
@@ -360,6 +584,12 @@ class QwtfDiscordBotPug # :nodoc:
360
584
 
361
585
  private
362
586
 
587
+ def team_name(team_no)
588
+ return "No team" if team_no == 0
589
+
590
+ [team_no, TEAM_NAMES[team_no]].join(" ")
591
+ end
592
+
363
593
  def mention_to_user_id(mention)
364
594
  mention[3..-2].to_i
365
595
  end
@@ -368,13 +598,18 @@ class QwtfDiscordBotPug # :nodoc:
368
598
  pug.join(e.user_id)
369
599
 
370
600
  if pug.joined_player_count == 1
371
- snippets = ["#{e.display_name} creates a PUG", pug.player_slots, pug.notify_roles]
601
+ snippets = ["#{e.display_name} creates a PUG", "#{pug.player_slots} joined"]
602
+ message = pug.notify_roles
372
603
  else
373
- snippets = ["#{e.display_name} joins the PUG", pug.player_slots]
374
- snippets << "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left.between?(1, 3)
604
+ snippets = ["#{e.display_name} joins the PUG", "#{pug.player_slots} joined"]
605
+ message = "#{pug.slots_left} more #{pug.notify_roles}" if pug.slots_left.between?(1, 3)
375
606
  end
376
607
 
377
- send_msg(snippets.join(MSG_SNIPPET_DELIMITER), e.channel)
608
+ send_embedded_message(
609
+ message: message,
610
+ description: snippets.join(MSG_SNIPPET_DELIMITER),
611
+ channel: e.channel
612
+ )
378
613
  end
379
614
 
380
615
  def setup_pug(event)
@@ -386,6 +621,10 @@ class QwtfDiscordBotPug # :nodoc:
386
621
 
387
622
  def start_pug(pug, event)
388
623
  if !pug.actual_teams.any?
624
+ send_embedded_message(
625
+ description: "Choosing fair teams...",
626
+ channel: event.channel
627
+ )
389
628
  teams = get_fair_teams(pug.joined_players)
390
629
 
391
630
  teams.each do |team_no, player_ids|
@@ -395,62 +634,61 @@ class QwtfDiscordBotPug # :nodoc:
395
634
  end
396
635
  end
397
636
 
398
- pug_teams = pug.teams.map do |team_no, player_ids|
399
- team_mentions = player_ids.map do |player_id|
400
- event.mention_for(player_id)
401
- end
637
+ footer = [
638
+ pug.game_map,
639
+ "#{pug.player_slots} joined",
640
+ ].compact.join(MSG_SNIPPET_DELIMITER)
402
641
 
403
- team_status_line(
404
- team_no: team_no.to_i,
405
- names: team_mentions,
406
- teamsize: pug.teamsize
407
- )
642
+ mentions = pug.joined_players.map do |player_id|
643
+ event.mention_for(player_id)
408
644
  end
409
645
 
410
- msg = [
411
- 'Time to play!',
412
- pug_teams
413
- ].join("\n")
414
-
415
- send_msg(msg, event.channel)
416
- end
417
-
418
- def pug_teams_message(pug, event)
419
- pug.teams.map do |team_no, player_ids|
420
- team_display_names = player_ids.map do |player_id|
421
- event.display_name_for(player_id)
422
- end
646
+ mention_line = "Time to play! #{mentions.join(" ")}"
423
647
 
424
- team_status_line(
425
- team_no: team_no.to_i,
426
- names: team_display_names,
427
- teamsize: pug.teamsize
648
+ send_embedded_message(
649
+ message: mention_line,
650
+ channel: event.channel
651
+ ) do |embed|
652
+ embed.footer = Discordrb::Webhooks::EmbedFooter.new(
653
+ text: footer
428
654
  )
429
- end
430
- end
431
655
 
432
- def team_status_line(team_no:, names:, teamsize:)
433
- if team_no.to_i.zero?
434
- ["No team: #{names.join(', ')}"]
435
- else
436
- [
437
- "Team #{team_no}: #{names.join(', ')}",
438
- "#{names.count}/#{teamsize}"
439
- ].join(MSG_SNIPPET_DELIMITER)
656
+ pug.teams.each do |team_no, player_ids|
657
+ team_mentions = player_ids.map do |player_id|
658
+ event.display_name_for(player_id)
659
+ end
660
+
661
+ embed.add_field(
662
+ Discordrb::Webhooks::EmbedField.new(
663
+ {
664
+ inline: true,
665
+ name: team_name(team_no),
666
+ value: team_mentions.join("\n")
667
+ }
668
+ )
669
+ )
670
+ end
440
671
  end
441
672
  end
442
673
 
443
674
  def end_pug(pug, channel_id)
444
675
  pug.end_pug
445
- send_msg('PUG ended', channel_id)
676
+
677
+ send_embedded_message(
678
+ description: 'PUG ended',
679
+ channel: channel_id
680
+ )
446
681
  end
447
682
 
448
683
  def no_active_pug_message
449
684
  "There's no active PUG"
450
685
  end
451
686
 
452
- def send_msg(message, channel)
453
- channel.send_message(message) && puts(message)
687
+ def send_embedded_message(message: nil, description: nil, channel:)
688
+ embed = Discordrb::Webhooks::Embed.new
689
+ embed.description = description
690
+ yield(embed) if block_given?
691
+ channel.send_embed(message, embed) && puts(message)
454
692
  end
455
693
 
456
694
  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.1
4
+ version: 5.4.6
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-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb