qwtf_discord_bot 5.1.1 → 5.1.2

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: 9a23eb8820860898165bbdf94e448a7141449fa3850a8e66f079e93ca8590f0f
4
+ data.tar.gz: 33ea995e466b5379746ee57b12e24f3337581dd0c58e4e526b30eb2a9377778d
5
5
  SHA512:
6
- metadata.gz: 1952f502bbcc26942fe362749e2f6f3640fa7c5b0b87d80a4d4d7abe179ad629c7b6fa366ad4f878c9b9e5ae4e1833bbce1a7675b09796f94ab51463649771fd
7
- data.tar.gz: 11dd44583e6a5cada8ceb31b89d9305016fc7ee12f8d3cf2aaba3781fa07f427de19014694c23c794faff6c8e589d8984a171d4b328abcf0828a68162c73592e
6
+ metadata.gz: 53393cfca043b1ff72cbc2a7f9e28d9a7f4c44381990ba23edf392f23afb84c66715e5ff274573d16587797fad5c9e76739edb67039eb72106f4767faf95e368
7
+ data.tar.gz: ae90377b7c6c4592e6811a91461ab13a3e8650d17c36a67f8c45717930e2956c738123c16db087c036508a0da1898fc0d0a1f5efac71a9149ce809da8d277067
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.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, *_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)
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
- bot.command :status do |event, *_args|
52
- e = EventDecorator.new(event)
53
- pug = Pug.for(e.channel_id)
43
+ send_and_log_message(message, e.channel)
54
44
 
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
45
+ if pug.full?
46
+ message = start_pug(
47
+ pug.player_slots,
48
+ e.mentions_for(pug.joined_players)
49
+ )
63
50
 
64
- send_and_log_message(message, e.channel)
51
+ send_and_log_message(message, e.channel)
52
+ end
53
+ end
65
54
  end
66
55
 
67
- bot.command :maxplayers do |event, *args|
68
- e = EventDecorator.new(event)
69
- pug = Pug.for(e.channel_id)
70
- new_maxplayers = args[0]
71
-
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
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 :leave do |event, *_args|
92
- e = EventDecorator.new(event)
93
- pug = Pug.for(e.channel_id)
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
- message = "#{e.username} leaves the PUG | #{pug.player_slots} remain"
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
- send_and_log_message(message, e.channel)
82
+ send_and_log_message(message, e.channel)
100
83
 
101
- if pug.empty?
102
- pug.end_pug
84
+ if pug.full?
85
+ message = start_pug(
86
+ pug.player_slots,
87
+ e.mentions_for(pug.joined_players)
88
+ )
103
89
 
104
- message = 'PUG ended'
105
- send_and_log_message(message, e.channel)
90
+ send_and_log_message(message, e.channel)
91
+ end
106
92
  end
107
93
  end
108
94
 
109
- bot.command :end do |event, *_args|
110
- e = EventDecorator.new(event)
111
- pug = Pug.for(e.channel_id)
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
- pug.end_pug
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
- message = 'PUG ended'
116
- send_and_log_message(message, e.channel)
124
+ send_and_log_message(message, e.channel)
125
+ end
117
126
  end
118
127
 
119
128
  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)
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 time_to_play_message(player_slots, mentions)
140
- ['Time to play!', player_slots, mentions.join(' ')].join(' | ')
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
metadata CHANGED
@@ -1,7 +1,7 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Johnson