qwtf_discord_bot 5.1.1 → 5.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +121 -98
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a23eb8820860898165bbdf94e448a7141449fa3850a8e66f079e93ca8590f0f
|
4
|
+
data.tar.gz: 33ea995e466b5379746ee57b12e24f3337581dd0c58e4e526b30eb2a9377778d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53393cfca043b1ff72cbc2a7f9e28d9a7f4c44381990ba23edf392f23afb84c66715e5ff274573d16587797fad5c9e76739edb67039eb72106f4767faf95e368
|
7
|
+
data.tar.gz: ae90377b7c6c4592e6811a91461ab13a3e8650d17c36a67f8c45717930e2956c738123c16db087c036508a0da1898fc0d0a1f5efac71a9149ce809da8d277067
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.1.
|
1
|
+
5.1.2
|
@@ -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,128 @@ 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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
].join(' | ')
|
41
|
-
else
|
42
|
-
[
|
43
|
-
"#{e.username} joins the PUG",
|
44
|
-
pug.player_slots
|
45
|
-
].join(' | ')
|
46
|
-
end
|
47
|
-
|
48
|
-
send_and_log_message(message, e.channel)
|
49
|
-
end
|
19
|
+
bot.command :join do |event, *args|
|
20
|
+
set_pug(event, args) do |e, pug|
|
21
|
+
pug.join(e.user_id)
|
22
|
+
|
23
|
+
message = if pug.joined_player_count == 1
|
24
|
+
[
|
25
|
+
"#{e.username} creates a PUG",
|
26
|
+
pug.player_slots,
|
27
|
+
pug.notify_roles
|
28
|
+
].join(' | ')
|
29
|
+
elsif pug.slots_left.between?(1,3)
|
30
|
+
[
|
31
|
+
"#{e.username} joins the PUG",
|
32
|
+
pug.player_slots,
|
33
|
+
"#{pug.slots_left} more",
|
34
|
+
pug.notify_roles
|
35
|
+
].join(' | ')
|
36
|
+
else
|
37
|
+
[
|
38
|
+
"#{e.username} joins the PUG",
|
39
|
+
pug.player_slots
|
40
|
+
].join(' | ')
|
41
|
+
end
|
50
42
|
|
51
|
-
|
52
|
-
e = EventDecorator.new(event)
|
53
|
-
pug = Pug.for(e.channel_id)
|
43
|
+
send_and_log_message(message, e.channel)
|
54
44
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
else
|
61
|
-
'No PUG has been started. `!join` to create'
|
62
|
-
end
|
45
|
+
if pug.full?
|
46
|
+
message = start_pug(
|
47
|
+
pug.player_slots,
|
48
|
+
e.mentions_for(pug.joined_players)
|
49
|
+
)
|
63
50
|
|
64
|
-
|
51
|
+
send_and_log_message(message, e.channel)
|
52
|
+
end
|
53
|
+
end
|
65
54
|
end
|
66
55
|
|
67
|
-
bot.command :
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
send_and_log_message(message, e.channel)
|
80
|
-
|
81
|
-
if pug.full?
|
82
|
-
message = time_to_play_message(
|
83
|
-
pug.player_slots,
|
84
|
-
e.mentions_for(pug.joined_players)
|
85
|
-
)
|
56
|
+
bot.command :status do |event, *args|
|
57
|
+
set_pug(event, args) do |e, pug|
|
58
|
+
message = if pug.active?
|
59
|
+
[
|
60
|
+
"#{e.usernames_for(pug.joined_players).join(', ')} joined",
|
61
|
+
pug.player_slots
|
62
|
+
].join(' | ')
|
63
|
+
else
|
64
|
+
'No PUG has been started. `!join` to create'
|
65
|
+
end
|
86
66
|
|
87
67
|
send_and_log_message(message, e.channel)
|
88
68
|
end
|
89
69
|
end
|
90
70
|
|
91
|
-
bot.command :
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
pug.leave(e.user_id)
|
71
|
+
bot.command :maxplayers do |event, *args|
|
72
|
+
set_pug(event, args) do |e, pug|
|
73
|
+
new_maxplayers = args[0]
|
96
74
|
|
97
|
-
|
75
|
+
message = if new_maxplayers
|
76
|
+
pug.maxplayers = new_maxplayers
|
77
|
+
"Max number of players set to #{pug.maxplayers} | #{pug.player_slots} joined"
|
78
|
+
else
|
79
|
+
"Current max number of players is #{pug.maxplayers} | #{pug.player_slots} joined"
|
80
|
+
end
|
98
81
|
|
99
|
-
|
82
|
+
send_and_log_message(message, e.channel)
|
100
83
|
|
101
|
-
|
102
|
-
|
84
|
+
if pug.full?
|
85
|
+
message = start_pug(
|
86
|
+
pug.player_slots,
|
87
|
+
e.mentions_for(pug.joined_players)
|
88
|
+
)
|
103
89
|
|
104
|
-
|
105
|
-
|
90
|
+
send_and_log_message(message, e.channel)
|
91
|
+
end
|
106
92
|
end
|
107
93
|
end
|
108
94
|
|
109
|
-
bot.command :
|
110
|
-
|
111
|
-
|
95
|
+
bot.command :leave do |event, *args|
|
96
|
+
set_pug(event, args) do |e, pug|
|
97
|
+
if !pug.active?
|
98
|
+
message = "There's no active PUG to leave"
|
99
|
+
send_and_log_message(message, e.channel)
|
100
|
+
elsif !pug.joined_players.include?(e.user_id)
|
101
|
+
message = "You're not in the PUG"
|
102
|
+
send_and_log_message(message, e.channel)
|
103
|
+
else
|
104
|
+
pug.leave(e.user_id)
|
105
|
+
message = "#{e.username} leaves the PUG | #{pug.player_slots} remain"
|
106
|
+
send_and_log_message(message, e.channel)
|
107
|
+
|
108
|
+
if pug.empty?
|
109
|
+
message = end_pug(pug)
|
110
|
+
send_and_log_message(message, e.channel)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
112
115
|
|
113
|
-
|
116
|
+
bot.command :end do |event, *args|
|
117
|
+
set_pug(event, args) do |e, pug|
|
118
|
+
message = if !pug.active?
|
119
|
+
"There's no active PUG to end"
|
120
|
+
else
|
121
|
+
end_pug(pug)
|
122
|
+
end
|
114
123
|
|
115
|
-
|
116
|
-
|
124
|
+
send_and_log_message(message, e.channel)
|
125
|
+
end
|
117
126
|
end
|
118
127
|
|
119
128
|
bot.command :notify do |event, *args|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
set_pug(event, args) do |e, pug|
|
130
|
+
roles = args.join(' ')
|
131
|
+
pug.notify_roles = roles
|
132
|
+
|
133
|
+
message = if roles.empty?
|
134
|
+
'Notification removed'
|
135
|
+
else
|
136
|
+
"Notification role set to #{roles}"
|
137
|
+
end
|
138
|
+
|
139
|
+
send_and_log_message(message, e.channel)
|
140
|
+
end
|
132
141
|
end
|
133
142
|
|
134
143
|
bot.run
|
@@ -136,12 +145,26 @@ class QwtfDiscordBotPug
|
|
136
145
|
|
137
146
|
private
|
138
147
|
|
139
|
-
def
|
140
|
-
|
148
|
+
def set_pug(event, *args)
|
149
|
+
e = EventDecorator.new(event)
|
150
|
+
pug = Pug.for(e.channel_id)
|
151
|
+
yield(e, pug)
|
152
|
+
end
|
153
|
+
|
154
|
+
def start_pug(player_slots, mentions)
|
155
|
+
[
|
156
|
+
'Time to play!',
|
157
|
+
player_slots,
|
158
|
+
mentions.join(' ')
|
159
|
+
].join(' | ')
|
160
|
+
end
|
161
|
+
|
162
|
+
def end_pug(pug)
|
163
|
+
pug.end_pug
|
164
|
+
'PUG ended'
|
141
165
|
end
|
142
166
|
|
143
167
|
def send_and_log_message(message, channel)
|
144
|
-
channel.send_message(message)
|
145
|
-
puts message
|
168
|
+
channel.send_message(message) && puts(message)
|
146
169
|
end
|
147
170
|
end
|