Class: Discorb::TextChannel
- Inherits:
-
GuildChannel
- Object
- DiscordModel
- Channel
- GuildChannel
- Discorb::TextChannel
- Includes:
- Messageable
- Defined in:
- lib/discorb/channel/text.rb
Overview
Represents a text channel.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_auto_archive_duration -> Integer
readonly
The default value of duration of auto archive.
-
#last_message_id -> Discorb::Snowflake
readonly
The id of the last message.
-
#last_pin_timestamp -> Time
(also: #last_pinned_at)
readonly
The time when the last pinned message was pinned.
-
#nsfw -> Boolean
readonly
Whether the channel is nsfw.
-
#rate_limit_per_user -> Integer
(also: #slowmode)
readonly
The rate limit per user (Slowmode) in the channel.
- #threads -> Object readonly
-
#topic -> String
readonly
The topic of the channel.
Attributes inherited from GuildChannel
#permission_overwrites, #position
Attributes inherited from Channel
Instance Method Summary collapse
-
#create_webhook(name, avatar: nil) -> Async::Task<Discorb::Webhook::IncomingWebhook>
Create webhook in the channel.
-
#delete_messages(*messages, force: false) -> Async::Task<void>
(also: #bulk_delete, #destroy_messages)
Bulk delete messages in the channel.
-
#edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, reason: nil) -> Async::Task<self>
(also: #modify)
Edits the channel.
-
#fetch_archived_private_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived private threads in the channel.
-
#fetch_archived_public_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived threads in the channel.
-
#fetch_joined_archived_private_threads(limit: nil, before: nil) -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch joined archived private threads in the channel.
-
#fetch_webhooks -> Async::Task<Array<Discorb::Webhook>>
Fetch webhooks in the channel.
-
#follow_from(target, reason: nil) -> Async::Task<void>
Follow the existing announcement channel.
-
#start_thread(name, message: nil, auto_archive_duration: nil, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil) -> Async::Task<Discorb::ThreadChannel>
(also: #create_thread)
Start thread in the channel.
Methods included from Messageable
#delete_message, #edit_message, #fetch_message, #fetch_messages, #fetch_pins, #pin_message, #post, #typing, #unpin_message
Methods inherited from GuildChannel
#<=>, #==, #create_invite, #delete, #delete_permissions, #fetch_invites, #guild, #inspect, #mention, #move, #parent, #set_permissions, #to_s
Methods inherited from Channel
Methods inherited from DiscordModel
Instance Attribute Details
#default_auto_archive_duration -> Integer (readonly)
Returns The default value of duration of auto archive.
21 22 23 |
# File 'lib/discorb/channel/text.rb', line 21 def default_auto_archive_duration @default_auto_archive_duration end |
#last_message_id -> Discorb::Snowflake (readonly)
Returns The id of the last message.
13 14 15 |
# File 'lib/discorb/channel/text.rb', line 13 def @last_message_id end |
#last_pin_timestamp -> Time (readonly) Also known as: last_pinned_at
Returns The time when the last pinned message was pinned.
18 19 20 |
# File 'lib/discorb/channel/text.rb', line 18 def @last_pin_timestamp end |
#nsfw -> Boolean (readonly)
Returns Whether the channel is nsfw.
11 12 13 |
# File 'lib/discorb/channel/text.rb', line 11 def nsfw @nsfw end |
#rate_limit_per_user -> Integer (readonly) Also known as: slowmode
Returns The rate limit per user (Slowmode) in the channel.
15 16 17 |
# File 'lib/discorb/channel/text.rb', line 15 def rate_limit_per_user @rate_limit_per_user end |
#threads -> Object (readonly)
29 30 31 |
# File 'lib/discorb/channel/text.rb', line 29 def threads guild.threads.select { |thread| thread.parent == self } end |
#topic -> String (readonly)
Returns The topic of the channel.
9 10 11 |
# File 'lib/discorb/channel/text.rb', line 9 def topic @topic end |
Instance Method Details
#create_webhook(name, avatar: nil) -> Async::Task<Discorb::Webhook::IncomingWebhook>
Create webhook in the channel.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/discorb/channel/text.rb', line 111 def create_webhook(name, avatar: nil) Async do payload = {} payload[:name] = name payload[:avatar] = avatar.to_s if avatar _resp, data = @client .http .request( Route.new( "/channels/#{@id}/webhooks", "//channels/:channel_id/webhooks", :post ), payload ) .wait Webhook.from_data(@client, data) end end |
#delete_messages(*messages, force: false) -> Async::Task<void> Also known as: bulk_delete, destroy_messages
Bulk delete messages in the channel.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/discorb/channel/text.rb', line 164 def (*, force: false) Async do = .flatten unless force time = Time.now .delete_if do || next false unless .is_a?(Message) time - .created_at > 60 * 60 * 24 * 14 end end = .map { |m| Discorb::Utils.try(m, :id).to_s } @client .http .request( Route.new( "/channels/#{@id}/messages/bulk-delete", "//channels/:channel_id/messages/bulk-delete", :post ), { messages: } ) .wait end end |
#edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, reason: nil) -> Async::Task<self> Also known as: modify
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
.
Edits the channel.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/discorb/channel/text.rb', line 53 def edit( name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, reason: nil ) Async do payload = {} payload[:name] = name if name != Discorb::Unset payload[:announce] = announce ? 5 : 0 if announce != Discorb::Unset payload[:position] = position if position != Discorb::Unset payload[:topic] = topic || "" if topic != Discorb::Unset payload[:nsfw] = nsfw if nsfw != Discorb::Unset slowmode = rate_limit_per_user if slowmode == Discorb::Unset payload[:rate_limit_per_user] = slowmode || 0 if slowmode != Discorb::Unset parent = category if parent == Discorb::Unset payload[:parent_id] = parent&.id if parent != Discorb::Unset default_auto_archive_duration ||= archive_in if default_auto_archive_duration != Discorb::Unset payload[ :default_auto_archive_duration ] = default_auto_archive_duration end @client .http .request( Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload, audit_log_reason: reason ) .wait self end end |
#fetch_archived_private_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived private threads in the channel.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/discorb/channel/text.rb', line 314 def fetch_archived_private_threads Async do _resp, data = @client .http .request( Route.new( "/channels/#{@id}/threads/archived/private", "//channels/:channel_id/threads/archived/private", :get ) ) .wait data.map { |thread| Channel.make_channel(@client, thread) } end end |
#fetch_archived_public_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived threads in the channel.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/discorb/channel/text.rb', line 291 def fetch_archived_public_threads Async do _resp, data = @client .http .request( Route.new( "/channels/#{@id}/threads/archived/public", "//channels/:channel_id/threads/archived/public", :get ) ) .wait data.map { |thread| Channel.make_channel(@client, thread) } end end |
#fetch_joined_archived_private_threads(limit: nil, before: nil) -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch joined archived private threads in the channel.
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/discorb/channel/text.rb', line 340 def fetch_joined_archived_private_threads(limit: nil, before: nil) Async do if limit.nil? before = Time.now threads = [] loop do _resp, data = @client .http .request( Route.new( "/channels/#{@id}/users/@me/threads/archived/private?before=#{before.iso8601}", "//channels/:channel_id/users/@me/threads/archived/private", :get ) ) .wait threads += data[:threads].map do |thread| Channel.make_channel(@client, thread) end break unless data[:has_more] before = Snowflake.new(data[:threads][-1][:id]). end threads else _resp, data = @client .http .request( Route.new( "/channels/#{@id}/users/@me/threads/archived/private?limit=#{limit}&before=#{before.iso8601}", "//channels/:channel_id/users/@me/threads/archived/private", :get ) ) .wait data.map { |thread| Channel.make_channel(@client, thread) } end end end |
#fetch_webhooks -> Async::Task<Array<Discorb::Webhook>>
Fetch webhooks in the channel.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/discorb/channel/text.rb', line 138 def fetch_webhooks Async do _resp, data = @client .http .request( Route.new( "/channels/#{@id}/webhooks", "//channels/:channel_id/webhooks", :get ) ) .wait data.map { |webhook| Webhook.from_data(@client, webhook) } end end |
#follow_from(target, reason: nil) -> Async::Task<void>
Follow the existing announcement channel.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/discorb/channel/text.rb', line 204 def follow_from(target, reason: nil) Async do @client .http .request( Route.new( "/channels/#{target.id}/followers", "//channels/:channel_id/followers", :post ), { webhook_channel_id: @id }, audit_log_reason: reason ) .wait end end |
#start_thread(name, message: nil, auto_archive_duration: nil, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil) -> Async::Task<Discorb::ThreadChannel> Also known as: create_thread
Start thread in the channel.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/discorb/channel/text.rb', line 235 def start_thread( name, message: nil, auto_archive_duration: nil, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil ) auto_archive_duration ||= @default_auto_archive_duration Async do _resp, data = if .nil? @client .http .request( Route.new( "/channels/#{@id}/threads", "//channels/:channel_id/threads", :post ), { name: name, auto_archive_duration: auto_archive_duration, type: public ? 11 : 10, rate_limit_per_user: rate_limit_per_user || slowmode }, audit_log_reason: reason ) .wait else @client .http .request( Route.new( "/channels/#{@id}/messages/#{Utils.try(, :id)}/threads", "//channels/:channel_id/messages/:message_id/threads", :post ), { name: name, auto_archive_duration: auto_archive_duration }, audit_log_reason: reason ) .wait end Channel.make_channel(@client, data) end end |