Class: Discorb::ThreadChannel Abstract
- Inherits:
-
Channel
- Object
- DiscordModel
- Channel
- Discorb::ThreadChannel
- Includes:
- Messageable
- Defined in:
- lib/discorb/channel.rb
Overview
Represents a thread.
Defined Under Namespace
Classes: Member, News, Private, Public
Class Attribute Summary collapse
-
.channel_type -> Object
readonly
Returns the value of attribute channel_type.
Instance Attribute Summary collapse
-
#archived -> Boolean
(also: #archived?)
readonly
Whether the thread is archived or not.
- #archived_timestamp -> Time? (also: #archived_at) readonly
-
#auto_archive_duration -> Integer
(also: #archive_in)
readonly
Auto archive duration in seconds.
-
#id -> Discorb::Snowflake
readonly
The ID of the channel.
-
#member_count -> Integer
(also: #recipient_count)
readonly
The number of recipients in the thread.
-
#members -> Array<Discorb::ThreadChannel::Member>
readonly
The members of the thread.
-
#message_count -> Integer
readonly
The number of messages in the thread.
-
#name -> String
readonly
The name of the thread.
-
#rate_limit_per_user -> Integer
(also: #slowmode)
readonly
The rate limit per user (slowmode) in the thread.
Instance Method Summary collapse
- #add_member(member = :me) -> Object (also: #join)
-
#archive(reason: nil) -> self
Helper method to archive the thread.
-
#edit(name: :unset, archived: :unset, auto_archive_duration: :unset, archive_in: :unset, locked: :unset, reason: nil) -> Async::Task<self>
Edit the thread.
- #fetch_members -> Object
- #guild -> Object
- #inspect -> Object
- #joined? -> Boolean
-
#lock(reason: nil) -> self
Helper method to lock the thread.
- #me -> Object
- #owner -> Object
- #parent -> Object (also: #channel)
- #remove_member(member = :me) -> Object (also: #leave)
-
#unarchive(reason: nil) -> self
Helper method to unarchive the thread.
-
#unlock(reason: nil) -> self
Helper method to unlock the thread.
Methods included from Messageable
#delete_message!, #edit_message, #fetch_message, #fetch_messages, #fetch_pins, #pin_message, #post, #typing, #unpin_message
Methods inherited from Channel
Methods inherited from DiscordModel
Class Attribute Details
.channel_type -> Object (readonly)
Returns the value of attribute channel_type.
959 960 961 |
# File 'lib/discorb/channel.rb', line 959 def channel_type @channel_type end |
Instance Attribute Details
#archived -> Boolean (readonly) Also known as: archived?
Returns Whether the thread is archived or not.
789 790 791 |
# File 'lib/discorb/channel.rb', line 789 def archived @archived end |
#archived_timestamp -> Time? (readonly) Also known as: archived_at
783 784 785 |
# File 'lib/discorb/channel.rb', line 783 def @archived_timestamp end |
#auto_archive_duration -> Integer (readonly) Also known as: archive_in
Returns Auto archive duration in seconds.
786 787 788 |
# File 'lib/discorb/channel.rb', line 786 def auto_archive_duration @auto_archive_duration end |
#id -> Discorb::Snowflake (readonly)
This ID is same as the starter message's ID
Returns The ID of the channel.
766 767 768 |
# File 'lib/discorb/channel.rb', line 766 def id @id end |
#member_count -> Integer (readonly) Also known as: recipient_count
This will stop counting at 50.
Returns The number of recipients in the thread.
774 775 776 |
# File 'lib/discorb/channel.rb', line 774 def member_count @member_count end |
#members -> Array<Discorb::ThreadChannel::Member> (readonly)
Returns The members of the thread.
780 781 782 |
# File 'lib/discorb/channel.rb', line 780 def members @members end |
#message_count -> Integer (readonly)
This will stop counting at 50.
Returns The number of messages in the thread.
771 772 773 |
# File 'lib/discorb/channel.rb', line 771 def @message_count end |
#name -> String (readonly)
Returns The name of the thread.
768 769 770 |
# File 'lib/discorb/channel.rb', line 768 def name @name end |
#rate_limit_per_user -> Integer (readonly) Also known as: slowmode
Returns The rate limit per user (slowmode) in the thread.
777 778 779 |
# File 'lib/discorb/channel.rb', line 777 def rate_limit_per_user @rate_limit_per_user end |
Instance Method Details
#add_member(member = :me) -> Object Also known as: join
915 916 917 918 919 920 921 922 923 |
# File 'lib/discorb/channel.rb', line 915 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.
848 849 850 |
# File 'lib/discorb/channel.rb', line 848 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>
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
This method calls HTTP request.
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.
828 829 830 831 832 833 834 835 836 837 838 839 |
# File 'lib/discorb/channel.rb', line 828 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
939 940 941 942 943 944 |
# File 'lib/discorb/channel.rb', line 939 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
903 904 905 |
# File 'lib/discorb/channel.rb', line 903 def guild @client.guilds[@guild] end |
#inspect -> Object
911 912 913 |
# File 'lib/discorb/channel.rb', line 911 def inspect "#<#{self.class} \"##{@name}\" id=#{@id}>" end |
#joined? -> Boolean
899 900 901 |
# File 'lib/discorb/channel.rb', line 899 def joined? @members[@client.user.id] end |
#lock(reason: nil) -> self
Helper method to lock the thread.
859 860 861 |
# File 'lib/discorb/channel.rb', line 859 def lock(reason: nil) edit(archived: true, locked: true, reason: reason) end |
#me -> Object
895 896 897 |
# File 'lib/discorb/channel.rb', line 895 def me @members[@client.user.id] end |
#owner -> Object
907 908 909 |
# File 'lib/discorb/channel.rb', line 907 def owner guild.members[@owner_id] end |
#parent -> Object Also known as: channel
887 888 889 890 891 |
# File 'lib/discorb/channel.rb', line 887 def parent return nil unless @parent_id @client.channels[@parent_id] end |
#remove_member(member = :me) -> Object Also known as: leave
927 928 929 930 931 932 933 934 935 |
# File 'lib/discorb/channel.rb', line 927 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.
870 871 872 |
# File 'lib/discorb/channel.rb', line 870 def unarchive(reason: nil) edit(archived: false, reason: reason) end |
#unlock(reason: nil) -> self
This method won't unarchive the thread. Use #unarchive instead.
Helper method to unlock the thread.
883 884 885 |
# File 'lib/discorb/channel.rb', line 883 def unlock(reason: nil) edit(archived: !unarchive, locked: false, reason: reason) end |