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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15afdd84de10528d7020797cbf211448eefa0ae8b6b7e13e9cab2e9bccdbc957
4
- data.tar.gz: 324e5b52860aec148206e4408b4dbc0dd56b4b7a3c1dbfc36e960ef469a6ea79
3
+ metadata.gz: be9d7e86ba5a7b1a38b2ad8f12d34295a3882e871d535f01c1d8fb1ada700129
4
+ data.tar.gz: 1fad670f56fe547f42b5f6b4a14e0769a8195080125536c64b480d29f6bf4f48
5
5
  SHA512:
6
- metadata.gz: 1952f502bbcc26942fe362749e2f6f3640fa7c5b0b87d80a4d4d7abe179ad629c7b6fa366ad4f878c9b9e5ae4e1833bbce1a7675b09796f94ab51463649771fd
7
- data.tar.gz: 11dd44583e6a5cada8ceb31b89d9305016fc7ee12f8d3cf2aaba3781fa07f427de19014694c23c794faff6c8e589d8984a171d4b328abcf0828a68162c73592e
6
+ metadata.gz: 8e6e67d9588c6806545133f3d37c473445b594c515d9621fdd2c6b95bad20e21af356756c949cff72445533611a2205b67989f8b58ae6b61da40a2dac20a7454
7
+ data.tar.gz: c7a8dcbeadf3074650526f3c8849db414dd6690699412182e9970fbdc893f2fb13be9f1997487af5329b785d548d7e4e93f9175d31f24ed7092e2b27ab531e0b
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.1
1
+ 5.1.6
@@ -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
@@ -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, *_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
+ 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
- if pug.empty?
102
- pug.end_pug
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 :end do |event, *_args|
110
- e = EventDecorator.new(event)
111
- pug = Pug.for(e.channel_id)
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
- message = 'PUG ended'
116
- send_and_log_message(message, e.channel)
117
- end
165
+ message = if roles.empty?
166
+ 'Notification removed'
167
+ else
168
+ "Notification role set to #{roles}"
169
+ end
118
170
 
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)
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 time_to_play_message(player_slots, mentions)
140
- ['Time to play!', player_slots, mentions.join(' ')].join(' | ')
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.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-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