Sha256: 1808867e35d0b37d81d0606ae387a1c547b1fc309f4595f400382f08c05a86fc

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

module Discorb
  #
  # Represents a button component.
  class Button < Discorb::Component
    STYLES: untyped

    #
    # Initialize a new button.
    #
    # @param [String] label The label of the button.
    # @param [:primary, :secondary, :success, :danger, :link] style The style of the button.
    # @param [Discorb::emoji] emoji The emoji of the button.
    # @param [String] custom_id The custom ID of the button.
    # @param [String] url The URL of the button.
    # @param [Boolean] disabled Whether the button is disabled.
    def initialize: (
      String label,
      ?Symbol style,
      ?emoji: Discorb::emoji?,
      ?custom_id: String?,
      ?url: String?,
      ?disabled: bool
    ) -> void

    #
    # Converts the button to a hash.
    #
    # @see https://discord.com/developers/docs/interactions/message-components#button-object-button-structure
    #  Official Discord API docs
    # @return [Hash] A hash representation of the button.
    %a{pure}
    def to_hash: -> Discorb::json

    %a{pure}
    def inspect: -> String

    #
    # Creates a new button from a hash.
    #
    # @param [Hash] data The hash to create the button from.
    #
    # @return [Discorb::Button] The created button.
    def self.from_hash: (Discorb::json data) -> Discorb::Button

    # @return [String] The label of the button.
    attr_accessor label: String

    # @return [:primary, :secondary, :success, :danger, :link] The style of the button.
    attr_accessor style: Symbol

    # @return [Discorb::emoji] The emoji of the button.
    attr_accessor emoji: Discorb::emoji?

    # @return [String] The custom ID of the button.
    #   Won't be used if the style is `:link`.
    attr_accessor custom_id: String?

    # @return [String] The URL of the button.
    #   Only used when the style is `:link`.
    attr_accessor url: String?

    # @return [Boolean] Whether the button is disabled.
    attr_accessor disabled: bool

    alias disabled? disabled
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
discorb-0.20.0 sig/discorb/component/button.rbs
discorb-0.19.0 sig/discorb/component/button.rbs