Class: OnyxCord::Components::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/onyxcord/models/component.rb

Overview

An interactable button component.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#custom_idString (readonly)

Returns the custom ID of the button.

Returns:

  • (String)

    the custom ID of the button.



101
102
103
# File 'lib/onyxcord/models/component.rb', line 101

def custom_id
  @custom_id
end

#disabledtrue, false (readonly)

Returns whether or not the button is disabled.

Returns:

  • (true, false)

    whether or not the button is disabled.



104
105
106
# File 'lib/onyxcord/models/component.rb', line 104

def disabled
  @disabled
end

#emojiEmoji? (readonly)

Returns the custom emoji of the button component.

Returns:

  • (Emoji, nil)

    the custom emoji of the button component.



113
114
115
# File 'lib/onyxcord/models/component.rb', line 113

def emoji
  @emoji
end

#idInteger (readonly)

Returns the numeric identifier of the button.

Returns:

  • (Integer)

    the numeric identifier of the button.



92
93
94
# File 'lib/onyxcord/models/component.rb', line 92

def id
  @id
end

#labelString (readonly)

Returns the label of the button.

Returns:

  • (String)

    the label of the button.



95
96
97
# File 'lib/onyxcord/models/component.rb', line 95

def label
  @label
end

#sku_idInteger? (readonly)

Returns the SKU ID of the button if it is a premium button.

Returns:

  • (Integer, nil)

    the SKU ID of the button if it is a premium button.



110
111
112
# File 'lib/onyxcord/models/component.rb', line 110

def sku_id
  @sku_id
end

#styleInteger (readonly)

Returns the style of the button.

Returns:

  • (Integer)

    the style of the button.



98
99
100
# File 'lib/onyxcord/models/component.rb', line 98

def style
  @style
end

#urlString? (readonly)

Returns the URL of the button if applicable.

Returns:

  • (String, nil)

    the URL of the button if applicable.



107
108
109
# File 'lib/onyxcord/models/component.rb', line 107

def url
  @url
end

Instance Method Details

#await_click(key, **attributes, &block) ⇒ Object

Await a button click.



147
148
149
# File 'lib/onyxcord/models/component.rb', line 147

def await_click(key, **attributes, &block)
  @bot.add_await(key, OnyxCord::Events::ButtonEvent, { custom_id: @custom_id }.merge!(attributes), &block)
end

#await_click!(**attributes, &block) ⇒ Object

Await a button click, blocking.



152
153
154
# File 'lib/onyxcord/models/component.rb', line 152

def await_click!(**attributes, &block)
  @bot.add_await!(OnyxCord::Events::ButtonEvent, { custom_id: @custom_id }.merge!(attributes), &block)
end

#danger?true, false

Returns whether the button denotes a dangerous action in the group.

Returns:

  • (true, false)

    whether the button denotes a dangerous action in the group.



140
141
142
143
144
# File 'lib/onyxcord/models/component.rb', line 140

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#link?true, false

Returns whether the button is a container for a URL that will open upon click.

Returns:

  • (true, false)

    whether the button is a container for a URL that will open upon click.



140
141
142
143
144
# File 'lib/onyxcord/models/component.rb', line 140

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#premium?true, false

Returns whether the button starts a premium SKU purchase.

Returns:

  • (true, false)

    whether the button starts a premium SKU purchase.



140
141
142
143
144
# File 'lib/onyxcord/models/component.rb', line 140

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#primary?true, false

Returns whether the button is a primary option in the group.

Returns:

  • (true, false)

    whether the button is a primary option in the group.



140
141
142
143
144
# File 'lib/onyxcord/models/component.rb', line 140

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#secondary?true, false

Returns whether the button denotes a secondary option in the group.

Returns:

  • (true, false)

    whether the button denotes a secondary option in the group.



140
141
142
143
144
# File 'lib/onyxcord/models/component.rb', line 140

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#success?true, false

Returns whether the button denotes a success action in the group.

Returns:

  • (true, false)

    whether the button denotes a success action in the group.



140
141
142
143
144
# File 'lib/onyxcord/models/component.rb', line 140

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end