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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acbc8b37f3b73372cb4417b810a76a960ee5fd640330587ef97e0b889338be04
4
- data.tar.gz: 47cc64ca3ca8cdf90e63a2197ac0b93e703427a26a0e5cf00ee6716938f73d9f
3
+ metadata.gz: d0adf9bb170277ec37dddc27d86049f6d678ddbb3b69530b114a177f11719d21
4
+ data.tar.gz: ff6c28db3deb0fad59b2ca45d4d53b3c45c622848cc15d6234d14b245c865413
5
5
  SHA512:
6
- metadata.gz: 99276bcc5e6a1e53364176301f09da6089f72bdd266cfbb0e1e72e551e2421bd11116504c907db6649b14f3ba8b6bdcc4534b550ee749761e2d1b99df596dbb7
7
- data.tar.gz: b1970a9a1465c72d1cdd3ab68f38d967eb8f9ea1d7072ef7da9c660d4b3ee15d5b3943498958e9f564d61e3a59d82455af1a6cd0e713d4a3240eb51b79b6e504
6
+ metadata.gz: 5dfb62990d27a5f250ea4ddbbe5f62583618e947c2c26d8df85308e2b99bb204a35a2b25347080a2352d4d1a7508e45e690fd7a636cd7e7baf1fc2305d8c9a60
7
+ data.tar.gz: 52590b32e2c4727c7ccd9b526bdc9f8abccb46b8d4e815d78cd7eb3cfd7dea669e57890b171dfdeb41c5a9de092d38147ae0b3469a97bb1450f96e713fe9b27a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.0
1
+ 5.1.5
@@ -11,8 +11,8 @@ class EventDecorator
11
11
  @event.channel.id
12
12
  end
13
13
 
14
- def username
15
- user.username
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 usernames_for(user_ids)
31
- find_users(user_ids).map(&:username)
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, *_args|
18
- e = EventDecorator.new(event)
19
- pug = Pug.for(e.channel_id)
20
-
21
- pug.join(e.user_id)
22
-
23
- message = if pug.full?
24
- time_to_play_message(
25
- pug.player_slots,
26
- e.mentions_for(pug.joined_players)
27
- )
28
- elsif pug.joined_player_count == 1
29
- [
30
- "#{e.username} creates a PUG",
31
- pug.player_slots,
32
- pug.notify_roles
33
- ].join(' | ')
34
- elsif pug.slots_left <= 3
35
- [
36
- "#{e.username} joins the PUG",
37
- pug.player_slots,
38
- "#{pug.slots_left} more",
39
- pug.notify_roles
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)
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, *_args|
52
- e = EventDecorator.new(event)
53
- pug = Pug.for(e.channel_id)
54
-
55
- message = if pug.active?
56
- [
57
- "#{e.usernames_for(pug.joined_players).join(' ')} joined",
58
- pug.player_slots
59
- ].join(' | ')
60
- else
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
- send_and_log_message(message, e.channel)
72
+ send_and_log_message(message, e.channel)
73
+ end
65
74
  end
66
75
 
67
76
  bot.command :maxplayers do |event, *args|
68
- e = EventDecorator.new(event)
69
- pug = Pug.for(e.channel_id)
70
- new_maxplayers = args[0]
77
+ set_pug(event) do |e, pug|
78
+ new_maxplayers = args[0]
71
79
 
72
- message = if new_maxplayers
73
- pug.maxplayers = new_maxplayers
74
- "Max number of players set to #{pug.maxplayers} | #{pug.player_slots} joined"
75
- else
76
- "Current max number of players is #{pug.maxplayers} | #{pug.player_slots} joined"
77
- end
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
- send_and_log_message(message, e.channel)
87
+ send_and_log_message(message, e.channel)
80
88
 
81
- if pug.full?
82
- message = time_to_play_message(
83
- pug.player_slots,
84
- e.mentions_for(pug.joined_players)
85
- )
89
+ if pug.full?
90
+ message = start_pug(
91
+ pug.player_slots,
92
+ e.mentions_for(pug.joined_players)
93
+ )
86
94
 
87
- send_and_log_message(message, e.channel)
95
+ send_and_log_message(message, e.channel)
96
+ end
88
97
  end
89
98
  end
90
99
 
91
- bot.command :leave do |event, *_args|
92
- e = EventDecorator.new(event)
93
- pug = Pug.for(e.channel_id)
94
-
95
- pug.leave(e.user_id)
96
-
97
- message = "#{e.username} leaves the PUG | #{pug.player_slots} remain"
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
- send_and_log_message(message, e.channel)
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
- if pug.empty?
102
- pug.end_pug
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 :end do |event, *_args|
110
- e = EventDecorator.new(event)
111
- pug = Pug.for(e.channel_id)
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
- message = 'PUG ended'
116
- send_and_log_message(message, e.channel)
117
- end
164
+ message = if roles.empty?
165
+ 'Notification removed'
166
+ else
167
+ "Notification role set to #{roles}"
168
+ end
118
169
 
119
- bot.command :notify do |event, *args|
120
- e = EventDecorator.new(event)
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 time_to_play_message(player_slots, mentions)
140
- ['Time to play!', player_slots, mentions.join(' ')].join(' | ')
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.0
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-24 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb