Class: Discordrb::Webhooks::Modal::LabelBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/webhooks/modal.rb

Overview

This builder is used when adding a label component to a modal.

Constant Summary collapse

TEXT_INPUT_STYLES =

A mapping of text input styles to symbol names. short is a single line where paragraph is a block.

{
  short: 1,
  paragraph: 2
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(label: nil, id: nil, description: nil) {|builder| ... } ⇒ LabelBuilder

Create a label component.

Parameters:

  • label (String, nil) (defaults to: nil)

    The label of the label component. This field should always be passed, and will be required in 4.0.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the label component.

  • description (String, nil) (defaults to: nil)

    The description of the label component.

Yield Parameters:

  • builder (LabelBuilder)

    Yields the initialized label component.



87
88
89
90
91
92
93
# File 'lib/discordrb/webhooks/modal.rb', line 87

def initialize(label: nil, id: nil, description: nil)
  @id = id
  @label = label
  @description = description

  yield self if block_given?
end

Instance Method Details

#channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, types: nil) ⇒ Object

Add a select channel to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the channel select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • required (true, false, nil) (defaults to: nil)

    Whether a value must be selected for the component.

  • types (Array<Symbol, Integer>, nil) (defaults to: nil)

    The channel types to include in the select menu.



187
188
189
190
191
192
193
# File 'lib/discordrb/webhooks/modal.rb', line 187

def channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil, types: nil)
  builder = Discordrb::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :channel_select, id: id, required: required).to_h

  builder[:channel_types] = types.map { |type| Discordrb::Channel::TYPES[type] || type } if types

  @component = builder
end

#checkbox(custom_id:, id: nil, default: false) ⇒ Object

Add a standalone checkbox component to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the checkbox component. This is not to be confused with the custom_id.

  • default (true, false, nil) (defaults to: false)

    Whether or not the checkbox is checked by default.



211
212
213
# File 'lib/discordrb/webhooks/modal.rb', line 211

def checkbox(custom_id:, id: nil, default: false)
  @component = { type: COMPONENT_TYPES[:checkbox], custom_id: custom_id, id: id, default: default }.compact
end

#checkbox_group(custom_id:, id: nil, checkboxes: [], min_values: nil, max_values: nil, required: nil) {|builder| ... } ⇒ Object

Add a group of checkboxes to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the checkbox group component. This is not to be confused with the custom_id.

  • checkboxes (Array<Hash>) (defaults to: [])

    Checkboxes for the group. Can also be provided via the yielded builder.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum number of checkboxes a user must check.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum number of checkboxes a user is allowed to check.

  • required (true, false, nil) (defaults to: nil)

    Whether or not a checkbox must be checked.

Yields:

  • (builder)


237
238
239
240
241
242
243
# File 'lib/discordrb/webhooks/modal.rb', line 237

def checkbox_group(custom_id:, id: nil, checkboxes: [], min_values: nil, max_values: nil, required: nil)
  builder = GroupBuilder.new(:checkbox_group, custom_id, id, checkboxes, required, min_values, max_values)

  yield builder if block_given?

  @component = builder.to_h
end

#file_upload(custom_id:, id: nil, min_values: nil, max_values: nil, required: nil) ⇒ Object

Add a file upload component to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the file upload component. This is not to be confused with the custom_id.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of files a user must upload.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of files a user has to upload.

  • required (true, false, nil) (defaults to: nil)

    Whether or not a file must be uploaded to the component.



202
203
204
# File 'lib/discordrb/webhooks/modal.rb', line 202

def file_upload(custom_id:, id: nil, min_values: nil, max_values: nil, required: nil)
  @component = { type: COMPONENT_TYPES[:file_upload], custom_id: custom_id, id: id, min_values: min_values, max_values: max_values, required: required }.compact
end

#mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil) ⇒ Object

Add a select mentionable to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the mentionable select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • required (true, false, nil) (defaults to: nil)

    Whether a value must be selected for the component.



174
175
176
# File 'lib/discordrb/webhooks/modal.rb', line 174

def mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil)
  @component = Discordrb::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :mentionable_select, id: id, required: required).to_h
end

#radio_group(custom_id:, id: nil, buttons: [], required: nil) {|builder| ... } ⇒ Object

Add a group of radio buttons to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the radio group component. This is not to be confused with the custom_id.

  • buttons (Array<Hash>) (defaults to: [])

    Radio buttons for the group. Can also be provided via the yielded builder.

  • required (true, false, nil) (defaults to: nil)

    Whether or not a radio button in the group must be selected.

Yields:

  • (builder)


221
222
223
224
225
226
227
# File 'lib/discordrb/webhooks/modal.rb', line 221

def radio_group(custom_id:, id: nil, buttons: [], required: nil)
  builder = GroupBuilder.new(:radio_group, custom_id, id, buttons, required)

  yield builder if block_given?

  @component = builder.to_h
end

#role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil) ⇒ Object

Add a select role to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the role select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • required (true, false, nil) (defaults to: nil)

    Whether a value must be selected for the component.



162
163
164
# File 'lib/discordrb/webhooks/modal.rb', line 162

def role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil)
  @component = Discordrb::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :role_select, id: id, required: required).to_h
end

#string_select(custom_id:, id: nil, options: [], placeholder: nil, min_values: nil, max_values: nil, required: nil) {|builder| ... } ⇒ Object Also known as: select_menu

Add a string select menu to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the string select. This is not to be confused with the custom_id.

  • options (Array<Hash>) (defaults to: [])

    Options that can be selected in this menu. Can also be provided via the yielded builder.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • required (true, false, nil) (defaults to: nil)

    Whether a value must be selected for the component.

Yield Parameters:

  • builder (SelectMenuBuilder)

    The select menu builder is yielded to allow for the modification of attributes.



132
133
134
135
136
137
138
# File 'lib/discordrb/webhooks/modal.rb', line 132

def string_select(custom_id:, id: nil, options: [], placeholder: nil, min_values: nil, max_values: nil, required: nil)
  builder = Discordrb::Webhooks::View::SelectMenuBuilder.new(custom_id, options, placeholder, min_values, max_values, nil, select_type: :string_select, id: id, required: required)

  yield builder if block_given?

  @component = builder.to_h
end

#text_input(style:, custom_id:, id: nil, min_length: nil, max_length: nil, required: nil, value: nil, placeholder: nil, label: nil) ⇒ Object

Add a text input to the label component.

Parameters:

  • style (Symbol, Integer)

    The text input's style type. See TEXT_INPUT_STYLES

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer) (defaults to: nil)

    The integer ID for this component. This is not to be confused with custom_id.

  • min_length (Integer, nil) (defaults to: nil)

    The minimum input length for a text input, min 0, max 4000.

  • max_length (Integer, nil) (defaults to: nil)

    The maximum input length for a text input, min 1, max 4000.

  • required (true, false, nil) (defaults to: nil)

    Whether this component is required to be filled, default true.

  • value (String, nil) (defaults to: nil)

    A pre-filled value for this component, max 4000 characters.

  • placeholder (String, nil) (defaults to: nil)

    Custom placeholder text if the input is empty, max 100 characters

  • label (String, nil) (defaults to: nil)

    This parameter is deprecated and will be removed soon. Please pass this argument to #initialize instead.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/discordrb/webhooks/modal.rb', line 106

def text_input(style:, custom_id:, id: nil, min_length: nil, max_length: nil, required: nil, value: nil, placeholder: nil, label: nil)
  @label = label unless label.nil?

  @component = {
    id: id,
    style: TEXT_INPUT_STYLES[style] || style,
    custom_id: custom_id,
    type: COMPONENT_TYPES[:text_input],
    min_length: min_length,
    max_length: max_length,
    required: required,
    value: value,
    placeholder: placeholder
  }.compact
end

#user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil) ⇒ Object

Add a select user to the label component.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the user select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • required (true, false, nil) (defaults to: nil)

    Whether a value must be selected for the component.



150
151
152
# File 'lib/discordrb/webhooks/modal.rb', line 150

def user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, required: nil)
  @component = Discordrb::Webhooks::View::SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, nil, select_type: :user_select, id: id, required: required).to_h
end