discorb 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/discorb/channel/text.rb
CHANGED
@@ -1,336 +1,430 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a text channel.
|
6
|
-
#
|
7
|
-
class TextChannel < GuildChannel
|
8
|
-
# @return [String] The topic of the channel.
|
9
|
-
attr_reader :topic
|
10
|
-
# @return [Boolean] Whether the channel is nsfw.
|
11
|
-
attr_reader :nsfw
|
12
|
-
# @return [Discorb::Snowflake] The id of the last message.
|
13
|
-
attr_reader :last_message_id
|
14
|
-
# @return [Integer] The rate limit per user (Slowmode) in the channel.
|
15
|
-
attr_reader :rate_limit_per_user
|
16
|
-
alias slowmode rate_limit_per_user
|
17
|
-
# @return [Time] The time when the last pinned message was pinned.
|
18
|
-
attr_reader :last_pin_timestamp
|
19
|
-
alias last_pinned_at last_pin_timestamp
|
20
|
-
# @return [Integer] The default value of duration of auto archive.
|
21
|
-
attr_reader :default_auto_archive_duration
|
22
|
-
|
23
|
-
include Messageable
|
24
|
-
|
25
|
-
@channel_type = 0
|
26
|
-
|
27
|
-
# @!attribute [r] threads
|
28
|
-
# @return [Array<Discorb::ThreadChannel>] The threads in the channel.
|
29
|
-
def threads
|
30
|
-
guild.threads.select { |thread| thread.parent == self }
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# Edits the channel.
|
35
|
-
# @async
|
36
|
-
# @macro edit
|
37
|
-
#
|
38
|
-
# @param [String] name The name of the channel.
|
39
|
-
# @param [Integer] position The position of the channel.
|
40
|
-
# @param [Discorb::CategoryChannel, nil] category The parent of channel. Specify `nil` to remove the parent.
|
41
|
-
# @param [Discorb::CategoryChannel, nil] parent Alias of `category`.
|
42
|
-
# @param [String] topic The topic of the channel.
|
43
|
-
# @param [Boolean] nsfw Whether the channel is nsfw.
|
44
|
-
# @param [Boolean] announce Whether the channel is announce channel.
|
45
|
-
# @param [Integer] rate_limit_per_user The rate limit per user (Slowmode) in the channel.
|
46
|
-
# @param [Integer] slowmode Alias of `rate_limit_per_user`.
|
47
|
-
# @param [Integer] default_auto_archive_duration The default auto archive duration of the channel.
|
48
|
-
# @param [Integer] archive_in Alias of `default_auto_archive_duration`.
|
49
|
-
# @param [String] reason The reason of editing the channel.
|
50
|
-
#
|
51
|
-
# @return [Async::Task<self>] The edited channel.
|
52
|
-
#
|
53
|
-
def edit(
|
54
|
-
name: Discorb::Unset,
|
55
|
-
position: Discorb::Unset,
|
56
|
-
category: Discorb::Unset,
|
57
|
-
parent: Discorb::Unset,
|
58
|
-
topic: Discorb::Unset,
|
59
|
-
nsfw: Discorb::Unset,
|
60
|
-
announce: Discorb::Unset,
|
61
|
-
rate_limit_per_user: Discorb::Unset,
|
62
|
-
slowmode: Discorb::Unset,
|
63
|
-
default_auto_archive_duration: Discorb::Unset,
|
64
|
-
archive_in: Discorb::Unset,
|
65
|
-
reason: nil
|
66
|
-
)
|
67
|
-
Async do
|
68
|
-
payload = {}
|
69
|
-
payload[:name] = name if name != Discorb::Unset
|
70
|
-
payload[:announce] = announce ? 5 : 0 if announce != Discorb::Unset
|
71
|
-
payload[:position] = position if position != Discorb::Unset
|
72
|
-
payload[:topic] = topic || "" if topic != Discorb::Unset
|
73
|
-
payload[:nsfw] = nsfw if nsfw != Discorb::Unset
|
74
|
-
|
75
|
-
slowmode = rate_limit_per_user if slowmode == Discorb::Unset
|
76
|
-
payload[:rate_limit_per_user] = slowmode || 0 if slowmode !=
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
#
|
134
|
-
# @
|
135
|
-
#
|
136
|
-
# @return [Async::Task<
|
137
|
-
#
|
138
|
-
def
|
139
|
-
Async do
|
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
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
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
|
-
|
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
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a text channel.
|
6
|
+
#
|
7
|
+
class TextChannel < GuildChannel
|
8
|
+
# @return [String] The topic of the channel.
|
9
|
+
attr_reader :topic
|
10
|
+
# @return [Boolean] Whether the channel is nsfw.
|
11
|
+
attr_reader :nsfw
|
12
|
+
# @return [Discorb::Snowflake] The id of the last message.
|
13
|
+
attr_reader :last_message_id
|
14
|
+
# @return [Integer] The rate limit per user (Slowmode) in the channel.
|
15
|
+
attr_reader :rate_limit_per_user
|
16
|
+
alias slowmode rate_limit_per_user
|
17
|
+
# @return [Time] The time when the last pinned message was pinned.
|
18
|
+
attr_reader :last_pin_timestamp
|
19
|
+
alias last_pinned_at last_pin_timestamp
|
20
|
+
# @return [Integer] The default value of duration of auto archive.
|
21
|
+
attr_reader :default_auto_archive_duration
|
22
|
+
|
23
|
+
include Messageable
|
24
|
+
|
25
|
+
@channel_type = 0
|
26
|
+
|
27
|
+
# @!attribute [r] threads
|
28
|
+
# @return [Array<Discorb::ThreadChannel>] The threads in the channel.
|
29
|
+
def threads
|
30
|
+
guild.threads.select { |thread| thread.parent == self }
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Edits the channel.
|
35
|
+
# @async
|
36
|
+
# @macro edit
|
37
|
+
#
|
38
|
+
# @param [String] name The name of the channel.
|
39
|
+
# @param [Integer] position The position of the channel.
|
40
|
+
# @param [Discorb::CategoryChannel, nil] category The parent of channel. Specify `nil` to remove the parent.
|
41
|
+
# @param [Discorb::CategoryChannel, nil] parent Alias of `category`.
|
42
|
+
# @param [String] topic The topic of the channel.
|
43
|
+
# @param [Boolean] nsfw Whether the channel is nsfw.
|
44
|
+
# @param [Boolean] announce Whether the channel is announce channel.
|
45
|
+
# @param [Integer] rate_limit_per_user The rate limit per user (Slowmode) in the channel.
|
46
|
+
# @param [Integer] slowmode Alias of `rate_limit_per_user`.
|
47
|
+
# @param [Integer] default_auto_archive_duration The default auto archive duration of the channel.
|
48
|
+
# @param [Integer] archive_in Alias of `default_auto_archive_duration`.
|
49
|
+
# @param [String] reason The reason of editing the channel.
|
50
|
+
#
|
51
|
+
# @return [Async::Task<self>] The edited channel.
|
52
|
+
#
|
53
|
+
def edit(
|
54
|
+
name: Discorb::Unset,
|
55
|
+
position: Discorb::Unset,
|
56
|
+
category: Discorb::Unset,
|
57
|
+
parent: Discorb::Unset,
|
58
|
+
topic: Discorb::Unset,
|
59
|
+
nsfw: Discorb::Unset,
|
60
|
+
announce: Discorb::Unset,
|
61
|
+
rate_limit_per_user: Discorb::Unset,
|
62
|
+
slowmode: Discorb::Unset,
|
63
|
+
default_auto_archive_duration: Discorb::Unset,
|
64
|
+
archive_in: Discorb::Unset,
|
65
|
+
reason: nil
|
66
|
+
)
|
67
|
+
Async do
|
68
|
+
payload = {}
|
69
|
+
payload[:name] = name if name != Discorb::Unset
|
70
|
+
payload[:announce] = announce ? 5 : 0 if announce != Discorb::Unset
|
71
|
+
payload[:position] = position if position != Discorb::Unset
|
72
|
+
payload[:topic] = topic || "" if topic != Discorb::Unset
|
73
|
+
payload[:nsfw] = nsfw if nsfw != Discorb::Unset
|
74
|
+
|
75
|
+
slowmode = rate_limit_per_user if slowmode == Discorb::Unset
|
76
|
+
payload[:rate_limit_per_user] = slowmode || 0 if slowmode !=
|
77
|
+
Discorb::Unset
|
78
|
+
parent = category if parent == Discorb::Unset
|
79
|
+
payload[:parent_id] = parent&.id if parent != Discorb::Unset
|
80
|
+
|
81
|
+
default_auto_archive_duration ||= archive_in
|
82
|
+
if default_auto_archive_duration != Discorb::Unset
|
83
|
+
payload[
|
84
|
+
:default_auto_archive_duration
|
85
|
+
] = default_auto_archive_duration
|
86
|
+
end
|
87
|
+
|
88
|
+
@client
|
89
|
+
.http
|
90
|
+
.request(
|
91
|
+
Route.new("/channels/#{@id}", "//channels/:channel_id", :patch),
|
92
|
+
payload,
|
93
|
+
audit_log_reason: reason
|
94
|
+
)
|
95
|
+
.wait
|
96
|
+
self
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
alias modify edit
|
101
|
+
|
102
|
+
#
|
103
|
+
# Create webhook in the channel.
|
104
|
+
# @async
|
105
|
+
#
|
106
|
+
# @param [String] name The name of the webhook.
|
107
|
+
# @param [Discorb::Image] avatar The avatar of the webhook.
|
108
|
+
#
|
109
|
+
# @return [Async::Task<Discorb::Webhook::IncomingWebhook>] The created webhook.
|
110
|
+
#
|
111
|
+
def create_webhook(name, avatar: nil)
|
112
|
+
Async do
|
113
|
+
payload = {}
|
114
|
+
payload[:name] = name
|
115
|
+
payload[:avatar] = avatar.to_s if avatar
|
116
|
+
_resp, data =
|
117
|
+
@client
|
118
|
+
.http
|
119
|
+
.request(
|
120
|
+
Route.new(
|
121
|
+
"/channels/#{@id}/webhooks",
|
122
|
+
"//channels/:channel_id/webhooks",
|
123
|
+
:post
|
124
|
+
),
|
125
|
+
payload
|
126
|
+
)
|
127
|
+
.wait
|
128
|
+
Webhook.from_data(@client, data)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Fetch webhooks in the channel.
|
134
|
+
# @async
|
135
|
+
#
|
136
|
+
# @return [Async::Task<Array<Discorb::Webhook>>] The webhooks in the channel.
|
137
|
+
#
|
138
|
+
def fetch_webhooks
|
139
|
+
Async do
|
140
|
+
_resp, data =
|
141
|
+
@client
|
142
|
+
.http
|
143
|
+
.request(
|
144
|
+
Route.new(
|
145
|
+
"/channels/#{@id}/webhooks",
|
146
|
+
"//channels/:channel_id/webhooks",
|
147
|
+
:get
|
148
|
+
)
|
149
|
+
)
|
150
|
+
.wait
|
151
|
+
data.map { |webhook| Webhook.from_data(@client, webhook) }
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# Bulk delete messages in the channel.
|
157
|
+
# @async
|
158
|
+
#
|
159
|
+
# @param [Discorb::Message] messages The messages to delete.
|
160
|
+
# @param [Boolean] force Whether to ignore the validation for message (14 days limit).
|
161
|
+
#
|
162
|
+
# @return [Async::Task<void>] The task.
|
163
|
+
#
|
164
|
+
def delete_messages(*messages, force: false)
|
165
|
+
Async do
|
166
|
+
messages = messages.flatten
|
167
|
+
unless force
|
168
|
+
time = Time.now
|
169
|
+
messages.delete_if do |message|
|
170
|
+
next false unless message.is_a?(Message)
|
171
|
+
|
172
|
+
time - message.created_at > 60 * 60 * 24 * 14
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
message_ids = messages.map { |m| Discorb::Utils.try(m, :id).to_s }
|
177
|
+
|
178
|
+
@client
|
179
|
+
.http
|
180
|
+
.request(
|
181
|
+
Route.new(
|
182
|
+
"/channels/#{@id}/messages/bulk-delete",
|
183
|
+
"//channels/:channel_id/messages/bulk-delete",
|
184
|
+
:post
|
185
|
+
),
|
186
|
+
{ messages: message_ids }
|
187
|
+
)
|
188
|
+
.wait
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
alias bulk_delete delete_messages
|
193
|
+
alias destroy_messages delete_messages
|
194
|
+
|
195
|
+
#
|
196
|
+
# Follow the existing announcement channel.
|
197
|
+
# @async
|
198
|
+
#
|
199
|
+
# @param [Discorb::NewsChannel] target The channel to follow.
|
200
|
+
# @param [String] reason The reason of following the channel.
|
201
|
+
#
|
202
|
+
# @return [Async::Task<void>] The task.
|
203
|
+
#
|
204
|
+
def follow_from(target, reason: nil)
|
205
|
+
Async do
|
206
|
+
@client
|
207
|
+
.http
|
208
|
+
.request(
|
209
|
+
Route.new(
|
210
|
+
"/channels/#{target.id}/followers",
|
211
|
+
"//channels/:channel_id/followers",
|
212
|
+
:post
|
213
|
+
),
|
214
|
+
{ webhook_channel_id: @id },
|
215
|
+
audit_log_reason: reason
|
216
|
+
)
|
217
|
+
.wait
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
#
|
222
|
+
# Start thread in the channel.
|
223
|
+
# @async
|
224
|
+
#
|
225
|
+
# @param [String] name The name of the thread.
|
226
|
+
# @param [Discorb::Message] message The message to start the thread.
|
227
|
+
# @param [:hour, :day, :three_days, :week] auto_archive_duration The duration of auto-archiving.
|
228
|
+
# @param [Boolean] public Whether the thread is public.
|
229
|
+
# @param [Integer] rate_limit_per_user The rate limit per user.
|
230
|
+
# @param [Integer] slowmode Alias of `rate_limit_per_user`.
|
231
|
+
# @param [String] reason The reason of starting the thread.
|
232
|
+
#
|
233
|
+
# @return [Async::Task<Discorb::ThreadChannel>] The started thread.
|
234
|
+
#
|
235
|
+
def start_thread(
|
236
|
+
name,
|
237
|
+
message: nil,
|
238
|
+
auto_archive_duration: nil,
|
239
|
+
public: true,
|
240
|
+
rate_limit_per_user: nil,
|
241
|
+
slowmode: nil,
|
242
|
+
reason: nil
|
243
|
+
)
|
244
|
+
auto_archive_duration ||= @default_auto_archive_duration
|
245
|
+
Async do
|
246
|
+
_resp, data =
|
247
|
+
if message.nil?
|
248
|
+
@client
|
249
|
+
.http
|
250
|
+
.request(
|
251
|
+
Route.new(
|
252
|
+
"/channels/#{@id}/threads",
|
253
|
+
"//channels/:channel_id/threads",
|
254
|
+
:post
|
255
|
+
),
|
256
|
+
{
|
257
|
+
name: name,
|
258
|
+
auto_archive_duration: auto_archive_duration,
|
259
|
+
type: public ? 11 : 10,
|
260
|
+
rate_limit_per_user: rate_limit_per_user || slowmode
|
261
|
+
},
|
262
|
+
audit_log_reason: reason
|
263
|
+
)
|
264
|
+
.wait
|
265
|
+
else
|
266
|
+
@client
|
267
|
+
.http
|
268
|
+
.request(
|
269
|
+
Route.new(
|
270
|
+
"/channels/#{@id}/messages/#{Utils.try(message, :id)}/threads",
|
271
|
+
"//channels/:channel_id/messages/:message_id/threads",
|
272
|
+
:post
|
273
|
+
),
|
274
|
+
{ name: name, auto_archive_duration: auto_archive_duration },
|
275
|
+
audit_log_reason: reason
|
276
|
+
)
|
277
|
+
.wait
|
278
|
+
end
|
279
|
+
Channel.make_channel(@client, data)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
alias create_thread start_thread
|
284
|
+
|
285
|
+
#
|
286
|
+
# Fetch archived threads in the channel.
|
287
|
+
# @async
|
288
|
+
#
|
289
|
+
# @return [Async::Task<Array<Discorb::ThreadChannel>>] The archived threads in the channel.
|
290
|
+
#
|
291
|
+
def fetch_archived_public_threads
|
292
|
+
Async do
|
293
|
+
_resp, data =
|
294
|
+
@client
|
295
|
+
.http
|
296
|
+
.request(
|
297
|
+
Route.new(
|
298
|
+
"/channels/#{@id}/threads/archived/public",
|
299
|
+
"//channels/:channel_id/threads/archived/public",
|
300
|
+
:get
|
301
|
+
)
|
302
|
+
)
|
303
|
+
.wait
|
304
|
+
data.map { |thread| Channel.make_channel(@client, thread) }
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
#
|
309
|
+
# Fetch archived private threads in the channel.
|
310
|
+
# @async
|
311
|
+
#
|
312
|
+
# @return [Async::Task<Array<Discorb::ThreadChannel>>] The archived private threads in the channel.
|
313
|
+
#
|
314
|
+
def fetch_archived_private_threads
|
315
|
+
Async do
|
316
|
+
_resp, data =
|
317
|
+
@client
|
318
|
+
.http
|
319
|
+
.request(
|
320
|
+
Route.new(
|
321
|
+
"/channels/#{@id}/threads/archived/private",
|
322
|
+
"//channels/:channel_id/threads/archived/private",
|
323
|
+
:get
|
324
|
+
)
|
325
|
+
)
|
326
|
+
.wait
|
327
|
+
data.map { |thread| Channel.make_channel(@client, thread) }
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
#
|
332
|
+
# Fetch joined archived private threads in the channel.
|
333
|
+
# @async
|
334
|
+
#
|
335
|
+
# @param [Integer] limit The limit of threads to fetch.
|
336
|
+
# @param [Time] before The time before which the threads are created.
|
337
|
+
#
|
338
|
+
# @return [Async::Task<Array<Discorb::ThreadChannel>>] The joined archived private threads in the channel.
|
339
|
+
#
|
340
|
+
def fetch_joined_archived_private_threads(limit: nil, before: nil)
|
341
|
+
Async do
|
342
|
+
if limit.nil?
|
343
|
+
before = Time.now
|
344
|
+
threads = []
|
345
|
+
loop do
|
346
|
+
_resp, data =
|
347
|
+
@client
|
348
|
+
.http
|
349
|
+
.request(
|
350
|
+
Route.new(
|
351
|
+
"/channels/#{@id}/users/@me/threads/archived/private?before=#{before.iso8601}",
|
352
|
+
"//channels/:channel_id/users/@me/threads/archived/private",
|
353
|
+
:get
|
354
|
+
)
|
355
|
+
)
|
356
|
+
.wait
|
357
|
+
threads +=
|
358
|
+
data[:threads].map do |thread|
|
359
|
+
Channel.make_channel(@client, thread)
|
360
|
+
end
|
361
|
+
|
362
|
+
break unless data[:has_more]
|
363
|
+
|
364
|
+
before = Snowflake.new(data[:threads][-1][:id]).timestamp
|
365
|
+
end
|
366
|
+
threads
|
367
|
+
else
|
368
|
+
_resp, data =
|
369
|
+
@client
|
370
|
+
.http
|
371
|
+
.request(
|
372
|
+
Route.new(
|
373
|
+
"/channels/#{@id}/users/@me/threads/archived/private?limit=#{limit}&before=#{before.iso8601}",
|
374
|
+
"//channels/:channel_id/users/@me/threads/archived/private",
|
375
|
+
:get
|
376
|
+
)
|
377
|
+
)
|
378
|
+
.wait
|
379
|
+
data.map { |thread| Channel.make_channel(@client, thread) }
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
private
|
385
|
+
|
386
|
+
def _set_data(data)
|
387
|
+
@topic = data[:topic]
|
388
|
+
@nsfw = data[:nsfw]
|
389
|
+
@last_message_id = data[:last_message_id]
|
390
|
+
@rate_limit_per_user = data[:rate_limit_per_user]
|
391
|
+
@last_pin_timestamp =
|
392
|
+
data[:last_pin_timestamp] && Time.iso8601(data[:last_pin_timestamp])
|
393
|
+
@default_auto_archive_duration = data[:default_auto_archive_duration]
|
394
|
+
super
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
#
|
399
|
+
# Represents a news channel (announcement channel).
|
400
|
+
#
|
401
|
+
class NewsChannel < TextChannel
|
402
|
+
@channel_type = 5
|
403
|
+
|
404
|
+
#
|
405
|
+
# Follow the existing announcement channel from self.
|
406
|
+
# @async
|
407
|
+
#
|
408
|
+
# @param [Discorb::TextChannel] target The channel to follow to.
|
409
|
+
# @param [String] reason The reason of following the channel.
|
410
|
+
#
|
411
|
+
# @return [Async::Task<void>] The task.
|
412
|
+
#
|
413
|
+
def follow_to(target, reason: nil)
|
414
|
+
Async do
|
415
|
+
@client
|
416
|
+
.http
|
417
|
+
.request(
|
418
|
+
Route.new(
|
419
|
+
"/channels/#{@id}/followers",
|
420
|
+
"//channels/:channel_id/followers",
|
421
|
+
:post
|
422
|
+
),
|
423
|
+
{ webhook_channel_id: target.id },
|
424
|
+
audit_log_reason: reason
|
425
|
+
)
|
426
|
+
.wait
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|