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