class Discorb::Channel

Represents a channel of Discord. @abstract

Attributes

channel_type[R]

@!visibility private

id[R]

@return [Discorb::Snowflake] The ID of the channel.

name[R]

@return [String] The name of the channel.

Public Class Methods

descendants() click to toggle source

@!visibility private

# File lib/discorb/channel.rb, line 48
def self.descendants
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end
make_channel(client, data, no_cache: false) click to toggle source

@!visibility private

# File lib/discorb/channel.rb, line 53
def self.make_channel(client, data, no_cache: false)
  descendants.each do |klass|
    return klass.new(client, data, no_cache: no_cache) if !klass.channel_type.nil? && klass.channel_type == data[:type]
  end
  client.log.warn("Unknown channel type #{data[:type]}, initialized GuildChannel")
  GuildChannel.new(client, data)
end
new(client, data, no_cache: false) click to toggle source

@!visibility private

# File lib/discorb/channel.rb, line 23
def initialize(client, data, no_cache: false)
  @client = client
  @data = {}
  @no_cache = no_cache
  _set_data(data)
end

Public Instance Methods

==(other) click to toggle source

Checks if the channel is other channel.

@param [Discorb::Channel] other The channel to check.

@return [Boolean] True if the channel is other channel.

# File lib/discorb/channel.rb, line 37
def ==(other)
  return false unless other.respond_to?(:id)

  @id == other.id
end
channel_id() click to toggle source

@!visibility private

# File lib/discorb/channel.rb, line 71
def channel_id
  Async do
    @id
  end
end
inspect() click to toggle source
# File lib/discorb/channel.rb, line 43
def inspect
  "#<#{self.class} \"##{@name}\" id=#{@id}>"
end
type() click to toggle source
# File lib/discorb/channel.rb, line 66
def type
  self.class.channel_type
end

Private Instance Methods

_set_data(data) click to toggle source
# File lib/discorb/channel.rb, line 79
def _set_data(data)
  @id = Snowflake.new(data[:id])
  @name = data[:name]
  @client.channels[@id] = self if !@no_cache && !(data[:no_cache])
  @data.update(data)
end