Class: Discordrb::Channel
- Inherits:
-
Object
- Object
- Discordrb::Channel
- Defined in:
- lib/discordrb/data.rb
Overview
A Discord channel, including data like the topic
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_private ⇒ Object
readonly
Returns the value of attribute is_private.
-
#name ⇒ Object
Returns the value of attribute name.
-
#permission_overwrites ⇒ Object
readonly
Returns the value of attribute permission_overwrites.
-
#position ⇒ Object
Returns the value of attribute position.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#topic ⇒ Object
Returns the value of attribute topic.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
ID based comparison.
-
#await(key, attributes = {}, &block) ⇒ Object
Add an await for a message in this channel.
- #delete ⇒ Object
- #history(amount, before_id = nil, after_id = nil) ⇒ Object
-
#initialize(data, bot, server = nil) ⇒ Channel
constructor
A new instance of Channel.
- #make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false) ⇒ Object (also: #invite)
- #private? ⇒ Boolean
- #send_file(file) ⇒ Object
- #send_message(content) ⇒ Object (also: #send, #message)
-
#start_typing ⇒ Object
Starts typing, which displays the typing indicator on the client for five seconds.
- #update_from(other) ⇒ Object
- #update_overwrites(overwrites) ⇒ Object
-
#users ⇒ Object
List of users currently in a channel.
Constructor Details
#initialize(data, bot, server = nil) ⇒ Channel
Returns a new instance of Channel.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/discordrb/data.rb', line 332 def initialize(data, bot, server = nil) @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'] @position = data['position'] @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) @server ||= server end # Populate permission overwrites = {} return unless data['permission_overwrites'] data['permission_overwrites'].each do |element| role_id = element['id'].to_i deny = Permissions.new(element['deny']) allow = Permissions.new(element['allow']) [role_id] = OpenStruct.new [role_id].deny = deny [role_id].allow = allow end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def id @id end |
#is_private ⇒ Object (readonly)
Returns the value of attribute is_private.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def is_private @is_private end |
#name ⇒ Object
Returns the value of attribute name.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def name @name end |
#permission_overwrites ⇒ Object (readonly)
Returns the value of attribute permission_overwrites.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def end |
#position ⇒ Object
Returns the value of attribute position.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def position @position end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def recipient @recipient end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def server @server end |
#topic ⇒ Object
Returns the value of attribute topic.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def topic @topic end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
326 327 328 |
# File 'lib/discordrb/data.rb', line 326 def type @type end |
Instance Method Details
#==(other) ⇒ Object
ID based comparison
367 368 369 |
# File 'lib/discordrb/data.rb', line 367 def ==(other) Discordrb.id_compare(@id, other) end |
#await(key, attributes = {}, &block) ⇒ Object
Add an await for a message in this channel
427 428 429 |
# File 'lib/discordrb/data.rb', line 427 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { in: @id }.merge(attributes), &block) end |
#delete ⇒ Object
379 380 381 |
# File 'lib/discordrb/data.rb', line 379 def delete API.delete_channel(@bot.token, @id) end |
#history(amount, before_id = nil, after_id = nil) ⇒ Object
417 418 419 420 |
# File 'lib/discordrb/data.rb', line 417 def history(amount, before_id = nil, after_id = nil) logs = API.channel_log(@bot.token, @id, amount, before_id, after_id) JSON.parse(logs).map { || Message.new(, @bot) } end |
#make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false) ⇒ Object Also known as: invite
431 432 433 434 |
# File 'lib/discordrb/data.rb', line 431 def make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false) response = API.create_invite(@bot.token, @id, max_age, max_uses, temporary, xkcd) Invite.new(JSON.parse(response), @bot) end |
#private? ⇒ Boolean
328 329 330 |
# File 'lib/discordrb/data.rb', line 328 def private? @server.nil? end |
#send_file(file) ⇒ Object
375 376 377 |
# File 'lib/discordrb/data.rb', line 375 def send_file(file) @bot.send_file(@id, file) end |
#send_message(content) ⇒ Object Also known as: send, message
371 372 373 |
# File 'lib/discordrb/data.rb', line 371 def (content) @bot.(@id, content) end |
#start_typing ⇒ Object
Starts typing, which displays the typing indicator on the client for five seconds. If you want to keep typing you'll have to resend this every five seconds. (An abstraction for this will eventually be coming)
439 440 441 |
# File 'lib/discordrb/data.rb', line 439 def start_typing API.start_typing(@bot.token, @id) end |
#update_from(other) ⇒ Object
398 399 400 401 402 403 404 |
# File 'lib/discordrb/data.rb', line 398 def update_from(other) @topic = other.topic @name = other.name @is_private = other.is_private @recipient = other.recipient = other. end |
#update_overwrites(overwrites) ⇒ Object
422 423 424 |
# File 'lib/discordrb/data.rb', line 422 def update_overwrites(overwrites) = overwrites end |
#users ⇒ Object
List of users currently in a channel
407 408 409 410 411 412 413 414 415 |
# File 'lib/discordrb/data.rb', line 407 def users if @type == 'text' @server.members.select { |u| u.status != :offline } else @server.members.select do |user| user.voice_channel.id == @id if user.voice_channel end end end |