class MijDiscord::Data::Channel
Constants
- TYPES
Attributes
bot[R]
cache[R]
name[R]
overwrites[R]
parent_id[R]
permission_overwrites[R]
position[R]
server[R]
type[R]
Public Class Methods
create(data, bot, server)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 44 def self.create(data, bot, server) case TYPES[data['type']] when :text, :pm, :group TextChannel.new(data, bot, server) when :voice VoiceChannel.new(data, bot, server) when :category ChannelCategory.new(data, bot, server) else raise 'Broken channel object!' end end
new(data, bot, server)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 32 def initialize(data, bot, server) @bot = bot @cache = MijDiscord::Cache::ChannelCache.new(self, @bot) data = data[-1] if data.is_a?(Array) @id = data['id'].to_i update_data(data) @server = server || @bot.server(data['guild_id']) unless private? end
Public Instance Methods
category?()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 97 def category? @type == :category end
default_channel?()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 105 def default_channel? @server.default_channel == self end
Also aliased as: default?
define_overwrite(object, reason = nil, allow: 0, deny: 0)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 167 def define_overwrite(object, reason = nil, allow: 0, deny: 0) unless object.is_a?(Overwrite) allow_bits = allow.respond_to?(:bits) ? allow.bits : allow deny_bits = deny.respond_to?(:bits) ? deny.bits : deny object = Overwrite.new(object, allow: allow_bits, deny: deny_bits) end MijDiscord::Core::API::Channel.update_permission(@bot.auth, @id, object.id, object.allow.bits, object.deny.bits, object.type, reason) nil end
delete(reason = nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 201 def delete(reason = nil) MijDiscord::Core::API::Channel.delete(@bot.auth, @id, reason) @server.cache.remove_channel(@id) end
delete_overwrite(object, reason = nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 184 def delete_overwrite(object, reason = nil) raise ArgumentError, 'Invalid overwrite target' unless object.respond_to?(:to_id) MijDiscord::Core::API::Channel.delete_permission(@bot.auth, @id, object.to_id, reason) nil end
Also aliased as: delete_permission_overwrite
group?()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 93 def group? @type == :group end
inspect()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 206 def inspect MijDiscord.make_inspect(self, :id, :name, :type, :position) end
member_overwrites()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 117 def member_overwrites @permission_overwrites.values.select {|v| v.type == :member } end
mention()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 73 def mention "<##{@id}>" end
Also aliased as: to_s
parent()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 111 def parent @parent_id ? @server.cache.get_channel(@parent_id) : nil end
Also aliased as: category
pm?()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 83 def pm? @type == :pm end
Also aliased as: dm?
private?()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 101 def private? pm? || group? end
role_overwrites()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 121 def role_overwrites @permission_overwrites.values.select {|v| v.type == :role } end
set_name(name, reason = nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 125 def set_name(name, reason = nil) set_options(reason, name: name) nil end
Also aliased as: name=
set_options(reason = nil, name: nil, topic: nil, nsfw: nil, parent: nil, position: nil, bitrate: nil, user_limit: nil, overwrites: nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 151 def set_options(reason = nil, name: nil, topic: nil, nsfw: nil, parent: nil, position: nil, bitrate: nil, user_limit: nil, overwrites: nil) response = MijDiscord::Core::API::Channel.update(@bot.auth, @id, name, topic, nsfw,parent&.to_id, position, bitrate, user_limit, overwrites, reason) @server.cache.put_channel(JSON.parse(response), update: true) end
set_overwrites(overwrites, reason = nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 158 def set_overwrites(overwrites, reason = nil) set_options(reason, overwrites: overwrites) nil end
set_parent(parent, reason = nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 139 def set_parent(parent, reason = nil) channel = @server.cache.get_channel(parent) raise ArgumentError, 'Specified channel is not a category' unless channel&.category? set_options(reason, parent: channel) nil end
set_position(position, reason = nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 132 def set_position(position, reason = nil) set_options(reason, position: position) nil end
Also aliased as: position=
sync_overwrites(reason = nil)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 193 def sync_overwrites(reason = nil) raise 'Cannot sync overwrites on a channel with no category set' unless @parent_id set_overwrites(parent.overwrites, reason) nil end
Also aliased as: sync_permission_overwrites
text?()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 79 def text? @type == :text end
update_data(data)
click to toggle source
# File lib/mij-discord/data/channel.rb, line 57 def update_data(data) @name = data.fetch('name', @name) unless pm? @type_id = data.fetch('type', @type_id || 0) @type = TYPES[@type_id] @position = data.fetch('position', @position) @parent_id = data.fetch('parent_id', @parent_id).to_i if (perms = data['permission_overwrites']) @permission_overwrites = perms.each_with_object({}) do |el, p| p[el['id'].to_i] = Overwrite.from_hash(el) end end @permission_overwrites ||= {} end
voice?()
click to toggle source
# File lib/mij-discord/data/channel.rb, line 89 def voice? @type == :voice end