class Discorb::ThreadChannel

Represents a thread. @abstract

Attributes

channel_type[R]
archive_in[R]

@return [Integer] Auto archive duration in seconds.

archived[R]

@return [Boolean] Whether the thread is archived or not.

archived?[R]

@return [Boolean] Whether the thread is archived or not.

archived_at[R]

@return [Time] The time the thread was archived. @return [nil] If the thread is not archived.

archived_timestamp[R]

@return [Time] The time the thread was archived. @return [nil] If the thread is not archived.

auto_archive_duration[R]

@return [Integer] Auto archive duration in seconds.

id[R]

@return [Discorb::Snowflake] The ID of the channel. @note This ID is same as the starter message's ID

member_count[R]

@return [Integer] The number of recipients in the thread. @note This will stop counting at 50.

members[R]

@return [Array<Discorb::ThreadChannel::Member>] The members of the thread.

message_count[R]

@return [Integer] The number of messages in the thread. @note This will stop counting at 50.

name[R]

@return [String] The name of the thread.

rate_limit_per_user[R]

@return [Integer] The rate limit per user (slowmode) in the thread.

recipient_count[R]

@return [Integer] The number of recipients in the thread. @note This will stop counting at 50.

slowmode[R]

@return [Integer] The rate limit per user (slowmode) in the thread.

Public Class Methods

new(client, data, no_cache: false) click to toggle source

@!visibility private

Calls superclass method Discorb::Channel::new
# File lib/discorb/channel.rb, line 835
def initialize(client, data, no_cache: false)
  @members = Dictionary.new
  super
  @client.channels[@parent_id].threads[@id] = self

  @client.channels[@id] = self unless no_cache
end

Public Instance Methods

add_member(member = :me) click to toggle source
# File lib/discorb/channel.rb, line 950
def add_member(member = :me)
  Async do
    if member == :me
      @client.http.post("/channels/#{@id}/thread-members/@me").wait
    else
      @client.http.post("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}").wait
    end
  end
end
Also aliased as: join
archive(reason: nil) click to toggle source

Helper method to archive the thread.

@param [String] reason The reason of archiving the thread.

@return [self] The archived thread.

# File lib/discorb/channel.rb, line 883
def archive(reason: nil)
  edit(archived: true, reason: reason)
end
channel()
Alias for: parent
edit(name: :unset, archived: :unset, auto_archive_duration: :unset, archive_in: :unset, locked: :unset, reason: nil) click to toggle source

Edit the thread. @macro async @macro http @macro edit

@param [String] name The name of the thread. @param [Boolean] archived Whether the thread is archived or not. @param [Integer] auto_archive_duration The auto archive duration in seconds. @param [Integer] archive_in Alias of `auto_archive_duration`. @param [Boolean] locked Whether the thread is locked or not. @param [String] reason The reason of editing the thread.

@return [self] The edited thread.

@see archive @see lock @see unarchive @see unlock

# File lib/discorb/channel.rb, line 863
def edit(name: :unset, archived: :unset, auto_archive_duration: :unset, archive_in: :unset, locked: :unset, reason: nil)
  Async do
    payload = {}
    payload[:name] = name if name != :unset
    payload[:archived] = archived if archived != :unset
    auto_archive_duration ||= archive_in
    payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration != :unset
    payload[:locked] = locked if locked != :unset
    @client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
    self
  end
end
fetch_members() click to toggle source
# File lib/discorb/channel.rb, line 974
def fetch_members
  Async do
    _resp, data = @client.http.get("/channels/#{@id}/thread-members").wait
    data.map { |d| @members[d[:id]] = Member.new(@client, d) }
  end
end
guild() click to toggle source
# File lib/discorb/channel.rb, line 938
def guild
  @client.guilds[@guild]
end
inspect() click to toggle source
# File lib/discorb/channel.rb, line 946
def inspect
  "#<#{self.class} \"##{@name}\" id=#{@id}>"
end
join(member = :me)
Alias for: add_member
joined?() click to toggle source
# File lib/discorb/channel.rb, line 934
def joined?
  @members[@client.user.id]
end
leave(member = :me)
Alias for: remove_member
lock(reason: nil) click to toggle source

Helper method to lock the thread.

@param [String] reason The reason of locking the thread.

@return [self] The locked thread.

# File lib/discorb/channel.rb, line 894
def lock(reason: nil)
  edit(archived: true, locked: true, reason: reason)
end
me() click to toggle source
# File lib/discorb/channel.rb, line 930
def me
  @members[@client.user.id]
end
owner() click to toggle source
# File lib/discorb/channel.rb, line 942
def owner
  guild.members[@owner_id]
end
parent() click to toggle source
# File lib/discorb/channel.rb, line 922
def parent
  return nil unless @parent_id

  @client.channels[@parent_id]
end
Also aliased as: channel
remove_member(member = :me) click to toggle source
# File lib/discorb/channel.rb, line 962
def remove_member(member = :me)
  Async do
    if member == :me
      @client.http.delete("/channels/#{@id}/thread-members/@me").wait
    else
      @client.http.delete("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}").wait
    end
  end
end
Also aliased as: leave
unarchive(reason: nil) click to toggle source

Helper method to unarchive the thread.

@param [String] reason The reason of unarchiving the thread.

@return [self] The unarchived thread.

# File lib/discorb/channel.rb, line 905
def unarchive(reason: nil)
  edit(archived: false, reason: reason)
end
unlock(reason: nil) click to toggle source

Helper method to unlock the thread.

@param [String] reason The reason of unlocking the thread.

@return [self] The unlocked thread.

@note This method won't unarchive the thread. Use {#unarchive} instead.

# File lib/discorb/channel.rb, line 918
def unlock(reason: nil)
  edit(archived: !unarchive, locked: false, reason: reason)
end

Private Instance Methods

_set_data(data) click to toggle source
# File lib/discorb/channel.rb, line 1030
def _set_data(data)
  @id = Snowflake.new(data[:id])
  @name = data[:name]
  @guild_id = data[:guild_id]
  @parent_id = data[:parent_id]
  @archived = data[:thread_metadata][:archived]
  @owner_id = data[:owner_id]
  @archived_timestamp = data[:thread_metadata][:archived_timestamp] && Time.iso8601(data[:thread_metadata][:archived_timestamp])
  @auto_archive_duration = data[:thread_metadata][:auto_archive_duration]
  @locked = data[:thread_metadata][:locked]
  @member_count = data[:member_count]
  @message_count = data[:message_count]
  @members[@client.user.id] = ThreadChannel::Member.new(@client, data[:member].merge({ id: data[:id], user_id: @client.user.id })) if data[:member]
  @data.merge!(data)
end