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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faa13116d56881eff441634bdd885ed2650739cdea9be5e3807ec94d0c4c8965
4
- data.tar.gz: 8738d765d59e229c5c1476bc1029e32c82f6ad1d417295380ffaae4fb8d65e22
3
+ metadata.gz: 30ab900742443c8552b97aa4d2a90c3ccd8caef0c74630ccfbd477e95ba0b250
4
+ data.tar.gz: af84a0ac8507a3cba1cdb2c94f24de381a183d0e934ed0458df447804ae6bf40
5
5
  SHA512:
6
- metadata.gz: e36c649784e3eda4f2928bf2801013072fabf8bd40b4f5bcba232fef37155fc36ccfa27041656ef988152a78d1bbe9b4d3145e7cf384169b8279d1f80417f5f6
7
- data.tar.gz: a4dd38f5c246e0bc9e9432ee0f75f54a641bbce30cf143a4b95eb73f8da08810baa76d4fd46e81e279e9d2cac5e4618df8f3f0acbb9c15ecc5643e411ac21592
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
@@ -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
- files = [*0...attachments.size].zip(attachments).to_h
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
- files = [*0...attachments.size].zip(attachments).to_h
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
- body = { tts: tts, content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, components: components, choices: choices, poll: poll }.compact
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
- files = [*0...attachments.size].zip(attachments).to_h
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: body }.to_json
36
+ { type: type, data: data }.to_json
21
37
  end
22
38
 
23
39
  headers = { content_type: :json } unless attachments
@@ -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), allowed_mentions: allowed_mentions, flags: flags, components: components, poll: poll }
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
- files = [*0...attachments.size].zip(attachments).to_h
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
- files = [*0...attachments.size].zip(attachments).to_h
136
- { **files, payload_json: body.to_json }
151
+ multipart_body(body, attachments)
137
152
  else
138
153
  body.to_json
139
154
  end
@@ -3,5 +3,5 @@
3
3
  # OnyxCord and all its functionality, in this case only the version.
4
4
  module OnyxCord
5
5
  # The current version of onyxcord.
6
- VERSION = '1.1.4'
6
+ VERSION = '1.1.5'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onyxcord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Silva