discorb-lib/discorb

View on GitHub
sig/discorb/automod.rbs

Summary

Maintainability
Test Coverage
module Discorb
  class AutoModRule < DiscordModel
    type trigger_type =
      :keyword | :harmful_link | :spam | :keyword_preset | :mention_spam
    type preset_type = :profanity | :sexual_content | :slurs

    # @return [Hash{Integer => Symbol}] The mapping of trigger types.
    # @private
    TRIGGER_TYPES: Hash[Integer, trigger_type]

    # @return [Hash{Integer => Symbol}] The mapping of preset types.
    # @private
    PRESET_TYPES: Hash[Integer, preset_type]

    # @return [Hash{Integer => Symbol}] The mapping of event types.
    # @private
    EVENT_TYPES: Hash[Integer, :message_send]

    # @return [Discorb::Snowflake] The ID of the rule.
    attr_reader id: Discorb::Snowflake

    # @return [String] The name of the rule.
    attr_reader name: String

    # @return [Boolean] Whether the rule is enabled.
    attr_reader enabled: bool
    alias enabled? enabled

    # @return [Array<Discorb::AutoModRule::Action>] The actions of the rule.
    attr_reader actions: Array[Discorb::AutoModRule::Action]

    # @return [Array<String>] Substrings which will be exempt from triggering the preset trigger type.
    # @note This is only available if the trigger type is `:keyword_preset`.
    attr_reader allow_list: Array[String]?

    # @return [Array<String>] The keywords that the rule is triggered by.
    # @note This is only available if the trigger type is `:keyword`.
    attr_reader keyword_filter: Array[String]?

    # @return [Integer] Total number of mentions allowed per message.
    # @note This is only available if the trigger type is `:mention_spam`.
    attr_reader mention_total_limit: Integer?

    # @return [Symbol] Returns the type of the preset.
    # @note This is only available if the trigger type is `:keyword_preset`.
    %a{pure}
    def preset_type: -> preset_type

    # @return [Symbol] Returns the type of the trigger.
    %a{pure}
    def trigger_type: -> trigger_type

    # @return [Symbol] Returns the type of the event.
    %a{pure}
    def event_type: -> :message_send

    %a{pure}
    def creator: -> Discorb::Member

    %a{pure}
    def guild: -> Discorb::Guild

    %a{pure}
    def exempt_roles: -> Array[Discorb::Role]

    %a{pure}
    def exempt_channels: -> Array[Discorb::Channel]

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

    #
    # Edit the rule.
    # @async
    # @edit
    #
    # @param [String] name The name of the rule.
    # @param [Symbol] event_type The event type of the rule. See {Discorb::AutoModRule::EVENT_TYPES}.
    # @param [Array<Discorb::AutoModRule::Action>] actions The actions of the rule.
    # @param [Boolean] enabled Whether the rule is enabled or not.
    # @param [Array<Discorb::Role>] exempt_roles The roles that are exempt from the rule.
    # @param [Array<Discorb::Channel>] exempt_channels The channels that are exempt from the rule.
    # @param [Array<String>] keyword_filter The keywords to filter.
    # @param [Symbol] presets The preset of the rule. See {Discorb::AutoModRule::PRESET_TYPES}.
    # @param [String] reason The reason for creating the rule.
    #
    # @return [Async::Task<void>] The task.
    def edit: (
      ?name: String,
      ?event_type: :message_send,
      ?actions: Array[Discorb::AutoModRule::Action],
      ?enabled: bool,
      ?exempt_roles: Array[Discorb::Role],
      ?exempt_channels: Array[Discorb::Channel],
      ?keyword_filter: Array[String]?,
      ?presets: :profanity | :sexual_content | :slurs,
      ?reason: nil
    ) -> Async::Task[void]

    #
    # Delete the rule.
    #
    # @param [String] reason The reason for deleting the rule.
    #
    # @return [Async::Task<void>] The task.
    def delete: (?reason: nil) -> Async::Task[void]

    class Action < Discorb::DiscordModel
      type action_type = :ban | :kick | :mute | :warn

      # @return [Hash{Integer => Symbol}] The mapping of action types.
      # @private
      ACTION_TYPES: Hash[Integer, action_type]

      # @return [Symbol] Returns the type of the action.
      attr_reader type: action_type

      # @return [Integer] The duration of the timeout.
      # @note This is only available if the action type is `:timeout`.
      attr_reader duration_seconds: Integer?

      #
      # Convert the action to hash.
      #
      # @return [Hash] The action hash.
      %a{pure}
      def to_hash: -> Discorb::json

      #
      # Initialize a new action.
      #
      # @param [Symbol] type The type of the action.
      # @param [Integer] duration_seconds The duration of the timeout.
      #   This is only available if the action type is `:timeout`.
      # @param [Discorb::Channel] channel The channel that the alert message is sent to.
      #   This is only available if the action type is `:send_alert_message`.
      def initialize: (
        action_type `type`,
        ?duration_seconds: Integer?,
        ?channel: Discorb::Channel?
      ) -> void

      # @return [Discorb::Channel] The channel that the alert message is sent to.
      # @note This is only available if the action type is `:send_alert_message`.
      %a{pure}
      def channel: -> Discorb::Channel?
    end
  end
end