onyxcord 1.1.4 → 1.1.6
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 +27 -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/data/component.rb +8 -0
- data/lib/onyxcord/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 48d2c8e46a2b9da91c5e60313e00bc15fb03d80d60cb08528680e4e848739194
|
|
4
|
+
data.tar.gz: bf4357fef270f6c86fa344352d9d1267a8e7ca6aa9a66589de36ec9ea1e86a63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b4b4fbe09bc0f5eab3104a3147947f600e2089406703c694d0ac1e090d6341af08f18581d8ba7d63f6773fb21d0cf74547bf5abf7204735de3d40a454cec231
|
|
7
|
+
data.tar.gz: 00b65d5043ccb3c265721d07acac65142c0a640bb9b4937049040c28fc23ae6ccb50fb2e92ca009a276e333856757897802a519cedfbc0ca19d3257b08bca675
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.6 - 2026-06-28
|
|
4
|
+
|
|
5
|
+
### Melhorias
|
|
6
|
+
|
|
7
|
+
- Adicionado suporte aos novos componentes de modal do Discord: `Label`, `File Upload`, `Radio Group`, `Checkbox Group` e `Checkbox`.
|
|
8
|
+
- Modais agora preservam o `id` do componente `Label` ao gerar o payload.
|
|
9
|
+
- Parser de componentes agora expoe `label` e `description` em `Components::Label`.
|
|
10
|
+
|
|
11
|
+
### Validacao
|
|
12
|
+
|
|
13
|
+
- `bundle exec rspec spec/components_v2_spec.rb`: 15 exemplos, 0 falhas.
|
|
14
|
+
- `ruby -c lib/onyxcord/webhooks/modal.rb`: sucesso.
|
|
15
|
+
- `ruby -c lib/onyxcord/data/component.rb`: sucesso.
|
|
16
|
+
- `ruby -c spec/components_v2_spec.rb`: sucesso.
|
|
17
|
+
|
|
18
|
+
## 1.1.5 - 2026-06-28
|
|
19
|
+
|
|
20
|
+
### Melhorias
|
|
21
|
+
|
|
22
|
+
- 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.
|
|
23
|
+
- Novos helpers `attachment_payload` e `multipart_body` adicionados nativamente em `API::Channel`, `API::Interaction` e `API::Webhook`.
|
|
24
|
+
- 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`.
|
|
25
|
+
|
|
26
|
+
### Correcoes
|
|
27
|
+
|
|
28
|
+
- Corrigido `Channel.create_message` para sanitizar o parametro `tts`, forçando `false` quando o valor nao e booleano.
|
|
29
|
+
|
|
3
30
|
## 1.1.4 - 2026-06-28
|
|
4
31
|
|
|
5
32
|
### 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
|
|
@@ -488,6 +488,12 @@ module OnyxCord
|
|
|
488
488
|
# @return [Integer] the numeric identifier of the label.
|
|
489
489
|
attr_reader :id
|
|
490
490
|
|
|
491
|
+
# @return [String] the visible label text for the modal component.
|
|
492
|
+
attr_reader :label
|
|
493
|
+
|
|
494
|
+
# @return [String, nil] the optional description text for the label.
|
|
495
|
+
attr_reader :description
|
|
496
|
+
|
|
491
497
|
# @return [Component] the interactive component of the label.
|
|
492
498
|
attr_reader :component
|
|
493
499
|
|
|
@@ -495,6 +501,8 @@ module OnyxCord
|
|
|
495
501
|
def initialize(data, bot)
|
|
496
502
|
@bot = bot
|
|
497
503
|
@id = data['id']
|
|
504
|
+
@label = data['label']
|
|
505
|
+
@description = data['description']
|
|
498
506
|
@component = Components.from_data(data['component'], @bot)
|
|
499
507
|
end
|
|
500
508
|
end
|
data/lib/onyxcord/version.rb
CHANGED
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
|
+
version: 1.1.6
|
|
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.
|
|
112
|
+
version: 1.1.6
|
|
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.
|
|
119
|
+
version: 1.1.6
|
|
120
120
|
- !ruby/object:Gem::Dependency
|
|
121
121
|
name: bundler
|
|
122
122
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -441,7 +441,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
441
441
|
- !ruby/object:Gem::Version
|
|
442
442
|
version: '0'
|
|
443
443
|
requirements: []
|
|
444
|
-
rubygems_version:
|
|
444
|
+
rubygems_version: 4.0.15
|
|
445
445
|
specification_version: 4
|
|
446
446
|
summary: Discord API for Ruby with Components V2 support
|
|
447
447
|
test_files: []
|