qwtf_discord_bot 5.1.1 → 5.1.6
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 +2 -1
- data/VERSION +1 -1
- data/lib/event_decorator.rb +8 -4
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +153 -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: be9d7e86ba5a7b1a38b2ad8f12d34295a3882e871d535f01c1d8fb1ada700129
|
4
|
+
data.tar.gz: 1fad670f56fe547f42b5f6b4a14e0769a8195080125536c64b480d29f6bf4f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e6e67d9588c6806545133f3d37c473445b594c515d9621fdd2c6b95bad20e21af356756c949cff72445533611a2205b67989f8b58ae6b61da40a2dac20a7454
|
7
|
+
data.tar.gz: c7a8dcbeadf3074650526f3c8849db414dd6690699412182e9970fbdc893f2fb13be9f1997487af5329b785d548d7e4e93f9175d31f24ed7092e2b27ab531e0b
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.1.
|
1
|
+
5.1.6
|
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,12 @@ 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
|
+
end
|
33
|
+
|
34
|
+
def display_name_for(user_id)
|
35
|
+
find_user(user_id).display_name
|
32
36
|
end
|
33
37
|
|
34
38
|
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,160 @@ 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
|
+
display_name = e.display_name_for(user_id)
|
131
|
+
|
132
|
+
if !pug.joined_players.include?(user_id)
|
133
|
+
message = "#{display_name} isn't in the PUG"
|
134
|
+
send_and_log_message(message, e.channel)
|
135
|
+
else
|
136
|
+
pug.leave(user_id)
|
137
|
+
message = "#{display_name} is kicked from the PUG | #{pug.player_slots} remain"
|
138
|
+
send_and_log_message(message, e.channel)
|
139
|
+
|
140
|
+
if pug.empty?
|
141
|
+
message = end_pug(pug)
|
142
|
+
send_and_log_message(message, e.channel)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
100
147
|
|
101
|
-
|
102
|
-
|
148
|
+
bot.command :end do |event, *args|
|
149
|
+
set_pug(event) do |e, pug|
|
150
|
+
message = if !pug.active?
|
151
|
+
"There's no active PUG to end"
|
152
|
+
else
|
153
|
+
end_pug(pug)
|
154
|
+
end
|
103
155
|
|
104
|
-
message = 'PUG ended'
|
105
156
|
send_and_log_message(message, e.channel)
|
106
157
|
end
|
107
158
|
end
|
108
159
|
|
109
|
-
bot.command :
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
pug.end_pug
|
160
|
+
bot.command :notify do |event, *args|
|
161
|
+
set_pug(event) do |e, pug|
|
162
|
+
roles = args.join(' ')
|
163
|
+
pug.notify_roles = roles
|
114
164
|
|
115
|
-
|
116
|
-
|
117
|
-
|
165
|
+
message = if roles.empty?
|
166
|
+
'Notification removed'
|
167
|
+
else
|
168
|
+
"Notification role set to #{roles}"
|
169
|
+
end
|
118
170
|
|
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)
|
171
|
+
send_and_log_message(message, e.channel)
|
172
|
+
end
|
132
173
|
end
|
133
174
|
|
134
175
|
bot.run
|
@@ -136,12 +177,26 @@ class QwtfDiscordBotPug
|
|
136
177
|
|
137
178
|
private
|
138
179
|
|
139
|
-
def
|
140
|
-
|
180
|
+
def set_pug(event)
|
181
|
+
e = EventDecorator.new(event)
|
182
|
+
pug = Pug.for(e.channel_id)
|
183
|
+
yield(e, pug)
|
184
|
+
end
|
185
|
+
|
186
|
+
def start_pug(player_slots, mentions)
|
187
|
+
[
|
188
|
+
'Time to play!',
|
189
|
+
player_slots,
|
190
|
+
mentions.join(' ')
|
191
|
+
].join(' | ')
|
192
|
+
end
|
193
|
+
|
194
|
+
def end_pug(pug)
|
195
|
+
pug.end_pug
|
196
|
+
'PUG ended'
|
141
197
|
end
|
142
198
|
|
143
199
|
def send_and_log_message(message, channel)
|
144
|
-
channel.send_message(message)
|
145
|
-
puts message
|
200
|
+
channel.send_message(message) && puts(message)
|
146
201
|
end
|
147
202
|
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.6
|
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
|