discordrb-webhooks 3.6.1 → 3.7.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/lib/discordrb/webhooks/client.rb +19 -10
- data/lib/discordrb/webhooks/version.rb +1 -1
- 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: 1fd4231a5be5dc1e5d6f731bc5a2b8edbe9737a527101c9b16a4eabeb37d8cea
|
|
4
|
+
data.tar.gz: fa8f69e94fd67b16b1915e6ff19237f5be5ee6b122bc3aba564b5464f93e2a0f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8bc105bb97f84aa22bf51f576029cc94486b5c0449740b338d5c75b3bbe786b7516b02c334d9599060d0671c0e8f3df6057b79f9cb6f796358ef2708a9e6299e
|
|
7
|
+
data.tar.gz: da63150a08d48567b2f671bde2a5980edfbb2771b8b4ceb36ad476bce6ad3d6728a6007f108e17c4fcfb2e81ddaac592c1290c89004139d296b193cc16d26b1e
|
|
@@ -22,6 +22,7 @@ module Discordrb::Webhooks
|
|
|
22
22
|
# @param builder [Builder, nil] The builder to start out with, or nil if one should be created anew.
|
|
23
23
|
# @param wait [true, false] Whether Discord should wait for the message to be successfully received by clients, or
|
|
24
24
|
# whether it should return immediately after sending the message.
|
|
25
|
+
# @param thread_id [String, Integer, nil] The thread_id of the thread if a thread should be targeted for the webhook execution
|
|
25
26
|
# @yield [builder] Gives the builder to the block to add additional steps, or to do the entire building process.
|
|
26
27
|
# @yieldparam builder [Builder] The builder given as a parameter which is used as the initial step to start from.
|
|
27
28
|
# @example Execute the webhook with an already existing builder
|
|
@@ -38,7 +39,7 @@ module Discordrb::Webhooks
|
|
|
38
39
|
# end
|
|
39
40
|
# end
|
|
40
41
|
# @return [RestClient::Response] the response returned by Discord.
|
|
41
|
-
def execute(builder = nil, wait = false, components = nil)
|
|
42
|
+
def execute(builder = nil, wait = false, components = nil, thread_id: nil)
|
|
42
43
|
raise TypeError, 'builder needs to be nil or like a Discordrb::Webhooks::Builder!' unless
|
|
43
44
|
(builder.respond_to?(:file) && builder.respond_to?(:to_multipart_hash)) || builder.respond_to?(:to_json_hash) || builder.nil?
|
|
44
45
|
|
|
@@ -50,9 +51,9 @@ module Discordrb::Webhooks
|
|
|
50
51
|
components ||= view
|
|
51
52
|
|
|
52
53
|
if builder.file
|
|
53
|
-
post_multipart(builder, components, wait)
|
|
54
|
+
post_multipart(builder, components, wait, thread_id)
|
|
54
55
|
else
|
|
55
|
-
post_json(builder, components, wait)
|
|
56
|
+
post_json(builder, components, wait, thread_id)
|
|
56
57
|
end
|
|
57
58
|
end
|
|
58
59
|
|
|
@@ -79,6 +80,7 @@ module Discordrb::Webhooks
|
|
|
79
80
|
# @param content [String] The message content.
|
|
80
81
|
# @param embeds [Array<Embed, Hash>]
|
|
81
82
|
# @param allowed_mentions [Hash]
|
|
83
|
+
# @param thread_id [String, Integer, nil] The id of the thread in which the message resides
|
|
82
84
|
# @return [RestClient::Response] the response returned by Discord.
|
|
83
85
|
# @example Edit message content
|
|
84
86
|
# client.edit_message(message_id, content: 'goodbye world!')
|
|
@@ -89,13 +91,17 @@ module Discordrb::Webhooks
|
|
|
89
91
|
# end
|
|
90
92
|
# end
|
|
91
93
|
# @note Not all builder options are available when editing.
|
|
92
|
-
def edit_message(message_id, builder: nil, content: nil, embeds: nil, allowed_mentions: nil)
|
|
94
|
+
def edit_message(message_id, builder: nil, content: nil, embeds: nil, allowed_mentions: nil, thread_id: nil)
|
|
93
95
|
builder ||= Builder.new
|
|
94
96
|
|
|
95
97
|
yield builder if block_given?
|
|
96
98
|
|
|
99
|
+
query = URI.encode_www_form({ thread_id: }.compact)
|
|
97
100
|
data = builder.to_json_hash.merge({ content: content, embeds: embeds, allowed_mentions: allowed_mentions }.compact)
|
|
98
|
-
RestClient.patch(
|
|
101
|
+
RestClient.patch(
|
|
102
|
+
"#{@url}/messages/#{message_id}#{(query.empty? ? '' : "?#{query}")}",
|
|
103
|
+
data.compact.to_json, content_type: :json
|
|
104
|
+
)
|
|
99
105
|
end
|
|
100
106
|
|
|
101
107
|
# Delete a message created by this webhook.
|
|
@@ -117,14 +123,17 @@ module Discordrb::Webhooks
|
|
|
117
123
|
end
|
|
118
124
|
end
|
|
119
125
|
|
|
120
|
-
def post_json(builder, components, wait)
|
|
126
|
+
def post_json(builder, components, wait, thread_id)
|
|
127
|
+
query = URI.encode_www_form({ wait:, thread_id: }.compact)
|
|
121
128
|
data = builder.to_json_hash.merge({ components: components.to_a })
|
|
122
|
-
RestClient.post(@url + (
|
|
129
|
+
RestClient.post(@url + (query.empty? ? '' : "?#{query}"), data.to_json, content_type: :json)
|
|
123
130
|
end
|
|
124
131
|
|
|
125
|
-
def post_multipart(builder, components, wait)
|
|
126
|
-
|
|
127
|
-
|
|
132
|
+
def post_multipart(builder, components, wait, thread_id)
|
|
133
|
+
query = URI.encode_www_form({ wait:, thread_id: }.compact)
|
|
134
|
+
data = builder.to_multipart_hash
|
|
135
|
+
data[:components] = components.to_a if components&.any?
|
|
136
|
+
RestClient.post(@url + (query.empty? ? '' : "?#{query}"), data.compact)
|
|
128
137
|
end
|
|
129
138
|
|
|
130
139
|
def generate_url(id, token)
|