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