onyxcord 1.1.3 → 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: 86ca3fde0fa78c2cee74a2d481d82aaa7f70d4988cb16d9af7dec046162e93cd
4
- data.tar.gz: c7a9ced4d4f29a8d4a03a765bea9f9779ab3662c55bf23872fc75b1abbe1d0a3
3
+ metadata.gz: 30ab900742443c8552b97aa4d2a90c3ccd8caef0c74630ccfbd477e95ba0b250
4
+ data.tar.gz: af84a0ac8507a3cba1cdb2c94f24de381a183d0e934ed0458df447804ae6bf40
5
5
  SHA512:
6
- metadata.gz: a095fe07369dde14d2a59d2d3562f7a04a6ee8665a0dcd00f629c19dd85065a029a2c02838d2e2acc106536f89734281551dc5b89533209bd51ab080183e89e4
7
- data.tar.gz: 9086e3c2e05157280aa58d65c5f177f1e1916c1861aa666badf2aa30fe6df8768e89ac8f4f22edc02441ee5067a1cc78370ac13ea087e4323fb9a0705e877d27
6
+ metadata.gz: c81505c21d6f84c76cbe48376803c0ccae18bd33c8d9bc9ac6ddf48935f1f1c2d0fa901696df453186acc5b457f5a432e0a1302ce6a2545c2a23678d6169c8d4
7
+ data.tar.gz: f0cfe6e84ae69cd957e3538a679cd856199f31282741d5fe2ba16c3202fd70e528424c56ca96a07f5a65d2a6e9d587419000d6268f5b338825bdc63c0fd2e36f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
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
+
15
+ ## 1.1.4 - 2026-06-28
16
+
17
+ ### Melhorias
18
+
19
+ - `MediaGallery` agora aceita URLs diretas e hashes no builder, como `media_gallery('https://...')`, alem do formato em bloco.
20
+ - `FileComponent`/`file_display` agora aceita a URL do attachment como primeiro argumento, como `file_display('attachment://arquivo.txt')`.
21
+
22
+ ### Correcoes
23
+
24
+ - Parser de `MediaGallery` e `FileUpload` ficou mais tolerante quando o payload nao traz `items` ou `values`.
25
+
26
+ ### Validacao
27
+
28
+ - `bundle exec rspec spec/components_v2_spec.rb`: 13 exemplos, 0 falhas.
29
+
3
30
  ## 1.1.3 - 2026-06-23
4
31
 
5
32
  ### 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
@@ -331,7 +331,7 @@ module OnyxCord
331
331
  def initialize(data, bot)
332
332
  @bot = bot
333
333
  @id = data['id']
334
- @items = data['items'].map { |item| Item.new(item, @bot) }
334
+ @items = Array(data['items']).map { |item| Item.new(item, @bot) }
335
335
  end
336
336
 
337
337
  # A singular media attachment.
@@ -515,7 +515,7 @@ module OnyxCord
515
515
  @bot = bot
516
516
  @id = data['id']
517
517
  @custom_id = data['custom_id']
518
- @values = data['values'].map(&:to_i)
518
+ @values = Array(data['values']).map(&:to_i)
519
519
  end
520
520
  end
521
521
 
@@ -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.3'
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.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Silva
@@ -109,14 +109,14 @@ dependencies:
109
109
  requirements:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: 1.1.3
112
+ version: 1.1.4
113
113
  type: :runtime
114
114
  prerelease: false
115
115
  version_requirements: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: 1.1.3
119
+ version: 1.1.4
120
120
  - !ruby/object:Gem::Dependency
121
121
  name: bundler
122
122
  requirement: !ruby/object:Gem::Requirement