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?, #hash

Class Attribute Details

.channel_type -> Object (readonly)

Returns the value of attribute channel_type.



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

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.



782
783
784
# File 'lib/discorb/channel.rb', line 782

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.



776
777
778
# File 'lib/discorb/channel.rb', line 776

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.



779
780
781
# File 'lib/discorb/channel.rb', line 779

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:



759
760
761
# File 'lib/discorb/channel.rb', line 759

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.



767
768
769
# File 'lib/discorb/channel.rb', line 767

def member_count
  @member_count
end

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

Returns The members of the thread.

Returns:



773
774
775
# File 'lib/discorb/channel.rb', line 773

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.



764
765
766
# File 'lib/discorb/channel.rb', line 764

def message_count
  @message_count
end

#name -> String (readonly)

Returns The name of the thread.

Returns:

  • (String)

    The name of the thread.



761
762
763
# File 'lib/discorb/channel.rb', line 761

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.



770
771
772
# File 'lib/discorb/channel.rb', line 770

def rate_limit_per_user
  @rate_limit_per_user
end

Instance Method Details

#add_member(member = :me) -> Object Also known as: join



908
909
910
911
912
913
914
915
916
# File 'lib/discorb/channel.rb', line 908

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

#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.



841
842
843
# File 'lib/discorb/channel.rb', line 841

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

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

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Note:

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

Edit the thread.

Parameters:

  • name (String) (defaults to: :unset)

    The name of the thread.

  • archived (Boolean) (defaults to: :unset)

    Whether the thread is archived or not.

  • auto_archive_duration (Integer) (defaults to: :unset)

    The auto archive duration in seconds.

  • archive_in (Integer) (defaults to: :unset)

    Alias of auto_archive_duration.

  • locked (Boolean) (defaults to: :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.

Raises:

See Also:



821
822
823
824
825
826
827
828
829
830
831
832
# File 'lib/discorb/channel.rb', line 821

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 -> Object



932
933
934
935
936
937
# File 'lib/discorb/channel.rb', line 932

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 -> Object



896
897
898
# File 'lib/discorb/channel.rb', line 896

def guild
  @client.guilds[@guild]
end

#inspect -> Object



904
905
906
# File 'lib/discorb/channel.rb', line 904

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

#joined? -> Boolean

Returns:

  • (Boolean)


892
893
894
# File 'lib/discorb/channel.rb', line 892

def joined?
  @members[@client.user.id]
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.



852
853
854
# File 'lib/discorb/channel.rb', line 852

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

#me -> Object



888
889
890
# File 'lib/discorb/channel.rb', line 888

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

#owner -> Object



900
901
902
# File 'lib/discorb/channel.rb', line 900

def owner
  guild.members[@owner_id]
end

#parent -> Object Also known as: channel



880
881
882
883
884
# File 'lib/discorb/channel.rb', line 880

def parent
  return nil unless @parent_id

  @client.channels[@parent_id]
end

#remove_member(member = :me) -> Object Also known as: leave



920
921
922
923
924
925
926
927
928
# File 'lib/discorb/channel.rb', line 920

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

#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.



863
864
865
# File 'lib/discorb/channel.rb', line 863

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.



876
877
878
# File 'lib/discorb/channel.rb', line 876

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