Class: MijDiscord::Data::Role
- Inherits:
-
Object
- Object
- MijDiscord::Data::Role
- Includes:
- IDObject
- Defined in:
- lib/mij-discord/data/role.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#hoist ⇒ Object
readonly
Returns the value of attribute hoist.
-
#managed ⇒ Object
(also: #managed?)
readonly
Returns the value of attribute managed.
-
#mentionable ⇒ Object
(also: #mentionable?)
readonly
Returns the value of attribute mentionable.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Attributes included from IDObject
Instance Method Summary collapse
- #delete(reason = nil) ⇒ Object
-
#initialize(data, server, bot) ⇒ Role
constructor
A new instance of Role.
- #members ⇒ Object (also: #users)
- #mention ⇒ Object (also: #to_s)
- #set_color(color) ⇒ Object (also: #color=)
- #set_hoist(flag) ⇒ Object (also: #hoist=)
- #set_mentionable(flag) ⇒ Object (also: #mentionable=)
- #set_name(name) ⇒ Object (also: #name=)
- #set_options(name: nil, color: nil, hoist: nil, mentionable: nil, permissions: nil) ⇒ Object
- #update_data(data) ⇒ Object
Methods included from IDObject
#==, #creation_time, #hash, synthesize
Constructor Details
#initialize(data, server, bot) ⇒ Role
Returns a new instance of Role.
23 24 25 26 27 28 29 30 31 |
# File 'lib/mij-discord/data/role.rb', line 23 def initialize(data, server, bot) @bot, @server = bot, server = Permissions.new @color = ColorRGB.new @id = data['id'].to_i update_data(data) end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
19 20 21 |
# File 'lib/mij-discord/data/role.rb', line 19 def color @color end |
#hoist ⇒ Object (readonly)
Returns the value of attribute hoist.
11 12 13 |
# File 'lib/mij-discord/data/role.rb', line 11 def hoist @hoist end |
#managed ⇒ Object (readonly) Also known as: managed?
Returns the value of attribute managed.
13 14 15 |
# File 'lib/mij-discord/data/role.rb', line 13 def managed @managed end |
#mentionable ⇒ Object (readonly) Also known as: mentionable?
Returns the value of attribute mentionable.
16 17 18 |
# File 'lib/mij-discord/data/role.rb', line 16 def mentionable @mentionable end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/mij-discord/data/role.rb', line 9 def name @name end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
7 8 9 |
# File 'lib/mij-discord/data/role.rb', line 7 def end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
21 22 23 |
# File 'lib/mij-discord/data/role.rb', line 21 def position @position end |
Instance Method Details
#delete(reason = nil) ⇒ Object
87 88 89 |
# File 'lib/mij-discord/data/role.rb', line 87 def delete(reason = nil) MijDiscord::Core::API::Server.delete_role(@bot.auth, @server.id, @id, reason) end |
#members ⇒ Object Also known as: users
53 54 55 |
# File 'lib/mij-discord/data/role.rb', line 53 def members @server.members.select {|x| x.role?(self) } end |
#mention ⇒ Object Also known as: to_s
47 48 49 |
# File 'lib/mij-discord/data/role.rb', line 47 def mention "<@&#{@id}>" end |
#set_color(color) ⇒ Object Also known as: color=
80 81 82 83 |
# File 'lib/mij-discord/data/role.rb', line 80 def set_color(color) (color: color) nil end |
#set_hoist(flag) ⇒ Object Also known as: hoist=
66 67 68 69 |
# File 'lib/mij-discord/data/role.rb', line 66 def set_hoist(flag) (hoist: flag) nil end |
#set_mentionable(flag) ⇒ Object Also known as: mentionable=
73 74 75 76 |
# File 'lib/mij-discord/data/role.rb', line 73 def set_mentionable(flag) (mentionable: flag) nil end |
#set_name(name) ⇒ Object Also known as: name=
59 60 61 62 |
# File 'lib/mij-discord/data/role.rb', line 59 def set_name(name) (name: name) nil end |
#set_options(name: nil, color: nil, hoist: nil, mentionable: nil, permissions: nil) ⇒ Object
91 92 93 94 95 |
# File 'lib/mij-discord/data/role.rb', line 91 def (name: nil, color: nil, hoist: nil, mentionable: nil, permissions: nil) response = MijDiscord::Core::API::Server.update_role(@bot.auth, @server.id, @id, name, color&.to_i, hoist, mentionable, &.to_i) @server.cache.put_role(JSON.parse(response), update: true) end |
#update_data(data) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mij-discord/data/role.rb', line 33 def update_data(data) @name = data.fetch('name', @name) @position = data.fetch('position', @position) @hoist = data.fetch('hoist', @hoist) @mentionable = data.fetch('mentionable', @mentionable) @managed = data.fetch('managed', @managed) @color.value = data.fetch('color', @color.value) if (bits = data['permissions']) .bits = bits.to_i end end |