Class: RubyCord::Guild::ThreadChannel

Inherits:
Channel show all
Includes:
Internal::Messageable
Defined in:
lib/rubycord/guild/channel/thread.rb

Direct Known Subclasses

ForumChannel::Post, News, Private, Public

Defined Under Namespace

Classes: Member, News, Private, Public

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Channel

#permission_overwrites, #position

Instance Method Summary collapse

Methods included from Internal::Messageable

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

Methods inherited from Channel

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

Methods inherited from Channel

#==, #type

Methods inherited from DiscordModel

#==, #eql?

Class Attribute Details

.channel_typeObject (readonly)

Returns the value of attribute channel_type.



323
324
325
# File 'lib/rubycord/guild/channel/thread.rb', line 323

def channel_type
  @channel_type
end

Instance Attribute Details

#archivedBoolean (readonly) Also known as: archived?

Returns Whether the thread is archived or not.

Returns:

  • (Boolean)

    Whether the thread is archived or not.



36
37
38
# File 'lib/rubycord/guild/channel/thread.rb', line 36

def archived
  @archived
end

#archived_timestampTime? (readonly) Also known as: archived_at

Returns:

  • (Time)

    The time the thread was archived.

  • (nil)

    If the thread is not archived.



30
31
32
# File 'lib/rubycord/guild/channel/thread.rb', line 30

def archived_timestamp
  @archived_timestamp
end

#auto_archive_durationInteger (readonly) Also known as: archive_in

Returns Auto archive duration in seconds.

Returns:

  • (Integer)

    Auto archive duration in seconds.



33
34
35
# File 'lib/rubycord/guild/channel/thread.rb', line 33

def auto_archive_duration
  @auto_archive_duration
end

#idRubyCord::Snowflake (readonly)

Note:

This ID is same as the starter message's ID

Returns The ID of the channel.

Returns:



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

def id
  @id
end

#member_countInteger (readonly) Also known as: recipient_count

Note:

This will stop counting at 50.

Returns The number of recipients in the thread.

Returns:

  • (Integer)

    The number of recipients in the thread.



21
22
23
# File 'lib/rubycord/guild/channel/thread.rb', line 21

def member_count
  @member_count
end

#membersArray<RubyCord::Guild::ThreadChannel::Member> (readonly)

Returns The members of the thread.

Returns:



27
28
29
# File 'lib/rubycord/guild/channel/thread.rb', line 27

def members
  @members
end

#message_countInteger (readonly)

Note:

This will stop counting at 50.

Returns The number of messages in the thread.

Returns:

  • (Integer)

    The number of messages in the thread.



18
19
20
# File 'lib/rubycord/guild/channel/thread.rb', line 18

def message_count
  @message_count
end

#nameString (readonly)

Returns The name of the thread.

Returns:

  • (String)

    The name of the thread.



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

def name
  @name
end

#rate_limit_per_userInteger (readonly) Also known as: slowmode

Returns The rate limit per user (slowmode) in the thread.

Returns:

  • (Integer)

    The rate limit per user (slowmode) in the thread.



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

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.

Parameters:

  • member (RubyCord::Guild::Member, :me) (defaults to: :me)

    The member to add. If :me is given, the bot will be added.

Returns:

  • (Async::Task<void>)

    The task.



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/rubycord/guild/channel/thread.rb', line 203

def add_member(member = :me)
  Async do
    if member == :me
      @client
        .http
        .request(
          RubyCord::Internal::Route.new(
            "/channels/#{@id}/thread-members/@me",
            "//channels/:channel_id/thread-members/@me",
            :post
          )
        )
        .wait
    else
      @client
        .http
        .request(
          RubyCord::Internal::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) ⇒ Async::Task<self>

Helper method to archive the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of archiving the thread.

Returns:

  • (Async::Task<self>)

    The archived thread.



125
126
127
# File 'lib/rubycord/guild/channel/thread.rb', line 125

def archive(reason: nil)
  edit(archived: true, reason:)
end

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

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.

Edit the thread.

Parameters:

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

    The name of the thread.

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

    Whether the thread is archived or not.

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

    The auto archive duration in seconds.

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

    Alias of auto_archive_duration.

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

    Whether the thread is locked or not.

  • reason (String) (defaults to: nil)

    The reason of editing the thread.

Returns:

  • (Async::Task<self>)

    The edited thread.

See Also:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rubycord/guild/channel/thread.rb', line 89

def edit(
  name: RubyCord::Unset,
  archived: RubyCord::Unset,
  auto_archive_duration: RubyCord::Unset,
  archive_in: RubyCord::Unset,
  locked: RubyCord::Unset,
  reason: nil
)
  Async do
    payload = {}
    payload[:name] = name if name != RubyCord::Unset
    payload[:archived] = archived if archived != RubyCord::Unset
    auto_archive_duration ||= archive_in
    payload[
      :auto_archive_duration
    ] = auto_archive_duration if auto_archive_duration != RubyCord::Unset
    payload[:locked] = locked if locked != RubyCord::Unset
    @client
      .http
      .request(
        RubyCord::Internal::Route.new("/channels/#{@id}", "//channels/:channel_id", :patch),
        payload,
        audit_log_reason: reason
      )
      .wait
    self
  end
end

#fetch_membersArray<RubyCord::Guild::ThreadChannel::Member>

Fetch members in the thread.

Returns:



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/rubycord/guild/channel/thread.rb', line 275

def fetch_members
  Async do
    _resp, data =
      @client
        .http
        .request(
          RubyCord::Internal::Route.new(
            "/channels/#{@id}/thread-members",
            "//channels/:channel_id/thread-members",
            :get
          )
        )
        .wait
    data.map { |d| @members[d[:id]] = RubyCord::Guild::Member.new(@client, d, @guild_id) }
  end
end

#guildRubyCord::Guild

Returns The guild of the thread.

Returns:



182
183
184
# File 'lib/rubycord/guild/channel/thread.rb', line 182

def guild
  @client.guilds[@guild]
end

#inspectString

Returns Object class and attributes.

Returns:

  • (String)

    Object class and attributes.



192
193
194
# File 'lib/rubycord/guild/channel/thread.rb', line 192

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

#joined?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/rubycord/guild/channel/thread.rb', line 177

def joined?
  !!me
end

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

Helper method to lock the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of locking the thread.

Returns:

  • (Async::Task<self>)

    The locked thread.



136
137
138
# File 'lib/rubycord/guild/channel/thread.rb', line 136

def lock(reason: nil)
  edit(archived: true, locked: true, reason:)
end

#meRubyCord::Guild::ThreadChannel::Member?



172
173
174
# File 'lib/rubycord/guild/channel/thread.rb', line 172

def me
  @members[@client.user.id]
end

#ownerRubyCord::Guild::Member

Returns The owner of the thread.

Returns:



187
188
189
# File 'lib/rubycord/guild/channel/thread.rb', line 187

def owner
  guild.members[@owner_id]
end

#parentRubyCord::Guild::TextChannel Also known as: channel



165
166
167
# File 'lib/rubycord/guild/channel/thread.rb', line 165

def parent
  @client.channels[@parent_id]
end

#remove_member(member = :me) ⇒ Async::Task<void> Also known as: leave

Remove a member from the thread.

Parameters:

  • member (RubyCord::Guild::Member, :me) (defaults to: :me)

    The member to remove. If :me is given, the bot will be removed.

Returns:

  • (Async::Task<void>)

    The task.



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
# File 'lib/rubycord/guild/channel/thread.rb', line 240

def remove_member(member = :me)
  Async do
    if member == :me
      @client
        .http
        .request(
          RubyCord::Internal::Route.new(
            "/channels/#{@id}/thread-members/@me",
            "//channels/:channel_id/thread-members/@me",
            :delete
          )
        )
        .wait
    else
      @client
        .http
        .request(
          RubyCord::Internal::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) ⇒ Async::Task<self>

Helper method to unarchive the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of unarchiving the thread.

Returns:

  • (Async::Task<self>)

    The unarchived thread.



147
148
149
# File 'lib/rubycord/guild/channel/thread.rb', line 147

def unarchive(reason: nil)
  edit(archived: false, reason:)
end

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

Note:

This method won't unarchive the thread. Use #unarchive instead.

Helper method to unlock the thread.

Parameters:

  • reason (String) (defaults to: nil)

    The reason of unlocking the thread.

Returns:

  • (Async::Task<self>)

    The unlocked thread.



160
161
162
# File 'lib/rubycord/guild/channel/thread.rb', line 160

def unlock(reason: nil)
  edit(archived: !unarchive, locked: false, reason:)
end