Class: OnyxCord::Webhooks::View::SectionBuilder
- Inherits:
-
Object
- Object
- OnyxCord::Webhooks::View::SectionBuilder
- Defined in:
- lib/onyxcord/webhooks/view/section_builder.rb
Instance Method Summary collapse
-
#button(style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil, sku_id: nil) ⇒ Object
Set the button for the section.
-
#initialize(id: nil) {|builder| ... } ⇒ SectionBuilder
constructor
Create a section component.
-
#text_display ⇒ Object
Add a text display component to this section.
-
#thumbnail(url:, id: nil, description: nil, spoiler: false) ⇒ Object
Set the thumbnail for the section.
Constructor Details
#initialize(id: nil) {|builder| ... } ⇒ SectionBuilder
Create a section component.
8 9 10 11 12 13 14 |
# File 'lib/onyxcord/webhooks/view/section_builder.rb', line 8 def initialize(id: nil) @id = id @accessory = nil @components = [] yield self if block_given? end |
Instance Method Details
#button(style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil, sku_id: nil) ⇒ Object
Set the button for the section. This is mutually exclusive with #thumbnail.
that responds to #to_h which returns a hash in the format of { id: Integer, name: string }.
There is a limit of 100 characters to each custom_id.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/onyxcord/webhooks/view/section_builder.rb', line 41 def (style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil, sku_id: nil) style = BUTTON_STYLES[style] || style emoji = case emoji when Integer, String emoji.to_i.positive? ? { id: emoji } : { name: emoji } else emoji&.to_h end @accessory = { type: COMPONENT_TYPES[:button], id: id, label: label, emoji: emoji, style: style, custom_id: custom_id, disabled: disabled, url: url, sku_id: sku_id }.compact end |
#text_display ⇒ Object
Add a text display component to this section.
18 19 20 |
# File 'lib/onyxcord/webhooks/view/section_builder.rb', line 18 def text_display(...) @components << TextDisplayBuilder.new(...) end |
#thumbnail(url:, id: nil, description: nil, spoiler: false) ⇒ Object
Set the thumbnail for the section. This is mutually exclusive with #button.
27 28 29 |
# File 'lib/onyxcord/webhooks/view/section_builder.rb', line 27 def thumbnail(url:, id: nil, description: nil, spoiler: false) @accessory = { type: COMPONENT_TYPES[:thumbnail], id: id, media: { url: }, description: description, spoiler: spoiler }.compact end |