Class: OnyxCord::Webhooks::View::RowBuilder
- Inherits:
-
Object
- Object
- OnyxCord::Webhooks::View::RowBuilder
- Defined in:
- lib/onyxcord/webhooks/view.rb
Overview
This builder is used when constructing an ActionRow. Button and select menu components must be within an action row, but this can change in the future. A message can have 10 action rows, each action row can hold a weight of 5. Buttons have a weight of 1, and dropdowns have a weight of 5.
Instance Method Summary collapse
-
#button(style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil, sku_id: nil) ⇒ Object
Add a button to this action row.
-
#channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, types: nil, default_values: nil) ⇒ Object
Add a channel select to this action row.
-
#mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) ⇒ Object
Add a mentionable select to this action row.
-
#role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) ⇒ Object
Add a role select to this action row.
-
#string_select(custom_id:, options: [], id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil) {|builder| ... } ⇒ Object
(also: #select_menu)
Add a string select to this action row.
-
#user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) ⇒ Object
Add a user select to this action row.
Instance Method Details
#button(style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil, sku_id: nil) ⇒ Object
Add a button to this action row.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/onyxcord/webhooks/view.rb', line 73 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 @components << { 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 |
#channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, types: nil, default_values: nil) ⇒ Object
Add a channel select to this action row.
155 156 157 158 159 160 161 |
# File 'lib/onyxcord/webhooks/view.rb', line 155 def channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, types: nil, default_values: nil) builder = SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :channel_select, id: id, default_values: default_values).to_h builder[:channel_types] = types.map { |type| OnyxCord::Channel::TYPES[type] || type } if types @components << builder end |
#mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) ⇒ Object
Add a mentionable select to this action row.
141 142 143 |
# File 'lib/onyxcord/webhooks/view.rb', line 141 def mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) @components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :mentionable_select, id: id, default_values: default_values).to_h end |
#role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) ⇒ Object
Add a role select to this action row.
128 129 130 |
# File 'lib/onyxcord/webhooks/view.rb', line 128 def role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) @components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :role_select, id: id, default_values: default_values).to_h end |
#string_select(custom_id:, options: [], id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil) {|builder| ... } ⇒ Object Also known as:
Add a string select to this action row.
96 97 98 99 100 101 102 |
# File 'lib/onyxcord/webhooks/view.rb', line 96 def string_select(custom_id:, options: [], id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil) builder = SelectMenuBuilder.new(custom_id, , placeholder, min_values, max_values, disabled, select_type: :string_select, id: id) yield builder if block_given? @components << builder.to_h end |
#user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) ⇒ Object
Add a user select to this action row.
115 116 117 |
# File 'lib/onyxcord/webhooks/view.rb', line 115 def user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, default_values: nil) @components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :user_select, id: id, default_values: default_values).to_h end |