Class: Rubord::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/rubord/models/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, client) ⇒ Channel

Returns a new instance of Channel.



7
8
9
10
11
12
13
14
# File 'lib/rubord/models/channel.rb', line 7

def initialize(data, client)
  @id     = data["id"]
  @name   = data["name"]
  @type   = data["type"]
  @client = client

  client&.channels&.set(@id, self)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/rubord/models/channel.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rubord/models/channel.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/rubord/models/channel.rb', line 3

def type
  @type
end

Instance Method Details

#fetch_message(message_id) ⇒ Object



26
27
28
# File 'lib/rubord/models/channel.rb', line 26

def fetch_message(message_id)
  @client.rest.get_message(@id, message_id)
end

#guildObject



30
31
32
33
# File 'lib/rubord/models/channel.rb', line 30

def guild
  return nil unless @client && @client.respond_to?(:guilds)
  @client.guilds.get(guild_id)
end

#inspectObject



43
44
45
# File 'lib/rubord/models/channel.rb', line 43

def inspect
  "#<Rubord::Channel id=#{id} name=#{name.inspect} type=#{type}>"
end

#post(content = nil, embeds: nil, components: nil, flags: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/rubord/models/channel.rb', line 16

def post(content = nil, embeds: nil, components: nil, flags: nil)
  @client.rest.send_message(
    @id,
    content: content,
    embeds: embeds,
    components: components,
    flags: flags
  )
end

#text?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rubord/models/channel.rb', line 35

def text?
  type == 0
end

#voice?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/rubord/models/channel.rb', line 39

def voice?
  type == 2
end