discorb 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +11 -1
- data/docs/faq.md +1 -1
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/gateway.rb +1 -3
- data/lib/discorb/interaction.rb +74 -7
- data/lib/discorb/utils.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb61003015daf1f1731f80809e9c739cad169f60b7b5f7cc6c1ac7580d61bd1
|
4
|
+
data.tar.gz: e2d7bcad6c493bea84b7f2608a1d1366f76e95675c50052b034742be322d0569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b2cee7155fe0273181fc7cf1fdd048ebd0b9d1adba4ca7c4444a31a92b5cd86a65c77511e581858c379e1abb53d1d092ab6115394b0a9fbc076b6692b04312b
|
7
|
+
data.tar.gz: 245db18f6b68599ccf199e5c1571a3f38181d4a4a6dc5371cf55e29bc9dd1d95766ff67047091558aaf392f41ea3fb0d28b726972c120ad7dd80a216a1e3699c
|
data/Changelog.md
CHANGED
@@ -234,4 +234,14 @@ end
|
|
234
234
|
|
235
235
|
## 0.9.1
|
236
236
|
|
237
|
-
- Fix: Fix member fetching
|
237
|
+
- Fix: Fix member fetching
|
238
|
+
|
239
|
+
## 0.9.2 (yanked)
|
240
|
+
|
241
|
+
- Add: Make `Async::Task#inspect` shorter
|
242
|
+
- Add: `SourceResponse#post` will return message now
|
243
|
+
- Fix: Fix member caching
|
244
|
+
|
245
|
+
## 0.9.3
|
246
|
+
|
247
|
+
- Fix: Fix interaction responding
|
data/docs/faq.md
CHANGED
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.9.
|
7
|
+
VERSION = "0.9.3"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/gateway.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require "async/http"
|
4
4
|
require "async/websocket"
|
5
5
|
require "async/barrier"
|
6
|
-
require "async/semaphore"
|
7
6
|
require "json"
|
8
7
|
require "zlib"
|
9
8
|
|
@@ -1035,10 +1034,9 @@ module Discorb
|
|
1035
1034
|
if @fetch_member
|
1036
1035
|
@log.debug "Fetching members"
|
1037
1036
|
barrier = Async::Barrier.new
|
1038
|
-
semaphore = Async::Semaphore.new(@guilds.length)
|
1039
1037
|
|
1040
1038
|
@guilds.each do |guild|
|
1041
|
-
|
1039
|
+
barrier.async(parent: barrier) do
|
1042
1040
|
guild.fetch_members
|
1043
1041
|
end
|
1044
1042
|
end
|
data/lib/discorb/interaction.rb
CHANGED
@@ -131,6 +131,8 @@ module Discorb
|
|
131
131
|
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
|
132
132
|
# @param [Boolean] ephemeral Whether to make the response ephemeral.
|
133
133
|
#
|
134
|
+
# @return [Discorb::Interaction::SourceResponse::CallbackMessage, Discorb::Webhook::Message] The callback message.
|
135
|
+
#
|
134
136
|
def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
|
135
137
|
Async do
|
136
138
|
payload = {}
|
@@ -165,14 +167,79 @@ module Discorb
|
|
165
167
|
end
|
166
168
|
payload[:flags] = (ephemeral ? 1 << 6 : 0)
|
167
169
|
|
168
|
-
if @responded
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
170
|
+
ret = if @responded
|
171
|
+
_resp, data = @client.http.post("/webhooks/#{@application_id}/#{@token}", payload).wait
|
172
|
+
webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}")
|
173
|
+
Webhook::Message.new(webhook, data, @client)
|
174
|
+
elsif @defered
|
175
|
+
@client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload).wait
|
176
|
+
CallbackMessage.new(@client, payload, @application_id, @token)
|
177
|
+
else
|
178
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait
|
179
|
+
CallbackMessage.new(@client, payload, @application_id, @token)
|
180
|
+
end
|
175
181
|
@responded = true
|
182
|
+
ret
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
class CallbackMessage
|
187
|
+
# @!visibility private
|
188
|
+
def initialize(client, data, application_id, token)
|
189
|
+
@client = client
|
190
|
+
@data = data
|
191
|
+
@application_id = application_id
|
192
|
+
@token = token
|
193
|
+
end
|
194
|
+
|
195
|
+
#
|
196
|
+
# Edits the callback message.
|
197
|
+
# @macro async
|
198
|
+
# @macro http
|
199
|
+
# @macro edit
|
200
|
+
#
|
201
|
+
# @param [Discorb::Webhook::Message] message The message to edit.
|
202
|
+
# @param [String] content The new content of the message.
|
203
|
+
# @param [Discorb::Embed] embed The new embed of the message.
|
204
|
+
# @param [Array<Discorb::Embed>] embeds The new embeds of the message.
|
205
|
+
# @param [Array<Discorb::Attachment>] attachments The attachments to remain.
|
206
|
+
# @param [Discorb::File] file The file to send.
|
207
|
+
# @param [Array<Discorb::File>] files The files to send.
|
208
|
+
#
|
209
|
+
def edit(
|
210
|
+
content = :unset,
|
211
|
+
embed: :unset, embeds: :unset,
|
212
|
+
file: :unset, files: :unset,
|
213
|
+
attachments: :unset
|
214
|
+
)
|
215
|
+
Async do
|
216
|
+
payload = {}
|
217
|
+
payload[:content] = content if content != :unset
|
218
|
+
payload[:embeds] = embed ? [embed.to_hash] : [] if embed != :unset
|
219
|
+
payload[:embeds] = embeds.map(&:to_hash) if embeds != :unset
|
220
|
+
payload[:attachments] = attachments.map(&:to_hash) if attachments != :unset
|
221
|
+
files = [file] if file != :unset
|
222
|
+
if files == :unset
|
223
|
+
headers = {
|
224
|
+
"Content-Type" => "application/json",
|
225
|
+
}
|
226
|
+
else
|
227
|
+
headers, payload = HTTP.multipart(payload, files)
|
228
|
+
end
|
229
|
+
@client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload, headers: headers).wait
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
alias modify edit
|
234
|
+
|
235
|
+
#
|
236
|
+
# Deletes the callback message.
|
237
|
+
# @note This will fail if the message is ephemeral.
|
238
|
+
#
|
239
|
+
def delete!
|
240
|
+
Async do
|
241
|
+
@client.http.delete("/webhooks/#{@application_id}/#{@token}/messages/@original").wait
|
242
|
+
end
|
176
243
|
end
|
177
244
|
end
|
178
245
|
end
|
data/lib/discorb/utils.rb
CHANGED
@@ -14,3 +14,23 @@ module Discorb
|
|
14
14
|
module_function :try
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
class Async::Node
|
19
|
+
def description
|
20
|
+
@object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? ' transient' : nil}"
|
21
|
+
|
22
|
+
if @annotation
|
23
|
+
"#{@object_name} #{@annotation}"
|
24
|
+
elsif line = self.backtrace(0, 1)&.first
|
25
|
+
"#{@object_name} #{line}"
|
26
|
+
else
|
27
|
+
@object_name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
"\#<#{self.description}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
alias inspect to_s
|
36
|
+
end
|