discorb-lib/discorb

View on GitHub
sig/discorb/permissions.rbs

Summary

Maintainability
Test Coverage
module Discorb
  #
  # Represents a permission per guild.
  # ## Flag fields
  #
  # | Field | Value |
  # |-------|-------|
  # |`1 << 0`|`:create_instant_invite`|
  # |`1 << 1`|`:kick_members`|
  # |`1 << 2`|`:ban_members`|
  # |`1 << 3`|`:administrator`|
  # |`1 << 4`|`:manage_channels`|
  # |`1 << 5`|`:manage_guild`|
  # |`1 << 6`|`:add_reactions`|
  # |`1 << 7`|`:view_audit_log`|
  # |`1 << 8`|`:priority_speaker`|
  # |`1 << 9`|`:stream`|
  # |`1 << 10`|`:view_channel`|
  # |`1 << 11`|`:send_messages`|
  # |`1 << 12`|`:send_tts_messages`|
  # |`1 << 13`|`:manage_messages`|
  # |`1 << 14`|`:embed_links`|
  # |`1 << 15`|`:attach_files`|
  # |`1 << 16`|`:read_message_history`|
  # |`1 << 17`|`:mention_everyone`|
  # |`1 << 18`|`:use_external_emojis`|
  # |`1 << 19`|`:view_guild_insights`|
  # |`1 << 20`|`:connect`|
  # |`1 << 21`|`:speak`|
  # |`1 << 22`|`:mute_members`|
  # |`1 << 23`|`:deafen_members`|
  # |`1 << 24`|`:move_members`|
  # |`1 << 25`|`:use_vad`|
  # |`1 << 26`|`:change_nickname`|
  # |`1 << 27`|`:manage_nicknames`|
  # |`1 << 28`|`:manage_roles`|
  # |`1 << 29`|`:manage_webhooks`|
  # |`1 << 30`|`:manage_emojis`|
  # |`1 << 31`|`:use_slash_commands`|
  # |`1 << 32`|`:request_to_speak`|
  # |`1 << 34`|`:manage_threads`|
  # |`1 << 35`|`:use_public_threads`|
  # |`1 << 36`|`:use_private_threads`|
  class Permission < Discorb::Flag
    attr_accessor create_instant_invite: bool
    attr_accessor kick_members: bool
    attr_accessor ban_members: bool
    attr_accessor administrator: bool
    attr_accessor manage_channels: bool
    attr_accessor manage_guild: bool
    attr_accessor add_reactions: bool
    attr_accessor view_audit_log: bool
    attr_accessor priority_speaker: bool
    attr_accessor stream: bool
    attr_accessor view_channel: bool
    attr_accessor send_messages: bool
    attr_accessor send_tts_messages: bool
    attr_accessor manage_messages: bool
    attr_accessor embed_links: bool
    attr_accessor attach_files: bool
    attr_accessor read_message_history: bool
    attr_accessor mention_everyone: bool
    attr_accessor use_external_emojis: bool
    attr_accessor view_guild_insights: bool
    attr_accessor connect: bool
    attr_accessor speak: bool
    attr_accessor mute_members: bool
    attr_accessor deafen_members: bool
    attr_accessor move_members: bool
    attr_accessor use_vad: bool
    attr_accessor change_nickname: bool
    attr_accessor manage_nicknames: bool
    attr_accessor manage_roles: bool
    attr_accessor manage_webhooks: bool
    attr_accessor manage_emojis: bool
    attr_accessor use_slash_commands: bool
    attr_accessor request_to_speak: bool
    attr_accessor manage_threads: bool
    attr_accessor use_public_threads: bool
    attr_accessor use_private_threads: bool
  end

  #
  # Represents a permission per channel.
  class PermissionOverwrite
    #
    # Initializes a new PermissionOverwrite.
    # @private
    #
    # @param allow [Integer] The allowed permissions.
    # @param deny [Integer] The denied permissions.
    def initialize: (Integer allow, Integer deny) -> void

    %a{pure}
    def allow: -> Discorb::Permission

    %a{pure}
    def deny: -> Discorb::Permission

    %a{pure}
    def allow_value: -> Integer

    %a{pure}
    def deny_value: -> Integer

    %a{pure}
    def inspect: -> String

    #
    # Converts the permission overwrite to a hash.
    #
    # @return [Hash] The permission overwrite as a hash.
    %a{pure}
    def to_hash: -> Hash[Symbol, bool]

    #
    # Union of the permission overwrites.
    #
    # @param [Discorb::PermissionOverwrite] other The other permission overwrite.
    #
    # @return [Discorb::PermissionOverwrite] The union of the permission overwrites.
    def +: (Discorb::PermissionOverwrite other) -> Discorb::PermissionOverwrite

    #
    # Returns whether overwrite of the given field.
    #
    # @param [Symbol] field The field to check.
    #
    # @return [true, false, nil] Whether the field is allowed, denied or not set.
    %a{pure}
    def []: (Symbol field) -> bool?

    #
    # Sets the given field to the given value.
    #
    # @param [Symbol] key The field to set.
    # @param [Boolean] bool The value to set.
    def []=: (Symbol key, bool `bool`) -> untyped

    #
    # Returns the value of the flag.
    def method_missing: (untyped method, ?untyped `bool`) -> untyped

    def respond_to_missing?: (untyped method, untyped _arg) -> bool

    #
    # Initializes a permission overwrite from a hash.
    #
    # @param [Hash] hash The hash to initialize the permission overwrite from.
    #
    # @return [Discorb::PermissionOverwrite] The permission overwrite.
    def self.from_hash: (
      ::Hash[Symbol, bool] hash
    ) -> Discorb::PermissionOverwrite
  end
end