Class: Discordrb::Role

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

Overview

A Discord role that contains permissions and applies to certain users

Defined Under Namespace

Classes: RoleWriter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, bot, server = nil) ⇒ Role

Returns a new instance of Role.



197
198
199
200
201
202
203
204
205
# File 'lib/discordrb/data.rb', line 197

def initialize(data, bot, server = nil)
  @bot = bot
  @server = server
  @permissions = Permissions.new(data['permissions'], RoleWriter.new(self, @bot.token))
  @name = data['name']
  @id = data['id'].to_i
  @hoist = data['hoist']
  @colour = ColourRGB.new(data['color'])
end

Instance Attribute Details

#colourObject Also known as: color

Returns the value of attribute colour.



182
183
184
# File 'lib/discordrb/data.rb', line 182

def colour
  @colour
end

#hoistObject

Returns the value of attribute hoist.



182
183
184
# File 'lib/discordrb/data.rb', line 182

def hoist
  @hoist
end

#idObject (readonly)

Returns the value of attribute id.



182
183
184
# File 'lib/discordrb/data.rb', line 182

def id
  @id
end

#nameObject

Returns the value of attribute name.



182
183
184
# File 'lib/discordrb/data.rb', line 182

def name
  @name
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



182
183
184
# File 'lib/discordrb/data.rb', line 182

def permissions
  @permissions
end

Instance Method Details

#deleteObject



240
241
242
243
# File 'lib/discordrb/data.rb', line 240

def delete
  API.delete_role(@bot.token, @server.id, @id)
  @server.delete_role(@id)
end

#packed=(packed, update_perms = true) ⇒ Object



235
236
237
238
# File 'lib/discordrb/data.rb', line 235

def packed=(packed, update_perms = true)
  update_role_data(permissions: packed)
  @permissions.bits = packed if update_perms
end

#update_data(new_data) ⇒ Object



214
215
216
217
218
219
# File 'lib/discordrb/data.rb', line 214

def update_data(new_data)
  @name = new_data[:name] || new_data['name'] || @name
  @hoist = new_data['hoist'] unless new_data['hoist'].nil?
  @hoist = new_data[:hoist] unless new_data[:hoist].nil?
  @colour = new_data[:colour] || (new_data['color'] ? ColourRGB.new(new_data['color']) : @colour)
end

#update_from(other) ⇒ Object



207
208
209
210
211
212
# File 'lib/discordrb/data.rb', line 207

def update_from(other)
  @permissions = other.permissions
  @name = other.name
  @hoist = other.hoist
  @colour = other.colour
end