qwtf_discord_bot 5.3.1 → 5.3.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: 020c98479af02b628d8218cb1fdc1225d8b8d38f942b3343504189f6f86af623
4
- data.tar.gz: 9bdcf614b0783cda3b7e5377a0fc51d808fcc3db4272e4f8a2c315099c40f62b
3
+ metadata.gz: 45dcf6ff7c764cda796f9048dde0184423bab3f0a45b6bd3d58341876435d6bc
4
+ data.tar.gz: f8e192337a8247a1fde818d5b1d53922d350734708ecaa0e1cf36865d1b3caff
5
5
  SHA512:
6
- metadata.gz: 20cdff7ed5d1d17e45b2b79c6b7f68d4a6c8161d086722dd827126f552abded756c0ead3ebd8622452f329eb2840148eff3e503e6cfa111274d09f0eeba2d145
7
- data.tar.gz: f9badce721eb64aa4812eb1ae139c2f18cc809c6e20803b67f29cc081dd563374bf452b74ab58bfc6c68badde07dacd6dac0bb50ea0a5dd56610fe7c75761760
6
+ metadata.gz: 0db6a8a62cbc130860904b63d169b4942b5264643fa507ee566dd3abddee682b1182b920eb1a06c83b044edebf5879cc88587dd94c1b520b5a9054608c072647
7
+ data.tar.gz: 62de3a2ef18d87b20c4804e9c311663d043b6c32d9aa9209ef63a94fa870cc1a589b27027613e44f319cf4ed1e1de8dc76a980cf0bcc1cc433c306454cb440fc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qwtf_discord_bot (5.1.12)
4
+ qwtf_discord_bot (5.3.5)
5
5
  discordrb (~> 3.3)
6
6
  redis (~> 4.1)
7
7
  thor (~> 0.20)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.3.1
1
+ 5.3.6
@@ -105,7 +105,7 @@ class QwtfDiscordBotPug # :nodoc:
105
105
  next
106
106
  end
107
107
 
108
- user_id = arg[3..-2].to_i
108
+ user_id = mention_to_user_id(arg)
109
109
  display_name = e.display_name_for(user_id) || arg
110
110
 
111
111
  unless pug.joined?(user_id)
@@ -134,23 +134,53 @@ class QwtfDiscordBotPug # :nodoc:
134
134
 
135
135
  bot.command :team do |event, *args|
136
136
  setup_pug(event) do |e, pug|
137
+ return send_msg("Which team? E.G. `!team 1`", e.channel) unless args.any?
138
+
137
139
  team_no = args[0].to_i
138
- return send_msg("Choose a team between 1 and 4", e.channel) unless team_no.between?(1, 4)
140
+ return send_msg("Choose a team between 0 and 4", e.channel) unless team_no.between?(0, 4)
139
141
 
140
- user_id = e.user_id
141
- return send_msg("You're already in team #{team_no}", e.channel) if pug.team(team_no).include?(user_id)
142
+ pug_already_full = pug.full?
142
143
 
143
- join_pug(e, pug) unless pug.joined?(user_id)
144
- pug.join_team(team_no: team_no, player_id: user_id)
144
+ if args.count == 1
145
+ user_id = e.user_id
146
+ return send_msg("You're already in team #{team_no}", e.channel) if pug.team(team_no).include?(user_id)
145
147
 
146
- send_msg(
147
- [
148
- "#{e.display_name} joins team #{team_no}",
149
- "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
150
- ].join(MSG_SNIPPET_DELIMITER), e.channel
151
- )
148
+ join_pug(e, pug) unless pug.joined?(user_id)
149
+ pug.join_team(team_no: team_no, player_id: user_id)
152
150
 
153
- start_pug(pug, e) if pug.full?
151
+ send_msg(
152
+ [
153
+ "#{e.display_name} joins team #{team_no}",
154
+ "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
155
+ ].join(MSG_SNIPPET_DELIMITER), e.channel
156
+ )
157
+ else
158
+ args[1..-1].each do |mention|
159
+ unless mention.match(/<@!\d+>/)
160
+ send_msg("#{arg} isn't a valid mention", e.channel)
161
+ next
162
+ end
163
+
164
+ user_id = mention_to_user_id(mention)
165
+ display_name = e.display_name_for(user_id) || arg
166
+
167
+ unless pug.joined?(user_id)
168
+ send_msg("#{display_name} isn't in the PUG", e.channel)
169
+ next
170
+ end
171
+
172
+ pug.join_team(team_no: team_no, player_id: user_id)
173
+
174
+ send_msg(
175
+ [
176
+ "#{display_name} joins team #{team_no}",
177
+ "#{pug.team_player_count(team_no)}/#{pug.teamsize}"
178
+ ].join(MSG_SNIPPET_DELIMITER), e.channel
179
+ )
180
+ end
181
+ end
182
+
183
+ start_pug(pug, e) if !pug_already_full && pug.full?
154
184
  end
155
185
  end
156
186
 
@@ -174,7 +204,13 @@ class QwtfDiscordBotPug # :nodoc:
174
204
 
175
205
  return send_msg("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
176
206
 
177
- team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
207
+ if pug.actual_teams.count < 2
208
+ return send_msg(
209
+ "There must be at least two teams with players to submit a result", e.channel
210
+ )
211
+ end
212
+
213
+ team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
178
214
  players = player_ids.inject({}) do |memo, id|
179
215
  memo.merge({ id => e.display_name_for(id) })
180
216
  end
@@ -187,7 +223,11 @@ class QwtfDiscordBotPug # :nodoc:
187
223
  {
188
224
  match: {
189
225
  map: pug.game_map,
190
- teams: team_results
226
+ teams: team_results,
227
+ discord_channel: {
228
+ channel_id: e.channel_id,
229
+ name: "#{e.channel.server.name} ##{e.channel.name}"
230
+ }
191
231
  }
192
232
  }.to_json
193
233
  )
@@ -210,19 +250,29 @@ class QwtfDiscordBotPug # :nodoc:
210
250
  setup_pug(event) do |e, pug|
211
251
  return send_msg(no_active_pug_message, e.channel) unless pug.active?
212
252
 
213
- team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
253
+ if pug.actual_teams.count < 2
254
+ return send_msg(
255
+ "There must be at least two teams with players to submit a result", e.channel
256
+ )
257
+ end
258
+
259
+ team_results = pug.actual_teams.inject({}) do |teams, (name, player_ids)|
214
260
  players = player_ids.inject({}) do |memo, id|
215
261
  memo.merge({ id => e.display_name_for(id) })
216
262
  end
217
263
 
218
- teams.merge({ name => { players: players, result: 0 } })
264
+ teams.merge({ name => { players: players, result: 0 } })
219
265
  end
220
266
 
221
267
  post_results(
222
268
  {
223
269
  match: {
224
270
  map: pug.game_map,
225
- teams: team_results
271
+ teams: team_results,
272
+ discord_channel: {
273
+ channel_id: e.channel_id,
274
+ name: "#{e.channel.server.name} ##{e.channel.name}"
275
+ }
226
276
  }
227
277
  }.to_json
228
278
  )
@@ -307,6 +357,10 @@ class QwtfDiscordBotPug # :nodoc:
307
357
 
308
358
  private
309
359
 
360
+ def mention_to_user_id(mention)
361
+ mention[3..-2].to_i
362
+ end
363
+
310
364
  def join_pug(e, pug)
311
365
  pug.join(e.user_id)
312
366
 
@@ -390,7 +444,7 @@ class QwtfDiscordBotPug # :nodoc:
390
444
  uri = URI("#{ENV['RATINGS_API_URL']}matches/")
391
445
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
392
446
  req.body = json
393
- res = Net::HTTP.start(uri.hostname, uri.port) do |http|
447
+ Net::HTTP.start(uri.hostname, uri.port) do |http|
394
448
  http.request(req)
395
449
  end
396
450
  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: 5.3.1
4
+ version: 5.3.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-03 00:00:00.000000000 Z
11
+ date: 2020-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb