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 +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/docker-compose.yml +1 -1
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +61 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e4ea9a3df5bcc8c8cb14ba1d22a0708bdf8c4a994531d4c06fb8bbc75b33410
|
4
|
+
data.tar.gz: 1568efc1c854b8d4d43d60fd0caa48b0e52e4b09ca04336b6b8c1969090fb146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50d22f311c0c29ce8df6f1a9c473559812a60d7602f79aa2a9976ffec4a44b6e2f096d6c7c7ac45d390569854393ea14b4ca2afa7f6b7213ba093330221bf48e
|
7
|
+
data.tar.gz: cb34ac9dd1c0f5ff46c09700c1998c8e0cae344cc4b0944a40e2c8fad25bb46cfe3db8ab202e0079f20d982d1dfe74382cf01efe152484abc7f652a83008316f
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.3.
|
1
|
+
5.3.5
|
data/docker-compose.yml
CHANGED
@@ -105,7 +105,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
105
105
|
next
|
106
106
|
end
|
107
107
|
|
108
|
-
user_id = arg
|
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
|
140
|
+
return send_msg("Choose a team between 0 and 4", e.channel) unless team_no.between?(0, 4)
|
139
141
|
|
140
|
-
|
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
|
-
|
144
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|