Class: RubyCord::Guild::ForumChannel

Inherits:
Channel show all
Defined in:
lib/rubycord/guild/channel/forum.rb

Defined Under Namespace

Classes: Post, Tag

Constant Summary collapse

DEFAULT_SORT_ORDER =
{ 1 => :latest_activity, 2 => :creation_date }.freeze

Instance Attribute Summary collapse

Attributes inherited from Channel

#permission_overwrites, #position

Attributes inherited from Channel

#id, #name

Instance Method Summary collapse

Methods inherited from Channel

#<=>, #==, #create_invite, #delete, #delete_permissions, #fetch_invites, #guild, #mention, #move, #parent, #set_permissions, #to_s

Methods inherited from Channel

#==, #type

Methods inherited from DiscordModel

#==, #eql?

Constructor Details

#initialize(client, data, no_cache: false) ⇒ ForumChannel

Returns a new instance of ForumChannel.



246
247
248
249
# File 'lib/rubycord/guild/channel/forum.rb', line 246

def initialize(client, data, no_cache: false)
  super
  _set_data(data)
end

Instance Attribute Details

#default_auto_archive_durationInteger (readonly)

Returns The default value of duration of auto archive.

Returns:

  • (Integer)

    The default value of duration of auto archive.



22
23
24
# File 'lib/rubycord/guild/channel/forum.rb', line 22

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.

Returns:

  • (:latest_activity, :creation_date)

    The default sort order of the channel.



24
25
26
# File 'lib/rubycord/guild/channel/forum.rb', line 24

def default_sort_order
  @default_sort_order
end

#guidelineString (readonly) Also known as: topic

Returns The guideline of the channel.

Returns:

  • (String)

    The guideline of the channel.



10
11
12
# File 'lib/rubycord/guild/channel/forum.rb', line 10

def guideline
  @guideline
end

#message_rate_limit_per_userInteger (readonly) Also known as: message_slowmode

Returns The rate limit to send message per user (Slowmode) in the channel.

Returns:

  • (Integer)

    The rate limit to send message per user (Slowmode) in the channel.



19
20
21
# File 'lib/rubycord/guild/channel/forum.rb', line 19

def message_rate_limit_per_user
  @message_rate_limit_per_user
end

#nsfwBoolean (readonly)

Returns Whether the channel is nsfw.

Returns:

  • (Boolean)

    Whether the channel is nsfw.



13
14
15
# File 'lib/rubycord/guild/channel/forum.rb', line 13

def nsfw
  @nsfw
end

#rate_limit_per_userInteger (readonly) Also known as: slowmode, thread_slowmode

Returns The rate limit to create thread per user (Slowmode) in the channel.

Returns:

  • (Integer)

    The rate limit to create thread per user (Slowmode) in the channel.



15
16
17
# File 'lib/rubycord/guild/channel/forum.rb', line 15

def rate_limit_per_user
  @rate_limit_per_user
end

#require_tagBoolean (readonly) Also known as: require_tag?

Returns Whether at least one tag is required.

Returns:

  • (Boolean)

    Whether at least one tag is required.



28
29
30
# File 'lib/rubycord/guild/channel/forum.rb', line 28

def require_tag
  @require_tag
end

#tagsArray<RubyCord::Guild::ForumChannel::Tag> (readonly)

Returns The tags in the channel.

Returns:



26
27
28
# File 'lib/rubycord/guild/channel/forum.rb', line 26

def tags
  @tags
end

#threadsObject (readonly)



35
36
37
# File 'lib/rubycord/guild/channel/forum.rb', line 35

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<RubyCord::Guild::ForumChannel::Post> Also known as: start_thread

Create post in the channel.

Parameters:

  • title (Title)

    The title of the thread.

  • content (String) (defaults to: nil)

    The message content.

  • embed (RubyCord::Embed) (defaults to: nil)

    The embed to send.

  • embeds (Array<RubyCord::Embed>) (defaults to: nil)

    The embeds to send.

  • allowed_mentions (RubyCord::AllowedMentions) (defaults to: nil)

    The allowed mentions.

  • components (Array<RubyCord::Component>, Array<Array<RubyCord::Component>>) (defaults to: nil)

    The components to send.

  • attachment (RubyCord::Attachment) (defaults to: nil)

    The attachment to send.

  • attachments (Array<RubyCord::Attachment>) (defaults to: nil)

    The attachments to send.

  • tags (Array<RubyCord::Guild::ForumChannel::Tag>) (defaults to: nil)

    The tags to attach.

  • auto_archive_duration (:hour, :day, :three_days, :week) (defaults to: nil)

    The duration of auto-archiving.

  • rate_limit_per_user (Integer) (defaults to: nil)

    The rate limit per user.

  • slowmode (Integer) (defaults to: nil)

    Alias of rate_limit_per_user.

Returns:



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
537
538
539
# File 'lib/rubycord/guild/channel/forum.rb', line 472

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
    message_payload = {}
    message_payload[:content] = content if content
    tmp_embed =
      if embed
        [embed]
      elsif embeds
        embeds
      end
    message_payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
    message_payload[:allowed_mentions] = (
      if allowed_mentions
        allowed_mentions.to_hash(@client.allowed_mentions)
      else
        @client.allowed_mentions.to_hash
      end
    )
    message_payload[:components] = Component.to_payload(
      components
    ) if components
    attachments ||= attachment ? [attachment] : []

    message_payload[:attachments] = 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] = message_payload
    payload[:applied_tags] = tags.map(&:id) if tags

    _resp, data =
      @client
        .http
        .multipart_request(
          RubyCord::Internal::Route.new(
            "/channels/#{channel_id.wait}/threads",
            "//channels/:channel_id/threads",
            :post
          ),
          payload,
          attachments,
          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.

Parameters:

Returns:

  • (Async::Task<self>)

    The edited channel.

See Also:



381
382
383
# File 'lib/rubycord/guild/channel/forum.rb', line 381

def create_tags(*tags, reason: nil)
  edit(tags: self.tags + tags, reason:)
end

#create_webhook(name, avatar: nil) ⇒ Async::Task<RubyCord::Guild::Webhook::IncomingWebhook>

Create webhook in the channel.

Parameters:

  • name (String)

    The name of the webhook.

  • avatar (RubyCord::Image) (defaults to: nil)

    The avatar of the webhook.

Returns:

  • (Async::Task<RubyCord::Guild::Webhook::IncomingWebhook>)

    The created webhook.



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/rubycord/guild/channel/forum.rb', line 409

def create_webhook(name, avatar: nil)
  Async do
    payload = {}
    payload[:name] = name
    payload[:avatar] = avatar.to_s if avatar
    _resp, data =
      @client
        .http
        .request(
          RubyCord::Internal::Route.new(
            "/channels/#{@id}/webhooks",
            "//channels/:channel_id/webhooks",
            :post
          ),
          payload
        )
        .wait
    Guild::Webhook.from_data(@client, data)
  end
end

#delete_tags(*tags, reason: nil) ⇒ Async::Task<self>

Deletes tags from the channel.

Parameters:

Returns:

  • (Async::Task<self>)

    The edited channel.

See Also:



396
397
398
# File 'lib/rubycord/guild/channel/forum.rb', line 396

def delete_tags(*tags, reason: nil)
  edit(tags: self.tags - tags, reason:)
end

#edit(name: RubyCord::Unset, position: RubyCord::Unset, category: RubyCord::Unset, parent: RubyCord::Unset, topic: RubyCord::Unset, guideline: RubyCord::Unset, nsfw: RubyCord::Unset, rate_limit_per_user: RubyCord::Unset, slowmode: RubyCord::Unset, thread_rate_limit_per_user: RubyCord::Unset, thread_slowmode: RubyCord::Unset, default_auto_archive_duration: RubyCord::Unset, archive_in: RubyCord::Unset, require_tag: RubyCord::Unset, default_reaction_emoji: RubyCord::Unset, default_sort_order: RubyCord::Unset, tags: RubyCord::Unset, reason: nil) ⇒ Async::Task<self> Also known as: modify

Note:

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

Edits the channel.

Parameters:

  • name (String) (defaults to: RubyCord::Unset)

    The name of the channel.

  • position (Integer) (defaults to: RubyCord::Unset)

    The position of the channel.

  • category (RubyCord::Guild::CategoryChannel, nil) (defaults to: RubyCord::Unset)

    The parent of channel. Specify nil to remove the parent.

  • parent (RubyCord::Guild::CategoryChannel, nil) (defaults to: RubyCord::Unset)

    Alias of category.

  • topic (String) (defaults to: RubyCord::Unset)

    The topic of the channel.

  • guideline (String) (defaults to: RubyCord::Unset)

    Alias of topic.

  • nsfw (Boolean) (defaults to: RubyCord::Unset)

    Whether the channel is nsfw.

  • rate_limit_per_user (Integer) (defaults to: RubyCord::Unset)

    The rate limit per user (Slowmode) in the channel.

  • slowmode (Integer) (defaults to: RubyCord::Unset)

    Alias of rate_limit_per_user.

  • thread_rate_limit_per_user (Integer) (defaults to: RubyCord::Unset)

    The rate limit per user (Slowmode) in threads.

  • thread_slowmode (Integer) (defaults to: RubyCord::Unset)

    Alias of thread_rate_limit_per_user.

  • default_auto_archive_duration (Integer) (defaults to: RubyCord::Unset)

    The default auto archive duration of the channel.

  • archive_in (Integer) (defaults to: RubyCord::Unset)

    Alias of default_auto_archive_duration.

  • require_tag (Boolean) (defaults to: RubyCord::Unset)

    Whether the channel requires tag to create thread.

  • default_reaction_emoji (RubyCord::Emoji) (defaults to: RubyCord::Unset)

    The default reaction emoji of the channel.

  • default_sort_order (:latest_activity, :creation_date) (defaults to: RubyCord::Unset)

    The default sort order of the channel.

  • tags (Array<RubyCord::Guild::ForumChannel::Tag>) (defaults to: RubyCord::Unset)

    The tags of the channel.

  • reason (String) (defaults to: nil)

    The reason of editing the channel.

Returns:

  • (Async::Task<self>)

    The edited channel.

See Also:



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
364
365
366
# File 'lib/rubycord/guild/channel/forum.rb', line 285

def edit(
  name: RubyCord::Unset,
  position: RubyCord::Unset,
  category: RubyCord::Unset,
  parent: RubyCord::Unset,
  topic: RubyCord::Unset,
  guideline: RubyCord::Unset,
  nsfw: RubyCord::Unset,
  rate_limit_per_user: RubyCord::Unset,
  slowmode: RubyCord::Unset,
  thread_rate_limit_per_user: RubyCord::Unset,
  thread_slowmode: RubyCord::Unset,
  default_auto_archive_duration: RubyCord::Unset,
  archive_in: RubyCord::Unset,
  require_tag: RubyCord::Unset,
  default_reaction_emoji: RubyCord::Unset,
  default_sort_order: RubyCord::Unset,
  tags: RubyCord::Unset,
  reason: nil
)
  Async do
    payload = {}
    payload[:name] = name unless name == RubyCord::Unset
    payload[:position] = position unless position == RubyCord::Unset
    payload[:parent_id] = category.id unless category == RubyCord::Unset
    payload[:parent_id] = parent.id unless parent == RubyCord::Unset
    payload[:topic] = topic unless topic == RubyCord::Unset
    payload[:topic] = guideline unless guideline == RubyCord::Unset
    payload[:nsfw] = nsfw unless nsfw == RubyCord::Unset
    payload[
      :rate_limit_per_user
    ] = rate_limit_per_user unless rate_limit_per_user == RubyCord::Unset
    payload[:rate_limit_per_user] = slowmode unless slowmode ==
      RubyCord::Unset
    payload[
      :thread_rate_limit_per_user
    ] = thread_rate_limit_per_user unless thread_rate_limit_per_user ==
      RubyCord::Unset
    payload[
      :thread_rate_limit_per_user
    ] = thread_slowmode unless thread_slowmode == RubyCord::Unset
    payload[
      :default_auto_archive_duration
    ] = default_auto_archive_duration unless default_auto_archive_duration ==
      RubyCord::Unset
    payload[
      :default_auto_archive_duration
    ] = archive_in unless archive_in == RubyCord::Unset
    payload[:flags] = (require_tag ? 1 << 4 : 0) unless require_tag ==
      RubyCord::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 == RubyCord::Unset
    payload[:default_sort_order] = DEFAULT_SORT_ORDER.key(
      default_sort_order
    ) unless default_sort_order == RubyCord::Unset
    payload[:available_tags] = tags.map(&:to_hash) unless tags ==
      RubyCord::Unset
    ret =
      @client
        .http
        .request(
          RubyCord::Internal::Route.new("/channels/#{id}", "//channels/:channel_id", :patch),
          reason:
        )
        .wait
    _set_data(ret)
    if tags != RubyCord::Unset
      tags
        .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_threadsAsync::Task<Array<RubyCord::Guild::ThreadChannel>>

Fetch archived threads in the channel.

Returns:



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/rubycord/guild/channel/forum.rb', line 550

def fetch_archived_threads
  Async do
    _resp, data =
      @client
        .http
        .request(
          RubyCord::Internal::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_webhooksAsync::Task<Array<RubyCord::Guild::Webhook>>

Fetch webhooks in the channel.

Returns:



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/rubycord/guild/channel/forum.rb', line 436

def fetch_webhooks
  Async do
    _resp, data =
      @client
        .http
        .request(
          RubyCord::Internal::Route.new(
            "/channels/#{@id}/webhooks",
            "//channels/:channel_id/webhooks",
            :get
          )
        )
        .wait
    data.map { |webhook| Webhook.from_data(@client, webhook) }
  end
end

#inspectString

Returns Object class and attributes.

Returns:

  • (String)

    Object class and attributes.



252
253
254
# File 'lib/rubycord/guild/channel/forum.rb', line 252

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