qwtf_discord_bot 5.2.6 → 5.3.4
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 +46 -11
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +162 -28
- 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: 287ada88fe7e7e8db0a61816eb5872adf7aa51aae6ceed90d55e446d42222484
|
4
|
+
data.tar.gz: 44b89de85fea1a429a14418d3fd0d5b3aabc7dec291502176a9ab16d5de45d69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a3ea4bf9ef15c27795e60610a981948487eb626f65edd34eca71da52b3752f9134574598695ffe870046e9ea4f59e8feaa360ac76bdf3a3abe4a043c5bdcaec
|
7
|
+
data.tar.gz: d06a5a2efacdee2ee0ba62e180d9ee82dcacabc469828459619dc15174851b78aa726fcb35f56c0114eb843afeb83c3f15a2ff4c1c7a74684d3683394ffac746
|
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.4
|
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
|
@@ -140,6 +163,18 @@ class Pug
|
|
140
163
|
[channel_key, 'teamsize'].join(':')
|
141
164
|
end
|
142
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(':')
|
176
|
+
end
|
177
|
+
|
143
178
|
def redis
|
144
179
|
Redis.current
|
145
180
|
end
|
@@ -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
|
@@ -89,12 +90,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
89
90
|
e.channel
|
90
91
|
)
|
91
92
|
|
92
|
-
|
93
|
+
end_pug(pug, e.channel) if pug.empty?
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
97
|
bot.command :kick do |event, *args|
|
97
98
|
setup_pug(event) do |e, pug|
|
99
|
+
return send_msg("Kick who? e.g. `!kick @#{e.display_name}`", e.channel) unless args.any?
|
98
100
|
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
99
101
|
|
100
102
|
args.each do |arg|
|
@@ -103,7 +105,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
103
105
|
next
|
104
106
|
end
|
105
107
|
|
106
|
-
user_id = arg
|
108
|
+
user_id = mention_to_user_id(arg)
|
107
109
|
display_name = e.display_name_for(user_id) || arg
|
108
110
|
|
109
111
|
unless pug.joined?(user_id)
|
@@ -125,30 +127,60 @@ class QwtfDiscordBotPug # :nodoc:
|
|
125
127
|
e.channel
|
126
128
|
)
|
127
129
|
|
128
|
-
break
|
130
|
+
break end_pug(pug, e.channel) if pug.empty?
|
129
131
|
end
|
130
132
|
end
|
131
133
|
end
|
132
134
|
|
133
135
|
bot.command :team do |event, *args|
|
134
136
|
setup_pug(event) do |e, pug|
|
137
|
+
return send_msg("Which team? E.G. `!team 1`", e.channel) unless args.any?
|
138
|
+
|
135
139
|
team_no = args[0].to_i
|
136
|
-
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)
|
137
141
|
|
138
|
-
|
139
|
-
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?
|
140
143
|
|
141
|
-
|
142
|
-
|
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)
|
143
147
|
|
144
|
-
|
145
|
-
|
146
|
-
"#{e.display_name} joins team #{team_no}",
|
147
|
-
"#{pug.team_player_count(team_no)}/#{pug.teamsize}"
|
148
|
-
].join(MSG_SNIPPET_DELIMITER), e.channel
|
149
|
-
)
|
148
|
+
join_pug(e, pug) unless pug.joined?(user_id)
|
149
|
+
pug.join_team(team_no: team_no, player_id: user_id)
|
150
150
|
|
151
|
-
|
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?
|
152
184
|
end
|
153
185
|
end
|
154
186
|
|
@@ -172,22 +204,64 @@ class QwtfDiscordBotPug # :nodoc:
|
|
172
204
|
|
173
205
|
return send_msg("Not a valid team", e.channel) unless pug.team(winning_team_no).any?
|
174
206
|
|
175
|
-
pug.
|
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
|
176
213
|
|
177
|
-
|
178
|
-
|
214
|
+
result = winning_team_no.to_i == name.to_i ? 1 : -1
|
215
|
+
teams.merge({ name => { players: players, result: result } })
|
179
216
|
end
|
180
217
|
|
181
|
-
|
218
|
+
post_results(
|
219
|
+
{
|
220
|
+
match: {
|
221
|
+
map: pug.game_map,
|
222
|
+
teams: team_results
|
223
|
+
}
|
224
|
+
}.to_json
|
225
|
+
)
|
226
|
+
|
227
|
+
# winning_team = pug.team(winning_team_no).map do |player_id|
|
228
|
+
# e.display_name_for(player_id)
|
229
|
+
# end
|
230
|
+
|
231
|
+
# non_winning_teams = pug.actual_teams.tap { |team| team.delete(winning_team_no) }
|
232
|
+
|
233
|
+
# losing_players = non_winning_teams.values.flatten.map do |player_id|
|
234
|
+
# e.display_name_for(player_id)
|
235
|
+
# end
|
182
236
|
|
183
|
-
|
184
|
-
|
237
|
+
send_msg("Team #{winning_team_no} wins", e.channel)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
bot.command :draw do |event, *args|
|
242
|
+
setup_pug(event) do |e, pug|
|
243
|
+
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
244
|
+
|
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
|
251
|
+
|
252
|
+
teams.merge({ name => { players: players, result: 0 } })
|
185
253
|
end
|
186
254
|
|
187
|
-
|
188
|
-
|
189
|
-
|
255
|
+
post_results(
|
256
|
+
{
|
257
|
+
match: {
|
258
|
+
map: pug.game_map,
|
259
|
+
teams: team_results
|
260
|
+
}
|
261
|
+
}.to_json
|
190
262
|
)
|
263
|
+
|
264
|
+
send_msg("Match drawn", e.channel)
|
191
265
|
end
|
192
266
|
end
|
193
267
|
|
@@ -195,9 +269,55 @@ class QwtfDiscordBotPug # :nodoc:
|
|
195
269
|
setup_pug(event) do |e, pug|
|
196
270
|
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
197
271
|
|
198
|
-
pug.
|
272
|
+
end_pug(pug, e.channel)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
bot.command :addmap do |event, *args|
|
277
|
+
setup_pug(event) do |e, pug|
|
278
|
+
maps = args
|
279
|
+
return send_msg("What map? e.g. `!addmap 2fort5r`", e.channel) unless maps.any?
|
280
|
+
|
281
|
+
pug.add_maps(maps)
|
282
|
+
send_msg("#{maps.join(', ')} added to maps", e.channel)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
bot.command :removemap do |event, *args|
|
287
|
+
setup_pug(event) do |e, pug|
|
288
|
+
maps = args
|
289
|
+
return send_msg("What map? e.g. `!removemap 2fort5r`", e.channel) unless maps.any?
|
290
|
+
|
291
|
+
pug.remove_maps(maps)
|
292
|
+
send_msg("#{maps.join(', ')} removed from maps", e.channel)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
bot.command :maps do |event, *args|
|
297
|
+
setup_pug(event) do |e, pug|
|
298
|
+
maps = pug.maps
|
299
|
+
return send_msg('No maps have been added. `!addmap`', e.channel) unless maps.any?
|
199
300
|
|
200
|
-
send_msg(
|
301
|
+
send_msg(maps.join(', '), e.channel)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
bot.command :map do |event, *args|
|
306
|
+
setup_pug(event) do |e, pug|
|
307
|
+
maps = pug.maps
|
308
|
+
return send_msg('No maps have been added. `!addmap`', e.channel) unless maps.any?
|
309
|
+
return send_msg(no_active_pug_message, e.channel) unless pug.active?
|
310
|
+
|
311
|
+
if args.empty?
|
312
|
+
return send_msg('No map has been set for the current PUG', e.channel) unless pug.game_map
|
313
|
+
send_msg("Current map is #{pug.game_map}", e.channel)
|
314
|
+
else
|
315
|
+
game_map = args.first
|
316
|
+
return send_msg("#{game_map} isn't in the map list. `!addmap` to add it.", e.channel) unless maps.include?(game_map)
|
317
|
+
|
318
|
+
pug.game_map = game_map
|
319
|
+
send_msg("Map set to #{game_map}", e.channel)
|
320
|
+
end
|
201
321
|
end
|
202
322
|
end
|
203
323
|
|
@@ -221,6 +341,10 @@ class QwtfDiscordBotPug # :nodoc:
|
|
221
341
|
|
222
342
|
private
|
223
343
|
|
344
|
+
def mention_to_user_id(mention)
|
345
|
+
mention[3..-2].to_i
|
346
|
+
end
|
347
|
+
|
224
348
|
def join_pug(e, pug)
|
225
349
|
pug.join(e.user_id)
|
226
350
|
|
@@ -287,8 +411,9 @@ class QwtfDiscordBotPug # :nodoc:
|
|
287
411
|
end
|
288
412
|
end
|
289
413
|
|
290
|
-
def
|
291
|
-
|
414
|
+
def end_pug(pug, channel_id)
|
415
|
+
pug.end_pug
|
416
|
+
send_msg('PUG ended', channel_id)
|
292
417
|
end
|
293
418
|
|
294
419
|
def no_active_pug_message
|
@@ -298,4 +423,13 @@ class QwtfDiscordBotPug # :nodoc:
|
|
298
423
|
def send_msg(message, channel)
|
299
424
|
channel.send_message(message) && puts(message)
|
300
425
|
end
|
426
|
+
|
427
|
+
def post_results(json)
|
428
|
+
uri = URI("#{ENV['RATINGS_API_URL']}matches/")
|
429
|
+
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
430
|
+
req.body = json
|
431
|
+
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
432
|
+
http.request(req)
|
433
|
+
end
|
434
|
+
end
|
301
435
|
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.4
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|