qwtf_discord_bot 6.0.4 → 6.1.0
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/VERSION +1 -1
- data/lib/pug.rb +50 -28
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +40 -21
- 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: a2cbd2052764c82fc832ccac617eb4a2c26e2861827c95b430ee0ad341274027
|
4
|
+
data.tar.gz: 4d67b365bda23d496afd20ea375a2486f52fe1b59cf29f6844435254cc7cacb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dbde41666f182f177cdc0a5d7e4329388769515e238918be21f7f5dd203f974c43034c95f7b02b0fa965d49885e06e435b5aec0a8a14bff9f87f33068b3ae4b
|
7
|
+
data.tar.gz: 2080539c53ec3a5225e000aa872860613b90aa50616fcf006c356835b78e2f2ccc9570a8f902d3bdcafe602ca48e83957e12703017ee71c11010b4585150f153
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
6.0
|
1
|
+
6.1.0
|
data/lib/pug.rb
CHANGED
@@ -11,17 +11,28 @@ class Pug
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def join(player_id)
|
14
|
-
|
15
|
-
redis.
|
14
|
+
timestamp = Time.now.to_i
|
15
|
+
redis.setnx(pug_key, timestamp)
|
16
|
+
redis.zadd(queue_key, timestamp, player_id, nx: true)
|
16
17
|
end
|
17
18
|
|
18
19
|
def join_team(team_no:, player_id:)
|
19
|
-
|
20
|
-
|
20
|
+
join(player_id)
|
21
|
+
unteam(player_id)
|
21
22
|
redis.sadd(team_key(team_no), player_id)
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
+
def up_now_players
|
26
|
+
players[0, maxplayers]
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy_teams
|
30
|
+
teamed_players.each do |player_id|
|
31
|
+
unteam(player_id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def teamed_players
|
25
36
|
teams_keys.inject([]) do |players, team|
|
26
37
|
players + redis.smembers(team).map(&:to_i)
|
27
38
|
end
|
@@ -55,16 +66,20 @@ class Pug
|
|
55
66
|
redis.set(teamsize_key, teamsize)
|
56
67
|
end
|
57
68
|
|
69
|
+
def total_player_count
|
70
|
+
players.count
|
71
|
+
end
|
72
|
+
|
58
73
|
def full?
|
59
|
-
|
74
|
+
total_player_count >= maxplayers
|
60
75
|
end
|
61
76
|
|
62
77
|
def empty?
|
63
|
-
|
78
|
+
total_player_count.zero?
|
64
79
|
end
|
65
80
|
|
66
|
-
def
|
67
|
-
|
81
|
+
def teamed_player_count
|
82
|
+
teamed_players.count
|
68
83
|
end
|
69
84
|
|
70
85
|
def team_player_count(team_no)
|
@@ -72,11 +87,11 @@ class Pug
|
|
72
87
|
end
|
73
88
|
|
74
89
|
def player_slots
|
75
|
-
"#{
|
90
|
+
"#{total_player_count}/#{maxplayers}"
|
76
91
|
end
|
77
92
|
|
78
93
|
def slots_left
|
79
|
-
maxplayers -
|
94
|
+
maxplayers - total_player_count
|
80
95
|
end
|
81
96
|
|
82
97
|
def game_map=(map)
|
@@ -104,7 +119,8 @@ class Pug
|
|
104
119
|
end
|
105
120
|
|
106
121
|
def leave(player_id)
|
107
|
-
|
122
|
+
leave_queue(player_id)
|
123
|
+
unteam(player_id)
|
108
124
|
end
|
109
125
|
|
110
126
|
def end_pug
|
@@ -114,13 +130,17 @@ class Pug
|
|
114
130
|
end
|
115
131
|
|
116
132
|
def joined?(player_id)
|
117
|
-
|
133
|
+
redis.zrank(queue_key, player_id)
|
118
134
|
end
|
119
135
|
|
120
136
|
def maxplayers
|
121
137
|
teamsize * no_of_teams
|
122
138
|
end
|
123
139
|
|
140
|
+
def queued_players
|
141
|
+
players - teamed_players
|
142
|
+
end
|
143
|
+
|
124
144
|
def teams
|
125
145
|
all_teams = teams_keys.inject({}) do |teams, team|
|
126
146
|
teams.merge({ team.split(':').last.to_i => redis.smembers(team).map(&:to_i) })
|
@@ -129,16 +149,6 @@ class Pug
|
|
129
149
|
all_teams.sort.to_h
|
130
150
|
end
|
131
151
|
|
132
|
-
def actual_teams
|
133
|
-
teams.tap { |team| team.delete(0) }
|
134
|
-
end
|
135
|
-
|
136
|
-
def unteam_all_players
|
137
|
-
joined_players.each do |player_id|
|
138
|
-
join_team(team_no: 0, player_id: player_id)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
152
|
def update_last_result_time
|
143
153
|
redis.set(last_result_time_key, Time.now.to_i)
|
144
154
|
end
|
@@ -148,25 +158,37 @@ class Pug
|
|
148
158
|
end
|
149
159
|
|
150
160
|
def equal_number_of_players_on_each_team?
|
151
|
-
team_player_counts =
|
161
|
+
team_player_counts = teams.map do |_name, players|
|
152
162
|
players.size
|
153
163
|
end
|
154
164
|
|
155
165
|
team_player_counts.uniq.size == 1
|
156
166
|
end
|
157
167
|
|
158
|
-
|
159
|
-
|
160
|
-
def leave_teams(player_id)
|
168
|
+
def unteam(player_id)
|
161
169
|
teams_keys.each do |team|
|
162
170
|
redis.srem(team, player_id)
|
163
171
|
end
|
164
172
|
end
|
165
173
|
|
174
|
+
def players
|
175
|
+
redis.zrange(queue_key, 0, -1).map(&:to_i)
|
176
|
+
end
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
def leave_queue(player_id)
|
181
|
+
redis.zrem(queue_key, player_id)
|
182
|
+
end
|
183
|
+
|
166
184
|
def teams_keys
|
167
185
|
redis.keys([pug_key, 'teams:*'].join(':'))
|
168
186
|
end
|
169
187
|
|
188
|
+
def queue_key
|
189
|
+
[pug_key, 'queue'].join(':')
|
190
|
+
end
|
191
|
+
|
170
192
|
def team_key(team_no)
|
171
193
|
[pug_key, 'teams', team_no].join(':')
|
172
194
|
end
|
@@ -208,6 +230,6 @@ class Pug
|
|
208
230
|
end
|
209
231
|
|
210
232
|
def no_of_teams
|
211
|
-
[
|
233
|
+
[teams.count, MIN_NO_OF_TEAMS].max
|
212
234
|
end
|
213
235
|
end
|
@@ -46,16 +46,9 @@ class QwtfDiscordBotPug # :nodoc:
|
|
46
46
|
|
47
47
|
bot.command :choose do |event, *args|
|
48
48
|
setup_pug(event) do |e, pug|
|
49
|
-
if pug.
|
50
|
-
return send_embedded_message(
|
51
|
-
description: "Too many players, increase `!teamsize` or `!kick` extras",
|
52
|
-
channel: event.channel
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
if pug.joined_players.count.odd?
|
49
|
+
if !pug.full?
|
57
50
|
return send_embedded_message(
|
58
|
-
description: "
|
51
|
+
description: "Not enough players, reduce !teamsize",
|
59
52
|
channel: event.channel
|
60
53
|
)
|
61
54
|
end
|
@@ -302,14 +295,14 @@ class QwtfDiscordBotPug # :nodoc:
|
|
302
295
|
)
|
303
296
|
end
|
304
297
|
|
305
|
-
if pug.
|
298
|
+
if !pug.teamed_players.include?(user_id)
|
306
299
|
return send_embedded_message(
|
307
300
|
description: "You aren't in a team",
|
308
301
|
channel: e.channel
|
309
302
|
)
|
310
303
|
end
|
311
304
|
|
312
|
-
pug.
|
305
|
+
pug.unteam(user_id)
|
313
306
|
|
314
307
|
send_embedded_message(
|
315
308
|
description: "#{e.display_name} leaves team",
|
@@ -327,7 +320,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
327
320
|
|
328
321
|
user_id = mention_to_user_id(mention)
|
329
322
|
display_name = e.display_name_for(user_id) || arg
|
330
|
-
pug.
|
323
|
+
pug.unteam(user_id)
|
331
324
|
|
332
325
|
send_embedded_message(
|
333
326
|
description: "#{display_name} leaves team",
|
@@ -384,14 +377,14 @@ class QwtfDiscordBotPug # :nodoc:
|
|
384
377
|
|
385
378
|
winning_team_no = args.first.to_i
|
386
379
|
|
387
|
-
if pug.
|
380
|
+
if pug.teams.count < 2
|
388
381
|
return send_embedded_message(
|
389
382
|
description: "There must be at least two teams with players to submit a result",
|
390
383
|
channel: e.channel
|
391
384
|
)
|
392
385
|
end
|
393
386
|
|
394
|
-
team_results = pug.
|
387
|
+
team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
|
395
388
|
players = player_ids.inject({}) do |memo, id|
|
396
389
|
memo.merge({ id => e.display_name_for(id) })
|
397
390
|
end
|
@@ -444,7 +437,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
444
437
|
)
|
445
438
|
end
|
446
439
|
|
447
|
-
if pug.
|
440
|
+
if pug.teams.count < 2
|
448
441
|
return send_embedded_message(
|
449
442
|
description: "There must be at least two teams with players to submit a result",
|
450
443
|
channel: e.channel
|
@@ -460,7 +453,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
460
453
|
)
|
461
454
|
end
|
462
455
|
|
463
|
-
team_results = pug.
|
456
|
+
team_results = pug.teams.inject({}) do |teams, (name, player_ids)|
|
464
457
|
players = player_ids.inject({}) do |memo, id|
|
465
458
|
memo.merge({ id => e.display_name_for(id) })
|
466
459
|
end
|
@@ -644,7 +637,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
644
637
|
def join_pug(e, pug)
|
645
638
|
pug.join(e.user_id)
|
646
639
|
|
647
|
-
if pug.
|
640
|
+
if pug.total_player_count == 1
|
648
641
|
snippets = ["#{e.display_name} creates a PUG", "#{pug.player_slots} joined"]
|
649
642
|
message = pug.notify_roles
|
650
643
|
else
|
@@ -669,7 +662,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
669
662
|
def choose_fair_teams(pug:, event:, iteration: 0)
|
670
663
|
if !pug.full?
|
671
664
|
return send_embedded_message(
|
672
|
-
description: "
|
665
|
+
description: "Not enough players, reduce !teamsize",
|
673
666
|
channel: event.channel
|
674
667
|
) && nil
|
675
668
|
end
|
@@ -680,7 +673,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
680
673
|
)
|
681
674
|
|
682
675
|
combinations = get_fair_teams(
|
683
|
-
channel_id: event.channel.id, players: pug.
|
676
|
+
channel_id: event.channel.id, players: pug.up_now_players
|
684
677
|
)
|
685
678
|
|
686
679
|
teams = combinations[iteration]
|
@@ -693,6 +686,8 @@ class QwtfDiscordBotPug # :nodoc:
|
|
693
686
|
) && nil
|
694
687
|
end
|
695
688
|
|
689
|
+
pug.destroy_teams
|
690
|
+
|
696
691
|
teams.each do |team_no, player_ids|
|
697
692
|
player_ids.each do |player_id|
|
698
693
|
pug.join_team(team_no: team_no, player_id: player_id)
|
@@ -717,6 +712,18 @@ class QwtfDiscordBotPug # :nodoc:
|
|
717
712
|
text: footer
|
718
713
|
)
|
719
714
|
|
715
|
+
if pug.queued_players.any?
|
716
|
+
queue_display_names = pug.queued_players.map do |player_id|
|
717
|
+
event.display_name_for(player_id)
|
718
|
+
end
|
719
|
+
|
720
|
+
embed.add_field(
|
721
|
+
inline: true,
|
722
|
+
name: "Queue",
|
723
|
+
value: queue_display_names.join("\n")
|
724
|
+
)
|
725
|
+
end
|
726
|
+
|
720
727
|
pug.teams.each do |team_no, player_ids|
|
721
728
|
team_display_names = player_ids.map do |player_id|
|
722
729
|
event.display_name_for(player_id)
|
@@ -732,14 +739,14 @@ class QwtfDiscordBotPug # :nodoc:
|
|
732
739
|
end
|
733
740
|
|
734
741
|
def start_pug(pug, event)
|
735
|
-
choose_fair_teams(pug: pug, event: event) unless pug.
|
742
|
+
choose_fair_teams(pug: pug, event: event) unless pug.teams.any?
|
736
743
|
|
737
744
|
footer = [
|
738
745
|
pug.game_map,
|
739
746
|
"#{pug.player_slots} joined",
|
740
747
|
].compact.join(MSG_SNIPPET_DELIMITER)
|
741
748
|
|
742
|
-
mentions = pug.
|
749
|
+
mentions = pug.players.map do |player_id|
|
743
750
|
event.mention_for(player_id)
|
744
751
|
end
|
745
752
|
|
@@ -753,6 +760,18 @@ class QwtfDiscordBotPug # :nodoc:
|
|
753
760
|
text: footer
|
754
761
|
)
|
755
762
|
|
763
|
+
if pug.queued_players.any?
|
764
|
+
queue_display_names = pug.queued_players.map do |player_id|
|
765
|
+
event.display_name_for(player_id)
|
766
|
+
end
|
767
|
+
|
768
|
+
embed.add_field(
|
769
|
+
inline: true,
|
770
|
+
name: "Queue",
|
771
|
+
value: queue_display_names.join("\n")
|
772
|
+
)
|
773
|
+
end
|
774
|
+
|
756
775
|
pug.teams.each do |team_no, player_ids|
|
757
776
|
team_mentions = player_ids.map do |player_id|
|
758
777
|
event.display_name_for(player_id)
|
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: 6.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|