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
- #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.
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
#colour ⇒ Object Also known as: color
Returns the value of attribute colour.
182 183 184 |
# File 'lib/discordrb/data.rb', line 182 def colour @colour end |
#hoist ⇒ Object
Returns the value of attribute hoist.
182 183 184 |
# File 'lib/discordrb/data.rb', line 182 def hoist @hoist end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
182 183 184 |
# File 'lib/discordrb/data.rb', line 182 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
182 183 184 |
# File 'lib/discordrb/data.rb', line 182 def name @name end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
182 183 184 |
# File 'lib/discordrb/data.rb', line 182 def @permissions end |
Instance Method Details
#delete ⇒ Object
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. @name = other.name @hoist = other.hoist @colour = other.colour end |