Class: Discorb::ForumChannel
- Inherits:
-
GuildChannel
- Object
- DiscordModel
- Channel
- GuildChannel
- Discorb::ForumChannel
- Defined in:
- lib/discorb/channel/forum.rb
Overview
Represents a forum channel.
Defined Under Namespace
Constant Summary collapse
- DEFAULT_SORT_ORDER =
{ 1 => :latest_activity, 2 => :creation_date }.freeze
Instance Attribute Summary collapse
-
#default_auto_archive_duration -> Integer
readonly
The default value of duration of auto archive.
-
#default_sort_order -> :latest_activity, :creation_date
readonly
The default sort order of the channel.
-
#guideline -> String
(also: #topic)
readonly
The guideline of the channel.
-
#message_rate_limit_per_user -> Integer
(also: #message_slowmode)
readonly
The rate limit to send message per user (Slowmode) in the channel.
-
#nsfw -> Boolean
readonly
Whether the channel is nsfw.
-
#rate_limit_per_user -> Integer
(also: #slowmode, #thread_slowmode)
readonly
The rate limit to create thread per user (Slowmode) in the channel.
-
#require_tag -> Boolean
(also: #require_tag?)
readonly
Whether at least one tag is required.
-
#tags -> Array<Discorb::ForumChannel::Tag>
readonly
The tags in the channel.
- #threads -> Object readonly
Attributes inherited from GuildChannel
#permission_overwrites, #position
Attributes inherited from Channel
Instance Method Summary collapse
-
#create_post(title, content = nil, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, attachment: nil, attachments: nil, tags: nil, auto_archive_duration: nil, rate_limit_per_user: nil, slowmode: nil, reason: nil) -> Async::Task<Discorb::PublicThread>
(also: #start_thread)
Create post in the channel.
-
#create_tags(*tags, reason: nil) -> Async::Task<self>
Creates tags in the channel.
-
#create_webhook(name, avatar: nil) -> Async::Task<Discorb::Webhook::IncomingWebhook>
Create webhook in the channel.
-
#delete_tags(*tags, reason: nil) -> Async::Task<self>
Deletes tags from the channel.
-
#edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, guideline: Discorb::Unset, nsfw: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, thread_rate_limit_per_user: Discorb::Unset, thread_slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, require_tag: Discorb::Unset, default_reaction_emoji: Discorb::Unset, default_sort_order: Discorb::Unset, tags: Discorb::Unset, reason: nil) -> Async::Task<self>
(also: #modify)
Edits the channel.
-
#fetch_archived_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived threads in the channel.
-
#fetch_webhooks -> Async::Task<Array<Discorb::Webhook>>
Fetch webhooks in the channel.
-
#initialize(client, data, no_cache: false) -> ForumChannel
constructor
A new instance of ForumChannel.
- #inspect -> Object
Methods inherited from GuildChannel
#<=>, #==, #create_invite, #delete, #delete_permissions, #fetch_invites, #guild, #mention, #move, #parent, #set_permissions, #to_s
Methods inherited from Channel
Methods inherited from DiscordModel
Constructor Details
#initialize(client, data, no_cache: false) -> ForumChannel
Returns a new instance of ForumChannel.
244 245 246 247 |
# File 'lib/discorb/channel/forum.rb', line 244 def initialize(client, data, no_cache: false) super _set_data(data) end |
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/forum.rb', line 21 def default_auto_archive_duration @default_auto_archive_duration end |
#default_sort_order -> :latest_activity, :creation_date (readonly)
Returns The default sort order of the channel.
23 24 25 |
# File 'lib/discorb/channel/forum.rb', line 23 def default_sort_order @default_sort_order end |
#guideline -> String (readonly) Also known as: topic
Returns The guideline of the channel.
9 10 11 |
# File 'lib/discorb/channel/forum.rb', line 9 def guideline @guideline end |
#message_rate_limit_per_user -> Integer (readonly) Also known as: message_slowmode
Returns The rate limit to send message per user (Slowmode) in the channel.
18 19 20 |
# File 'lib/discorb/channel/forum.rb', line 18 def @message_rate_limit_per_user end |
#nsfw -> Boolean (readonly)
Returns Whether the channel is nsfw.
12 13 14 |
# File 'lib/discorb/channel/forum.rb', line 12 def nsfw @nsfw end |
#rate_limit_per_user -> Integer (readonly) Also known as: slowmode, thread_slowmode
Returns The rate limit to create thread per user (Slowmode) in the channel.
14 15 16 |
# File 'lib/discorb/channel/forum.rb', line 14 def rate_limit_per_user @rate_limit_per_user end |
#require_tag -> Boolean (readonly) Also known as: require_tag?
Returns Whether at least one tag is required.
27 28 29 |
# File 'lib/discorb/channel/forum.rb', line 27 def require_tag @require_tag end |
#tags -> Array<Discorb::ForumChannel::Tag> (readonly)
Returns The tags in the channel.
25 26 27 |
# File 'lib/discorb/channel/forum.rb', line 25 def @tags end |
#threads -> Object (readonly)
34 35 36 |
# File 'lib/discorb/channel/forum.rb', line 34 def threads guild.threads.select { |thread| thread.parent == self } end |
Instance Method Details
#create_post(title, content = nil, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, attachment: nil, attachments: nil, tags: nil, auto_archive_duration: nil, rate_limit_per_user: nil, slowmode: nil, reason: nil) -> Async::Task<Discorb::PublicThread> Also known as: start_thread
Create post in the channel.
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/discorb/channel/forum.rb', line 469 def create_post( title, content = nil, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, attachment: nil, attachments: nil, tags: nil, auto_archive_duration: nil, rate_limit_per_user: nil, slowmode: nil, reason: nil ) Async do = {} [:content] = content if content = if [] elsif end [:embeds] = .map(&:to_hash) if [:allowed_mentions] = ( if allowed_mentions allowed_mentions.to_hash(@client.allowed_mentions) else @client.allowed_mentions.to_hash end ) [:components] = Component.to_payload( components ) if components ||= ? [] : [] [:attachments] = .map.with_index do |a, i| { id: i, filename: a.filename, description: a.description } end payload = {} payload[:name] = title payload[ :auto_archive_duration ] = auto_archive_duration if auto_archive_duration payload[:rate_limit_per_user] = rate_limit_per_user || slowmode if rate_limit_per_user || slowmode payload[:message] = payload[:applied_tags] = .map(&:id) if _resp, data = @client .http .multipart_request( Route.new( "/channels/#{channel_id.wait}/threads", "//channels/:channel_id/threads", :post ), payload, , audit_log_reason: reason ) .wait Channel.make_channel(@client, data) end end |
#create_tags(*tags, reason: nil) -> Async::Task<self>
Creates tags in the channel.
378 379 380 |
# File 'lib/discorb/channel/forum.rb', line 378 def (*, reason: nil) edit(tags: self. + , reason: reason) end |
#create_webhook(name, avatar: nil) -> Async::Task<Discorb::Webhook::IncomingWebhook>
Create webhook in the channel.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/discorb/channel/forum.rb', line 406 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_tags(*tags, reason: nil) -> Async::Task<self>
Deletes tags from the channel.
393 394 395 |
# File 'lib/discorb/channel/forum.rb', line 393 def (*, reason: nil) edit(tags: self. - , reason: reason) end |
#edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, guideline: Discorb::Unset, nsfw: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, thread_rate_limit_per_user: Discorb::Unset, thread_slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, require_tag: Discorb::Unset, default_reaction_emoji: Discorb::Unset, default_sort_order: Discorb::Unset, tags: 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.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/discorb/channel/forum.rb', line 282 def edit( name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, guideline: Discorb::Unset, nsfw: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, thread_rate_limit_per_user: Discorb::Unset, thread_slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, require_tag: Discorb::Unset, default_reaction_emoji: Discorb::Unset, default_sort_order: Discorb::Unset, tags: Discorb::Unset, reason: nil ) Async do payload = {} payload[:name] = name unless name == Discorb::Unset payload[:position] = position unless position == Discorb::Unset payload[:parent_id] = category.id unless category == Discorb::Unset payload[:parent_id] = parent.id unless parent == Discorb::Unset payload[:topic] = topic unless topic == Discorb::Unset payload[:topic] = guideline unless guideline == Discorb::Unset payload[:nsfw] = nsfw unless nsfw == Discorb::Unset payload[ :rate_limit_per_user ] = rate_limit_per_user unless rate_limit_per_user == Discorb::Unset payload[:rate_limit_per_user] = slowmode unless slowmode == Discorb::Unset payload[ :thread_rate_limit_per_user ] = thread_rate_limit_per_user unless thread_rate_limit_per_user == Discorb::Unset payload[ :thread_rate_limit_per_user ] = thread_slowmode unless thread_slowmode == Discorb::Unset payload[ :default_auto_archive_duration ] = default_auto_archive_duration unless default_auto_archive_duration == Discorb::Unset payload[ :default_auto_archive_duration ] = archive_in unless archive_in == Discorb::Unset payload[:flags] = (require_tag ? 1 << 4 : 0) unless require_tag == Discorb::Unset payload[:default_reaction_emoji] = default_reaction_emoji .to_hash .then do |e| { emoji_name: e[:name], emoji_id: e[:id] } end unless default_reaction_emoji == Discorb::Unset payload[:default_sort_order] = DEFAULT_SORT_ORDER.key( default_sort_order ) unless default_sort_order == Discorb::Unset payload[:available_tags] = .map(&:to_hash) unless == Discorb::Unset ret = @client .http .request( Route.new("/channels/#{id}", "//channels/:channel_id", :patch), reason: reason ) .wait _set_data(ret) if != Discorb::Unset .reject(&:id) .each do |tag| tag.instance_variable_set( :@id, ret[:available_tags].find { |t| t.to_hash == tag.to_hash }[:id] ) end end self end end |
#fetch_archived_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived threads in the channel.
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/discorb/channel/forum.rb', line 547 def fetch_archived_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_webhooks -> Async::Task<Array<Discorb::Webhook>>
Fetch webhooks in the channel.
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/discorb/channel/forum.rb', line 433 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 |
#inspect -> Object
249 250 251 |
# File 'lib/discorb/channel/forum.rb', line 249 def inspect "#<#{self.class}: #{name} id=#{id}>" end |