class Discordrb::Overwrite

A permissions overwrite, when applied to channels describes additional permissions a member needs to perform certain actions in context.

Attributes

allow[RW]

@return [Permissions] allowed permissions for this overwrite type

deny[RW]

@return [Permissions] denied permissions for this overwrite type

id[RW]

@return [Integer] id of the thing associated with this overwrite type

type[RW]

@return [Symbol] either :role or :member

Public Class Methods

from_hash(data) click to toggle source

@return [Overwrite] create an overwrite from a hash payload @!visibility private

# File lib/discordrb/data.rb, line 1268
def self.from_hash(data)
  new(
    data['id'].to_i,
    type: data['type'],
    allow: Permissions.new(data['allow']),
    deny: Permissions.new(data['deny'])
  )
end
from_other(other) click to toggle source

@return [Overwrite] copies an overwrite from another Overwrite @!visibility private

# File lib/discordrb/data.rb, line 1279
def self.from_other(other)
  new(
    other.id,
    type: other.type,
    allow: Permissions.new(other.allow.bits),
    deny: Permissions.new(other.deny.bits)
  )
end
new(object = nil, type: nil, allow: 0, deny: 0) click to toggle source

Creates a new Overwrite object @example Create an overwrite for a role that can mention everyone, send TTS messages, but can't create instant invites

allow = Discordrb::Permissions.new
allow.can_mention_everyone = true
allow.can_send_tts_messages = true

deny = Discordrb::Permissions.new
deny.can_create_instant_invite = true

# Find some role by name
role = server.roles.find { |r| r.name == 'some role' }

Overwrite.new(role, allow: allow, deny: deny)

@example Create an overwrite by ID and permissions bits

Overwrite.new(120571255635181568, type: 'member', allow: 1024, deny: 0)

@param object [Integer, id] the ID or object this overwrite is for @param type [String] the type of object this overwrite is for (only required if object is an Integer) @param allow [Integer, Permissions] allowed permissions for this overwrite, by bits or a Permissions object @param deny [Integer, Permissions] denied permissions for this overwrite, by bits or a Permissions object @raise [ArgumentError] if type is not :member or :role

# File lib/discordrb/data.rb, line 1237
def initialize(object = nil, type: nil, allow: 0, deny: 0)
  if type
    type = type.to_sym
    raise ArgumentError, 'Overwrite type must be :member or :role' unless (type != :member) || (type != :role)
  end

  @id = object.respond_to?(:id) ? object.id : object

  @type = if object.is_a?(User) || object.is_a?(Member) || object.is_a?(Recipient) || object.is_a?(Profile)
            :member
          elsif object.is_a? Role
            :role
          else
            type
          end

  @allow = allow.is_a?(Permissions) ? allow : Permissions.new(allow)
  @deny = deny.is_a?(Permissions) ? deny : Permissions.new(deny)
end

Public Instance Methods

==(other) click to toggle source

Comparison by attributes [:id, :type, :allow, :deny]

# File lib/discordrb/data.rb, line 1258
def ==(other)
  false unless other.is_a? Discordrb::Overwrite
  id == other.id &&
    type == other.type &&
    allow == other.allow &&
    deny == other.deny
end
to_hash() click to toggle source

@return [Hash] hash representation of an overwrite @!visibility private

# File lib/discordrb/data.rb, line 1290
def to_hash
  {
    id: id,
    type: type,
    allow: allow.bits,
    deny: deny.bits
  }
end