qwtf_discord_bot 5.1.6 → 5.1.8
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 +9 -4
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +90 -100
- 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: cfcb9cea490b3e0de6db8028dbe88bdc5989186b97225f92f9a87cf0e0eeb05a
|
4
|
+
data.tar.gz: 814fc6269bec9872b68fed72b96a78322735534cb8969f7e1d74618aa9fef5cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d853f68c400f0ec91e7da0185c77a98e96958168c6057143d646d0f007c3496b9cab2a8f20936c6d4d504a82e9bdd76234949358a5bf5c58b07d79dd7eab7fe6
|
7
|
+
data.tar.gz: 334b46c0db3144f305c19f0d24923c4a487460fdac0413ded541aafb80edde9fcbb8835499fc29f7723e5730771c411951383a764e6bb78418a236ccf09448c9
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.1.
|
1
|
+
5.1.8
|
data/lib/pug.rb
CHANGED
@@ -56,10 +56,7 @@ class Pug
|
|
56
56
|
|
57
57
|
def leave(player_id)
|
58
58
|
redis.srem(players_key, player_id)
|
59
|
-
|
60
|
-
|
61
|
-
def empty?
|
62
|
-
joined_player_count == 0
|
59
|
+
end_pug if empty?
|
63
60
|
end
|
64
61
|
|
65
62
|
def end_pug
|
@@ -67,8 +64,16 @@ class Pug
|
|
67
64
|
redis.del(players_key)
|
68
65
|
end
|
69
66
|
|
67
|
+
def joined?(player_id)
|
68
|
+
joined_players.include?(player_id)
|
69
|
+
end
|
70
|
+
|
70
71
|
private
|
71
72
|
|
73
|
+
def empty?
|
74
|
+
joined_player_count.zero?
|
75
|
+
end
|
76
|
+
|
72
77
|
def maxplayers_key
|
73
78
|
[pug_key, "maxplayers"].join(":")
|
74
79
|
end
|
@@ -6,8 +6,6 @@ require 'event_decorator'
|
|
6
6
|
class QwtfDiscordBotPug # :nodoc:
|
7
7
|
include QwtfDiscordBot
|
8
8
|
|
9
|
-
FOUR_HOURS = 4 * 60 * 60
|
10
|
-
|
11
9
|
def run
|
12
10
|
bot = Discordrb::Commands::CommandBot.new(
|
13
11
|
token: QwtfDiscordBot.config.token,
|
@@ -17,49 +15,46 @@ class QwtfDiscordBotPug # :nodoc:
|
|
17
15
|
)
|
18
16
|
|
19
17
|
bot.command :join do |event, *args|
|
20
|
-
|
21
|
-
if pug.
|
22
|
-
message = "You've already joined"
|
23
|
-
send_and_log_message(message, e.channel)
|
24
|
-
else
|
25
|
-
pug.join(e.user_id)
|
26
|
-
|
27
|
-
message = if pug.joined_player_count == 1
|
28
|
-
[
|
29
|
-
"#{e.display_name} creates a PUG",
|
30
|
-
pug.player_slots,
|
31
|
-
pug.notify_roles
|
32
|
-
].join(' | ')
|
33
|
-
elsif pug.slots_left.between?(1,3)
|
34
|
-
[
|
35
|
-
"#{e.display_name} joins the PUG",
|
36
|
-
pug.player_slots,
|
37
|
-
"#{pug.slots_left} more",
|
38
|
-
pug.notify_roles
|
39
|
-
].join(' | ')
|
40
|
-
else
|
41
|
-
[
|
42
|
-
"#{e.display_name} joins the PUG",
|
43
|
-
pug.player_slots
|
44
|
-
].join(' | ')
|
45
|
-
end
|
46
|
-
|
47
|
-
send_and_log_message(message, e.channel)
|
48
|
-
|
49
|
-
if pug.full?
|
50
|
-
message = start_pug(
|
51
|
-
pug.player_slots,
|
52
|
-
e.mentions_for(pug.joined_players)
|
53
|
-
)
|
18
|
+
setup_pug(event) do |e, pug|
|
19
|
+
return message("You've already joined", e.channel) if pug.joined?(e.user_id)
|
54
20
|
|
55
|
-
|
56
|
-
|
21
|
+
pug.join(e.user_id)
|
22
|
+
|
23
|
+
message = if pug.joined_player_count == 1
|
24
|
+
[
|
25
|
+
"#{e.display_name} creates a PUG",
|
26
|
+
pug.player_slots,
|
27
|
+
pug.notify_roles
|
28
|
+
].join(' | ')
|
29
|
+
elsif pug.slots_left.between?(1, 3)
|
30
|
+
[
|
31
|
+
"#{e.display_name} joins the PUG",
|
32
|
+
pug.player_slots,
|
33
|
+
"#{pug.slots_left} more",
|
34
|
+
pug.notify_roles
|
35
|
+
].join(' | ')
|
36
|
+
else
|
37
|
+
[
|
38
|
+
"#{e.display_name} joins the PUG",
|
39
|
+
pug.player_slots
|
40
|
+
].join(' | ')
|
41
|
+
end
|
42
|
+
|
43
|
+
message(message, e.channel)
|
44
|
+
|
45
|
+
if pug.full?
|
46
|
+
message = start_pug_message(
|
47
|
+
player_slots: pug.player_slots,
|
48
|
+
mentions: e.mentions_for(pug.joined_players)
|
49
|
+
)
|
50
|
+
|
51
|
+
message(message, e.channel)
|
57
52
|
end
|
58
53
|
end
|
59
54
|
end
|
60
55
|
|
61
56
|
bot.command :status do |event, *args|
|
62
|
-
|
57
|
+
setup_pug(event) do |e, pug|
|
63
58
|
message = if pug.active?
|
64
59
|
[
|
65
60
|
"#{e.display_names_for(pug.joined_players).join(', ')} joined",
|
@@ -69,12 +64,12 @@ class QwtfDiscordBotPug # :nodoc:
|
|
69
64
|
'No PUG has been started. `!join` to create'
|
70
65
|
end
|
71
66
|
|
72
|
-
|
67
|
+
message(message, e.channel)
|
73
68
|
end
|
74
69
|
end
|
75
70
|
|
76
71
|
bot.command :maxplayers do |event, *args|
|
77
|
-
|
72
|
+
setup_pug(event) do |e, pug|
|
78
73
|
new_maxplayers = args[0]
|
79
74
|
|
80
75
|
message = if new_maxplayers
|
@@ -84,81 +79,76 @@ class QwtfDiscordBotPug # :nodoc:
|
|
84
79
|
"Current max number of players is #{pug.maxplayers} | #{pug.player_slots} joined"
|
85
80
|
end
|
86
81
|
|
87
|
-
|
82
|
+
message(message, e.channel)
|
88
83
|
|
89
84
|
if pug.full?
|
90
|
-
message =
|
91
|
-
pug.player_slots,
|
92
|
-
e.mentions_for(pug.joined_players)
|
85
|
+
message = start_pug_message(
|
86
|
+
player_slots: pug.player_slots,
|
87
|
+
mentions: e.mentions_for(pug.joined_players)
|
93
88
|
)
|
94
89
|
|
95
|
-
|
90
|
+
message(message, e.channel)
|
96
91
|
end
|
97
92
|
end
|
98
93
|
end
|
99
94
|
|
100
95
|
bot.command :leave do |event, *args|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if pug.empty?
|
114
|
-
message = end_pug(pug)
|
115
|
-
send_and_log_message(message, e.channel)
|
116
|
-
end
|
117
|
-
end
|
96
|
+
setup_pug(event) do |e, pug|
|
97
|
+
return message(no_active_pug_message, e.channel) unless pug.active?
|
98
|
+
return message("You're not in the PUG", e.channel) unless pug.joined?(e.user_id)
|
99
|
+
|
100
|
+
pug.leave(e.user_id)
|
101
|
+
|
102
|
+
message(
|
103
|
+
"#{e.display_name} leaves the PUG | #{pug.player_slots} remain",
|
104
|
+
e.channel
|
105
|
+
)
|
106
|
+
|
107
|
+
message(end_pug_message, e.channel) unless pug.active?
|
118
108
|
end
|
119
109
|
end
|
120
110
|
|
121
111
|
bot.command :kick do |event, *args|
|
122
|
-
|
123
|
-
|
124
|
-
message = "There's no active PUG"
|
125
|
-
return send_and_log_message(message, e.channel)
|
126
|
-
end
|
112
|
+
setup_pug(event) do |e, pug|
|
113
|
+
return message(no_active_pug_message, e.channel) unless pug.active?
|
127
114
|
|
128
|
-
|
129
|
-
|
130
|
-
|
115
|
+
args.each do |mention|
|
116
|
+
user_id = mention[3..-2].to_i
|
117
|
+
display_name = e.display_name_for(user_id)
|
131
118
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
message = "#{display_name} is kicked from the PUG | #{pug.player_slots} remain"
|
138
|
-
send_and_log_message(message, e.channel)
|
119
|
+
unless pug.joined?(user_id)
|
120
|
+
message(
|
121
|
+
"#{display_name} isn't in the PUG",
|
122
|
+
e.channel
|
123
|
+
)
|
139
124
|
|
140
|
-
|
141
|
-
message = end_pug(pug)
|
142
|
-
send_and_log_message(message, e.channel)
|
125
|
+
next
|
143
126
|
end
|
127
|
+
|
128
|
+
pug.leave(user_id)
|
129
|
+
|
130
|
+
message(
|
131
|
+
"#{display_name} is kicked from the PUG | #{pug.player_slots} remain",
|
132
|
+
e.channel
|
133
|
+
)
|
134
|
+
|
135
|
+
break message(end_pug_message, e.channel) unless pug.active?
|
144
136
|
end
|
145
137
|
end
|
146
138
|
end
|
147
139
|
|
148
140
|
bot.command :end do |event, *args|
|
149
|
-
|
150
|
-
message
|
151
|
-
|
152
|
-
|
153
|
-
end_pug(pug)
|
154
|
-
end
|
141
|
+
setup_pug(event) do |e, pug|
|
142
|
+
return message(no_active_pug_message, e.channel) unless pug.active?
|
143
|
+
|
144
|
+
pug.end_pug
|
155
145
|
|
156
|
-
|
146
|
+
message(end_pug_message, e.channel)
|
157
147
|
end
|
158
148
|
end
|
159
149
|
|
160
150
|
bot.command :notify do |event, *args|
|
161
|
-
|
151
|
+
setup_pug(event) do |e, pug|
|
162
152
|
roles = args.join(' ')
|
163
153
|
pug.notify_roles = roles
|
164
154
|
|
@@ -168,7 +158,7 @@ class QwtfDiscordBotPug # :nodoc:
|
|
168
158
|
"Notification role set to #{roles}"
|
169
159
|
end
|
170
160
|
|
171
|
-
|
161
|
+
message(message, e.channel)
|
172
162
|
end
|
173
163
|
end
|
174
164
|
|
@@ -177,26 +167,26 @@ class QwtfDiscordBotPug # :nodoc:
|
|
177
167
|
|
178
168
|
private
|
179
169
|
|
180
|
-
def
|
170
|
+
def setup_pug(event)
|
181
171
|
e = EventDecorator.new(event)
|
182
172
|
pug = Pug.for(e.channel_id)
|
183
173
|
yield(e, pug)
|
174
|
+
nil # stop discordrb printing return value
|
184
175
|
end
|
185
176
|
|
186
|
-
def
|
187
|
-
[
|
188
|
-
'Time to play!',
|
189
|
-
player_slots,
|
190
|
-
mentions.join(' ')
|
191
|
-
].join(' | ')
|
177
|
+
def start_pug_message(player_slots:, mentions:)
|
178
|
+
['Time to play!', player_slots, mentions.join(' ')].join(' | ')
|
192
179
|
end
|
193
180
|
|
194
|
-
def
|
195
|
-
pug.end_pug
|
181
|
+
def end_pug_message
|
196
182
|
'PUG ended'
|
197
183
|
end
|
198
184
|
|
199
|
-
def
|
185
|
+
def no_active_pug_message
|
186
|
+
"There's no active PUG"
|
187
|
+
end
|
188
|
+
|
189
|
+
def message(message, channel)
|
200
190
|
channel.send_message(message) && puts(message)
|
201
191
|
end
|
202
192
|
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.1.
|
4
|
+
version: 5.1.8
|
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-08-
|
11
|
+
date: 2020-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|