onyxcord 1.1.4 → 1.1.5
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/CHANGELOG.md +12 -0
- data/lib/onyxcord/api/channel.rb +22 -5
- data/lib/onyxcord/api/interaction.rb +20 -4
- data/lib/onyxcord/api/webhook.rb +21 -6
- data/lib/onyxcord/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: 30ab900742443c8552b97aa4d2a90c3ccd8caef0c74630ccfbd477e95ba0b250
|
|
4
|
+
data.tar.gz: af84a0ac8507a3cba1cdb2c94f24de381a183d0e934ed0458df447804ae6bf40
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c81505c21d6f84c76cbe48376803c0ccae18bd33c8d9bc9ac6ddf48935f1f1c2d0fa901696df453186acc5b457f5a432e0a1302ce6a2545c2a23678d6169c8d4
|
|
7
|
+
data.tar.gz: f0cfe6e84ae69cd957e3538a679cd856199f31282741d5fe2ba16c3202fd70e528424c56ca96a07f5a65d2a6e9d587419000d6268f5b338825bdc63c0fd2e36f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.5 - 2026-06-28
|
|
4
|
+
|
|
5
|
+
### Melhorias
|
|
6
|
+
|
|
7
|
+
- Attachment uploads agora enviam metadata (`id`, `filename`) no payload JSON e usam chaves `files[N]` no multipart body, seguindo a especificacao da API do Discord.
|
|
8
|
+
- Novos helpers `attachment_payload` e `multipart_body` adicionados nativamente em `API::Channel`, `API::Interaction` e `API::Webhook`.
|
|
9
|
+
- Metodos afetados: `Channel.create_message`, `Channel.start_thread_in_forum_or_media_channel`, `Interaction.create_interaction_response`, `Webhook.token_edit_message` e `Webhook.token_execute_webhook`.
|
|
10
|
+
|
|
11
|
+
### Correcoes
|
|
12
|
+
|
|
13
|
+
- Corrigido `Channel.create_message` para sanitizar o parametro `tts`, forçando `false` quando o valor nao e booleano.
|
|
14
|
+
|
|
3
15
|
## 1.1.4 - 2026-06-28
|
|
4
16
|
|
|
5
17
|
### Melhorias
|
data/lib/onyxcord/api/channel.rb
CHANGED
|
@@ -6,6 +6,24 @@ require 'onyxcord/message_components'
|
|
|
6
6
|
module OnyxCord::API::Channel
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
|
+
# Build attachment metadata payload for multipart uploads.
|
|
10
|
+
# Returns an array of { id:, filename: } hashes.
|
|
11
|
+
def attachment_payload(attachments)
|
|
12
|
+
Array(attachments).map.with_index do |attachment, index|
|
|
13
|
+
{ id: index, filename: File.basename(attachment.path) }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Build multipart body with named file fields and JSON payload.
|
|
18
|
+
def multipart_body(body, attachments)
|
|
19
|
+
files = Array(attachments).map.with_index.to_h do |attachment, index|
|
|
20
|
+
["files[#{index}]", attachment]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
{ **files, payload_json: body.to_json }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
9
27
|
# Get a channel's data
|
|
10
28
|
# https://discord.com/developers/docs/resources/channel#get-channel
|
|
11
29
|
def resolve(token, channel_id)
|
|
@@ -93,12 +111,12 @@ module OnyxCord::API::Channel
|
|
|
93
111
|
# @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
|
|
94
112
|
# https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
|
|
95
113
|
def create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = nil, enforce_nonce = false, poll = nil)
|
|
114
|
+
tts = false unless tts == true || tts == false
|
|
96
115
|
components = OnyxCord::MessageComponents.payload(components) unless components.nil?
|
|
97
116
|
flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
|
|
98
|
-
body = { content: message, tts: tts, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components, flags: flags, enforce_nonce: enforce_nonce, poll: poll }
|
|
117
|
+
body = { content: message, tts: tts == true, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components, attachments: attachments ? attachment_payload(attachments) : nil, flags: flags, enforce_nonce: enforce_nonce, poll: poll }.compact
|
|
99
118
|
body = if attachments
|
|
100
|
-
|
|
101
|
-
{ **files, payload_json: body.to_json }
|
|
119
|
+
multipart_body(body, attachments)
|
|
102
120
|
else
|
|
103
121
|
body.to_json
|
|
104
122
|
end
|
|
@@ -652,8 +670,7 @@ module OnyxCord::API::Channel
|
|
|
652
670
|
body = { name: name, message: message, rate_limit_per_user: rate_limit_per_user, auto_archive_duration: auto_archive_duration, applied_tags: applied_tags }.compact
|
|
653
671
|
|
|
654
672
|
body = if attachments
|
|
655
|
-
|
|
656
|
-
{ **files, payload_json: body.to_json }
|
|
673
|
+
multipart_body(body, attachments)
|
|
657
674
|
else
|
|
658
675
|
body.to_json
|
|
659
676
|
end
|
|
@@ -6,18 +6,34 @@ require 'onyxcord/message_components'
|
|
|
6
6
|
module OnyxCord::API::Interaction
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
|
+
# Build attachment metadata payload for multipart uploads.
|
|
10
|
+
# Returns an array of { id:, filename: } hashes.
|
|
11
|
+
def attachment_payload(attachments)
|
|
12
|
+
Array(attachments).map.with_index do |attachment, index|
|
|
13
|
+
{ id: index, filename: File.basename(attachment.path) }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Build multipart body with named file fields and JSON payload.
|
|
18
|
+
def multipart_body(body, attachments)
|
|
19
|
+
files = Array(attachments).map.with_index.to_h do |attachment, index|
|
|
20
|
+
["files[#{index}]", attachment]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
{ **files, payload_json: body.to_json }
|
|
24
|
+
end
|
|
25
|
+
|
|
9
26
|
# Respond to an interaction.
|
|
10
27
|
# https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
|
|
11
28
|
def create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, choices = nil, with_response = nil, poll = nil)
|
|
12
29
|
components = OnyxCord::MessageComponents.payload(components) unless components.nil?
|
|
13
30
|
flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
|
|
14
|
-
|
|
31
|
+
data = { tts: tts, content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, components: components, attachments: attachments ? attachment_payload(attachments) : nil, choices: choices, poll: poll }.compact
|
|
15
32
|
|
|
16
33
|
body = if attachments
|
|
17
|
-
|
|
18
|
-
{ **files, payload_json: { type: type, data: body }.to_json }
|
|
34
|
+
multipart_body({ type: type, data: data }, attachments)
|
|
19
35
|
else
|
|
20
|
-
{ type: type, data:
|
|
36
|
+
{ type: type, data: data }.to_json
|
|
21
37
|
end
|
|
22
38
|
|
|
23
39
|
headers = { content_type: :json } unless attachments
|
data/lib/onyxcord/api/webhook.rb
CHANGED
|
@@ -6,6 +6,23 @@ require 'onyxcord/message_components'
|
|
|
6
6
|
module OnyxCord::API::Webhook
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
|
+
# Build attachment metadata payload for multipart uploads.
|
|
10
|
+
# Returns an array of { id:, filename: } hashes.
|
|
11
|
+
def attachment_payload(attachments)
|
|
12
|
+
Array(attachments).map.with_index do |attachment, index|
|
|
13
|
+
{ id: index, filename: File.basename(attachment.path) }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Build multipart body with named file fields and JSON payload.
|
|
18
|
+
def multipart_body(body, attachments)
|
|
19
|
+
files = Array(attachments).map.with_index.to_h do |attachment, index|
|
|
20
|
+
["files[#{index}]", attachment]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
{ **files, payload_json: body.to_json }
|
|
24
|
+
end
|
|
25
|
+
|
|
9
26
|
# Get a webhook
|
|
10
27
|
# https://discord.com/developers/docs/resources/webhook#get-webhook
|
|
11
28
|
def webhook(token, webhook_id)
|
|
@@ -34,13 +51,12 @@ module OnyxCord::API::Webhook
|
|
|
34
51
|
def token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, poll = nil)
|
|
35
52
|
components = OnyxCord::MessageComponents.payload(components) unless components.nil?
|
|
36
53
|
flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
|
|
37
|
-
body = { content: content, username: username, avatar_url: avatar_url, tts: tts, embeds: embeds&.map(&:to_hash),
|
|
54
|
+
body = { content: content, username: username, avatar_url: avatar_url, tts: tts, embeds: embeds&.map(&:to_hash), allowed_mentions: allowed_mentions, flags: flags, components: components, attachments: attachments ? attachment_payload(attachments) : nil, poll: poll }.compact
|
|
38
55
|
|
|
39
56
|
body = if file
|
|
40
57
|
{ file: file, payload_json: body.to_json }
|
|
41
58
|
elsif attachments
|
|
42
|
-
|
|
43
|
-
{ **files, payload_json: body.to_json }
|
|
59
|
+
multipart_body(body, attachments)
|
|
44
60
|
else
|
|
45
61
|
body.to_json
|
|
46
62
|
end
|
|
@@ -129,11 +145,10 @@ module OnyxCord::API::Webhook
|
|
|
129
145
|
def token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil)
|
|
130
146
|
components = OnyxCord::MessageComponents.payload(components) unless components.nil?
|
|
131
147
|
flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components)
|
|
132
|
-
body = { content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components, flags: flags, poll: poll }
|
|
148
|
+
body = { content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components, attachments: attachments ? attachment_payload(attachments) : nil, flags: flags, poll: poll }.compact
|
|
133
149
|
|
|
134
150
|
body = if attachments
|
|
135
|
-
|
|
136
|
-
{ **files, payload_json: body.to_json }
|
|
151
|
+
multipart_body(body, attachments)
|
|
137
152
|
else
|
|
138
153
|
body.to_json
|
|
139
154
|
end
|
data/lib/onyxcord/version.rb
CHANGED