discorb 0.19.0 → 0.20.0
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 +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- 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 -621
- 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 -804
- 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 -336
- data/lib/discorb/interaction/root.rb +271 -257
- 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 -291
- 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/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
@@ -1,398 +1,466 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
module ApplicationCommand
|
5
|
-
#
|
6
|
-
# Represents a application command.
|
7
|
-
# @abstract
|
8
|
-
#
|
9
|
-
class Command < DiscordModel
|
10
|
-
# @return [Hash{String => String}] The name of the command.
|
11
|
-
attr_reader :name
|
12
|
-
# @return [Array<#to_s>] The guild ids that the command is enabled in.
|
13
|
-
attr_reader :guild_ids
|
14
|
-
# @return [Proc] The block of the command.
|
15
|
-
attr_reader :block
|
16
|
-
# @return [:chat_input, :user, :message] The type of the command.
|
17
|
-
attr_reader :type
|
18
|
-
# @return [Integer] The raw type of the command.
|
19
|
-
attr_reader :type_raw
|
20
|
-
# @return [Discorb::Permission] The default permissions for this command.
|
21
|
-
attr_reader :default_permission
|
22
|
-
# @return [Boolean] Whether the command is enabled in DMs.
|
23
|
-
attr_reader :dm_permission
|
24
|
-
|
25
|
-
# @private
|
26
|
-
# @return [{Integer => Symbol}] The mapping of raw types to types.
|
27
|
-
TYPES = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# @
|
36
|
-
#
|
37
|
-
# @param [
|
38
|
-
# @param [
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
#
|
106
|
-
# @param [
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
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
|
-
# @return [Discorb::ApplicationCommand::Command
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
#
|
293
|
-
#
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
end
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
#
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
#
|
366
|
-
#
|
367
|
-
# @
|
368
|
-
#
|
369
|
-
# @
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
module ApplicationCommand
|
5
|
+
#
|
6
|
+
# Represents a application command.
|
7
|
+
# @abstract
|
8
|
+
#
|
9
|
+
class Command < DiscordModel
|
10
|
+
# @return [Hash{String => String}] The name of the command.
|
11
|
+
attr_reader :name
|
12
|
+
# @return [Array<#to_s>] The guild ids that the command is enabled in.
|
13
|
+
attr_reader :guild_ids
|
14
|
+
# @return [Proc] The block of the command.
|
15
|
+
attr_reader :block
|
16
|
+
# @return [:chat_input, :user, :message] The type of the command.
|
17
|
+
attr_reader :type
|
18
|
+
# @return [Integer] The raw type of the command.
|
19
|
+
attr_reader :type_raw
|
20
|
+
# @return [Discorb::Permission] The default permissions for this command.
|
21
|
+
attr_reader :default_permission
|
22
|
+
# @return [Boolean] Whether the command is enabled in DMs.
|
23
|
+
attr_reader :dm_permission
|
24
|
+
|
25
|
+
# @private
|
26
|
+
# @return [{Integer => Symbol}] The mapping of raw types to types.
|
27
|
+
TYPES = { 1 => :chat_input, 2 => :user, 3 => :message }.freeze
|
28
|
+
|
29
|
+
#
|
30
|
+
# Initialize a new command.
|
31
|
+
# @private
|
32
|
+
#
|
33
|
+
# @param [String, Hash{Symbol => String}] name The name of the command.
|
34
|
+
# @param [Array<#to_s>, false, nil] guild_ids The guild ids that the command is enabled in.
|
35
|
+
# @param [Proc] block The block of the command.
|
36
|
+
# @param [Integer] type The type of the command.
|
37
|
+
# @param [Boolean] dm_permission Whether the command is enabled in DMs.
|
38
|
+
# @param [Discorb::Permission] default_permission The default permission of the command.
|
39
|
+
#
|
40
|
+
def initialize(
|
41
|
+
name,
|
42
|
+
guild_ids,
|
43
|
+
block,
|
44
|
+
type,
|
45
|
+
dm_permission = true,
|
46
|
+
default_permission = nil
|
47
|
+
)
|
48
|
+
@name =
|
49
|
+
(
|
50
|
+
if name.is_a?(String)
|
51
|
+
{ "default" => name }
|
52
|
+
else
|
53
|
+
ApplicationCommand.modify_localization_hash(name)
|
54
|
+
end
|
55
|
+
)
|
56
|
+
@guild_ids = guild_ids&.map(&:to_s)
|
57
|
+
@block = block
|
58
|
+
@type = Discorb::ApplicationCommand::Command::TYPES[type]
|
59
|
+
@type_raw = type
|
60
|
+
@dm_permission = dm_permission
|
61
|
+
@default_permission = default_permission
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Changes the self pointer of block to the given object.
|
66
|
+
# @private
|
67
|
+
#
|
68
|
+
# @param [Object] instance The object to change the self pointer to.
|
69
|
+
#
|
70
|
+
def replace_block(instance)
|
71
|
+
current_block = @block.dup
|
72
|
+
@block = proc { |*args| instance.instance_exec(*args, ¤t_block) }
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Converts the object to a hash.
|
77
|
+
# @private
|
78
|
+
#
|
79
|
+
# @return [Hash] The hash represents the object.
|
80
|
+
#
|
81
|
+
def to_hash
|
82
|
+
{
|
83
|
+
name: @name["default"],
|
84
|
+
name_localizations: @name.except("default"),
|
85
|
+
type: @type_raw,
|
86
|
+
dm_permission: @dm_permission,
|
87
|
+
default_member_permissions: @default_permission&.value&.to_s
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Represents the slash command.
|
93
|
+
#
|
94
|
+
class ChatInputCommand < Command
|
95
|
+
# @return [Hash{String => String}] The description of the command.
|
96
|
+
attr_reader :description
|
97
|
+
# @return [Hash{String => Hash}] The options of the command.
|
98
|
+
attr_reader :options
|
99
|
+
|
100
|
+
#
|
101
|
+
# Initialize a new slash command.
|
102
|
+
# @private
|
103
|
+
#
|
104
|
+
# @param [String, Hash{Symbol => String}] name The name of the command.
|
105
|
+
# The hash should have `default`, and language keys.
|
106
|
+
# @param [String, Hash{Symbol => String}] description The description of the command.
|
107
|
+
# The hash should have `default`, and language keys.
|
108
|
+
# @param [Hash{String => Hash}] options The options of the command.
|
109
|
+
# @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
|
110
|
+
# @param [Proc] block The block of the command.
|
111
|
+
# @param [Integer] type The type of the command.
|
112
|
+
# @param [Discorb::ApplicationCommand::Command, nil] parent The parent command.
|
113
|
+
# @param [Boolean] dm_permission Whether the command is enabled in DMs.
|
114
|
+
# @param [Discorb::Permission] default_permission The default permission of the command.
|
115
|
+
#
|
116
|
+
def initialize(
|
117
|
+
name,
|
118
|
+
description,
|
119
|
+
options,
|
120
|
+
guild_ids,
|
121
|
+
block,
|
122
|
+
type,
|
123
|
+
parent,
|
124
|
+
dm_permission,
|
125
|
+
default_permission
|
126
|
+
)
|
127
|
+
super(name, guild_ids, block, type, dm_permission, default_permission)
|
128
|
+
@description =
|
129
|
+
if description.is_a?(String)
|
130
|
+
{ "default" => description }
|
131
|
+
else
|
132
|
+
ApplicationCommand.modify_localization_hash(description)
|
133
|
+
end
|
134
|
+
@options = options
|
135
|
+
@parent = parent
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# Returns the commands name.
|
140
|
+
#
|
141
|
+
# @return [String] The name of the command.
|
142
|
+
#
|
143
|
+
def to_s
|
144
|
+
"#{@parent} #{@name["default"]}".strip
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Converts the object to a hash.
|
149
|
+
# @private
|
150
|
+
#
|
151
|
+
# @return [Hash] The hash represents the object.
|
152
|
+
#
|
153
|
+
def to_hash
|
154
|
+
options_payload =
|
155
|
+
options.map do |name, value|
|
156
|
+
ret = {
|
157
|
+
type:
|
158
|
+
case value[:type]
|
159
|
+
when String, :string, :str
|
160
|
+
3
|
161
|
+
when Integer, :integer, :int
|
162
|
+
4
|
163
|
+
when TrueClass, FalseClass, :boolean, :bool
|
164
|
+
5
|
165
|
+
when Discorb::User, Discorb::Member, :user, :member
|
166
|
+
6
|
167
|
+
when Discorb::Channel, :channel
|
168
|
+
7
|
169
|
+
when Discorb::Role, :role
|
170
|
+
8
|
171
|
+
when :mentionable
|
172
|
+
9
|
173
|
+
when Float, :float
|
174
|
+
10
|
175
|
+
when :attachment
|
176
|
+
11
|
177
|
+
else
|
178
|
+
raise ArgumentError, "Invalid option type: #{value[:type]}"
|
179
|
+
end,
|
180
|
+
name: name,
|
181
|
+
name_localizations:
|
182
|
+
ApplicationCommand.modify_localization_hash(
|
183
|
+
value[:name_localizations]
|
184
|
+
),
|
185
|
+
required:
|
186
|
+
value[:required].nil? ? !value[:optional] : value[:required]
|
187
|
+
}
|
188
|
+
|
189
|
+
if value[:description].is_a?(String)
|
190
|
+
ret[:description] = value[:description]
|
191
|
+
else
|
192
|
+
description =
|
193
|
+
ApplicationCommand.modify_localization_hash(
|
194
|
+
value[:description]
|
195
|
+
)
|
196
|
+
ret[:description] = description["default"]
|
197
|
+
ret[:description_localizations] = description.except("default")
|
198
|
+
end
|
199
|
+
if value[:choices]
|
200
|
+
ret[:choices] = value[:choices].map do |k, v|
|
201
|
+
r = { name: k, value: v }
|
202
|
+
if choices_localizations = value[:choices_localizations].clone
|
203
|
+
name_localizations =
|
204
|
+
ApplicationCommand.modify_localization_hash(
|
205
|
+
choices_localizations.delete(k) do
|
206
|
+
warn "Missing localization for #{k}"
|
207
|
+
{}
|
208
|
+
end
|
209
|
+
)
|
210
|
+
r[:name_localizations] = name_localizations.except(
|
211
|
+
"default"
|
212
|
+
)
|
213
|
+
r[:name] = name_localizations["default"]
|
214
|
+
r.delete(:name_localizations) if r[:name_localizations].nil?
|
215
|
+
end
|
216
|
+
r
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
ret[:channel_types] = value[:channel_types].map(
|
221
|
+
&:channel_type
|
222
|
+
) if value[:channel_types]
|
223
|
+
|
224
|
+
ret[:autocomplete] = !value[:autocomplete].nil? if value[
|
225
|
+
:autocomplete
|
226
|
+
]
|
227
|
+
if value[:range]
|
228
|
+
ret[:min_value] = value[:range].begin
|
229
|
+
ret[:max_value] = value[:range].end
|
230
|
+
end
|
231
|
+
if value[:length]
|
232
|
+
ret[:min_length] = value[:length].begin
|
233
|
+
ret[:max_length] = value[:length].end
|
234
|
+
end
|
235
|
+
ret
|
236
|
+
end
|
237
|
+
{
|
238
|
+
name: @name["default"],
|
239
|
+
name_localizations: @name.except("default"),
|
240
|
+
description: @description["default"],
|
241
|
+
description_localizations: @description.except("default"),
|
242
|
+
options: options_payload,
|
243
|
+
dm_permission: @dm_permission,
|
244
|
+
default_member_permissions: @default_permission&.value&.to_s
|
245
|
+
}
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
#
|
250
|
+
# Represents the command with subcommands.
|
251
|
+
#
|
252
|
+
class GroupCommand < Command
|
253
|
+
# @return [Array<Discorb::ApplicationCommand::Command>] The subcommands of the command.
|
254
|
+
attr_reader :commands
|
255
|
+
# @return [Hash{String => String}] The description of the command.
|
256
|
+
attr_reader :description
|
257
|
+
|
258
|
+
#
|
259
|
+
# Initialize a new group command.
|
260
|
+
# @private
|
261
|
+
#
|
262
|
+
# @param [String, Hash{Symbol => String}] name The name of the command.
|
263
|
+
# @param [String, Hash{Symbol => String}] description The description of the command.
|
264
|
+
# @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
|
265
|
+
# @param [Discorb::Client] client The client of the command.
|
266
|
+
# @param [Boolean] dm_permission Whether the command is enabled in DMs.
|
267
|
+
# @param [Discorb::Permission] default_permission The default permission of the command.
|
268
|
+
#
|
269
|
+
def initialize(
|
270
|
+
name,
|
271
|
+
description,
|
272
|
+
guild_ids,
|
273
|
+
client,
|
274
|
+
dm_permission,
|
275
|
+
default_permission
|
276
|
+
)
|
277
|
+
super(name, guild_ids, block, 1, dm_permission, default_permission)
|
278
|
+
@description =
|
279
|
+
if description.is_a?(String)
|
280
|
+
{ "default" => description }
|
281
|
+
else
|
282
|
+
ApplicationCommand.modify_localization_hash(description)
|
283
|
+
end
|
284
|
+
@commands = []
|
285
|
+
@client = client
|
286
|
+
end
|
287
|
+
|
288
|
+
#
|
289
|
+
# Add new subcommand.
|
290
|
+
#
|
291
|
+
# @param (see Discorb::ApplicationCommand::Handler#slash)
|
292
|
+
# @return [Discorb::ApplicationCommand::Command::ChatInputCommand] The added subcommand.
|
293
|
+
#
|
294
|
+
def slash(
|
295
|
+
command_name,
|
296
|
+
description,
|
297
|
+
options = {},
|
298
|
+
dm_permission: true,
|
299
|
+
default_permission: nil,
|
300
|
+
&block
|
301
|
+
)
|
302
|
+
command =
|
303
|
+
Discorb::ApplicationCommand::Command::ChatInputCommand.new(
|
304
|
+
command_name,
|
305
|
+
description,
|
306
|
+
options,
|
307
|
+
[],
|
308
|
+
block,
|
309
|
+
1,
|
310
|
+
self,
|
311
|
+
dm_permission,
|
312
|
+
default_permission
|
313
|
+
)
|
314
|
+
@client.callable_commands << command
|
315
|
+
@commands << command
|
316
|
+
command
|
317
|
+
end
|
318
|
+
|
319
|
+
#
|
320
|
+
# Add new subcommand group.
|
321
|
+
#
|
322
|
+
# @param [String] command_name Group name.
|
323
|
+
# @param [String] description Group description.
|
324
|
+
#
|
325
|
+
# @yield Block to yield with the command.
|
326
|
+
# @yieldparam [Discorb::ApplicationCommand::Command::SubcommandGroup] group Group command.
|
327
|
+
#
|
328
|
+
# @return [Discorb::ApplicationCommand::Command::SubcommandGroup] Command object.
|
329
|
+
#
|
330
|
+
# @see file:docs/application_command.md Application Commands
|
331
|
+
#
|
332
|
+
def group(command_name, description)
|
333
|
+
command =
|
334
|
+
Discorb::ApplicationCommand::Command::SubcommandGroup.new(
|
335
|
+
command_name,
|
336
|
+
description,
|
337
|
+
self,
|
338
|
+
@client
|
339
|
+
)
|
340
|
+
yield command if block_given?
|
341
|
+
@commands << command
|
342
|
+
command
|
343
|
+
end
|
344
|
+
|
345
|
+
#
|
346
|
+
# Returns the command name.
|
347
|
+
#
|
348
|
+
# @return [String] The command name.
|
349
|
+
#
|
350
|
+
def to_s
|
351
|
+
@name["default"]
|
352
|
+
end
|
353
|
+
|
354
|
+
#
|
355
|
+
# Changes the self pointer to the given object.
|
356
|
+
# @private
|
357
|
+
#
|
358
|
+
# @param [Object] instance The object to change to.
|
359
|
+
#
|
360
|
+
def block_replace(instance)
|
361
|
+
super
|
362
|
+
@commands.each { |c| c.replace_block(instance) }
|
363
|
+
end
|
364
|
+
|
365
|
+
#
|
366
|
+
# Converts the object to a hash.
|
367
|
+
# @private
|
368
|
+
#
|
369
|
+
# @return [Hash] The hash represents the object.
|
370
|
+
#
|
371
|
+
def to_hash
|
372
|
+
options_payload =
|
373
|
+
@commands.map do |command|
|
374
|
+
if command.is_a?(ChatInputCommand)
|
375
|
+
{
|
376
|
+
name: command.name["default"],
|
377
|
+
name_localizations: command.name.except("default"),
|
378
|
+
description: command.description["default"],
|
379
|
+
description_localizations:
|
380
|
+
command.description.except("default"),
|
381
|
+
type: 1,
|
382
|
+
options: command.to_hash[:options]
|
383
|
+
}
|
384
|
+
else
|
385
|
+
{
|
386
|
+
name: command.name["default"],
|
387
|
+
name_localizations: command.name.except("default"),
|
388
|
+
description: command.description["default"],
|
389
|
+
description_localizations:
|
390
|
+
command.description.except("default"),
|
391
|
+
type: 2,
|
392
|
+
options:
|
393
|
+
command.commands.map do |c|
|
394
|
+
c
|
395
|
+
.to_hash
|
396
|
+
.merge(type: 1)
|
397
|
+
.except(:dm_permission, :default_member_permissions)
|
398
|
+
end
|
399
|
+
}
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
{
|
404
|
+
name: @name["default"],
|
405
|
+
name_localizations: @name.except("default"),
|
406
|
+
description: @description["default"],
|
407
|
+
description_localizations: @description.except("default"),
|
408
|
+
dm_permission: @dm_permission,
|
409
|
+
default_member_permissions: @default_permission&.value&.to_s,
|
410
|
+
options: options_payload
|
411
|
+
}
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
#
|
416
|
+
# Represents the subcommand group.
|
417
|
+
#
|
418
|
+
class SubcommandGroup < GroupCommand
|
419
|
+
# @return [Array<Discorb::ApplicationCommand::Command::ChatInputCommand>] The subcommands of the command.
|
420
|
+
attr_reader :commands
|
421
|
+
|
422
|
+
#
|
423
|
+
# Initialize a new subcommand group.
|
424
|
+
# @private
|
425
|
+
#
|
426
|
+
# @param [String] name The name of the command.
|
427
|
+
# @param [String] description The description of the command.
|
428
|
+
# @param [Discorb::ApplicationCommand::Command::GroupCommand] parent The parent command.
|
429
|
+
# @param [Discorb::Client] client The client.
|
430
|
+
def initialize(name, description, parent, client)
|
431
|
+
super(name, description, [], client, nil, nil)
|
432
|
+
|
433
|
+
@commands = []
|
434
|
+
@parent = parent
|
435
|
+
end
|
436
|
+
|
437
|
+
def to_s
|
438
|
+
"#{@parent} #{@name}"
|
439
|
+
end
|
440
|
+
|
441
|
+
#
|
442
|
+
# Add new subcommand.
|
443
|
+
# @param (see Discorb::ApplicationCommand::Handler#slash)
|
444
|
+
# @return [Discorb::ApplicationCommand::Command::ChatInputCommand] The added subcommand.
|
445
|
+
#
|
446
|
+
def slash(command_name, description, options = {}, &block)
|
447
|
+
command =
|
448
|
+
Discorb::ApplicationCommand::Command::ChatInputCommand.new(
|
449
|
+
command_name,
|
450
|
+
description,
|
451
|
+
options,
|
452
|
+
[],
|
453
|
+
block,
|
454
|
+
1,
|
455
|
+
self,
|
456
|
+
nil,
|
457
|
+
nil
|
458
|
+
)
|
459
|
+
@commands << command
|
460
|
+
@client.callable_commands << command
|
461
|
+
command
|
462
|
+
end
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|