Class: Discordrb::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, bot) ⇒ Channel

Returns a new instance of Channel.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/discordrb/data.rb', line 44

def initialize(data, bot)
  @bot = bot

  #data is a sometimes a Hash and othertimes an array of Hashes, you only want the last one if it's an array
  data = data[-1] if data.is_a?(Array)

  @id = data['id'].to_i
  @type = data['type'] || 'text'
  @topic = data['topic']

  @is_private = data['is_private']
  if @is_private
    @recipient = User.new(data['recipient'], bot)
    @name = @recipient.username
  else
    @name = data['name']
    @server = bot.server(data['guild_id'].to_i)
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



42
43
44
# File 'lib/discordrb/data.rb', line 42

def id
  @id
end

#is_privateObject (readonly)

Returns the value of attribute is_private.



42
43
44
# File 'lib/discordrb/data.rb', line 42

def is_private
  @is_private
end

#nameObject (readonly)

Returns the value of attribute name.



42
43
44
# File 'lib/discordrb/data.rb', line 42

def name
  @name
end

#recipientObject (readonly)

Returns the value of attribute recipient.



42
43
44
# File 'lib/discordrb/data.rb', line 42

def recipient
  @recipient
end

#serverObject (readonly)

Returns the value of attribute server.



42
43
44
# File 'lib/discordrb/data.rb', line 42

def server
  @server
end

#topicObject (readonly)

Returns the value of attribute topic.



42
43
44
# File 'lib/discordrb/data.rb', line 42

def topic
  @topic
end

#typeObject (readonly)

Returns the value of attribute type.



42
43
44
# File 'lib/discordrb/data.rb', line 42

def type
  @type
end

Instance Method Details

#send_message(content) ⇒ Object Also known as: send, message



64
65
66
# File 'lib/discordrb/data.rb', line 64

def send_message(content)
  @bot.send_message(@id, content)
end