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.



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

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.



184
185
186
# File 'lib/discordrb/data.rb', line 184

def colour
  @colour
end

#hoistObject

Returns the value of attribute hoist.



184
185
186
# File 'lib/discordrb/data.rb', line 184

def hoist
  @hoist
end

#idObject (readonly)

Returns the value of attribute id.



184
185
186
# File 'lib/discordrb/data.rb', line 184

def id
  @id
end

#nameObject

Returns the value of attribute name.



184
185
186
# File 'lib/discordrb/data.rb', line 184

def name
  @name
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



184
185
186
# File 'lib/discordrb/data.rb', line 184

def permissions
  @permissions
end

Instance Method Details

#deleteObject



242
243
244
245
# File 'lib/discordrb/data.rb', line 242

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

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



237
238
239
240
# File 'lib/discordrb/data.rb', line 237

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

#update_data(new_data) ⇒ Object



216
217
218
219
220
221
# File 'lib/discordrb/data.rb', line 216

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



209
210
211
212
213
214
# File 'lib/discordrb/data.rb', line 209

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