discorb-lib/discorb

View on GitHub
sig/discorb/interaction/message_component.rbs

Summary

Maintainability
Test Coverage
module Discorb
  #
  # Represents a message component interaction.
  # @abstract
  class MessageComponentInteraction < Discorb::Interaction
    include Discorb::Interaction::SourceResponder
    include Discorb::Interaction::UpdateResponder
    include Discorb::Interaction::ModalResponder

    #
    # Initialize a new message component interaction.
    # @private
    #
    # @param [Discorb::Client] client The client.
    # @param [Hash] data The data.
    def initialize: (Discorb::Client client, Discorb::json data) -> void

    #
    # Create a MessageComponentInteraction instance for the given data.
    # @private
    def self.make_interaction: (untyped client, untyped data) -> untyped

    #
    # Returns the classes under this class.
    # @private
    def self.nested_classes: -> untyped

    #
    # Response with `MODAL`(`9`).
    #
    # @param [String] title The title of the modal.
    # @param [String] custom_id The custom id of the modal.
    # @param [Array<Discorb::TextInput>] components The text inputs to send.
    #
    # @return [Async::Task<void>] The task.
    def show_modal: (
      String title,
      String custom_id,
      ::Array[Discorb::TextInput] components
    ) -> Async::Task[void]

    #
    # Response with `DEFERRED_UPDATE_MESSAGE`(`6`).
    # @async
    #
    # @param [Boolean] ephemeral Whether to make the response ephemeral.
    #
    # @return [Async::Task<void>] The task.
    def defer_update: (?ephemeral: bool) -> Async::Task[void]

    #
    # Response with `UPDATE_MESSAGE`(`7`).
    #
    # @async
    #
    # @param [String] content The content of the response.
    # @param [Boolean] tts Whether to send the message as text-to-speech.
    # @param [Discorb::Embed] embed The embed to send.
    # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
    # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
    # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
    # @param [Boolean] ephemeral Whether to make the response ephemeral.
    #
    # @return [Async::Task<void>] The task.
    def edit: (
      String content,
      ?tts: bool,
      ?embed: Discorb::Embed?,
      ?embeds: ::Array[Discorb::Embed]?,
      ?allowed_mentions: Discorb::AllowedMentions?,
      ?components: (::Array[Discorb::Component]
      | ::Array[::Array[Discorb::Component]])?,
      ?ephemeral: bool
    ) -> Async::Task[void]

    #
    # Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
    #
    # @async
    #
    # @param [Boolean] ephemeral Whether to make the response ephemeral.
    #
    # @return [Async::Task<void>] The task.
    def defer_source: (?ephemeral: bool) -> Async::Task[void]

    #
    # Response with `CHANNEL_MESSAGE_WITH_SOURCE`(`4`).
    #
    # @async
    #
    # @param [String] content The content of the response.
    # @param [Boolean] tts Whether to send the message as text-to-speech.
    # @param [Discorb::Embed] embed The embed to send.
    # @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10)
    # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
    # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
    # @param [Boolean] ephemeral Whether to make the response ephemeral.
    #
    # @return [Discorb::Interaction::SourceResponder::CallbackMessage, Discorb::Webhook::Message]
    #   The callback message.
    def post: (
      ?String? content,
      ?tts: bool,
      ?embed: Discorb::Embed?,
      ?embeds: ::Array[Discorb::Embed]?,
      ?allowed_mentions: Discorb::AllowedMentions?,
      ?components: (::Array[Discorb::Component]
      | ::Array[::Array[Discorb::Component]])?,
      ?ephemeral: bool
    ) -> (Discorb::Interaction::CallbackMessage | Discorb::Webhook::Message)

    # @return [String] The content of the response.
    attr_reader custom_id: String

    # @return [Discorb::Message] The target message.
    attr_reader message: Discorb::Message

    #
    # Represents a button interaction.
    class Button < Discorb::MessageComponentInteraction
      # @return [String] The custom id of the button.
      attr_reader custom_id: String
    end

    #
    # Represents a select menu interaction.
    class SelectMenu < Discorb::MessageComponentInteraction
      # @return [String] The custom id of the select menu.
      attr_reader custom_id: String

      # @return [Array<String>] The selected options.
      attr_reader values: ::Array[String]

      # @!attribute [r] value
      #   @return [String] The first selected value.
      attr_reader value: untyped
    end
  end
end