Class: Discorb::ThreadChannel Abstract

Inherits:
Channel show all
Includes:
Messageable
Defined in:
lib/discorb/channel.rb

Overview

This class is abstract.

Represents a thread.

Direct Known Subclasses

News, Private, Public

Defined Under Namespace

Classes: Member, News, Private, Public

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Messageable

#delete_message!, #edit_message, #fetch_message, #fetch_messages, #fetch_pins, #pin_message, #post, #typing, #unpin_message

Methods inherited from Channel

#==, #type

Methods inherited from DiscordModel

#==, #eql?

Class Attribute Details

.channel_type -> Object (readonly)

Returns the value of attribute channel_type.



1045
1046
1047
# File 'lib/discorb/channel.rb', line 1045

def channel_type
  @channel_type
end

Instance Attribute Details

#archived -> Boolean (readonly) Also known as: archived?

Returns Whether the thread is archived or not.

Returns:

  • (Boolean)

    Whether the thread is archived or not.



831
832
833
# File 'lib/discorb/channel.rb', line 831

def archived
  @archived
end

#archived_timestamp -> Time? (readonly) Also known as: archived_at

Returns:

  • (Time)

    The time the thread was archived.

  • (nil)

    If the thread is not archived.



825
826
827
# File 'lib/discorb/channel.rb', line 825

def archived_timestamp
  @archived_timestamp
end

#auto_archive_duration -> Integer (readonly) Also known as: archive_in

Returns Auto archive duration in seconds.

Returns:

  • (Integer)

    Auto archive duration in seconds.



828
829
830
# File 'lib/discorb/channel.rb', line 828

def auto_archive_duration
  @auto_archive_duration
end

#id -> Discorb::Snowflake (readonly)

Note:

This ID is same as the starter message's ID

Returns The ID of the channel.

Returns:



808
809
810
# File 'lib/discorb/channel.rb', line 808

def id
  @id
end

#member_count -> Integer (readonly) Also known as: recipient_count

Note:

This will stop counting at 50.

Returns The number of recipients in the thread.

Returns:

  • (Integer)

    The number of recipients in the thread.



816
817
818
# File 'lib/discorb/channel.rb', line 816

def member_count
  @member_count
end

#members -> Array<Discorb::ThreadChannel::Member> (readonly)

Returns The members of the thread.

Returns:



822
823
824
# File 'lib/discorb/channel.rb', line 822

def members
  @members
end

#message_count -> Integer (readonly)

Note:

This will stop counting at 50.

Returns The number of messages in the thread.

Returns:

  • (Integer)

    The number of messages in the thread.



813
814
815
# File 'lib/discorb/channel.rb', line 813

def message_count
  @message_count
end

#name -> String (readonly)

Returns The name of the thread.

Returns:

  • (String)

    The name of the thread.



810
811
812
# File 'lib/discorb/channel.rb', line 810

def name
  @name
end

#rate_limit_per_user -> Integer (readonly) Also known as: slowmode

Returns The rate limit per user (slowmode) in the thread.

Returns:

  • (Integer)

    The rate limit per user (slowmode) in the thread.



819
820
821
# File 'lib/discorb/channel.rb', line 819

def rate_limit_per_user
  @rate_limit_per_user
end

Instance Method Details

#add_member(member = :me) -> Async::Task<void> Also known as: join

Add a member to the thread.

Parameters:

  • member (Discorb::Member, :me) (defaults to: :me)

    The member to add. If :me is given, the bot will be added.

Returns:

  • (Async::Task<void>)

    The task.



980
981
982
983
984
985
986
987
988
# File 'lib/discorb/channel.rb', line 980

def add_member(member = :me)
  Async do
    if member == :me
      @client.http.request(Route.new("/channels/#{@id}/thread-members/@me", "//channels/:channel_id/thread-members/@me", :post)).wait
    else
      @client.http.request(Route.new("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}", "//channels/:channel_id/thread-members/:user_id", :post)).wait
    end
  end
end

#archive(reason: nil) -> self

Helper method to archive the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of archiving the thread.

Returns:

  • (self)

    The archived thread.



906
907
908
# File 'lib/discorb/channel.rb', line 906

def archive(reason: nil)
  edit(archived: true, reason: reason)
end

#edit(name: Discorb::Unset, archived: Discorb::Unset, auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, locked: Discorb::Unset, reason: nil) -> Async::Task<self>

Note:

The arguments of this method are defaultly set to Discorb::Unset. Specify value to set the value, if not don't specify or specify Discorb::Unset.

Edit the thread.

Parameters:

  • name (String) (defaults to: Discorb::Unset)

    The name of the thread.

  • archived (Boolean) (defaults to: Discorb::Unset)

    Whether the thread is archived or not.

  • auto_archive_duration (Integer) (defaults to: Discorb::Unset)

    The auto archive duration in seconds.

  • archive_in (Integer) (defaults to: Discorb::Unset)

    Alias of auto_archive_duration.

  • locked (Boolean) (defaults to: Discorb::Unset)

    Whether the thread is locked or not.

  • reason (String) (defaults to: nil)

    The reason of editing the thread.

Returns:

  • (Async::Task<self>)

    The edited thread.

See Also:



886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/discorb/channel.rb', line 886

def edit(name: Discorb::Unset, archived: Discorb::Unset, auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, locked: Discorb::Unset, reason: nil)
  Async do
    payload = {}
    payload[:name] = name if name != Discorb::Unset
    payload[:archived] = archived if archived != Discorb::Unset
    auto_archive_duration ||= archive_in
    payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration != Discorb::Unset
    payload[:locked] = locked if locked != Discorb::Unset
    @client.http.request(Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload, audit_log_reason: reason).wait
    self
  end
end

#fetch_members -> Array<Discorb::ThreadChannel::Member>

Fetch members in the thread.

Returns:



1016
1017
1018
1019
1020
1021
# File 'lib/discorb/channel.rb', line 1016

def fetch_members
  Async do
    _resp, data = @client.http.request(Route.new("/channels/#{@id}/thread-members", "//channels/:channel_id/thread-members", :get)).wait
    data.map { |d| @members[d[:id]] = Member.new(@client, d) }
  end
end

#guild -> Object



961
962
963
# File 'lib/discorb/channel.rb', line 961

def guild
  @client.guilds[@guild]
end

#inspect -> Object



969
970
971
# File 'lib/discorb/channel.rb', line 969

def inspect
  "#<#{self.class} \"##{@name}\" id=#{@id}>"
end

#joined? -> Boolean

Returns:

  • (Boolean)


957
958
959
# File 'lib/discorb/channel.rb', line 957

def joined?
  !!me
end

#lock(reason: nil) -> self

Helper method to lock the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of locking the thread.

Returns:

  • (self)

    The locked thread.



917
918
919
# File 'lib/discorb/channel.rb', line 917

def lock(reason: nil)
  edit(archived: true, locked: true, reason: reason)
end

#me -> Object



953
954
955
# File 'lib/discorb/channel.rb', line 953

def me
  @members[@client.user.id]
end

#owner -> Object



965
966
967
# File 'lib/discorb/channel.rb', line 965

def owner
  guild.members[@owner_id]
end

#parent -> Object Also known as: channel



945
946
947
948
949
# File 'lib/discorb/channel.rb', line 945

def parent
  return nil unless @parent_id

  @client.channels[@parent_id]
end

#remove_member(member = :me) -> Async::Task<void> Also known as: leave

Remove a member from the thread.

Parameters:

  • member (Discorb::Member, :me) (defaults to: :me)

    The member to remove. If :me is given, the bot will be removed.

Returns:

  • (Async::Task<void>)

    The task.



999
1000
1001
1002
1003
1004
1005
1006
1007
# File 'lib/discorb/channel.rb', line 999

def remove_member(member = :me)
  Async do
    if member == :me
      @client.http.request(Route.new("/channels/#{@id}/thread-members/@me", "//channels/:channel_id/thread-members/@me", :delete)).wait
    else
      @client.http.request(Route.new("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}", "//channels/:channel_id/thread-members/:user_id", :delete)).wait
    end
  end
end

#unarchive(reason: nil) -> self

Helper method to unarchive the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of unarchiving the thread.

Returns:

  • (self)

    The unarchived thread.



928
929
930
# File 'lib/discorb/channel.rb', line 928

def unarchive(reason: nil)
  edit(archived: false, reason: reason)
end

#unlock(reason: nil) -> self

Note:

This method won't unarchive the thread. Use #unarchive instead.

Helper method to unlock the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of unlocking the thread.

Returns:

  • (self)

    The unlocked thread.



941
942
943
# File 'lib/discorb/channel.rb', line 941

def unlock(reason: nil)
  edit(archived: !unarchive, locked: false, reason: reason)
end