discorb 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
@@ -1,325 +1,374 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a thread.
|
6
|
-
# @abstract
|
7
|
-
#
|
8
|
-
class ThreadChannel < Channel
|
9
|
-
# @return [Discorb::Snowflake] The ID of the channel.
|
10
|
-
# @note This ID is same as the starter message's ID
|
11
|
-
attr_reader :id
|
12
|
-
# @return [String] The name of the thread.
|
13
|
-
attr_reader :name
|
14
|
-
# @return [Integer] The number of messages in the thread.
|
15
|
-
# @note This will stop counting at 50.
|
16
|
-
attr_reader :message_count
|
17
|
-
# @return [Integer] The number of recipients in the thread.
|
18
|
-
# @note This will stop counting at 50.
|
19
|
-
attr_reader :member_count
|
20
|
-
alias recipient_count member_count
|
21
|
-
# @return [Integer] The rate limit per user (slowmode) in the thread.
|
22
|
-
attr_reader :rate_limit_per_user
|
23
|
-
alias slowmode rate_limit_per_user
|
24
|
-
# @return [Array<Discorb::ThreadChannel::Member>] The members of the thread.
|
25
|
-
attr_reader :members
|
26
|
-
# @return [Time] The time the thread was archived.
|
27
|
-
# @return [nil] If the thread is not archived.
|
28
|
-
attr_reader :archived_timestamp
|
29
|
-
alias archived_at archived_timestamp
|
30
|
-
# @return [Integer] Auto archive duration in seconds.
|
31
|
-
attr_reader :auto_archive_duration
|
32
|
-
alias archive_in auto_archive_duration
|
33
|
-
# @return [Boolean] Whether the thread is archived or not.
|
34
|
-
attr_reader :archived
|
35
|
-
alias archived? archived
|
36
|
-
|
37
|
-
# @!attribute [r] parent
|
38
|
-
# @macro client_cache
|
39
|
-
# @return [Discorb::GuildChannel] The parent channel of the thread.
|
40
|
-
# @!attribute [r] me
|
41
|
-
# @return [Discorb::ThreadChannel::Member] The bot's member in the thread.
|
42
|
-
# @return [nil] If the bot is not in the thread.
|
43
|
-
# @!attribute [r] joined?
|
44
|
-
# @return [Boolean] Whether the bot is in the thread or not.
|
45
|
-
# @!attribute [r] guild
|
46
|
-
# @macro client_cache
|
47
|
-
# @return [Discorb::Guild] The guild of the thread.
|
48
|
-
# @!attribute [r] owner
|
49
|
-
# @macro client_cache
|
50
|
-
# @macro members_intent
|
51
|
-
# @return [Discorb::Member] The owner of the thread.
|
52
|
-
|
53
|
-
include Messageable
|
54
|
-
@channel_type = nil
|
55
|
-
|
56
|
-
#
|
57
|
-
# Initialize a new thread channel.
|
58
|
-
# @private
|
59
|
-
#
|
60
|
-
# @param [Discorb::Client] client The client.
|
61
|
-
# @param [Hash] data The data of the thread channel.
|
62
|
-
# @param [Boolean] no_cache Whether to disable the cache.
|
63
|
-
#
|
64
|
-
def initialize(client, data, no_cache: false)
|
65
|
-
@members = Dictionary.new
|
66
|
-
super
|
67
|
-
@client.channels[@id] = self unless no_cache
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# Edit the thread.
|
72
|
-
# @async
|
73
|
-
# @macro edit
|
74
|
-
#
|
75
|
-
# @param [String] name The name of the thread.
|
76
|
-
# @param [Boolean] archived Whether the thread is archived or not.
|
77
|
-
# @param [Integer] auto_archive_duration The auto archive duration in seconds.
|
78
|
-
# @param [Integer] archive_in Alias of `auto_archive_duration`.
|
79
|
-
# @param [Boolean] locked Whether the thread is locked or not.
|
80
|
-
# @param [String] reason The reason of editing the thread.
|
81
|
-
#
|
82
|
-
# @return [Async::Task<self>] The edited thread.
|
83
|
-
#
|
84
|
-
# @see #archive
|
85
|
-
# @see #lock
|
86
|
-
# @see #unarchive
|
87
|
-
# @see #unlock
|
88
|
-
#
|
89
|
-
def edit(
|
90
|
-
name: Discorb::Unset,
|
91
|
-
archived: Discorb::Unset,
|
92
|
-
auto_archive_duration: Discorb::Unset,
|
93
|
-
archive_in: Discorb::Unset,
|
94
|
-
locked: Discorb::Unset,
|
95
|
-
reason: nil
|
96
|
-
)
|
97
|
-
Async do
|
98
|
-
payload = {}
|
99
|
-
payload[:name] = name if name != Discorb::Unset
|
100
|
-
payload[:archived] = archived if archived != Discorb::Unset
|
101
|
-
auto_archive_duration ||= archive_in
|
102
|
-
payload[
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
#
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
def
|
165
|
-
@
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
def
|
173
|
-
@client.
|
174
|
-
end
|
175
|
-
|
176
|
-
def
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
def
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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
|
-
#
|
230
|
-
#
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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
|
-
end
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
#
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a thread.
|
6
|
+
# @abstract
|
7
|
+
#
|
8
|
+
class ThreadChannel < Channel
|
9
|
+
# @return [Discorb::Snowflake] The ID of the channel.
|
10
|
+
# @note This ID is same as the starter message's ID
|
11
|
+
attr_reader :id
|
12
|
+
# @return [String] The name of the thread.
|
13
|
+
attr_reader :name
|
14
|
+
# @return [Integer] The number of messages in the thread.
|
15
|
+
# @note This will stop counting at 50.
|
16
|
+
attr_reader :message_count
|
17
|
+
# @return [Integer] The number of recipients in the thread.
|
18
|
+
# @note This will stop counting at 50.
|
19
|
+
attr_reader :member_count
|
20
|
+
alias recipient_count member_count
|
21
|
+
# @return [Integer] The rate limit per user (slowmode) in the thread.
|
22
|
+
attr_reader :rate_limit_per_user
|
23
|
+
alias slowmode rate_limit_per_user
|
24
|
+
# @return [Array<Discorb::ThreadChannel::Member>] The members of the thread.
|
25
|
+
attr_reader :members
|
26
|
+
# @return [Time] The time the thread was archived.
|
27
|
+
# @return [nil] If the thread is not archived.
|
28
|
+
attr_reader :archived_timestamp
|
29
|
+
alias archived_at archived_timestamp
|
30
|
+
# @return [Integer] Auto archive duration in seconds.
|
31
|
+
attr_reader :auto_archive_duration
|
32
|
+
alias archive_in auto_archive_duration
|
33
|
+
# @return [Boolean] Whether the thread is archived or not.
|
34
|
+
attr_reader :archived
|
35
|
+
alias archived? archived
|
36
|
+
|
37
|
+
# @!attribute [r] parent
|
38
|
+
# @macro client_cache
|
39
|
+
# @return [Discorb::GuildChannel] The parent channel of the thread.
|
40
|
+
# @!attribute [r] me
|
41
|
+
# @return [Discorb::ThreadChannel::Member] The bot's member in the thread.
|
42
|
+
# @return [nil] If the bot is not in the thread.
|
43
|
+
# @!attribute [r] joined?
|
44
|
+
# @return [Boolean] Whether the bot is in the thread or not.
|
45
|
+
# @!attribute [r] guild
|
46
|
+
# @macro client_cache
|
47
|
+
# @return [Discorb::Guild] The guild of the thread.
|
48
|
+
# @!attribute [r] owner
|
49
|
+
# @macro client_cache
|
50
|
+
# @macro members_intent
|
51
|
+
# @return [Discorb::Member] The owner of the thread.
|
52
|
+
|
53
|
+
include Messageable
|
54
|
+
@channel_type = nil
|
55
|
+
|
56
|
+
#
|
57
|
+
# Initialize a new thread channel.
|
58
|
+
# @private
|
59
|
+
#
|
60
|
+
# @param [Discorb::Client] client The client.
|
61
|
+
# @param [Hash] data The data of the thread channel.
|
62
|
+
# @param [Boolean] no_cache Whether to disable the cache.
|
63
|
+
#
|
64
|
+
def initialize(client, data, no_cache: false)
|
65
|
+
@members = Dictionary.new
|
66
|
+
super
|
67
|
+
@client.channels[@id] = self unless no_cache
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Edit the thread.
|
72
|
+
# @async
|
73
|
+
# @macro edit
|
74
|
+
#
|
75
|
+
# @param [String] name The name of the thread.
|
76
|
+
# @param [Boolean] archived Whether the thread is archived or not.
|
77
|
+
# @param [Integer] auto_archive_duration The auto archive duration in seconds.
|
78
|
+
# @param [Integer] archive_in Alias of `auto_archive_duration`.
|
79
|
+
# @param [Boolean] locked Whether the thread is locked or not.
|
80
|
+
# @param [String] reason The reason of editing the thread.
|
81
|
+
#
|
82
|
+
# @return [Async::Task<self>] The edited thread.
|
83
|
+
#
|
84
|
+
# @see #archive
|
85
|
+
# @see #lock
|
86
|
+
# @see #unarchive
|
87
|
+
# @see #unlock
|
88
|
+
#
|
89
|
+
def edit(
|
90
|
+
name: Discorb::Unset,
|
91
|
+
archived: Discorb::Unset,
|
92
|
+
auto_archive_duration: Discorb::Unset,
|
93
|
+
archive_in: Discorb::Unset,
|
94
|
+
locked: Discorb::Unset,
|
95
|
+
reason: nil
|
96
|
+
)
|
97
|
+
Async do
|
98
|
+
payload = {}
|
99
|
+
payload[:name] = name if name != Discorb::Unset
|
100
|
+
payload[:archived] = archived if archived != Discorb::Unset
|
101
|
+
auto_archive_duration ||= archive_in
|
102
|
+
payload[
|
103
|
+
:auto_archive_duration
|
104
|
+
] = auto_archive_duration if auto_archive_duration != Discorb::Unset
|
105
|
+
payload[:locked] = locked if locked != Discorb::Unset
|
106
|
+
@client
|
107
|
+
.http
|
108
|
+
.request(
|
109
|
+
Route.new("/channels/#{@id}", "//channels/:channel_id", :patch),
|
110
|
+
payload,
|
111
|
+
audit_log_reason: reason
|
112
|
+
)
|
113
|
+
.wait
|
114
|
+
self
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Helper method to archive the thread.
|
120
|
+
#
|
121
|
+
# @param [String] reason The reason of archiving the thread.
|
122
|
+
#
|
123
|
+
# @return [Async::Task<self>] The archived thread.
|
124
|
+
#
|
125
|
+
def archive(reason: nil)
|
126
|
+
edit(archived: true, reason: reason)
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# Helper method to lock the thread.
|
131
|
+
#
|
132
|
+
# @param [String] reason The reason of locking the thread.
|
133
|
+
#
|
134
|
+
# @return [Async::Task<self>] The locked thread.
|
135
|
+
#
|
136
|
+
def lock(reason: nil)
|
137
|
+
edit(archived: true, locked: true, reason: reason)
|
138
|
+
end
|
139
|
+
|
140
|
+
#
|
141
|
+
# Helper method to unarchive the thread.
|
142
|
+
#
|
143
|
+
# @param [String] reason The reason of unarchiving the thread.
|
144
|
+
#
|
145
|
+
# @return [Async::Task<self>] The unarchived thread.
|
146
|
+
#
|
147
|
+
def unarchive(reason: nil)
|
148
|
+
edit(archived: false, reason: reason)
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Helper method to unlock the thread.
|
153
|
+
#
|
154
|
+
# @param [String] reason The reason of unlocking the thread.
|
155
|
+
#
|
156
|
+
# @return [Async::Task<self>] The unlocked thread.
|
157
|
+
#
|
158
|
+
# @note This method won't unarchive the thread. Use {#unarchive} instead.
|
159
|
+
#
|
160
|
+
def unlock(reason: nil)
|
161
|
+
edit(archived: !unarchive, locked: false, reason: reason)
|
162
|
+
end
|
163
|
+
|
164
|
+
def parent
|
165
|
+
return nil unless @parent_id
|
166
|
+
|
167
|
+
@client.channels[@parent_id]
|
168
|
+
end
|
169
|
+
|
170
|
+
alias channel parent
|
171
|
+
|
172
|
+
def me
|
173
|
+
@members[@client.user.id]
|
174
|
+
end
|
175
|
+
|
176
|
+
def joined?
|
177
|
+
!!me
|
178
|
+
end
|
179
|
+
|
180
|
+
def guild
|
181
|
+
@client.guilds[@guild]
|
182
|
+
end
|
183
|
+
|
184
|
+
def owner
|
185
|
+
guild.members[@owner_id]
|
186
|
+
end
|
187
|
+
|
188
|
+
def inspect
|
189
|
+
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
190
|
+
end
|
191
|
+
|
192
|
+
#
|
193
|
+
# Add a member to the thread.
|
194
|
+
#
|
195
|
+
# @param [Discorb::Member, :me] member The member to add. If `:me` is given, the bot will be added.
|
196
|
+
#
|
197
|
+
# @return [Async::Task<void>] The task.
|
198
|
+
#
|
199
|
+
def add_member(member = :me)
|
200
|
+
Async do
|
201
|
+
if member == :me
|
202
|
+
@client
|
203
|
+
.http
|
204
|
+
.request(
|
205
|
+
Route.new(
|
206
|
+
"/channels/#{@id}/thread-members/@me",
|
207
|
+
"//channels/:channel_id/thread-members/@me",
|
208
|
+
:post
|
209
|
+
)
|
210
|
+
)
|
211
|
+
.wait
|
212
|
+
else
|
213
|
+
@client
|
214
|
+
.http
|
215
|
+
.request(
|
216
|
+
Route.new(
|
217
|
+
"/channels/#{@id}/thread-members/#{Utils.try(member, :id)}",
|
218
|
+
"//channels/:channel_id/thread-members/:user_id",
|
219
|
+
:post
|
220
|
+
)
|
221
|
+
)
|
222
|
+
.wait
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
alias join add_member
|
228
|
+
|
229
|
+
#
|
230
|
+
# Remove a member from the thread.
|
231
|
+
#
|
232
|
+
# @param [Discorb::Member, :me] member The member to remove. If `:me` is given, the bot will be removed.
|
233
|
+
#
|
234
|
+
# @return [Async::Task<void>] The task.
|
235
|
+
#
|
236
|
+
def remove_member(member = :me)
|
237
|
+
Async do
|
238
|
+
if member == :me
|
239
|
+
@client
|
240
|
+
.http
|
241
|
+
.request(
|
242
|
+
Route.new(
|
243
|
+
"/channels/#{@id}/thread-members/@me",
|
244
|
+
"//channels/:channel_id/thread-members/@me",
|
245
|
+
:delete
|
246
|
+
)
|
247
|
+
)
|
248
|
+
.wait
|
249
|
+
else
|
250
|
+
@client
|
251
|
+
.http
|
252
|
+
.request(
|
253
|
+
Route.new(
|
254
|
+
"/channels/#{@id}/thread-members/#{Utils.try(member, :id)}",
|
255
|
+
"//channels/:channel_id/thread-members/:user_id",
|
256
|
+
:delete
|
257
|
+
)
|
258
|
+
)
|
259
|
+
.wait
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
alias leave remove_member
|
265
|
+
|
266
|
+
#
|
267
|
+
# Fetch members in the thread.
|
268
|
+
#
|
269
|
+
# @return [Array<Discorb::ThreadChannel::Member>] The members in the thread.
|
270
|
+
#
|
271
|
+
def fetch_members
|
272
|
+
Async do
|
273
|
+
_resp, data =
|
274
|
+
@client
|
275
|
+
.http
|
276
|
+
.request(
|
277
|
+
Route.new(
|
278
|
+
"/channels/#{@id}/thread-members",
|
279
|
+
"//channels/:channel_id/thread-members",
|
280
|
+
:get
|
281
|
+
)
|
282
|
+
)
|
283
|
+
.wait
|
284
|
+
data.map { |d| @members[d[:id]] = Member.new(@client, d, @guild_id) }
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
#
|
289
|
+
# Represents a thread in news channel(aka announcement channel).
|
290
|
+
#
|
291
|
+
class News < ThreadChannel
|
292
|
+
@channel_type = 10
|
293
|
+
end
|
294
|
+
|
295
|
+
#
|
296
|
+
# Represents a public thread in text channel.
|
297
|
+
#
|
298
|
+
class Public < ThreadChannel
|
299
|
+
@channel_type = 11
|
300
|
+
end
|
301
|
+
|
302
|
+
#
|
303
|
+
# Represents a private thread in text channel.
|
304
|
+
#
|
305
|
+
class Private < ThreadChannel
|
306
|
+
@channel_type = 12
|
307
|
+
end
|
308
|
+
|
309
|
+
class << self
|
310
|
+
attr_reader :channel_type
|
311
|
+
end
|
312
|
+
|
313
|
+
#
|
314
|
+
# Represents a member in a thread.
|
315
|
+
#
|
316
|
+
class Member < DiscordModel
|
317
|
+
attr_reader :joined_at
|
318
|
+
|
319
|
+
def initialize(client, data, guild_id)
|
320
|
+
@client = client
|
321
|
+
@thread_id = data[:id]
|
322
|
+
@user_id = data[:user_id]
|
323
|
+
@joined_at = Time.iso8601(data[:join_timestamp])
|
324
|
+
@guild_id = guild_id
|
325
|
+
end
|
326
|
+
|
327
|
+
def thread
|
328
|
+
@client.channels[@thread_id]
|
329
|
+
end
|
330
|
+
|
331
|
+
def member
|
332
|
+
@client.guilds[@guild_id].members[@user_id]
|
333
|
+
end
|
334
|
+
|
335
|
+
def id
|
336
|
+
@user_id
|
337
|
+
end
|
338
|
+
|
339
|
+
def user
|
340
|
+
@client.users[@user_id]
|
341
|
+
end
|
342
|
+
|
343
|
+
def inspect
|
344
|
+
"#<#{self.class} id=#{@id.inspect}>"
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
private
|
349
|
+
|
350
|
+
def _set_data(data)
|
351
|
+
@id = Snowflake.new(data[:id])
|
352
|
+
@name = data[:name]
|
353
|
+
@guild_id = data[:guild_id]
|
354
|
+
@parent_id = data[:parent_id]
|
355
|
+
@archived = data[:thread_metadata][:archived]
|
356
|
+
@owner_id = data[:owner_id]
|
357
|
+
@archived_timestamp =
|
358
|
+
data[:thread_metadata][:archived_timestamp] &&
|
359
|
+
Time.iso8601(data[:thread_metadata][:archived_timestamp])
|
360
|
+
@auto_archive_duration = data[:thread_metadata][:auto_archive_duration]
|
361
|
+
@locked = data[:thread_metadata][:locked]
|
362
|
+
@member_count = data[:member_count]
|
363
|
+
@message_count = data[:message_count]
|
364
|
+
if data[:member]
|
365
|
+
@members[@client.user.id] = ThreadChannel::Member.new(
|
366
|
+
@client,
|
367
|
+
data[:member].merge({ id: data[:id], user_id: @client.user.id }),
|
368
|
+
@guild_id
|
369
|
+
)
|
370
|
+
end
|
371
|
+
@data.merge!(data)
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|