discorb 0.17.0 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +1 -3
- data/.github/workflows/spec.yml +4 -1
- data/.github/workflows/validate.yml +21 -0
- data/.gitignore +2 -0
- data/Changelog.md +22 -0
- data/Gemfile +6 -0
- data/README.md +2 -1
- data/Rakefile +210 -97
- data/Steepfile +28 -0
- data/docs/application_command.md +22 -4
- data/docs/events.md +42 -6
- data/docs/tutorial.md +7 -7
- data/docs/voice_events.md +2 -2
- data/examples/commands/message.rb +12 -7
- data/examples/commands/permission.rb +2 -1
- data/examples/commands/slash.rb +23 -19
- data/examples/commands/user.rb +15 -12
- data/examples/components/authorization_button.rb +2 -1
- data/examples/components/select_menu.rb +4 -1
- data/examples/extension/main.rb +1 -0
- data/examples/extension/message_expander.rb +1 -0
- data/examples/sig/commands/message.rbs +5 -0
- data/examples/simple/eval.rb +1 -0
- data/examples/simple/ping_pong.rb +1 -0
- data/examples/simple/rolepanel.rb +16 -5
- data/examples/simple/shard.rb +2 -1
- data/examples/simple/wait_for_message.rb +3 -0
- data/exe/discorb +3 -3
- data/lib/discorb/allowed_mentions.rb +1 -1
- data/lib/discorb/app_command/command.rb +17 -17
- data/lib/discorb/app_command/handler.rb +22 -6
- data/lib/discorb/audit_logs.rb +9 -3
- data/lib/discorb/automod.rb +269 -0
- data/lib/discorb/channel/guild.rb +2 -1
- data/lib/discorb/channel/stage.rb +1 -1
- data/lib/discorb/channel/text.rb +11 -20
- data/lib/discorb/channel/thread.rb +15 -11
- data/lib/discorb/client.rb +12 -10
- data/lib/discorb/color.rb +37 -60
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +4 -3
- data/lib/discorb/emoji.rb +2 -2
- data/lib/discorb/emoji_table.rb +4 -4
- data/lib/discorb/exe/about.rb +1 -1
- data/lib/discorb/exe/new.rb +1 -5
- data/lib/discorb/extension.rb +0 -4
- data/lib/discorb/flag.rb +2 -2
- data/lib/discorb/gateway.rb +26 -584
- data/lib/discorb/gateway_events.rb +638 -0
- data/lib/discorb/guild.rb +136 -17
- data/lib/discorb/guild_template.rb +1 -1
- data/lib/discorb/http.rb +48 -26
- data/lib/discorb/intents.rb +27 -18
- data/lib/discorb/interaction/command.rb +14 -10
- data/lib/discorb/interaction/response.rb +76 -16
- data/lib/discorb/interaction/root.rb +3 -0
- data/lib/discorb/member.rb +3 -3
- data/lib/discorb/message.rb +13 -11
- data/lib/discorb/message_meta.rb +2 -3
- data/lib/discorb/modules.rb +3 -2
- data/lib/discorb/presence.rb +4 -2
- data/lib/discorb/reaction.rb +6 -6
- data/lib/discorb/role.rb +1 -1
- data/lib/discorb/sticker.rb +3 -3
- data/lib/discorb/user.rb +2 -2
- data/lib/discorb/voice_state.rb +5 -5
- data/lib/discorb/webhook.rb +42 -21
- data/lib/discorb.rb +2 -2
- data/po/yard.pot +11 -11
- data/rbs_collection.lock.yaml +88 -0
- data/rbs_collection.yaml +21 -0
- data/sig/async.rbs +11 -0
- data/sig/discorb/activity.rbs +23 -0
- data/sig/discorb/allowed_mentions.rbs +44 -0
- data/sig/discorb/app_command/base.rbs +282 -0
- data/sig/discorb/app_command/handler.rbs +171 -0
- data/sig/discorb/application.rbs +142 -0
- data/sig/discorb/asset.rbs +32 -0
- data/sig/discorb/attachment.rbs +91 -0
- data/sig/discorb/audit_log.rbs +231 -0
- data/sig/discorb/automod.rbs +128 -0
- data/sig/discorb/avatar.rbs +26 -0
- data/sig/discorb/channel/base.rbs +179 -0
- data/sig/discorb/channel/category.rbs +56 -0
- data/sig/discorb/channel/container.rbs +29 -0
- data/sig/discorb/channel/dm.rbs +14 -0
- data/sig/discorb/channel/news.rbs +20 -0
- data/sig/discorb/channel/stage.rbs +77 -0
- data/sig/discorb/channel/text.rbs +158 -0
- data/sig/discorb/channel/thread.rbs +185 -0
- data/sig/discorb/channel/voice.rbs +41 -0
- data/sig/discorb/client.rbs +2495 -0
- data/sig/discorb/color.rbs +142 -0
- data/sig/discorb/component/base.rbs +28 -0
- data/sig/discorb/component/button.rbs +65 -0
- data/sig/discorb/component/select_menu.rbs +107 -0
- data/sig/discorb/component/text_input.rbs +69 -0
- data/sig/discorb/connectable.rbs +8 -0
- data/sig/discorb/custom_emoji.rbs +90 -0
- data/sig/discorb/dictionary.rbs +85 -0
- data/sig/discorb/discord_model.rbs +15 -0
- data/sig/discorb/embed.rbs +279 -0
- data/sig/discorb/emoji.rbs +13 -0
- data/sig/discorb/error.rbs +73 -0
- data/sig/discorb/event_handler.rbs +27 -0
- data/sig/discorb/extension.rbs +1734 -0
- data/sig/discorb/flag.rbs +72 -0
- data/sig/discorb/gateway.rbs +481 -0
- data/sig/discorb/guild.rbs +870 -0
- data/sig/discorb/guild_template.rbs +174 -0
- data/sig/discorb/http.rbs +147 -0
- data/sig/discorb/image.rbs +20 -0
- data/sig/discorb/integration.rbs +118 -0
- data/sig/discorb/intents.rbs +97 -0
- data/sig/discorb/interaction/autocomplete.rbs +9 -0
- data/sig/discorb/interaction/base.rbs +69 -0
- data/sig/discorb/interaction/command.rbs +66 -0
- data/sig/discorb/interaction/message_component.rbs +140 -0
- data/sig/discorb/interaction/modal.rbs +50 -0
- data/sig/discorb/interaction/responder.rbs +157 -0
- data/sig/discorb/invite.rbs +86 -0
- data/sig/discorb/member.rbs +187 -0
- data/sig/discorb/message.rbs +469 -0
- data/sig/discorb/messageable.rbs +153 -0
- data/sig/discorb/partial_emoji.rbs +35 -0
- data/sig/discorb/permissions.rbs +149 -0
- data/sig/discorb/presence.rbs +237 -0
- data/sig/discorb/reaction.rbs +33 -0
- data/sig/discorb/role.rbs +145 -0
- data/sig/discorb/scheduled_event.rbs +148 -0
- data/sig/discorb/shard.rbs +62 -0
- data/sig/discorb/snowflake.rbs +56 -0
- data/sig/discorb/stage_instance.rbs +63 -0
- data/sig/discorb/sticker.rbs +116 -0
- data/sig/discorb/system_channel_flag.rbs +17 -0
- data/sig/discorb/unicode_emoji.rbs +49 -0
- data/sig/discorb/user.rbs +93 -0
- data/sig/discorb/utils.rbs +8 -0
- data/sig/discorb/voice_region.rbs +30 -0
- data/sig/discorb/voice_state.rbs +71 -0
- data/sig/discorb/webhook.rbs +327 -0
- data/sig/discorb/welcome_screen.rbs +78 -0
- data/sig/discorb.rbs +11 -7232
- data/sig/manifest.yaml +3 -0
- data/sig/override.rbs +19 -0
- data/template-replace/files/css/common.css +4 -0
- metadata +83 -3
@@ -25,6 +25,8 @@ module Discorb
|
|
25
25
|
# @return [Symbol] The locale of the guild that created the interaction.
|
26
26
|
# @note This modifies the language code, `-` will be replaced with `_`.
|
27
27
|
attr_reader :guild_locale
|
28
|
+
# @return [Discorb::Permission] The permissions of the bot.
|
29
|
+
attr_reader :app_permissions
|
28
30
|
|
29
31
|
# @!attribute [r] guild
|
30
32
|
# @macro client_cache
|
@@ -62,6 +64,7 @@ module Discorb
|
|
62
64
|
@token = data[:token]
|
63
65
|
@locale = data[:locale].to_s.gsub("-", "_").to_sym
|
64
66
|
@guild_locale = data[:guild_locale].to_s.gsub("-", "_").to_sym
|
67
|
+
@app_permissions = data[:app_permissions] && Permission.new(data[:app_permissions].to_i)
|
65
68
|
@version = data[:version]
|
66
69
|
@defered = false
|
67
70
|
@responded = false
|
data/lib/discorb/member.rb
CHANGED
@@ -52,10 +52,10 @@ module Discorb
|
|
52
52
|
# @return [Discorb::Presence] The presence of the member.
|
53
53
|
# @!attribute [r] activity
|
54
54
|
# @macro client_cache
|
55
|
-
# @return [Discorb::Activity] The activity of the member. It's from the {#presence}.
|
55
|
+
# @return [Discorb::Presence::Activity] The activity of the member. It's from the {#presence}.
|
56
56
|
# @!attribute [r] activities
|
57
57
|
# @macro client_cache
|
58
|
-
# @return [Array<Discorb::Activity>] The activities of the member. It's from the {#presence}.
|
58
|
+
# @return [Array<Discorb::Presence::Activity>] The activities of the member. It's from the {#presence}.
|
59
59
|
# @!attribute [r] status
|
60
60
|
# @macro client_cache
|
61
61
|
# @return [Symbol] The status of the member. It's from the {#presence}.
|
@@ -303,7 +303,7 @@ module Discorb
|
|
303
303
|
@deaf = member_data[:deaf]
|
304
304
|
@custom_avatar = member_data[:avatar] && Asset.new(self, member_data[:avatar])
|
305
305
|
super(user_data)
|
306
|
-
@display_avatar = @
|
306
|
+
@display_avatar = @custom_avatar || @avatar
|
307
307
|
@client.guilds[@guild_id].members[@id] = self unless @guild_id.nil? || @client.guilds[@guild_id].nil?
|
308
308
|
@_member_data.update(member_data)
|
309
309
|
end
|
data/lib/discorb/message.rb
CHANGED
@@ -7,7 +7,7 @@ module Discorb
|
|
7
7
|
class Message < DiscordModel
|
8
8
|
# @return [Discorb::Snowflake] The ID of the message.
|
9
9
|
attr_reader :id
|
10
|
-
# @return [Discorb::User, Discorb::Member] The user that sent the message.
|
10
|
+
# @return [Discorb::User, Discorb::Member, Webhook::Message::Author] The user that sent the message.
|
11
11
|
attr_reader :author
|
12
12
|
# @return [String] The content of the message.
|
13
13
|
attr_reader :content
|
@@ -217,8 +217,8 @@ module Discorb
|
|
217
217
|
end
|
218
218
|
if role
|
219
219
|
ret.gsub!(/<@&(\d+)>/) do |_match|
|
220
|
-
|
221
|
-
|
220
|
+
r = guild&.roles&.[]($1)
|
221
|
+
r ? "@#{r.name}" : "@Unknown Role"
|
222
222
|
end
|
223
223
|
end
|
224
224
|
if emoji
|
@@ -293,15 +293,17 @@ module Discorb
|
|
293
293
|
#
|
294
294
|
# @param [Boolean] fail_if_not_exists Whether to raise an error if the message does not exist.
|
295
295
|
#
|
296
|
-
# @return [
|
296
|
+
# @return [Discorb::Message::Reference] The reference object.
|
297
297
|
#
|
298
298
|
def to_reference(fail_if_not_exists: true)
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
299
|
+
Reference.from_hash(
|
300
|
+
{
|
301
|
+
message_id: @id,
|
302
|
+
channel_id: @channel_id,
|
303
|
+
guild_id: @guild_id,
|
304
|
+
fail_if_not_exists: fail_if_not_exists,
|
305
|
+
}
|
306
|
+
)
|
305
307
|
end
|
306
308
|
|
307
309
|
def embed
|
@@ -400,7 +402,7 @@ module Discorb
|
|
400
402
|
# Fetch reacted users of reaction.
|
401
403
|
# @async
|
402
404
|
#
|
403
|
-
# @param [Discorb::Emoji] emoji The emoji to fetch.
|
405
|
+
# @param [Discorb::Emoji, Discorb::PartialEmoji] emoji The emoji to fetch.
|
404
406
|
# @param [Integer, nil] limit The maximum number of users to fetch. `nil` for no limit.
|
405
407
|
# @param [Discorb::Snowflake, nil] after The ID of the user to start fetching from.
|
406
408
|
#
|
data/lib/discorb/message_meta.rb
CHANGED
@@ -76,8 +76,6 @@ module Discorb
|
|
76
76
|
}
|
77
77
|
end
|
78
78
|
|
79
|
-
alias to_reference to_hash
|
80
|
-
|
81
79
|
#
|
82
80
|
# Initialize a new reference from a hash.
|
83
81
|
#
|
@@ -141,7 +139,8 @@ module Discorb
|
|
141
139
|
def initialize(client, data)
|
142
140
|
@id = Snowflake.new(data[:id])
|
143
141
|
@name = data[:name]
|
144
|
-
@type = Discorb::Interaction.descendants.find { |c| c.interaction_type == data[:type] }
|
142
|
+
@type = (Discorb::Interaction.descendants.find { |c| c.interaction_type == data[:type] } or
|
143
|
+
raise "Unknown interaction type: #{data[:type]}")
|
145
144
|
@user = client.users[data[:user][:id]] || User.new(client, data[:user])
|
146
145
|
end
|
147
146
|
|
data/lib/discorb/modules.rb
CHANGED
@@ -44,7 +44,7 @@ module Discorb
|
|
44
44
|
payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
|
45
45
|
payload[:allowed_mentions] =
|
46
46
|
allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
|
47
|
-
payload[:message_reference] = reference.to_reference if reference
|
47
|
+
payload[:message_reference] = reference.to_reference.to_hash if reference
|
48
48
|
payload[:components] = Component.to_payload(components) if components
|
49
49
|
attachments ||= attachment ? [attachment] : []
|
50
50
|
|
@@ -265,10 +265,11 @@ module Discorb
|
|
265
265
|
sleep(5)
|
266
266
|
end
|
267
267
|
end
|
268
|
-
yield
|
268
|
+
ret = yield
|
269
269
|
ensure
|
270
270
|
post_task.stop
|
271
271
|
end
|
272
|
+
ret
|
272
273
|
else
|
273
274
|
Async do |_task|
|
274
275
|
@client.http.request(Route.new("/channels/#{@id}/typing", "//channels/:channel_id/typing", :post), {})
|
data/lib/discorb/presence.rb
CHANGED
@@ -113,8 +113,8 @@ module Discorb
|
|
113
113
|
@details = data[:details]
|
114
114
|
@state = data[:state]
|
115
115
|
@emoji = if data[:emoji]
|
116
|
-
|
117
|
-
|
116
|
+
data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
|
117
|
+
end
|
118
118
|
@party = data[:party] && Party.new(data[:party])
|
119
119
|
@assets = data[:assets] && Asset.new(data[:assets])
|
120
120
|
@instance = data[:instance]
|
@@ -141,6 +141,8 @@ module Discorb
|
|
141
141
|
"#{@emoji} #{@state}"
|
142
142
|
when :competing
|
143
143
|
"Competing in #{@name}"
|
144
|
+
else
|
145
|
+
raise "Unknown activity type: #{@type}"
|
144
146
|
end
|
145
147
|
end
|
146
148
|
|
data/lib/discorb/reaction.rb
CHANGED
@@ -7,7 +7,7 @@ module Discorb
|
|
7
7
|
class Reaction < DiscordModel
|
8
8
|
# @return [Integer] The number of users that have reacted with this emoji.
|
9
9
|
attr_reader :count
|
10
|
-
# @return [Discorb::Emoji] The emoji that was reacted with.
|
10
|
+
# @return [Discorb::Emoji, Discorb::PartialEmoji] The emoji that was reacted with.
|
11
11
|
attr_reader :emoji
|
12
12
|
# @return [Discorb::Message] The message that this reaction is on.
|
13
13
|
attr_reader :message
|
@@ -33,7 +33,7 @@ module Discorb
|
|
33
33
|
#
|
34
34
|
# @param (see Message#fetch_reacted_users)
|
35
35
|
#
|
36
|
-
# @return [Array<Discorb::User
|
36
|
+
# @return [Async::Task<Array<Discorb::User>>] The users that reacted with this emoji.
|
37
37
|
#
|
38
38
|
def fetch_users(...)
|
39
39
|
message.fetch_reacted_users(@emoji, ...)
|
@@ -45,10 +45,10 @@ module Discorb
|
|
45
45
|
@count = data[:count]
|
46
46
|
@me = data[:me]
|
47
47
|
@emoji = if data[:emoji][:id].nil?
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
UnicodeEmoji.new(data[:emoji][:name])
|
49
|
+
else
|
50
|
+
PartialEmoji.new(data[:emoji])
|
51
|
+
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/lib/discorb/role.rb
CHANGED
@@ -69,7 +69,7 @@ module Discorb
|
|
69
69
|
# @return [Integer] -1 if the other role is higher, 0 if they are equal, 1 if the other role is lower.
|
70
70
|
#
|
71
71
|
def <=>(other)
|
72
|
-
return
|
72
|
+
return nil unless other.is_a?(Role)
|
73
73
|
|
74
74
|
@position <=> other.position
|
75
75
|
end
|
data/lib/discorb/sticker.rb
CHANGED
@@ -17,7 +17,7 @@ module Discorb
|
|
17
17
|
attr_reader :format
|
18
18
|
# @return [String] The URL of the sticker.
|
19
19
|
attr_reader :description
|
20
|
-
# @return [Discorb::
|
20
|
+
# @return [Discorb::Snowflake] The ID of the sticker pack.
|
21
21
|
attr_reader :pack_id
|
22
22
|
# @return [Integer] The sort value of the sticker.
|
23
23
|
attr_reader :sort_value
|
@@ -87,7 +87,7 @@ module Discorb
|
|
87
87
|
payload[:tags] = tag.name unless tag == Discorb::Unset
|
88
88
|
@client.http.request(
|
89
89
|
Route.new("/guilds/#{@guild_id}/stickers/#{@id}", "//guilds/:guild_id/stickers/:sticker_id",
|
90
|
-
:patch), payload, audit_log_reason: reason
|
90
|
+
:patch), payload, audit_log_reason: reason,
|
91
91
|
).wait
|
92
92
|
end
|
93
93
|
end
|
@@ -104,7 +104,7 @@ module Discorb
|
|
104
104
|
Async do
|
105
105
|
@client.http.request(
|
106
106
|
Route.new("/guilds/#{@guild_id}/stickers/#{@id}", "//guilds/:guild_id/stickers/:sticker_id",
|
107
|
-
:delete), {}, audit_log_reason: reason
|
107
|
+
:delete), {}, audit_log_reason: reason,
|
108
108
|
).wait
|
109
109
|
end
|
110
110
|
end
|
data/lib/discorb/user.rb
CHANGED
@@ -16,7 +16,7 @@ module Discorb
|
|
16
16
|
attr_reader :flag
|
17
17
|
# @return [String] The user's discriminator.
|
18
18
|
attr_reader :discriminator
|
19
|
-
# @return [Discorb::Asset] The user's avatar.
|
19
|
+
# @return [Discorb::Asset, Discorb::DefaultAvatar] The user's avatar.
|
20
20
|
attr_reader :avatar
|
21
21
|
# @return [Boolean] Whether the user is a bot.
|
22
22
|
attr_reader :bot
|
@@ -147,7 +147,7 @@ module Discorb
|
|
147
147
|
@flag = User::Flag.new(data[:public_flags] | (data[:flags] || 0))
|
148
148
|
@discriminator = data[:discriminator]
|
149
149
|
@avatar = data[:avatar] ? Asset.new(self, data[:avatar]) : DefaultAvatar.new(data[:discriminator])
|
150
|
-
@bot = data[:bot]
|
150
|
+
@bot = data[:bot] || false
|
151
151
|
@raw_data = data
|
152
152
|
@client.users[@id] = self unless data[:no_cache]
|
153
153
|
@created_at = @id.timestamp
|
data/lib/discorb/voice_state.rb
CHANGED
@@ -95,10 +95,10 @@ module Discorb
|
|
95
95
|
@user_id = data[:user_id]
|
96
96
|
unless guild.nil?
|
97
97
|
@member = if data.key?(:member)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
guild.members[data[:user_id]] || Member.new(@client, @guild_id, data[:member][:user], data[:member])
|
99
|
+
else
|
100
|
+
guild.members[data[:user_id]]
|
101
|
+
end
|
102
102
|
end
|
103
103
|
@session_id = data[:session_id]
|
104
104
|
@deaf = data[:deaf]
|
@@ -217,7 +217,7 @@ module Discorb
|
|
217
217
|
Async do
|
218
218
|
@client.http.request(
|
219
219
|
Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:stage_instance_id",
|
220
|
-
:delete), {}, audit_log_reason: reason
|
220
|
+
:delete), {}, audit_log_reason: reason,
|
221
221
|
).wait
|
222
222
|
self
|
223
223
|
end
|
data/lib/discorb/webhook.rb
CHANGED
@@ -56,8 +56,8 @@ module Discorb
|
|
56
56
|
# @param [Discorb::Embed] embed The embed to send.
|
57
57
|
# @param [Array<Discorb::Embed>] embeds The embeds to send.
|
58
58
|
# @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
|
59
|
-
# @param [Discorb::
|
60
|
-
# @param [Array<Discorb::
|
59
|
+
# @param [Discorb::Attachment] attachment The attachment to send.
|
60
|
+
# @param [Array<Discorb::Attachment>] attachment The attachments to send.
|
61
61
|
# @param [String] username The username of the message.
|
62
62
|
# @param [String] avatar_url The avatar URL of the message.
|
63
63
|
# @param [Boolean] wait Whether to wait for the message to be sent.
|
@@ -65,24 +65,41 @@ module Discorb
|
|
65
65
|
# @return [Discorb::Webhook::Message] The message that was sent.
|
66
66
|
# @return [Async::Task<nil>] If `wait` is false.
|
67
67
|
#
|
68
|
-
def post(
|
69
|
-
|
68
|
+
def post(
|
69
|
+
content = nil,
|
70
|
+
tts: false,
|
71
|
+
embed: nil,
|
72
|
+
embeds: nil,
|
73
|
+
allowed_mentions: nil,
|
74
|
+
attachment: nil,
|
75
|
+
attachments: nil,
|
76
|
+
username: nil,
|
77
|
+
avatar_url: Discorb::Unset,
|
78
|
+
wait: true
|
79
|
+
)
|
70
80
|
Async do
|
71
81
|
payload = {}
|
72
82
|
payload[:content] = content if content
|
73
83
|
payload[:tts] = tts
|
74
84
|
tmp_embed = if embed
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
85
|
+
[embed]
|
86
|
+
elsif embeds
|
87
|
+
embeds
|
88
|
+
end
|
79
89
|
payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
|
80
90
|
payload[:allowed_mentions] = allowed_mentions&.to_hash
|
81
91
|
payload[:username] = username if username
|
82
92
|
payload[:avatar_url] = avatar_url if avatar_url != Discorb::Unset
|
83
|
-
|
84
|
-
_resp, data = @http.multipart_request(
|
85
|
-
|
93
|
+
attachments = [attachment] if attachment
|
94
|
+
_resp, data = @http.multipart_request(
|
95
|
+
Route.new(
|
96
|
+
"#{url}?wait=#{wait}",
|
97
|
+
"//webhooks/:webhook_id/:token",
|
98
|
+
:post
|
99
|
+
),
|
100
|
+
attachments,
|
101
|
+
payload
|
102
|
+
).wait
|
86
103
|
data && Webhook::Message.new(self, data)
|
87
104
|
end
|
88
105
|
end
|
@@ -137,8 +154,8 @@ module Discorb
|
|
137
154
|
# @param [Discorb::Embed] embed The new embed of the message.
|
138
155
|
# @param [Array<Discorb::Embed>] embeds The new embeds of the message.
|
139
156
|
# @param [Array<Discorb::Attachment>] attachments The attachments to remain.
|
140
|
-
# @param [Discorb::
|
141
|
-
# @param [Array<Discorb::
|
157
|
+
# @param [Discorb::Attachment] file The file to send.
|
158
|
+
# @param [Array<Discorb::Attachment>] files The files to send.
|
142
159
|
# @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
|
143
160
|
#
|
144
161
|
# @return [Async::Task<void>] The task.
|
@@ -176,10 +193,12 @@ module Discorb
|
|
176
193
|
#
|
177
194
|
def delete_message!(message)
|
178
195
|
Async do
|
179
|
-
@http.request(
|
180
|
-
|
181
|
-
|
182
|
-
|
196
|
+
@http.request(
|
197
|
+
Route.new(
|
198
|
+
"#{url}/messages/#{Utils.try(message, :id)}",
|
199
|
+
"//webhooks/:webhook_id/:token/messages/:message_id", :delete
|
200
|
+
)
|
201
|
+
).wait
|
183
202
|
message
|
184
203
|
end
|
185
204
|
end
|
@@ -195,11 +214,12 @@ module Discorb
|
|
195
214
|
# Initializes the webhook from URL.
|
196
215
|
#
|
197
216
|
# @param [String] url The URL of the webhook.
|
217
|
+
# @param [Discorb::Client] client The client to associate with the webhook.
|
198
218
|
#
|
199
|
-
def initialize(url)
|
219
|
+
def initialize(url, client: nil)
|
200
220
|
@url = url
|
201
221
|
@token = ""
|
202
|
-
@http = Discorb::HTTP.new(
|
222
|
+
@http = Discorb::HTTP.new(client || Discorb::Client.new)
|
203
223
|
end
|
204
224
|
end
|
205
225
|
|
@@ -447,12 +467,13 @@ module Discorb
|
|
447
467
|
# Creates URLWebhook.
|
448
468
|
#
|
449
469
|
# @param [String] url The URL of the webhook.
|
470
|
+
# @param [Discorb::Client] client The client to associate with the webhook.
|
450
471
|
#
|
451
472
|
# @return [Discorb::Webhook::URLWebhook] The URLWebhook.
|
452
473
|
#
|
453
|
-
def new(url)
|
474
|
+
def new(url, client: nil)
|
454
475
|
if self == Webhook
|
455
|
-
URLWebhook.new(url)
|
476
|
+
URLWebhook.new(url, client: client)
|
456
477
|
else
|
457
478
|
super
|
458
479
|
end
|
data/lib/discorb.rb
CHANGED
@@ -46,10 +46,10 @@ end
|
|
46
46
|
require_order = %w[common flag dictionary error rate_limit http intents emoji_table modules] +
|
47
47
|
%w[channel/container message_meta allowed_mentions] +
|
48
48
|
%w[user member guild emoji channel embed message] +
|
49
|
-
%w[application audit_logs color components event event_handler] +
|
49
|
+
%w[application audit_logs color components event event_handler automod] +
|
50
50
|
%w[attachment guild_template image integration interaction invite permission] +
|
51
51
|
%w[presence reaction role sticker utils voice_state webhook] +
|
52
|
-
%w[gateway_requests gateway app_command] +
|
52
|
+
%w[gateway_requests gateway_events gateway app_command] +
|
53
53
|
%w[asset extension shard client extend]
|
54
54
|
require_order.each do |name|
|
55
55
|
require_relative "discorb/#{name}.rb"
|
data/po/yard.pot
CHANGED
@@ -2907,23 +2907,23 @@ msgid "### How can I send files?"
|
|
2907
2907
|
msgstr ""
|
2908
2908
|
|
2909
2909
|
#: ../docs/faq.md:65
|
2910
|
-
msgid "Use {Discorb::
|
2910
|
+
msgid "Use {Discorb::Attachment} class."
|
2911
2911
|
msgstr ""
|
2912
2912
|
|
2913
2913
|
#: ../docs/faq.md:67
|
2914
2914
|
msgid "```ruby\n"
|
2915
2915
|
"# Send a file\n"
|
2916
|
-
"message.channel.post file: Discorb::
|
2916
|
+
"message.channel.post file: Discorb::Attachment.new(File.open(\"./README.md\"))"
|
2917
2917
|
msgstr ""
|
2918
2918
|
|
2919
2919
|
#: ../docs/faq.md:71
|
2920
2920
|
msgid "# Send some files with text\n"
|
2921
|
-
"message.channel.post \"File!\", files: [Discorb::
|
2921
|
+
"message.channel.post \"File!\", files: [Discorb::Attachment.new(File.open(\"./README.md\")), Discorb::Attachment.new(File.open(\"./License.txt\"))]"
|
2922
2922
|
msgstr ""
|
2923
2923
|
|
2924
2924
|
#: ../docs/faq.md:74
|
2925
2925
|
msgid "# Send a string as a file\n"
|
2926
|
-
"message.channel.post file: Discorb::
|
2926
|
+
"message.channel.post file: Discorb::Attachment.from_string(\"Hello world!\", \"hello.txt\")\n"
|
2927
2927
|
"```"
|
2928
2928
|
msgstr ""
|
2929
2929
|
|
@@ -9511,7 +9511,7 @@ msgstr ""
|
|
9511
9511
|
msgid "a new instance of Attachment"
|
9512
9512
|
msgstr ""
|
9513
9513
|
|
9514
|
-
# Discorb::
|
9514
|
+
# Discorb::Attachment
|
9515
9515
|
#: ../lib/discorb/file.rb:53
|
9516
9516
|
msgid "Represents a file to send as an attachment."
|
9517
9517
|
msgstr ""
|
@@ -9537,7 +9537,7 @@ msgstr ""
|
|
9537
9537
|
msgid "The content type of the file. If not set, it is guessed from the filename."
|
9538
9538
|
msgstr ""
|
9539
9539
|
|
9540
|
-
# Discorb::
|
9540
|
+
# Discorb::Attachment#initialize
|
9541
9541
|
#: ../lib/discorb/file.rb:64
|
9542
9542
|
msgid "Creates a new file from IO."
|
9543
9543
|
msgstr ""
|
@@ -9570,7 +9570,7 @@ msgstr ""
|
|
9570
9570
|
msgid "tag|param|content_type"
|
9571
9571
|
msgstr ""
|
9572
9572
|
|
9573
|
-
# Discorb::
|
9573
|
+
# Discorb::Attachment.from_string
|
9574
9574
|
#: ../lib/discorb/file.rb:79
|
9575
9575
|
msgid "Creates a new file from a string."
|
9576
9576
|
msgstr ""
|
@@ -11738,7 +11738,7 @@ msgstr ""
|
|
11738
11738
|
msgid "A helper method to send multipart/form-data requests for creating messages."
|
11739
11739
|
msgstr ""
|
11740
11740
|
|
11741
|
-
# @param [Array<Discorb::
|
11741
|
+
# @param [Array<Discorb::Attachment>]
|
11742
11742
|
#: ../lib/discorb/http.rb:154
|
11743
11743
|
#: ../lib/discorb/interaction/response.rb:91
|
11744
11744
|
#: ../lib/discorb/interaction/response.rb:115
|
@@ -11750,7 +11750,7 @@ msgstr ""
|
|
11750
11750
|
msgid "tag|param|files"
|
11751
11751
|
msgstr ""
|
11752
11752
|
|
11753
|
-
# @param [Array<Discorb::
|
11753
|
+
# @param [Array<Discorb::Attachment>] files
|
11754
11754
|
#: ../lib/discorb/http.rb:154
|
11755
11755
|
#: ../lib/discorb/interaction/response.rb:91
|
11756
11756
|
#: ../lib/discorb/interaction/response.rb:115
|
@@ -12357,7 +12357,7 @@ msgstr ""
|
|
12357
12357
|
msgid "tag|param|attachments"
|
12358
12358
|
msgstr ""
|
12359
12359
|
|
12360
|
-
# @param [Discorb::
|
12360
|
+
# @param [Discorb::Attachment]
|
12361
12361
|
#: ../lib/discorb/interaction/response.rb:91
|
12362
12362
|
#: ../lib/discorb/interaction/response.rb:115
|
12363
12363
|
#: ../lib/discorb/modules.rb:25
|
@@ -12375,7 +12375,7 @@ msgstr ""
|
|
12375
12375
|
msgid "The new embeds of the message."
|
12376
12376
|
msgstr ""
|
12377
12377
|
|
12378
|
-
# @param [Discorb::
|
12378
|
+
# @param [Discorb::Attachment] file
|
12379
12379
|
#: ../lib/discorb/interaction/response.rb:91
|
12380
12380
|
#: ../lib/discorb/interaction/response.rb:115
|
12381
12381
|
#: ../lib/discorb/modules.rb:25
|
@@ -0,0 +1,88 @@
|
|
1
|
+
---
|
2
|
+
sources:
|
3
|
+
- name: ruby/gem_rbs_collection
|
4
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
5
|
+
revision: main
|
6
|
+
repo_dir: gems
|
7
|
+
path: ".gem_rbs_collection"
|
8
|
+
gems:
|
9
|
+
- name: net-http
|
10
|
+
version: '0'
|
11
|
+
source:
|
12
|
+
type: stdlib
|
13
|
+
- name: logger
|
14
|
+
version: '0'
|
15
|
+
source:
|
16
|
+
type: stdlib
|
17
|
+
- name: ast
|
18
|
+
version: '2.4'
|
19
|
+
source:
|
20
|
+
type: git
|
21
|
+
name: ruby/gem_rbs_collection
|
22
|
+
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
|
23
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
24
|
+
repo_dir: gems
|
25
|
+
- name: forwardable
|
26
|
+
version: '0'
|
27
|
+
source:
|
28
|
+
type: stdlib
|
29
|
+
- name: i18n
|
30
|
+
version: '1.10'
|
31
|
+
source:
|
32
|
+
type: git
|
33
|
+
name: ruby/gem_rbs_collection
|
34
|
+
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
|
35
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
36
|
+
repo_dir: gems
|
37
|
+
- name: listen
|
38
|
+
version: '3.2'
|
39
|
+
source:
|
40
|
+
type: git
|
41
|
+
name: ruby/gem_rbs_collection
|
42
|
+
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
|
43
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
44
|
+
repo_dir: gems
|
45
|
+
- name: minitest
|
46
|
+
version: '0'
|
47
|
+
source:
|
48
|
+
type: stdlib
|
49
|
+
- name: parallel
|
50
|
+
version: '1.20'
|
51
|
+
source:
|
52
|
+
type: git
|
53
|
+
name: ruby/gem_rbs_collection
|
54
|
+
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
|
55
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
56
|
+
repo_dir: gems
|
57
|
+
- name: prime
|
58
|
+
version: '0'
|
59
|
+
source:
|
60
|
+
type: stdlib
|
61
|
+
- name: rainbow
|
62
|
+
version: '3.0'
|
63
|
+
source:
|
64
|
+
type: git
|
65
|
+
name: ruby/gem_rbs_collection
|
66
|
+
revision: 347858a6750d478f6cf1285b4ebd6ae945af2609
|
67
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
68
|
+
repo_dir: gems
|
69
|
+
- name: singleton
|
70
|
+
version: '0'
|
71
|
+
source:
|
72
|
+
type: stdlib
|
73
|
+
- name: uri
|
74
|
+
version: '0'
|
75
|
+
source:
|
76
|
+
type: stdlib
|
77
|
+
- name: timeout
|
78
|
+
version: '0'
|
79
|
+
source:
|
80
|
+
type: stdlib
|
81
|
+
- name: monitor
|
82
|
+
version: '0'
|
83
|
+
source:
|
84
|
+
type: stdlib
|
85
|
+
- name: mutex_m
|
86
|
+
version: '0'
|
87
|
+
source:
|
88
|
+
type: stdlib
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- name: ruby/gem_rbs_collection
|
4
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
5
|
+
revision: main
|
6
|
+
repo_dir: gems
|
7
|
+
|
8
|
+
# A directory to install the downloaded RBSs
|
9
|
+
path: .gem_rbs_collection
|
10
|
+
|
11
|
+
gems:
|
12
|
+
# Skip loading rbs gem's RBS.
|
13
|
+
# It's unnecessary if you don't use rbs as a library.
|
14
|
+
- name: rbs
|
15
|
+
ignore: true
|
16
|
+
- name: discorb
|
17
|
+
ignore: true
|
18
|
+
- name: net-http
|
19
|
+
- name: logger
|
20
|
+
- name: activesupport
|
21
|
+
ignore: true
|
data/sig/async.rbs
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Discorb
|
2
|
+
#
|
3
|
+
# Represents an activity for Gateway Command.
|
4
|
+
class Activity
|
5
|
+
TYPES: untyped
|
6
|
+
|
7
|
+
#
|
8
|
+
# Initializes a new Activity.
|
9
|
+
#
|
10
|
+
# @param [String] name The name of the activity.
|
11
|
+
# @param [:playing, :streaming, :listening, :watching, :competing] type The type of activity.
|
12
|
+
# @param [String] url The URL of the activity.
|
13
|
+
def initialize: (String name, ?Symbol `type`, ?String? url) -> void
|
14
|
+
|
15
|
+
#
|
16
|
+
# Converts the activity to a hash.
|
17
|
+
#
|
18
|
+
# @return [Hash] A hash representation of the activity.
|
19
|
+
def to_hash: -> Discorb::json
|
20
|
+
|
21
|
+
def inspect: -> String
|
22
|
+
end
|
23
|
+
end
|