discorb 0.19.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 +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,266 +1,304 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
module ApplicationCommand
|
5
|
-
#
|
6
|
-
# Module to handle application commands.
|
7
|
-
#
|
8
|
-
module Handler
|
9
|
-
# @type instance: Discorb::Client
|
10
|
-
|
11
|
-
#
|
12
|
-
# Add new top-level command.
|
13
|
-
#
|
14
|
-
# @param [String, Hash{Symbol => String}] command_name Command name.
|
15
|
-
# If hash is passed, it must be a pair of Language code and Command name, and `:default` key is required.
|
16
|
-
# You can use `_` instead of `-` in language code.
|
17
|
-
# @param [String, Hash{Symbol => String}] description Command description.
|
18
|
-
# If hash is passed, it must be a pair of Language code and Command description, and `:default` key is required.
|
19
|
-
# You can use `_` instead of `-` in language code.
|
20
|
-
# @param [Hash{String => Hash{:description => String, :optional => Boolean, :type => Object}}] options
|
21
|
-
# Command options.
|
22
|
-
# The key is the option name, the value is a hash with the following keys:
|
23
|
-
#
|
24
|
-
# | Key | Type | Description |
|
25
|
-
# | --- | --- | --- |
|
26
|
-
# | `:name_localizations` | Hash{Symbol => String} | Localizations of option name. |
|
27
|
-
# | `:description` | `String` \| `Hash{Symbol => String}` |
|
28
|
-
# Description of the option. If hash is passed, it must be a pair of Language code and description,
|
29
|
-
# and `:default` key is required. You can use `_` instead of `-` in language code. |
|
30
|
-
# | `:required` | Boolean(true | false) |
|
31
|
-
# Whether the argument is required. `optional` will be used if not specified. |
|
32
|
-
# | `:optional` | Boolean(true | false) |
|
33
|
-
# Whether the argument is optional. `required` will be used if not specified. |
|
34
|
-
# | `:type` | `Object` | Type of the option. |
|
35
|
-
# | `:choices` | `Hash{String => String, Integer, Float}` | Type of the option. |
|
36
|
-
# | `:choices_localizations` | `Hash{String => Hash{Symbol => String}}` |
|
37
|
-
# Localization of the choice. Key must be the name of a choice. |
|
38
|
-
# | `:default` | `Object` | Default value of the option. |
|
39
|
-
# | `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
|
40
|
-
# | `:autocomplete` | `Proc` | Autocomplete function. |
|
41
|
-
# | `:range` | `Range` | Range of the option. Only valid for numeric options. (`:int`, `:float`) |
|
42
|
-
# | `:length` | `Range` | Range of length of the option. Only valid for `:string`. |
|
43
|
-
#
|
44
|
-
# @param [Array<#to_s>, false, nil] guild_ids
|
45
|
-
# Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
46
|
-
# @param [Boolean] dm_permission Whether the command is available in DM.
|
47
|
-
# @param [Discorb::Permission] default_permission The default permission of the command.
|
48
|
-
# @param [Proc] block Command block.
|
49
|
-
#
|
50
|
-
# @return [Discorb::ApplicationCommand::Command::ChatInputCommand] Command object.
|
51
|
-
#
|
52
|
-
# @see file:docs/application_command.md#register-slash-command Application Comamnds: Register Slash Command
|
53
|
-
# @see file:docs/cli/setup.md CLI: setup
|
54
|
-
#
|
55
|
-
def slash(
|
56
|
-
command_name,
|
57
|
-
description,
|
58
|
-
options = {},
|
59
|
-
guild_ids: nil,
|
60
|
-
dm_permission: true,
|
61
|
-
default_permission: nil,
|
62
|
-
&block
|
63
|
-
)
|
64
|
-
command_name = { default: command_name } if command_name.is_a?(String)
|
65
|
-
description = { default: description } if description.is_a?(String)
|
66
|
-
command_name = ApplicationCommand.modify_localization_hash(command_name)
|
67
|
-
description = ApplicationCommand.modify_localization_hash(description)
|
68
|
-
command =
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
@
|
81
|
-
command
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
# @param [String, Hash{Symbol => String}]
|
89
|
-
# @param [
|
90
|
-
#
|
91
|
-
#
|
92
|
-
# @param [
|
93
|
-
#
|
94
|
-
#
|
95
|
-
# @
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
# @see file:docs/
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
module ApplicationCommand
|
5
|
+
#
|
6
|
+
# Module to handle application commands.
|
7
|
+
#
|
8
|
+
module Handler
|
9
|
+
# @type instance: Discorb::Client
|
10
|
+
|
11
|
+
#
|
12
|
+
# Add new top-level command.
|
13
|
+
#
|
14
|
+
# @param [String, Hash{Symbol => String}] command_name Command name.
|
15
|
+
# If hash is passed, it must be a pair of Language code and Command name, and `:default` key is required.
|
16
|
+
# You can use `_` instead of `-` in language code.
|
17
|
+
# @param [String, Hash{Symbol => String}] description Command description.
|
18
|
+
# If hash is passed, it must be a pair of Language code and Command description, and `:default` key is required.
|
19
|
+
# You can use `_` instead of `-` in language code.
|
20
|
+
# @param [Hash{String => Hash{:description => String, :optional => Boolean, :type => Object}}] options
|
21
|
+
# Command options.
|
22
|
+
# The key is the option name, the value is a hash with the following keys:
|
23
|
+
#
|
24
|
+
# | Key | Type | Description |
|
25
|
+
# | --- | --- | --- |
|
26
|
+
# | `:name_localizations` | Hash{Symbol => String} | Localizations of option name. |
|
27
|
+
# | `:description` | `String` \| `Hash{Symbol => String}` |
|
28
|
+
# Description of the option. If hash is passed, it must be a pair of Language code and description,
|
29
|
+
# and `:default` key is required. You can use `_` instead of `-` in language code. |
|
30
|
+
# | `:required` | Boolean(true | false) |
|
31
|
+
# Whether the argument is required. `optional` will be used if not specified. |
|
32
|
+
# | `:optional` | Boolean(true | false) |
|
33
|
+
# Whether the argument is optional. `required` will be used if not specified. |
|
34
|
+
# | `:type` | `Object` | Type of the option. |
|
35
|
+
# | `:choices` | `Hash{String => String, Integer, Float}` | Type of the option. |
|
36
|
+
# | `:choices_localizations` | `Hash{String => Hash{Symbol => String}}` |
|
37
|
+
# Localization of the choice. Key must be the name of a choice. |
|
38
|
+
# | `:default` | `Object` | Default value of the option. |
|
39
|
+
# | `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
|
40
|
+
# | `:autocomplete` | `Proc` | Autocomplete function. |
|
41
|
+
# | `:range` | `Range` | Range of the option. Only valid for numeric options. (`:int`, `:float`) |
|
42
|
+
# | `:length` | `Range` | Range of length of the option. Only valid for `:string`. |
|
43
|
+
#
|
44
|
+
# @param [Array<#to_s>, false, nil] guild_ids
|
45
|
+
# Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
46
|
+
# @param [Boolean] dm_permission Whether the command is available in DM.
|
47
|
+
# @param [Discorb::Permission] default_permission The default permission of the command.
|
48
|
+
# @param [Proc] block Command block.
|
49
|
+
#
|
50
|
+
# @return [Discorb::ApplicationCommand::Command::ChatInputCommand] Command object.
|
51
|
+
#
|
52
|
+
# @see file:docs/application_command.md#register-slash-command Application Comamnds: Register Slash Command
|
53
|
+
# @see file:docs/cli/setup.md CLI: setup
|
54
|
+
#
|
55
|
+
def slash(
|
56
|
+
command_name,
|
57
|
+
description,
|
58
|
+
options = {},
|
59
|
+
guild_ids: nil,
|
60
|
+
dm_permission: true,
|
61
|
+
default_permission: nil,
|
62
|
+
&block
|
63
|
+
)
|
64
|
+
command_name = { default: command_name } if command_name.is_a?(String)
|
65
|
+
description = { default: description } if description.is_a?(String)
|
66
|
+
command_name = ApplicationCommand.modify_localization_hash(command_name)
|
67
|
+
description = ApplicationCommand.modify_localization_hash(description)
|
68
|
+
command =
|
69
|
+
Discorb::ApplicationCommand::Command::ChatInputCommand.new(
|
70
|
+
command_name,
|
71
|
+
description,
|
72
|
+
options,
|
73
|
+
guild_ids,
|
74
|
+
block,
|
75
|
+
1,
|
76
|
+
nil,
|
77
|
+
dm_permission,
|
78
|
+
default_permission
|
79
|
+
)
|
80
|
+
@commands << command
|
81
|
+
@callable_commands << command
|
82
|
+
command
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Add new command with group.
|
87
|
+
#
|
88
|
+
# @param [String, Hash{Symbol => String}] command_name Command name.
|
89
|
+
# @param [String, Hash{Symbol => String}] description Command description.
|
90
|
+
# @param [Array<#to_s>, false, nil] guild_ids
|
91
|
+
# Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
92
|
+
# @param [Boolean] dm_permission Whether the command is available in DM.
|
93
|
+
# @param [Discorb::Permission] default_permission The default permission of the command.
|
94
|
+
#
|
95
|
+
# @yield Block to yield with the command.
|
96
|
+
# @yieldparam [Discorb::ApplicationCommand::Command::GroupCommand] group Group command.
|
97
|
+
#
|
98
|
+
# @return [Discorb::ApplicationCommand::Command::GroupCommand] Command object.
|
99
|
+
#
|
100
|
+
# @see file:docs/application_command.md Application Commands
|
101
|
+
# @see file:docs/cli/setup.md CLI: setup
|
102
|
+
#
|
103
|
+
def slash_group(
|
104
|
+
command_name,
|
105
|
+
description,
|
106
|
+
guild_ids: nil,
|
107
|
+
dm_permission: true,
|
108
|
+
default_permission: nil
|
109
|
+
)
|
110
|
+
command_name = { default: command_name } if command_name.is_a?(String)
|
111
|
+
description = { default: description } if description.is_a?(String)
|
112
|
+
command_name = ApplicationCommand.modify_localization_hash(command_name)
|
113
|
+
description = ApplicationCommand.modify_localization_hash(description)
|
114
|
+
command =
|
115
|
+
Discorb::ApplicationCommand::Command::GroupCommand.new(
|
116
|
+
command_name,
|
117
|
+
description,
|
118
|
+
guild_ids,
|
119
|
+
self,
|
120
|
+
dm_permission,
|
121
|
+
default_permission
|
122
|
+
)
|
123
|
+
yield command if block_given?
|
124
|
+
@commands << command
|
125
|
+
command
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Add message context menu command.
|
130
|
+
#
|
131
|
+
# @param [String, Hash{Symbol => String}] command_name Command name.
|
132
|
+
# @param [Array<#to_s>, false, nil] guild_ids
|
133
|
+
# Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
134
|
+
# @param [Boolean] dm_permission Whether the command is available in DM.
|
135
|
+
# @param [Discorb::Permission] default_permission The default permission of the command.
|
136
|
+
# @param [Proc] block Command block.
|
137
|
+
# @yield [interaction, message] Block to execute.
|
138
|
+
# @yieldparam [Discorb::CommandInteraction::UserMenuCommand] interaction Interaction object.
|
139
|
+
# @yieldparam [Discorb::Message] message Message object.
|
140
|
+
#
|
141
|
+
# @return [Discorb::ApplicationCommand::Command] Command object.
|
142
|
+
#
|
143
|
+
def message_command(
|
144
|
+
command_name,
|
145
|
+
guild_ids: nil,
|
146
|
+
dm_permission: true,
|
147
|
+
default_permission: nil,
|
148
|
+
&block
|
149
|
+
)
|
150
|
+
command_name = { default: command_name } if command_name.is_a?(String)
|
151
|
+
command_name = ApplicationCommand.modify_localization_hash(command_name)
|
152
|
+
command =
|
153
|
+
Discorb::ApplicationCommand::Command.new(
|
154
|
+
command_name,
|
155
|
+
guild_ids,
|
156
|
+
block,
|
157
|
+
3,
|
158
|
+
dm_permission,
|
159
|
+
default_permission
|
160
|
+
)
|
161
|
+
@commands << command
|
162
|
+
command
|
163
|
+
end
|
164
|
+
|
165
|
+
#
|
166
|
+
# Add user context menu command.
|
167
|
+
#
|
168
|
+
# @param [String, Hash{Symbol => String}] command_name Command name.
|
169
|
+
# @param [Array<#to_s>, false, nil] guild_ids
|
170
|
+
# Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
171
|
+
# @param [Boolean] dm_permission Whether the command is available in DM.
|
172
|
+
# @param [Discorb::Permission] default_permission The default permission of the command.
|
173
|
+
# @param [Proc] block Command block.
|
174
|
+
# @yield [interaction, user] Block to execute.
|
175
|
+
# @yieldparam [Discorb::CommandInteraction::UserMenuCommand] interaction Interaction object.
|
176
|
+
# @yieldparam [Discorb::User] user User object.
|
177
|
+
#
|
178
|
+
# @return [Discorb::ApplicationCommand::Command] Command object.
|
179
|
+
#
|
180
|
+
def user_command(
|
181
|
+
command_name,
|
182
|
+
guild_ids: nil,
|
183
|
+
dm_permission: true,
|
184
|
+
default_permission: nil,
|
185
|
+
&block
|
186
|
+
)
|
187
|
+
command_name = { default: command_name } if command_name.is_a?(String)
|
188
|
+
command_name = ApplicationCommand.modify_localization_hash(command_name)
|
189
|
+
command =
|
190
|
+
Discorb::ApplicationCommand::Command.new(
|
191
|
+
command_name,
|
192
|
+
guild_ids,
|
193
|
+
block,
|
194
|
+
2,
|
195
|
+
dm_permission,
|
196
|
+
default_permission
|
197
|
+
)
|
198
|
+
@commands << command
|
199
|
+
command
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Setup commands.
|
204
|
+
# @async
|
205
|
+
# @see Client#initialize
|
206
|
+
#
|
207
|
+
# @param [String] token Bot token.
|
208
|
+
# @param [Array<#to_s>, false, nil] guild_ids
|
209
|
+
# Guild IDs to use as default. If `false` is given, it will be global command.
|
210
|
+
#
|
211
|
+
# @note `token` parameter only required if you don't run client.
|
212
|
+
#
|
213
|
+
def setup_commands(token = nil, guild_ids: nil)
|
214
|
+
Async do
|
215
|
+
@token ||= token
|
216
|
+
@http = HTTP.new(self)
|
217
|
+
global_commands =
|
218
|
+
@commands.select { |c| c.guild_ids == false or c.guild_ids == [] }
|
219
|
+
local_commands =
|
220
|
+
@commands.select do |c|
|
221
|
+
c.guild_ids.is_a?(Array) and c.guild_ids.any?
|
222
|
+
end
|
223
|
+
default_commands = @commands.select { |c| c.guild_ids.nil? }
|
224
|
+
if guild_ids.is_a?(Array)
|
225
|
+
default_commands.each do |command|
|
226
|
+
command.instance_variable_set(:@guild_ids, guild_ids)
|
227
|
+
end
|
228
|
+
local_commands += default_commands
|
229
|
+
else
|
230
|
+
global_commands += default_commands
|
231
|
+
end
|
232
|
+
final_guild_ids =
|
233
|
+
local_commands.map(&:guild_ids).flatten.map(&:to_s).uniq
|
234
|
+
app_info = fetch_application.wait
|
235
|
+
unless global_commands.empty?
|
236
|
+
@http.request(
|
237
|
+
Route.new(
|
238
|
+
"/applications/#{app_info.id}/commands",
|
239
|
+
"//applications/:application_id/commands",
|
240
|
+
:put
|
241
|
+
),
|
242
|
+
global_commands.map(&:to_hash)
|
243
|
+
).wait
|
244
|
+
end
|
245
|
+
if ENV.fetch("DISCORB_CLI_FLAG", nil) == "setup"
|
246
|
+
sputs "Registered commands for global:"
|
247
|
+
global_commands.each do |command|
|
248
|
+
iputs "- #{command.name["default"]}"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
unless final_guild_ids.empty?
|
252
|
+
final_guild_ids.each do |guild_id|
|
253
|
+
commands =
|
254
|
+
local_commands.select { |c| c.guild_ids.include?(guild_id) }
|
255
|
+
@http.request(
|
256
|
+
Route.new(
|
257
|
+
"/applications/#{app_info.id}/guilds/#{guild_id}/commands",
|
258
|
+
"//applications/:application_id/guilds/:guild_id/commands",
|
259
|
+
:put
|
260
|
+
),
|
261
|
+
commands.map(&:to_hash)
|
262
|
+
).wait
|
263
|
+
sputs "Registered commands for #{guild_id}:"
|
264
|
+
commands.each { |command| iputs "- #{command.name["default"]}" }
|
265
|
+
end
|
266
|
+
end
|
267
|
+
@logger.info "Successfully setup commands"
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
#
|
272
|
+
# Claer commands in specified guilds.
|
273
|
+
# @async
|
274
|
+
# @see Client#initialize
|
275
|
+
#
|
276
|
+
# @param [String] token Bot token.
|
277
|
+
# @param [Array<#to_s>, false, nil] guild_ids Guild IDs to clear.
|
278
|
+
#
|
279
|
+
# @note `token` parameter only required if you don't run client.
|
280
|
+
#
|
281
|
+
def clear_commands(token, guild_ids)
|
282
|
+
Async do
|
283
|
+
@token ||= token
|
284
|
+
@http = HTTP.new(self)
|
285
|
+
app_info = fetch_application.wait
|
286
|
+
|
287
|
+
guild_ids.each do |guild_id|
|
288
|
+
@http.request(
|
289
|
+
Route.new(
|
290
|
+
"/applications/#{app_info.id}/guilds/#{guild_id}/commands",
|
291
|
+
"//applications/:application_id/guilds/:guild_id/commands",
|
292
|
+
:put
|
293
|
+
),
|
294
|
+
[]
|
295
|
+
).wait
|
296
|
+
end
|
297
|
+
if ENV.fetch("DISCORB_CLI_FLAG", nil) == "setup"
|
298
|
+
sputs "Cleared commands for #{guild_ids.length} guilds."
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
data/lib/discorb/app_command.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
%w[common command handler].each do |file|
|
4
|
-
require_relative "app_command/#{file}.rb"
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
%w[common command handler].each do |file|
|
4
|
+
require_relative "app_command/#{file}.rb"
|
5
|
+
end
|