class Discorb::ThreadChannel
Represents a thread. @abstract
Attributes
@return [Integer] Auto archive duration in seconds.
@return [Boolean] Whether the thread is archived or not.
@return [Boolean] Whether the thread is archived or not.
@return [Time] The time the thread was archived. @return [nil] If the thread is not archived.
@return [Time] The time the thread was archived. @return [nil] If the thread is not archived.
@return [Integer] Auto archive duration in seconds.
@return [Discorb::Snowflake] The ID of the channel. @note This ID is same as the starter message's ID
@return [Integer] The number of recipients in the thread. @note This will stop counting at 50.
@return [Array<Discorb::ThreadChannel::Member>] The members of the thread.
@return [Integer] The number of messages in the thread. @note This will stop counting at 50.
@return [String] The name of the thread.
@return [Integer] The rate limit per user (slowmode) in the thread.
@return [Integer] The number of recipients in the thread. @note This will stop counting at 50.
@return [Integer] The rate limit per user (slowmode) in the thread.
Public Class Methods
@!visibility private
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
# 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
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
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
# 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
# File lib/discorb/channel.rb, line 938 def guild @client.guilds[@guild] end
# File lib/discorb/channel.rb, line 946 def inspect "#<#{self.class} \"##{@name}\" id=#{@id}>" end
# File lib/discorb/channel.rb, line 934 def joined? @members[@client.user.id] end
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
# File lib/discorb/channel.rb, line 930 def me @members[@client.user.id] end
# File lib/discorb/channel.rb, line 942 def owner guild.members[@owner_id] end
# File lib/discorb/channel.rb, line 922 def parent return nil unless @parent_id @client.channels[@parent_id] end
# 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
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
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
# 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