Class: Discorb::ForumChannel::Post

Inherits:
ThreadChannel show all
Defined in:
lib/discorb/channel/forum.rb

Overview

Represents a thread in the forum channel.

Instance Attribute Summary collapse

Attributes inherited from ThreadChannel

#archived, #archived_timestamp, #auto_archive_duration, #id, #member_count, #members, #message_count, #name, #rate_limit_per_user

Attributes inherited from Channel

#id, #name

Instance Method Summary collapse

Methods inherited from ThreadChannel

#add_member, #archive, #fetch_members, #guild, #inspect, #joined?, #lock, #me, #owner, #parent, #remove_member, #unarchive, #unlock

Methods included from Messageable

#delete_message, #edit_message, #fetch_message, #fetch_messages, #fetch_pins, #pin_message, #post, #typing, #unpin_message

Methods inherited from Channel

#==, #inspect, #type

Methods inherited from DiscordModel

#==, #eql?, #inspect

Instance Attribute Details

#pinnedBoolean (readonly) Also known as: pinned?

Returns Whether the post is pinned.

Returns:

  • (Boolean)

    Whether the post is pinned.



114
115
116
# File 'lib/discorb/channel/forum.rb', line 114

def pinned
  @pinned
end

#tagsArray<Discorb::ForumChannel::Tag> (readonly)

Returns The tags of the post.

Returns:



112
113
114
# File 'lib/discorb/channel/forum.rb', line 112

def tags
  @tags
end

Instance Method Details

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

Adds tags to the thread.

Parameters:

Returns:

  • (Async::Task<self>)

    The thread with added tags.

See Also:



216
217
218
# File 'lib/discorb/channel/forum.rb', line 216

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

#edit(name: Discorb::Unset, archived: Discorb::Unset, auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, locked: Discorb::Unset, pinned: Discorb::Unset, tags: Discorb::Unset, reason: nil) ⇒ Async::Task<self>

Note:

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.

Parameters:

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

    The name of the thread.

  • archived (Boolean) (defaults to: Discorb::Unset)

    Whether the thread is archived or not.

  • auto_archive_duration (Integer) (defaults to: Discorb::Unset)

    The auto archive duration in seconds.

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

    Alias of auto_archive_duration.

  • locked (Boolean) (defaults to: Discorb::Unset)

    Whether the thread is locked or not.

  • reason (String) (defaults to: nil)

    The reason of editing the thread.

  • pinned (Boolean) (defaults to: Discorb::Unset)

    Whether the thread is pinned or not.

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

    The tags of the thread.

Returns:

  • (Async::Task<self>)

    The edited thread.

See Also:



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/discorb/channel/forum.rb', line 142

def edit(
  name: Discorb::Unset,
  archived: Discorb::Unset,
  auto_archive_duration: Discorb::Unset,
  archive_in: Discorb::Unset,
  locked: Discorb::Unset,
  pinned: Discorb::Unset,
  tags: 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
    payload[:flags] = pinned ? 1 : 0 if pinned != Discorb::Unset
    payload[:applied_tags] = tags.map(&:id) if tags != Discorb::Unset
    @client
      .http
      .request(
        Route.new("/channels/#{@id}", "//channels/:channel_id", :patch),
        payload,
        audit_log_reason: reason
      )
      .wait
    self
  end
end

#pin(reason: nil) ⇒ Async::Task<self>

Pins the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of pinning the thread.

Returns:

  • (Async::Task<self>)

    The pinned thread.

See Also:



186
187
188
# File 'lib/discorb/channel/forum.rb', line 186

def pin(reason: nil)
  edit(pinned: true, reason:)
end

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

Removes tags from the thread.

Parameters:

  • tags (Array<Discorb::ForumChannel::Tag>)

    The tags to remove.

  • reason (String) (defaults to: nil)

    The reason of removing tags.

Returns:

  • (Async::Task<self>)

    The thread with removed tags.

See Also:



231
232
233
# File 'lib/discorb/channel/forum.rb', line 231

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

#unpin(reason: nil) ⇒ Async::Task<self>

Unpins the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of unpinning the thread.

Returns:

  • (Async::Task<self>)

    The unpinned thread.

See Also:



201
202
203
# File 'lib/discorb/channel/forum.rb', line 201

def unpin(reason: nil)
  edit(pinned: false, reason:)
end