discorb 0.13.4 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +2 -0
- data/.github/workflows/build_version.yml +1 -1
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.github/workflows/lint-push.yml +20 -0
- data/.github/workflows/lint.yml +16 -0
- data/.rubocop.yml +74 -0
- data/Changelog.md +30 -0
- data/Gemfile +7 -3
- data/Rakefile +28 -22
- data/discorb.gemspec +1 -0
- data/docs/events.md +50 -0
- data/docs/faq.md +8 -8
- data/examples/commands/bookmarker.rb +2 -1
- data/examples/commands/hello.rb +1 -0
- data/examples/commands/inspect.rb +3 -2
- data/examples/components/authorization_button.rb +2 -1
- data/examples/components/select_menu.rb +2 -1
- data/examples/extension/main.rb +1 -0
- data/examples/extension/message_expander.rb +1 -0
- data/examples/simple/eval.rb +3 -2
- data/examples/simple/ping_pong.rb +1 -0
- data/examples/simple/rolepanel.rb +1 -0
- data/examples/simple/wait_for_message.rb +4 -3
- data/exe/discorb +8 -7
- data/lib/discorb/allowed_mentions.rb +71 -0
- data/lib/discorb/app_command/command.rb +336 -0
- data/lib/discorb/app_command/handler.rb +168 -0
- data/lib/discorb/app_command.rb +2 -426
- data/lib/discorb/application.rb +16 -7
- data/lib/discorb/asset.rb +11 -0
- data/lib/discorb/{file.rb → attachment.rb} +55 -33
- data/lib/discorb/audit_logs.rb +45 -7
- data/lib/discorb/channel.rb +65 -15
- data/lib/discorb/client.rb +34 -27
- data/lib/discorb/common.rb +19 -27
- data/lib/discorb/components/button.rb +105 -0
- data/lib/discorb/components/select_menu.rb +143 -0
- data/lib/discorb/components/text_input.rb +96 -0
- data/lib/discorb/components.rb +11 -276
- data/lib/discorb/dictionary.rb +5 -0
- data/lib/discorb/embed.rb +73 -40
- data/lib/discorb/emoji.rb +48 -5
- data/lib/discorb/error.rb +9 -5
- data/lib/discorb/event.rb +36 -24
- data/lib/discorb/exe/about.rb +1 -0
- data/lib/discorb/exe/irb.rb +4 -3
- data/lib/discorb/exe/new.rb +6 -7
- data/lib/discorb/exe/run.rb +2 -1
- data/lib/discorb/exe/setup.rb +8 -5
- data/lib/discorb/exe/show.rb +1 -0
- data/lib/discorb/extend.rb +19 -14
- data/lib/discorb/extension.rb +5 -1
- data/lib/discorb/gateway.rb +112 -51
- data/lib/discorb/gateway_requests.rb +4 -7
- data/lib/discorb/guild.rb +73 -41
- data/lib/discorb/guild_template.rb +26 -5
- data/lib/discorb/http.rb +38 -18
- data/lib/discorb/integration.rb +24 -9
- data/lib/discorb/intents.rb +16 -11
- data/lib/discorb/interaction/autocomplete.rb +6 -5
- data/lib/discorb/interaction/command.rb +66 -12
- data/lib/discorb/interaction/components.rb +19 -3
- data/lib/discorb/interaction/modal.rb +33 -0
- data/lib/discorb/interaction/response.rb +45 -4
- data/lib/discorb/interaction/root.rb +16 -0
- data/lib/discorb/interaction.rb +2 -1
- data/lib/discorb/invite.rb +11 -7
- data/lib/discorb/log.rb +5 -5
- data/lib/discorb/member.rb +22 -3
- data/lib/discorb/message.rb +39 -234
- data/lib/discorb/message_meta.rb +186 -0
- data/lib/discorb/modules.rb +39 -15
- data/lib/discorb/permission.rb +16 -7
- data/lib/discorb/presence.rb +45 -9
- data/lib/discorb/rate_limit.rb +7 -4
- data/lib/discorb/reaction.rb +6 -0
- data/lib/discorb/role.rb +12 -0
- data/lib/discorb/sticker.rb +22 -14
- data/lib/discorb/user.rb +12 -1
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +23 -2
- data/lib/discorb/webhook.rb +54 -3
- data/lib/discorb.rb +5 -2
- data/sig/discorb.rbs +838 -702
- data/template-replace/scripts/arrow.rb +1 -0
- data/template-replace/scripts/favicon.rb +1 -0
- data/template-replace/scripts/index.rb +2 -1
- data/template-replace/scripts/locale_ja.rb +5 -4
- data/template-replace/scripts/sidebar.rb +1 -0
- data/template-replace/scripts/version.rb +7 -10
- data/template-replace/scripts/yard_replace.rb +5 -4
- metadata +17 -3
data/lib/discorb/voice_state.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a state of user in voice channel.
|
6
|
+
#
|
4
7
|
class VoiceState < DiscordModel
|
5
8
|
# @return [Discorb::Member] The member associated with this voice state.
|
6
9
|
attr_reader :member
|
@@ -43,7 +46,13 @@ module Discorb
|
|
43
46
|
# @macro client_cache
|
44
47
|
# @return [Discorb::User] The user this voice state is for.
|
45
48
|
|
49
|
+
#
|
50
|
+
# Initialize a new voice state.
|
46
51
|
# @private
|
52
|
+
#
|
53
|
+
# @param [Discorb::Client] client The client this voice state belongs to.
|
54
|
+
# @param [Hash] data The data of the voice state.
|
55
|
+
#
|
47
56
|
def initialize(client, data)
|
48
57
|
@client = client
|
49
58
|
_set_data(data)
|
@@ -132,7 +141,14 @@ module Discorb
|
|
132
141
|
2 => :guild_only,
|
133
142
|
}
|
134
143
|
|
144
|
+
#
|
145
|
+
# Initialize a new instance of the StageInstance class.
|
135
146
|
# @private
|
147
|
+
#
|
148
|
+
# @param [Discorb::Client] client The client.
|
149
|
+
# @param [Hash] data The data of the stage instance.
|
150
|
+
# @param [Boolean] no_cache Whether to disable caching.
|
151
|
+
#
|
136
152
|
def initialize(client, data, no_cache: false)
|
137
153
|
@client = client
|
138
154
|
@data = data
|
@@ -179,7 +195,7 @@ module Discorb
|
|
179
195
|
Async do
|
180
196
|
payload = {}
|
181
197
|
payload[:topic] = topic if topic != Discorb::Unset
|
182
|
-
payload[:privacy_level] =
|
198
|
+
payload[:privacy_level] = PRIVACY_LEVEL.key(privacy_level) if privacy_level != Discorb::Unset
|
183
199
|
@client.http.request(
|
184
200
|
Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:channel_id", :patch), payload, audit_log_reason: reason,
|
185
201
|
).wait
|
@@ -213,7 +229,7 @@ module Discorb
|
|
213
229
|
@guild_id = Snowflake.new(data[:guild_id])
|
214
230
|
@channel_id = Snowflake.new(data[:channel_id])
|
215
231
|
@topic = data[:topic]
|
216
|
-
@privacy_level =
|
232
|
+
@privacy_level = PRIVACY_LEVEL[data[:privacy_level]]
|
217
233
|
@discoverable_disabled = data[:discoverable_disabled]
|
218
234
|
end
|
219
235
|
|
@@ -243,7 +259,12 @@ module Discorb
|
|
243
259
|
attr_reader :custom
|
244
260
|
alias custom? custom
|
245
261
|
|
262
|
+
#
|
263
|
+
# Initialize a new instance of the VoiceRegion class.
|
246
264
|
# @private
|
265
|
+
#
|
266
|
+
# @param [Hash] data The data of the voice region.
|
267
|
+
#
|
247
268
|
def initialize(data)
|
248
269
|
@id = data[:id]
|
249
270
|
@name = data[:name]
|
data/lib/discorb/webhook.rb
CHANGED
@@ -22,7 +22,13 @@ module Discorb
|
|
22
22
|
# @return [String] The URL of the webhook.
|
23
23
|
attr_reader :token
|
24
24
|
|
25
|
+
#
|
26
|
+
# Initializes a webhook.
|
25
27
|
# @private
|
28
|
+
#
|
29
|
+
# @param [Discorb::Client] client The client.
|
30
|
+
# @param [Hash] data The data of the webhook.
|
31
|
+
#
|
26
32
|
def initialize(client, data)
|
27
33
|
@name = data[:name]
|
28
34
|
@guild_id = data[:guild_id] && Snowflake.new(data[:guild_id])
|
@@ -151,7 +157,7 @@ module Discorb
|
|
151
157
|
payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
|
152
158
|
payload[:allowed_mentions] = allowed_mentions if allowed_mentions != Discorb::Unset
|
153
159
|
files = [file] if file != Discorb::Unset
|
154
|
-
_resp, data = @http.multipart_request(Route.new("#{url}/messages/#{Utils.try(message, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id", :patch), payload,
|
160
|
+
_resp, data = @http.multipart_request(Route.new("#{url}/messages/#{Utils.try(message, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id", :patch), payload, files).wait
|
155
161
|
message.send(:_set_data, data)
|
156
162
|
message
|
157
163
|
end
|
@@ -200,7 +206,13 @@ module Discorb
|
|
200
206
|
# @!attribute [r] url
|
201
207
|
# @return [String] The URL of the webhook.
|
202
208
|
|
209
|
+
#
|
210
|
+
# Initializes the incoming webhook.
|
203
211
|
# @private
|
212
|
+
#
|
213
|
+
# @param [Discorb::Client] client The client.
|
214
|
+
# @param [String] url The URL of the webhook.
|
215
|
+
#
|
204
216
|
def initialize(client, data)
|
205
217
|
super
|
206
218
|
@token = data[:token]
|
@@ -222,7 +234,13 @@ module Discorb
|
|
222
234
|
# Represents a source channel of follower webhook.
|
223
235
|
# @return [Discorb::Channel, Discorb::Webhook::FollowerWebhook::Channel] The source channel of follower webhook.
|
224
236
|
|
237
|
+
#
|
238
|
+
# Initializes the follower webhook.
|
225
239
|
# @private
|
240
|
+
#
|
241
|
+
# @param [Discorb::Client] client The client.
|
242
|
+
# @param [Hash] data The data of the follower webhook.
|
243
|
+
#
|
226
244
|
def initialize(client, data)
|
227
245
|
super
|
228
246
|
@source_guild = FollowerWebhook::Guild.new(data[:source_guild])
|
@@ -248,12 +266,21 @@ module Discorb
|
|
248
266
|
# @return [Discorb::Asset] The icon of the guild.
|
249
267
|
attr_reader :icon
|
250
268
|
|
269
|
+
#
|
270
|
+
# Initialize a new guild.
|
251
271
|
# @private
|
272
|
+
#
|
273
|
+
# @param [Hash] data The data of the guild.
|
274
|
+
#
|
252
275
|
def initialize(data)
|
253
276
|
@id = Snowflake.new(data[:id])
|
254
277
|
@name = data[:name]
|
255
278
|
@icon = Asset.new(self, data[:icon])
|
256
279
|
end
|
280
|
+
|
281
|
+
def inspect
|
282
|
+
"#<#{self.class.name} #{@id}: #{@name}>"
|
283
|
+
end
|
257
284
|
end
|
258
285
|
|
259
286
|
#
|
@@ -265,11 +292,20 @@ module Discorb
|
|
265
292
|
# @return [String] The name of the channel.
|
266
293
|
attr_reader :name
|
267
294
|
|
295
|
+
#
|
296
|
+
# Initialize a new channel.
|
268
297
|
# @private
|
298
|
+
#
|
299
|
+
# @param [Hash] data The data of the channel.
|
300
|
+
#
|
269
301
|
def initialize(data)
|
270
302
|
@id = Snowflake.new(data[:id])
|
271
303
|
@name = data[:name]
|
272
304
|
end
|
305
|
+
|
306
|
+
def inspect
|
307
|
+
"#<#{self.class.name} #{@id}: #{@name}>"
|
308
|
+
end
|
273
309
|
end
|
274
310
|
end
|
275
311
|
|
@@ -290,7 +326,13 @@ module Discorb
|
|
290
326
|
# @return [Discorb::Snowflake] The ID of the guild.
|
291
327
|
attr_reader :guild_id
|
292
328
|
|
329
|
+
#
|
330
|
+
# Initializes the message.
|
293
331
|
# @private
|
332
|
+
#
|
333
|
+
# @param [Discorb::Webhook] webhook The webhook.
|
334
|
+
# @param [Hash] data The data of the message.
|
335
|
+
# @param [Discorb::Client] client The client. This will be nil if it's created from {URLWebhook}.
|
294
336
|
def initialize(webhook, data, client = nil)
|
295
337
|
@client = client
|
296
338
|
@webhook = webhook
|
@@ -329,12 +371,12 @@ module Discorb
|
|
329
371
|
|
330
372
|
def _set_data(data)
|
331
373
|
@id = Snowflake.new(data[:id])
|
332
|
-
@type = Discorb::Message
|
374
|
+
@type = Discorb::Message::MESSAGE_TYPE[data[:type]]
|
333
375
|
@content = data[:content]
|
334
376
|
@channel_id = Snowflake.new(data[:channel_id])
|
335
377
|
@author = Author.new(data[:author])
|
336
378
|
@attachments = data[:attachments].map { |a| Attachment.new(a) }
|
337
|
-
@embeds = data[:embeds] ? data[:embeds].map { |e| Embed.
|
379
|
+
@embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : []
|
338
380
|
@mentions = data[:mentions].map { |m| Mention.new(m) }
|
339
381
|
@mention_roles = data[:mention_roles].map { |m| Snowflake.new(m) }
|
340
382
|
@mention_everyone = data[:mention_everyone]
|
@@ -364,7 +406,12 @@ module Discorb
|
|
364
406
|
# @return [String] The discriminator of the author.
|
365
407
|
attr_reader :discriminator
|
366
408
|
|
409
|
+
#
|
410
|
+
# Initializes the author.
|
367
411
|
# @private
|
412
|
+
#
|
413
|
+
# @param [Hash] data The data of the author.
|
414
|
+
#
|
368
415
|
def initialize(data)
|
369
416
|
@data = data
|
370
417
|
@bot = data[:bot]
|
@@ -384,6 +431,10 @@ module Discorb
|
|
384
431
|
end
|
385
432
|
|
386
433
|
alias to_s_user to_s
|
434
|
+
|
435
|
+
def inspect
|
436
|
+
"#<#{self.class.name} #{self}>"
|
437
|
+
end
|
387
438
|
end
|
388
439
|
end
|
389
440
|
|
data/lib/discorb.rb
CHANGED
@@ -4,7 +4,10 @@
|
|
4
4
|
#
|
5
5
|
# @author sevenc-nanashi
|
6
6
|
module Discorb
|
7
|
+
#
|
8
|
+
# Method to define a macro for YARD.
|
7
9
|
# @private
|
10
|
+
#
|
8
11
|
# @!macro [new] async
|
9
12
|
# @note This is an asynchronous method, it will return a `Async::Task` object. Use `Async::Task#wait` to get the result.
|
10
13
|
#
|
@@ -23,7 +26,6 @@ module Discorb
|
|
23
26
|
# @raise [Discorb::HTTPError] HTTP request failed.
|
24
27
|
#
|
25
28
|
def macro
|
26
|
-
# NOTE: this method is only for YARD.
|
27
29
|
puts "Wow, You found the easter egg!\n"
|
28
30
|
red = "\e[31m"
|
29
31
|
reset = "\e[m"
|
@@ -40,9 +42,10 @@ module Discorb
|
|
40
42
|
end
|
41
43
|
|
42
44
|
require_order = %w[common flag dictionary error rate_limit http intents emoji_table modules] +
|
45
|
+
%w[message_meta allowed_mentions] +
|
43
46
|
%w[user member guild emoji channel embed message] +
|
44
47
|
%w[application audit_logs color components event event_handler] +
|
45
|
-
%w[
|
48
|
+
%w[attachment guild_template image integration interaction invite log permission] +
|
46
49
|
%w[presence reaction role sticker utils voice_state webhook] +
|
47
50
|
%w[gateway_requests gateway app_command] +
|
48
51
|
%w[asset extension client extend]
|