qwtf_discord_bot 5.3.0 → 5.3.5

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: ccd211cda52ba5e8319f7c4cc1466abf47112c8d46b13180d8b89a09a1a2ca68
4
- data.tar.gz: df7bd13a55e52d63128fceeaf07f3ea8c9237471480bbb6cb3e967e73c20babf
3
+ metadata.gz: 1e4ea9a3df5bcc8c8cb14ba1d22a0708bdf8c4a994531d4c06fb8bbc75b33410
4
+ data.tar.gz: 1568efc1c854b8d4d43d60fd0caa48b0e52e4b09ca04336b6b8c1969090fb146
5
5
  SHA512:
6
- metadata.gz: 0b4a3e1df6ff63f47b167c959570d6d994d92fdc52bdf35b36a70734a09afe3b1caa20b2181b366bea83050c25ca1f3d748b1bf52cc93dfc26e5afd7c6d82150
7
- data.tar.gz: 2974c3a18e557b7788fc75af370a781b43a50eafe85c47740b9298276c79fa33f7e260fc196e5e53eef4fca72a62b8ef19d7607397532469c15e4d8f7f6da911
6
+ metadata.gz: 50d22f311c0c29ce8df6f1a9c473559812a60d7602f79aa2a9976ffec4a44b6e2f096d6c7c7ac45d390569854393ea14b4ca2afa7f6b7213ba093330221bf48e
7
+ data.tar.gz: cb34ac9dd1c0f5ff46c09700c1998c8e0cae344cc4b0944a40e2c8fad25bb46cfe3db8ab202e0079f20d982d1dfe74382cf01efe152484abc7f652a83008316f
@@ -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.0
1
+ 5.3.5
@@ -34,7 +34,7 @@ services:
34
34
  - redis
35
35
  environment:
36
36
  - REDIS_URL=redis://redis
37
- - RATINGS_API_URL=http://ratings.fortressone.org/api/v1/
37
+ - RATINGS_API_URL
38
38
  volumes:
39
39
  - type: bind
40
40
  source: "/home/ubuntu/.config/qwtf_discord_bot/config.yaml"
@@ -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,11 +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
- players = pug.joined_players.inject({}) do |memo, id|
178
- memo.merge({ id => e.display_name_for(id) })
179
- end
207
+ actual_teams = pug.teams.reject { |k| k == "0" }
208
+
209
+ team_results = actual_teams.inject({}) do |teams, (name, player_ids)|
210
+ players = player_ids.inject({}) do |memo, id|
211
+ memo.merge({ id => e.display_name_for(id) })
212
+ end
180
213
 
181
- team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
182
214
  result = winning_team_no.to_i == name.to_i ? 1 : -1
183
215
  teams.merge({ name => { players: players, result: result } })
184
216
  end
@@ -210,12 +242,14 @@ class QwtfDiscordBotPug # :nodoc:
210
242
  setup_pug(event) do |e, pug|
211
243
  return send_msg(no_active_pug_message, e.channel) unless pug.active?
212
244
 
213
- players = pug.joined_players.inject({}) do |memo, id|
214
- memo.merge({ id => e.display_name_for(id) })
215
- end
245
+ actual_teams = pug.teams.reject! { |k| k == "0" }
246
+
247
+ team_results = actual_teams.inject({}) do |teams, (name, player_ids)|
248
+ players = player_ids.inject({}) do |memo, id|
249
+ memo.merge({ id => e.display_name_for(id) })
250
+ end
216
251
 
217
- team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
218
- teams.merge({ name => { players: players, result: 0 } })
252
+ teams.merge({ name => { players: players, result: 0 } })
219
253
  end
220
254
 
221
255
  post_results(
@@ -307,6 +341,10 @@ class QwtfDiscordBotPug # :nodoc:
307
341
 
308
342
  private
309
343
 
344
+ def mention_to_user_id(mention)
345
+ mention[3..-2].to_i
346
+ end
347
+
310
348
  def join_pug(e, pug)
311
349
  pug.join(e.user_id)
312
350
 
@@ -390,7 +428,7 @@ class QwtfDiscordBotPug # :nodoc:
390
428
  uri = URI("#{ENV['RATINGS_API_URL']}matches/")
391
429
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
392
430
  req.body = json
393
- res = Net::HTTP.start(uri.hostname, uri.port) do |http|
431
+ Net::HTTP.start(uri.hostname, uri.port) do |http|
394
432
  http.request(req)
395
433
  end
396
434
  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.0
4
+ version: 5.3.5
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-02 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb