Class: Discordrb::Role
- Inherits:
-
Object
- Object
- Discordrb::Role
- 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
-
#colour ⇒ Object
(also: #color)
Returns the value of attribute colour.
-
#hoist ⇒ Object
Returns the value of attribute hoist.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
Instance Method Summary collapse
-
#==(other) ⇒ Object
ID based comparison.
- #delete ⇒ Object
-
#initialize(data, bot, server = nil) ⇒ Role
constructor
A new instance of Role.
- #packed=(packed, update_perms = true) ⇒ Object
- #update_data(new_data) ⇒ Object
- #update_from(other) ⇒ Object
Constructor Details
#initialize(data, bot, server = nil) ⇒ Role
Returns a new instance of Role.
225 226 227 228 229 230 231 232 233 |
# File 'lib/discordrb/data.rb', line 225 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
#colour ⇒ Object Also known as: color
Returns the value of attribute colour.
210 211 212 |
# File 'lib/discordrb/data.rb', line 210 def colour @colour end |
#hoist ⇒ Object
Returns the value of attribute hoist.
210 211 212 |
# File 'lib/discordrb/data.rb', line 210 def hoist @hoist end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
210 211 212 |
# File 'lib/discordrb/data.rb', line 210 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
210 211 212 |
# File 'lib/discordrb/data.rb', line 210 def name @name end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
210 211 212 |
# File 'lib/discordrb/data.rb', line 210 def @permissions end |
Instance Method Details
#==(other) ⇒ Object
ID based comparison
236 237 238 |
# File 'lib/discordrb/data.rb', line 236 def ==(other) Discordrb.id_compare(@id, other) end |
#delete ⇒ Object
273 274 275 276 |
# File 'lib/discordrb/data.rb', line 273 def delete API.delete_role(@bot.token, @server.id, @id) @server.delete_role(@id) end |
#packed=(packed, update_perms = true) ⇒ Object
268 269 270 271 |
# File 'lib/discordrb/data.rb', line 268 def packed=(packed, update_perms = true) update_role_data(permissions: packed) @permissions.bits = packed if update_perms end |
#update_data(new_data) ⇒ Object
247 248 249 250 251 252 |
# File 'lib/discordrb/data.rb', line 247 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
240 241 242 243 244 245 |
# File 'lib/discordrb/data.rb', line 240 def update_from(other) @permissions = other. @name = other.name @hoist = other.hoist @colour = other.colour end |