qwtf_discord_bot 5.2.5 → 5.3.3
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/README.md +8 -3
- data/VERSION +1 -1
- data/docker-compose.yml +1 -0
- data/lib/event_decorator.rb +4 -0
- data/lib/pug.rb +47 -12
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +159 -27
- 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: 601af47db687365971e97efd281732ed5effb977d1cd0d451aeda38be1ab27df
|
4
|
+
data.tar.gz: 2d06e9cb9f311d0b427445760a13729df7f8a59b582ed8c536e219137c930a25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b67d9dcc35b75b0ea64dc482df3f0c2d9e180aa70288b9ebb98f2c58016e08d9eb504a542cfaf2e51e449a40e3dda33f9ed05da992c226f5a0f465dc1805f951
|
7
|
+
data.tar.gz: 3a75ce85122e1d3db1e2dc8dfa5dc7f3c614633f2506353d31cee66a7db2d09d29fe9130030f036885ed8d56fcbea776fdb5ad087251ae75698f8239ebf87e43
|
data/README.md
CHANGED
@@ -86,15 +86,20 @@ This responds to discord messages:
|
|
86
86
|
qwtf-discord-bot pug
|
87
87
|
|
88
88
|
This responds to discord messages:
|
89
|
+
- `!status`
|
89
90
|
- `!join`
|
90
91
|
- `!leave`
|
91
|
-
- `!status`
|
92
|
-
- `!kick <@player>`
|
93
92
|
- `!teamsize <no_of_players>`
|
93
|
+
- `!kick <@player>`
|
94
94
|
- `!team <team_no>`
|
95
95
|
- `!unteam`
|
96
|
+
- `!addmap <map_name>`
|
97
|
+
- `!removemap <map_name>`
|
98
|
+
- `!maps`
|
99
|
+
- `!map <map_name>`
|
96
100
|
- `!win <team_no>`
|
97
|
-
- `!
|
101
|
+
- `!draw`
|
102
|
+
- `!notify <@role>`
|
98
103
|
- `!end`
|
99
104
|
|
100
105
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.3.3
|
data/docker-compose.yml
CHANGED
data/lib/event_decorator.rb
CHANGED
data/lib/pug.rb
CHANGED
@@ -27,6 +27,26 @@ class Pug
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def add_maps(maps)
|
31
|
+
redis.sadd(maps_key, maps)
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_maps(maps)
|
35
|
+
redis.srem(maps_key, maps)
|
36
|
+
end
|
37
|
+
|
38
|
+
def maps
|
39
|
+
redis.smembers(maps_key)
|
40
|
+
end
|
41
|
+
|
42
|
+
def vote(player_id:, map:)
|
43
|
+
redis.sadd(votes_key(map), player_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def vote_count(map)
|
47
|
+
redis.scard(votes_key(map)).to_i
|
48
|
+
end
|
49
|
+
|
30
50
|
def team(number)
|
31
51
|
redis.smembers(team_key(number)).map(&:to_i)
|
32
52
|
end
|
@@ -39,6 +59,10 @@ class Pug
|
|
39
59
|
joined_player_count >= maxplayers
|
40
60
|
end
|
41
61
|
|
62
|
+
def empty?
|
63
|
+
joined_player_count.zero?
|
64
|
+
end
|
65
|
+
|
42
66
|
def joined_player_count
|
43
67
|
joined_players.count
|
44
68
|
end
|
@@ -55,6 +79,14 @@ class Pug
|
|
55
79
|
maxplayers - joined_player_count
|
56
80
|
end
|
57
81
|
|
82
|
+
def game_map=(map)
|
83
|
+
redis.set([pug_key, 'map'].join(':'), map)
|
84
|
+
end
|
85
|
+
|
86
|
+
def game_map
|
87
|
+
redis.get([pug_key, 'map'].join(':'))
|
88
|
+
end
|
89
|
+
|
58
90
|
def notify_roles=(roles)
|
59
91
|
redis.set(notify_roles_key, roles)
|
60
92
|
end
|
@@ -73,7 +105,6 @@ class Pug
|
|
73
105
|
|
74
106
|
def leave(player_id)
|
75
107
|
leave_teams(player_id)
|
76
|
-
end_pug if empty?
|
77
108
|
end
|
78
109
|
|
79
110
|
def end_pug
|
@@ -90,10 +121,6 @@ class Pug
|
|
90
121
|
teamsize * no_of_teams
|
91
122
|
end
|
92
123
|
|
93
|
-
def won_by(team_no)
|
94
|
-
{ teams: teams, winner: team_no }
|
95
|
-
end
|
96
|
-
|
97
124
|
def teams
|
98
125
|
teams_keys.inject({}) do |teams, team|
|
99
126
|
teams.merge({ team.split(':').last => redis.smembers(team).map(&:to_i) })
|
@@ -116,10 +143,6 @@ class Pug
|
|
116
143
|
redis.keys([pug_key, 'teams:*'].join(':'))
|
117
144
|
end
|
118
145
|
|
119
|
-
def empty?
|
120
|
-
joined_player_count.zero?
|
121
|
-
end
|
122
|
-
|
123
146
|
def team_key(team_no)
|
124
147
|
[pug_key, 'teams', team_no].join(':')
|
125
148
|
end
|
@@ -128,8 +151,8 @@ class Pug
|
|
128
151
|
[channel_key, 'pug'].join(':')
|
129
152
|
end
|
130
153
|
|
131
|
-
def
|
132
|
-
['
|
154
|
+
def maps_key
|
155
|
+
[channel_key, 'maps'].join(':')
|
133
156
|
end
|
134
157
|
|
135
158
|
def notify_roles_key
|
@@ -137,7 +160,19 @@ class Pug
|
|
137
160
|
end
|
138
161
|
|
139
162
|
def teamsize_key
|
140
|
-
[
|
163
|
+
[channel_key, 'teamsize'].join(':')
|
164
|
+
end
|
165
|
+
|
166
|
+
def votes_keys
|
167
|
+
redis.keys([pug_key, 'votes:*'].join(':'))
|
168
|
+
end
|
169
|
+
|
170
|
+
def votes_key(map)
|
171
|
+
[channel_key, 'votes', map].join(':')
|
172
|
+
end
|
173
|
+
|
174
|
+
def channel_key
|
175
|
+
['channel', @channel_id].join(':')
|
141
176
|
end
|
142
177
|
|
143
178
|
def redis
|
@@ -32,6 +32,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
32
32
|
send_msg(
|
33
33
|
[
|
34
34
|
"#{pug.player_slots} joined",
|
35
|
+
"Map: #{pug.game_map}",
|
35
36
|
pug_teams_message(pug, e).join("\n")
|
36
37
|
].join("\n"),
|
37
38
|
e.channel
|
@@ -41,6 +42,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
41
42
|
|
42
43
|
bot.command :teamsize do |event, *args|
|
43
44
|
setup_pug(event) do |e, pug|
|
45
|
+
return send_msg("Team size is #{pug.teamsize}", e.channel) unless args.any?
|
46
|
+
|
44
47
|
new_teamsize = args[0].to_i
|
45
48
|
return send_msg('Team size should be a number higher than 0', e.channel) unless new_teamsize > 0
|
46
49
|
|
@@ -87,12 +90,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
87
90
|
e.channel
|
88
91
|
)
|
89
92
|
|
90
|
-
|
93
|
+
end_pug(pug, e.channel) if pug.empty?
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
94
97
|
bot.command :kick do |event, *args|
|
95
98
|
setup_pug(event) do |e, pug|
|
99
|
+
return send_msg("Kick who? e.g. `!kick @#{e.display_name}`", e.channel) unless args.any?
|
96
100
|
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
97
101
|
|
98
102
|
args.each do |arg|
|
@@ -101,7 +105,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
101
105
|
next
|
102
106
|
end
|
103
107
|
|
104
|
-
user_id = arg
|
108
|
+
user_id = mention_to_user_id(arg)
|
105
109
|
display_name = e.display_name_for(user_id) || arg
|
106
110
|
|
107
111
|
unless pug.joined?(user_id)
|
@@ -123,30 +127,60 @@ class QwtfDiscordBotPug # :nodoc:
|
|
123
127
|
e.channel
|
124
128
|
)
|
125
129
|
|
126
|
-
break
|
130
|
+
break end_pug(pug, e.channel) if pug.empty?
|
127
131
|
end
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
131
135
|
bot.command :team do |event, *args|
|
132
136
|
setup_pug(event) do |e, pug|
|
137
|
+
return send_msg("Which team? E.G. `!team 1`", e.channel) unless args.any?
|
138
|
+
|
133
139
|
team_no = args[0].to_i
|
134
140
|
return send_msg("Choose a team between 1 and 4", e.channel) unless team_no.between?(1, 4)
|
135
141
|
|
136
|
-
|
137
|
-
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?
|
138
143
|
|
139
|
-
|
140
|
-
|
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)
|
141
147
|
|
142
|
-
|
143
|
-
|
144
|
-
"#{e.display_name} joins team #{team_no}",
|
145
|
-
"#{pug.team_player_count(team_no)}/#{pug.teamsize}"
|
146
|
-
].join(MSG_SNIPPET_DELIMITER), e.channel
|
147
|
-
)
|
148
|
+
join_pug(e, pug) unless pug.joined?(user_id)
|
149
|
+
pug.join_team(team_no: team_no, player_id: user_id)
|
148
150
|
|
149
|
-
|
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?
|
150
184
|
end
|
151
185
|
end
|
152
186
|
|
@@ -170,22 +204,60 @@ class QwtfDiscordBotPug # :nodoc:
|
|
170
204
|
|
171
205
|
return send_msg("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
|
172
206
|
|
173
|
-
pug.
|
207
|
+
team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
|
208
|
+
players = player_ids.inject({}) do |memo, id|
|
209
|
+
memo.merge({ id => e.display_name_for(id) })
|
210
|
+
end
|
174
211
|
|
175
|
-
|
176
|
-
|
212
|
+
result = winning_team_no.to_i == name.to_i ? 1 : -1
|
213
|
+
teams.merge({ name => { players: players, result: result } })
|
177
214
|
end
|
178
215
|
|
179
|
-
|
216
|
+
post_results(
|
217
|
+
{
|
218
|
+
match: {
|
219
|
+
map: pug.game_map,
|
220
|
+
teams: team_results
|
221
|
+
}
|
222
|
+
}.to_json
|
223
|
+
)
|
224
|
+
|
225
|
+
# winning_team = pug.team(winning_team_no).map do |player_id|
|
226
|
+
# e.display_name_for(player_id)
|
227
|
+
# end
|
228
|
+
|
229
|
+
# non_winning_teams = pug.actual_teams.tap { |team| team.delete(winning_team_no) }
|
230
|
+
|
231
|
+
# losing_players = non_winning_teams.values.flatten.map do |player_id|
|
232
|
+
# e.display_name_for(player_id)
|
233
|
+
# end
|
234
|
+
|
235
|
+
send_msg("Team #{winning_team_no} wins", e.channel)
|
236
|
+
end
|
237
|
+
end
|
180
238
|
|
181
|
-
|
182
|
-
|
239
|
+
bot.command :draw do |event, *args|
|
240
|
+
setup_pug(event) do |e, pug|
|
241
|
+
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
242
|
+
|
243
|
+
team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
|
244
|
+
players = player_ids.inject({}) do |memo, id|
|
245
|
+
memo.merge({ id => e.display_name_for(id) })
|
246
|
+
end
|
247
|
+
|
248
|
+
teams.merge({ name => { players: players, result: 0 } })
|
183
249
|
end
|
184
250
|
|
185
|
-
|
186
|
-
|
187
|
-
|
251
|
+
post_results(
|
252
|
+
{
|
253
|
+
match: {
|
254
|
+
map: pug.game_map,
|
255
|
+
teams: team_results
|
256
|
+
}
|
257
|
+
}.to_json
|
188
258
|
)
|
259
|
+
|
260
|
+
send_msg("Match drawn", e.channel)
|
189
261
|
end
|
190
262
|
end
|
191
263
|
|
@@ -193,9 +265,55 @@ class QwtfDiscordBotPug # :nodoc:
|
|
193
265
|
setup_pug(event) do |e, pug|
|
194
266
|
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
195
267
|
|
196
|
-
pug.
|
268
|
+
end_pug(pug, e.channel)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
bot.command :addmap do |event, *args|
|
273
|
+
setup_pug(event) do |e, pug|
|
274
|
+
maps = args
|
275
|
+
return send_msg("What map? e.g. `!addmap 2fort5r`", e.channel) unless maps.any?
|
276
|
+
|
277
|
+
pug.add_maps(maps)
|
278
|
+
send_msg("#{maps.join(', ')} added to maps", e.channel)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
bot.command :removemap do |event, *args|
|
283
|
+
setup_pug(event) do |e, pug|
|
284
|
+
maps = args
|
285
|
+
return send_msg("What map? e.g. `!removemap 2fort5r`", e.channel) unless maps.any?
|
286
|
+
|
287
|
+
pug.remove_maps(maps)
|
288
|
+
send_msg("#{maps.join(', ')} removed from maps", e.channel)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
bot.command :maps do |event, *args|
|
293
|
+
setup_pug(event) do |e, pug|
|
294
|
+
maps = pug.maps
|
295
|
+
return send_msg('No maps have been added. `!addmap`', e.channel) unless maps.any?
|
197
296
|
|
198
|
-
send_msg(
|
297
|
+
send_msg(maps.join(', '), e.channel)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
bot.command :map do |event, *args|
|
302
|
+
setup_pug(event) do |e, pug|
|
303
|
+
maps = pug.maps
|
304
|
+
return send_msg('No maps have been added. `!addmap`', e.channel) unless maps.any?
|
305
|
+
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
306
|
+
|
307
|
+
if args.empty?
|
308
|
+
return send_msg('No map has been set for the current PUG', e.channel) unless pug.game_map
|
309
|
+
send_msg("Current map is #{pug.game_map}", e.channel)
|
310
|
+
else
|
311
|
+
game_map = args.first
|
312
|
+
return send_msg("#{game_map} isn't in the map list. `!addmap` to add it.", e.channel) unless maps.include?(game_map)
|
313
|
+
|
314
|
+
pug.game_map = game_map
|
315
|
+
send_msg("Map set to #{game_map}", e.channel)
|
316
|
+
end
|
199
317
|
end
|
200
318
|
end
|
201
319
|
|
@@ -219,6 +337,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
219
337
|
|
220
338
|
private
|
221
339
|
|
340
|
+
def mention_to_user_id(mention)
|
341
|
+
mention[3..-2].to_i
|
342
|
+
end
|
343
|
+
|
222
344
|
def join_pug(e, pug)
|
223
345
|
pug.join(e.user_id)
|
224
346
|
|
@@ -285,8 +407,9 @@ class QwtfDiscordBotPug # :nodoc:
|
|
285
407
|
end
|
286
408
|
end
|
287
409
|
|
288
|
-
def
|
289
|
-
|
410
|
+
def end_pug(pug, channel_id)
|
411
|
+
pug.end_pug
|
412
|
+
send_msg('PUG ended', channel_id)
|
290
413
|
end
|
291
414
|
|
292
415
|
def no_active_pug_message
|
@@ -296,4 +419,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
296
419
|
def send_msg(message, channel)
|
297
420
|
channel.send_message(message) && puts(message)
|
298
421
|
end
|
422
|
+
|
423
|
+
def post_results(json)
|
424
|
+
uri = URI("#{ENV['RATINGS_API_URL']}matches/")
|
425
|
+
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
426
|
+
req.body = json
|
427
|
+
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
428
|
+
http.request(req)
|
429
|
+
end
|
430
|
+
end
|
299
431
|
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.
|
4
|
+
version: 5.3.3
|
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-
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|