Class: Discorb::ThreadChannel Abstract
- Inherits:
-
Channel
- Object
- DiscordModel
- Channel
- Discorb::ThreadChannel
- Includes:
- Messageable
- Defined in:
- lib/discorb/channel/thread.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) -> Async::Task<void>
(also: #join)
Add a member to the thread.
-
#archive(reason: nil) -> self
Helper method to archive the thread.
-
#edit(name: Discorb::Unset, archived: Discorb::Unset, auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, locked: Discorb::Unset, reason: nil) -> Async::Task<self>
Edit the thread.
-
#fetch_members -> Array<Discorb::ThreadChannel::Member>
Fetch members in the thread.
- #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) -> Async::Task<void>
(also: #leave)
Remove a member from the thread.
-
#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.
261 262 263 |
# File 'lib/discorb/channel/thread.rb', line 261 def channel_type @channel_type end |
Instance Attribute Details
#archived -> Boolean (readonly) Also known as: archived?
Returns Whether the thread is archived or not.
34 35 36 |
# File 'lib/discorb/channel/thread.rb', line 34 def archived @archived end |
#archived_timestamp -> Time? (readonly) Also known as: archived_at
28 29 30 |
# File 'lib/discorb/channel/thread.rb', line 28 def @archived_timestamp end |
#auto_archive_duration -> Integer (readonly) Also known as: archive_in
Returns Auto archive duration in seconds.
31 32 33 |
# File 'lib/discorb/channel/thread.rb', line 31 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.
11 12 13 |
# File 'lib/discorb/channel/thread.rb', line 11 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.
19 20 21 |
# File 'lib/discorb/channel/thread.rb', line 19 def member_count @member_count end |
#members -> Array<Discorb::ThreadChannel::Member> (readonly)
Returns The members of the thread.
25 26 27 |
# File 'lib/discorb/channel/thread.rb', line 25 def members @members end |
#message_count -> Integer (readonly)
This will stop counting at 50.
Returns The number of messages in the thread.
16 17 18 |
# File 'lib/discorb/channel/thread.rb', line 16 def @message_count end |
#name -> String (readonly)
Returns The name of the thread.
13 14 15 |
# File 'lib/discorb/channel/thread.rb', line 13 def name @name end |
#rate_limit_per_user -> Integer (readonly) Also known as: slowmode
Returns The rate limit per user (slowmode) in the thread.
22 23 24 |
# File 'lib/discorb/channel/thread.rb', line 22 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.
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/discorb/channel/thread.rb', line 191 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.
117 118 119 |
# File 'lib/discorb/channel/thread.rb', line 117 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>
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.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/discorb/channel/thread.rb', line 89 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.
231 232 233 234 235 236 237 |
# File 'lib/discorb/channel/thread.rb', line 231 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
172 173 174 |
# File 'lib/discorb/channel/thread.rb', line 172 def guild @client.guilds[@guild] end |
#inspect -> Object
180 181 182 |
# File 'lib/discorb/channel/thread.rb', line 180 def inspect "#<#{self.class} \"##{@name}\" id=#{@id}>" end |
#joined? -> Boolean
168 169 170 |
# File 'lib/discorb/channel/thread.rb', line 168 def joined? !!me end |
#lock(reason: nil) -> self
Helper method to lock the thread.
128 129 130 |
# File 'lib/discorb/channel/thread.rb', line 128 def lock(reason: nil) edit(archived: true, locked: true, reason: reason) end |
#me -> Object
164 165 166 |
# File 'lib/discorb/channel/thread.rb', line 164 def me @members[@client.user.id] end |
#owner -> Object
176 177 178 |
# File 'lib/discorb/channel/thread.rb', line 176 def owner guild.members[@owner_id] end |
#parent -> Object Also known as: channel
156 157 158 159 160 |
# File 'lib/discorb/channel/thread.rb', line 156 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.
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/discorb/channel/thread.rb', line 212 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.
139 140 141 |
# File 'lib/discorb/channel/thread.rb', line 139 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.
152 153 154 |
# File 'lib/discorb/channel/thread.rb', line 152 def unlock(reason: nil) edit(archived: !unarchive, locked: false, reason: reason) end |