class MijDiscord::Data::Role
Attributes
color[R]
hoist[R]
managed[R]
managed?[R]
mentionable[R]
mentionable?[R]
name[R]
permissions[R]
position[R]
Public Class Methods
new(data, server, bot)
click to toggle source
# File lib/mij-discord/data/role.rb, line 23 def initialize(data, server, bot) @bot, @server = bot, server @permissions = Permissions.new @color = ColorRGB.new @id = data['id'].to_i update_data(data) end
Public Instance Methods
delete(reason = nil)
click to toggle source
# 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
inspect()
click to toggle source
# File lib/mij-discord/data/role.rb, line 97 def inspect MijDiscord.make_inspect(self, :id, :name, :color, :position, :hoist, :mentionable, :managed, :permissions) end
members()
click to toggle source
# File lib/mij-discord/data/role.rb, line 53 def members @server.members.select {|x| x.role?(self) } end
Also aliased as: users
mention()
click to toggle source
# File lib/mij-discord/data/role.rb, line 47 def mention "<@&#{@id}>" end
Also aliased as: to_s
set_color(color)
click to toggle source
# File lib/mij-discord/data/role.rb, line 80 def set_color(color) set_options(color: color) nil end
Also aliased as: color=
set_hoist(flag)
click to toggle source
# File lib/mij-discord/data/role.rb, line 66 def set_hoist(flag) set_options(hoist: flag) nil end
Also aliased as: hoist=
set_mentionable(flag)
click to toggle source
# File lib/mij-discord/data/role.rb, line 73 def set_mentionable(flag) set_options(mentionable: flag) nil end
Also aliased as: mentionable=
set_name(name)
click to toggle source
# File lib/mij-discord/data/role.rb, line 59 def set_name(name) set_options(name: name) nil end
Also aliased as: name=
set_options(name: nil, color: nil, hoist: nil, mentionable: nil, permissions: nil)
click to toggle source
# File lib/mij-discord/data/role.rb, line 91 def set_options(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, permissions&.to_i) @server.cache.put_role(JSON.parse(response), update: true) end
update_data(data)
click to toggle source
# 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']) @permissions.bits = bits.to_i end end