Class: Discordrb::Permissions

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/permissions.rb

Overview

List of permissions Discord uses

Constant Summary collapse

Flags =

This hash maps bit positions to logical permissions. I'm not sure what the unlabeled bits are reserved for.

{
  # Bit => Permission # Value
  0 => :create_instant_invite, # 1
  1 => :kick_members,          # 2
  2 => :ban_members,           # 4
  3 => :manage_roles,          # 8, also Manage Permissions
  4 => :manage_channels,       # 16
  5 => :manage_server,         # 32
  # 6                          # 64
  # 7                          # 128
  # 8                          # 256
  # 9                          # 512
  10 => :read_messages,        # 1024
  11 => :send_messages,        # 2048
  12 => :send_tts_messages,    # 4096
  13 => :manage_messages,      # 8192
  14 => :embed_links,          # 16384
  15 => :attach_files,         # 32768
  16 => :read_message_history, # 65536
  17 => :mention_everyone,     # 131072
  # 18                         # 262144
  # 19                         # 524288
  20 => :connect,              # 1048576
  21 => :speak,                # 2097152
  22 => :mute_members,         # 4194304
  23 => :deafen_members,       # 8388608
  24 => :move_members,         # 16777216
  25 => :use_voice_activity    # 33554432
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bits = 0, writer = nil) ⇒ Permissions

Create a new Permissions object either as a blank slate to add permissions to (for example for Channel#define_overwrite) or from existing bit data to read out.

Parameters:

  • bits (Integer) (defaults to: 0)

    The permission bits that should be set from the beginning.

  • writer (RoleWriter) (defaults to: nil)

    The writer that should be used to update data when a permission is set.



74
75
76
77
78
# File 'lib/discordrb/permissions.rb', line 74

def initialize(bits = 0, writer = nil)
  @writer = writer
  @bits = bits
  init_vars
end

Instance Attribute Details

#bitsObject

Returns the value of attribute bits.



53
54
55
# File 'lib/discordrb/permissions.rb', line 53

def bits
  @bits
end

Instance Method Details

#init_varsObject

Initialize the instance variables based on the bitset.



63
64
65
66
67
68
# File 'lib/discordrb/permissions.rb', line 63

def init_vars
  Flags.each do |position, flag|
    flag_set = ((@bits >> position) & 0x1) == 1
    instance_variable_set "@#{flag}", flag_set
  end
end