discorb 0.18.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +25 -0
- data/Gemfile +4 -4
- data/README.md +2 -1
- data/Rakefile +482 -459
- data/Steepfile +8 -6
- data/docs/application_command.md +1 -0
- data/docs/events.md +2 -2
- data/docs/voice_events.md +6 -6
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -394
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -265
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -623
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -794
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -330
- data/lib/discorb/interaction/root.rb +271 -118
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -289
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/activity.rbs +1 -0
- data/sig/discorb/allowed_mentions.rbs +1 -0
- data/sig/discorb/app_command/base.rbs +7 -1
- data/sig/discorb/application.rbs +6 -0
- data/sig/discorb/asset.rbs +2 -0
- data/sig/discorb/attachment.rbs +8 -0
- data/sig/discorb/audit_log.rbs +7 -0
- data/sig/discorb/automod.rbs +32 -6
- data/sig/discorb/avatar.rbs +1 -0
- data/sig/discorb/channel/base.rbs +8 -1
- data/sig/discorb/channel/category.rbs +1 -0
- data/sig/discorb/channel/container.rbs +4 -0
- data/sig/discorb/channel/stage.rbs +4 -0
- data/sig/discorb/channel/text.rbs +2 -2
- data/sig/discorb/channel/thread.rbs +11 -0
- data/sig/discorb/channel/voice.rbs +2 -0
- data/sig/discorb/client.rbs +21 -20
- data/sig/discorb/color.rbs +6 -0
- data/sig/discorb/component/base.rbs +1 -0
- data/sig/discorb/component/button.rbs +2 -0
- data/sig/discorb/component/select_menu.rbs +4 -0
- data/sig/discorb/component/text_input.rbs +1 -0
- data/sig/discorb/custom_emoji.rbs +5 -1
- data/sig/discorb/dictionary.rbs +2 -0
- data/sig/discorb/discord_model.rbs +2 -0
- data/sig/discorb/embed.rbs +7 -0
- data/sig/discorb/emoji.rbs +1 -0
- data/sig/discorb/event_handler.rbs +2 -1
- data/sig/discorb/extension.rbs +13 -12
- data/sig/discorb/flag.rbs +2 -0
- data/sig/discorb/gateway.rbs +5 -0
- data/sig/discorb/guild.rbs +8 -4
- data/sig/discorb/guild_template.rbs +1 -1
- data/sig/discorb/http.rbs +4 -1
- data/sig/discorb/image.rbs +2 -0
- data/sig/discorb/integration.rbs +1 -1
- data/sig/discorb/intents.rbs +4 -3
- data/sig/discorb/interaction/base.rbs +36 -0
- data/sig/discorb/interaction/message_component.rbs +1 -2
- data/sig/discorb/interaction/modal.rbs +1 -2
- data/sig/discorb/interaction/responder.rbs +49 -49
- data/sig/discorb/invite.rbs +1 -1
- data/sig/discorb/member.rbs +2 -0
- data/sig/discorb/message.rbs +8 -1
- data/sig/discorb/messageable.rbs +1 -4
- data/sig/discorb/partial_emoji.rbs +3 -0
- data/sig/discorb/permissions.rbs +7 -0
- data/sig/discorb/presence.rbs +2 -0
- data/sig/discorb/reaction.rbs +5 -1
- data/sig/discorb/role.rbs +7 -1
- data/sig/discorb/scheduled_event.rbs +2 -1
- data/sig/discorb/shard.rbs +2 -1
- data/sig/discorb/snowflake.rbs +2 -0
- data/sig/discorb/stage_instance.rbs +9 -3
- data/sig/discorb/sticker.rbs +1 -1
- data/sig/discorb/unicode_emoji.rbs +4 -0
- data/sig/discorb/user.rbs +24 -20
- data/sig/discorb/webhook.rbs +17 -6
- data/sig/discorb/welcome_screen.rbs +1 -0
- data/sig/override.rbs +2 -0
- metadata +3 -3
data/lib/discorb/automod.rb
CHANGED
@@ -1,269 +1,279 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a rule of auto moderation.
|
6
|
-
#
|
7
|
-
class AutoModRule < DiscordModel
|
8
|
-
# @return [Hash{Integer => Symbol}] The mapping of trigger types.
|
9
|
-
# @private
|
10
|
-
TRIGGER_TYPES = {
|
11
|
-
1 => :keyword,
|
12
|
-
2 => :harmful_link,
|
13
|
-
3 => :spam,
|
14
|
-
4 => :keyword_preset,
|
15
|
-
|
16
|
-
|
17
|
-
# @
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}.freeze
|
23
|
-
|
24
|
-
# @
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# @return [
|
32
|
-
attr_reader :
|
33
|
-
# @return [
|
34
|
-
|
35
|
-
|
36
|
-
# @return [Array<
|
37
|
-
|
38
|
-
|
39
|
-
# @
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# @param [
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
# @
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
# @
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
#
|
100
|
-
#
|
101
|
-
# @
|
102
|
-
#
|
103
|
-
#
|
104
|
-
# @param [
|
105
|
-
# @param [
|
106
|
-
# @param [
|
107
|
-
# @param [
|
108
|
-
# @param [Array<Discorb::
|
109
|
-
# @param [Array<
|
110
|
-
# @param [
|
111
|
-
# @param [
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
payload
|
128
|
-
|
129
|
-
|
130
|
-
payload[:
|
131
|
-
|
132
|
-
payload[:actions] = actions unless actions == Discorb::Unset
|
133
|
-
payload[:enabled] = enabled unless enabled == Discorb::Unset
|
134
|
-
payload[:exempt_roles] = exempt_roles.map(&:id) unless exempt_roles ==
|
135
|
-
|
136
|
-
payload[:
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
#
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
@
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
# @return [Integer] The
|
205
|
-
# @
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
# @
|
213
|
-
|
214
|
-
# @
|
215
|
-
#
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
#
|
251
|
-
#
|
252
|
-
#
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a rule of auto moderation.
|
6
|
+
#
|
7
|
+
class AutoModRule < DiscordModel
|
8
|
+
# @return [Hash{Integer => Symbol}] The mapping of trigger types.
|
9
|
+
# @private
|
10
|
+
TRIGGER_TYPES = {
|
11
|
+
1 => :keyword,
|
12
|
+
2 => :harmful_link,
|
13
|
+
3 => :spam,
|
14
|
+
4 => :keyword_preset,
|
15
|
+
5 => :mention_spam
|
16
|
+
}.freeze
|
17
|
+
# @return [Hash{Integer => Symbol}] The mapping of preset types.
|
18
|
+
# @private
|
19
|
+
PRESET_TYPES = { 1 => :profanity, 2 => :sexual_content, 3 => :slurs }.freeze
|
20
|
+
# @return [Hash{Integer => Symbol}] The mapping of event types.
|
21
|
+
# @private
|
22
|
+
EVENT_TYPES = { 1 => :message_send }.freeze
|
23
|
+
|
24
|
+
# @return [Discorb::Snowflake] The ID of the rule.
|
25
|
+
attr_reader :id
|
26
|
+
# @return [String] The name of the rule.
|
27
|
+
attr_reader :name
|
28
|
+
# @return [Boolean] Whether the rule is enabled.
|
29
|
+
attr_reader :enabled
|
30
|
+
alias enabled? enabled
|
31
|
+
# @return [Array<Discorb::AutoModRule::Action>] The actions of the rule.
|
32
|
+
attr_reader :actions
|
33
|
+
# @return [Array<String>] The keywords that the rule is triggered by.
|
34
|
+
# @note This is only available if the trigger type is `:keyword`.
|
35
|
+
attr_reader :keyword_filter
|
36
|
+
# @return [Array<String>] Substrings which will be exempt from triggering the preset trigger type.
|
37
|
+
# @note This is only available if the trigger type is `:keyword_preset`.
|
38
|
+
attr_reader :allow_list
|
39
|
+
# @return [Integer] Total number of mentions allowed per message.
|
40
|
+
# @note This is only available if the trigger type is `:mention_spam`.
|
41
|
+
attr_reader :mention_total_limit
|
42
|
+
|
43
|
+
#
|
44
|
+
# Initialize a new auto mod.
|
45
|
+
# @private
|
46
|
+
#
|
47
|
+
# @param [Discorb::Client] client The client.
|
48
|
+
# @param [Hash] data The auto mod data.
|
49
|
+
#
|
50
|
+
def initialize(client, data)
|
51
|
+
@client = client
|
52
|
+
_set_data(data)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @!attribute [r]
|
56
|
+
# @return [Symbol] Returns the type of the preset.
|
57
|
+
# @note This is only available if the trigger type is `:keyword_preset`.
|
58
|
+
def preset_type
|
59
|
+
PRESET_TYPES[@presets_raw]
|
60
|
+
end
|
61
|
+
|
62
|
+
# @!attribute [r]
|
63
|
+
# @return [Symbol] Returns the type of the trigger.
|
64
|
+
def trigger_type
|
65
|
+
TRIGGER_TYPES[@trigger_type_raw]
|
66
|
+
end
|
67
|
+
|
68
|
+
# @!attribute [r]
|
69
|
+
# @return [Symbol] Returns the type of the event.
|
70
|
+
def event_type
|
71
|
+
EVENT_TYPES[@event_type_raw]
|
72
|
+
end
|
73
|
+
|
74
|
+
# @!attribute [r]
|
75
|
+
# @macro client_cache
|
76
|
+
# @return [Discorb::Member] The member who created the rule.
|
77
|
+
def creator
|
78
|
+
guild.members[@creator_id]
|
79
|
+
end
|
80
|
+
|
81
|
+
# @!attribute [r]
|
82
|
+
# @return [Discorb::Guild] The guild that the rule is in.
|
83
|
+
def guild
|
84
|
+
@client.guilds[@guild_id]
|
85
|
+
end
|
86
|
+
|
87
|
+
# @!attribute [r]
|
88
|
+
# @return [Array<Discorb::Role>] The roles that the rule is exempt from.
|
89
|
+
def exempt_roles
|
90
|
+
@exempt_roles_id.map { |id| guild.roles[id] }
|
91
|
+
end
|
92
|
+
|
93
|
+
# @!attribute [r]
|
94
|
+
# @return [Array<Discorb::Channel>] The channels that the rule is exempt from.
|
95
|
+
def exempt_channels
|
96
|
+
@exempt_channels_id.map { |id| guild.channels[id] }
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Edit the rule.
|
101
|
+
# @async
|
102
|
+
# @edit
|
103
|
+
#
|
104
|
+
# @param [String] name The name of the rule.
|
105
|
+
# @param [Symbol] event_type The event type of the rule. See {Discorb::AutoModRule::EVENT_TYPES}.
|
106
|
+
# @param [Array<Discorb::AutoModRule::Action>] actions The actions of the rule.
|
107
|
+
# @param [Boolean] enabled Whether the rule is enabled or not.
|
108
|
+
# @param [Array<Discorb::Role>] exempt_roles The roles that are exempt from the rule.
|
109
|
+
# @param [Array<Discorb::Channel>] exempt_channels The channels that are exempt from the rule.
|
110
|
+
# @param [Array<String>] keyword_filter The keywords to filter.
|
111
|
+
# @param [Symbol] presets The preset of the rule. See {Discorb::AutoModRule::PRESET_TYPES}.
|
112
|
+
# @param [String] reason The reason for creating the rule.
|
113
|
+
#
|
114
|
+
# @return [Async::Task<void>] The task.
|
115
|
+
#
|
116
|
+
def edit(
|
117
|
+
name: Discorb::Unset,
|
118
|
+
event_type: Discorb::Unset,
|
119
|
+
actions: Discorb::Unset,
|
120
|
+
enabled: Discorb::Unset,
|
121
|
+
exempt_roles: Discorb::Unset,
|
122
|
+
exempt_channels: Discorb::Unset,
|
123
|
+
keyword_filter: Discorb::Unset,
|
124
|
+
presets: Discorb::Unset,
|
125
|
+
reason: nil
|
126
|
+
)
|
127
|
+
# @type var payload: Hash[Symbol, untyped]
|
128
|
+
payload = { metadata: {} }
|
129
|
+
payload[:name] = name unless name == Discorb::Unset
|
130
|
+
payload[:event_type] = EVENT_TYPES.key(event_type) unless event_type ==
|
131
|
+
Discorb::Unset
|
132
|
+
payload[:actions] = actions unless actions == Discorb::Unset
|
133
|
+
payload[:enabled] = enabled unless enabled == Discorb::Unset
|
134
|
+
payload[:exempt_roles] = exempt_roles.map(&:id) unless exempt_roles ==
|
135
|
+
Discorb::Unset
|
136
|
+
payload[:exempt_channels] = exempt_channels.map(
|
137
|
+
&:id
|
138
|
+
) unless exempt_channels == Discorb::Unset
|
139
|
+
payload[:metadata][
|
140
|
+
:keyword_filter
|
141
|
+
] = keyword_filter unless keyword_filter == Discorb::Unset
|
142
|
+
payload[:metadata][:presets] = PRESET_TYPES.key(presets) unless presets ==
|
143
|
+
Discorb::Unset
|
144
|
+
|
145
|
+
@client.http.request(
|
146
|
+
Route.new(
|
147
|
+
"/guilds/#{@guild_id}/automod/rules/#{@id}",
|
148
|
+
"//guilds/:guild_id/automod/rules/:id",
|
149
|
+
:patch
|
150
|
+
),
|
151
|
+
payload,
|
152
|
+
audit_log_reason: reason
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# Delete the rule.
|
158
|
+
#
|
159
|
+
# @param [String] reason The reason for deleting the rule.
|
160
|
+
#
|
161
|
+
# @return [Async::Task<void>] The task.
|
162
|
+
#
|
163
|
+
def delete(reason: nil)
|
164
|
+
Async do
|
165
|
+
@client.http.request(
|
166
|
+
Route.new(
|
167
|
+
"/guilds/#{@guild_id}/automod/rules/#{@id}",
|
168
|
+
"//guilds/:guild_id/automod/rules/:id",
|
169
|
+
:delete
|
170
|
+
),
|
171
|
+
audit_log_reason: reason
|
172
|
+
)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# @private
|
177
|
+
def _set_data(data)
|
178
|
+
@id = Snowflake.new(data[:id])
|
179
|
+
@guild_id = data[:guild_id]
|
180
|
+
@name = data[:name]
|
181
|
+
@creator_id = data[:creator_id]
|
182
|
+
@trigger_type_raw = data[:trigger_type]
|
183
|
+
@event_type_raw = data[:event_type]
|
184
|
+
@actions =
|
185
|
+
data[:actions].map { |action| Action.from_hash(@client, action) }
|
186
|
+
case trigger_type
|
187
|
+
when :keyword
|
188
|
+
@keyword_filter = data[:trigger_metadata][:keyword_filter]
|
189
|
+
when :keyword_preset
|
190
|
+
@presets_raw = data[:trigger_metadata][:presets]
|
191
|
+
@allow_list = data[:trigger_metadata][:allow_list]
|
192
|
+
when :mention_spam
|
193
|
+
@mention_total_limit = data[:metadata][:mention_total_limit]
|
194
|
+
end
|
195
|
+
@enabled = data[:enabled]
|
196
|
+
@exempt_roles_id = data[:exempt_roles]
|
197
|
+
@exempt_channels_id = data[:exempt_channels]
|
198
|
+
end
|
199
|
+
|
200
|
+
#
|
201
|
+
# Represents the action of auto moderation.
|
202
|
+
#
|
203
|
+
class Action < DiscordModel
|
204
|
+
# @return [Hash{Integer => Symbol}] The mapping of action types.
|
205
|
+
# @private
|
206
|
+
ACTION_TYPES = {
|
207
|
+
1 => :block_message,
|
208
|
+
2 => :send_alert_message,
|
209
|
+
3 => :timeout
|
210
|
+
}.freeze
|
211
|
+
|
212
|
+
# @return [Symbol] Returns the type of the action.
|
213
|
+
attr_reader :type
|
214
|
+
# @return [Integer] The duration of the timeout.
|
215
|
+
# @note This is only available if the action type is `:timeout`.
|
216
|
+
attr_reader :duration_seconds
|
217
|
+
|
218
|
+
#
|
219
|
+
# Initialize a new action.
|
220
|
+
#
|
221
|
+
# @param [Symbol] type The type of the action.
|
222
|
+
# @param [Integer] duration_seconds The duration of the timeout.
|
223
|
+
# This is only available if the action type is `:timeout`.
|
224
|
+
# @param [Discorb::Channel] channel The channel that the alert message is sent to.
|
225
|
+
# This is only available if the action type is `:send_alert_message`.
|
226
|
+
#
|
227
|
+
def initialize(type, duration_seconds: nil, channel: nil)
|
228
|
+
@type = type
|
229
|
+
@duration_seconds = duration_seconds
|
230
|
+
@channel = channel
|
231
|
+
end
|
232
|
+
|
233
|
+
#
|
234
|
+
# Convert the action to hash.
|
235
|
+
#
|
236
|
+
# @return [Hash] The action hash.
|
237
|
+
#
|
238
|
+
def to_hash
|
239
|
+
{
|
240
|
+
type: @type,
|
241
|
+
metadata: {
|
242
|
+
channel_id: @channel&.id,
|
243
|
+
duration_seconds: @duration_seconds
|
244
|
+
}
|
245
|
+
}
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# Initialize a new action from hash.
|
250
|
+
# @private
|
251
|
+
#
|
252
|
+
# @param [Discorb::Client] client The client.
|
253
|
+
# @param [Hash] data The action data.
|
254
|
+
#
|
255
|
+
def initialize_hash(client, data)
|
256
|
+
@client = client
|
257
|
+
_set_data(data)
|
258
|
+
end
|
259
|
+
|
260
|
+
# @!attribute [r]
|
261
|
+
# @return [Discorb::Channel] The channel that the alert message is sent to.
|
262
|
+
# @note This is only available if the action type is `:send_alert_message`.
|
263
|
+
def channel
|
264
|
+
@client.channels[@channel_id]
|
265
|
+
end
|
266
|
+
|
267
|
+
# @private
|
268
|
+
def _set_data(data)
|
269
|
+
@type = ACTION_TYPES[data[:type]]
|
270
|
+
@channel_id = data[:metadata][:channel_id]
|
271
|
+
@duration_seconds = data[:metadata][:duration_seconds]
|
272
|
+
end
|
273
|
+
|
274
|
+
def self.from_hash(client, data)
|
275
|
+
allocate.tap { |action| action.initialize_hash(client, data) }
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|