@fluxerjs/core 3.2.0 → 3.3.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.
- package/dist/{SubpathMessage-DW9TgPNl.d.mts → SubpathMessage-CNJlnR6y.d.mts} +2174 -1928
- package/dist/{SubpathMessage-DHo7ltTz.d.ts → SubpathMessage-DjLo6il5.d.ts} +2174 -1928
- package/dist/{Sudo-DwxTf-jj.d.mts → Sudo-mzPLv6YU.d.mts} +339 -3
- package/dist/{Sudo-DwxTf-jj.d.ts → Sudo-mzPLv6YU.d.ts} +339 -3
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2376 -1413
- package/dist/client.mjs +2346 -1377
- package/dist/cluster.d.mts +2 -2
- package/dist/cluster.d.ts +2 -2
- package/dist/cluster.js +2376 -1413
- package/dist/cluster.mjs +2346 -1377
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1219 -232
- package/dist/index.mjs +1122 -136
- package/dist/internal.d.mts +3 -2
- package/dist/internal.d.ts +3 -2
- package/dist/internal.js +52 -0
- package/dist/internal.mjs +54 -0
- package/dist/message.d.mts +2 -2
- package/dist/message.d.ts +2 -2
- package/dist/message.js +717 -34
- package/dist/message.mjs +708 -23
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -7,8 +7,11 @@ import {
|
|
|
7
7
|
} from "@fluxerjs/builders";
|
|
8
8
|
import {
|
|
9
9
|
AuditLogActionType,
|
|
10
|
-
ChannelType as
|
|
10
|
+
ChannelType as ChannelType11,
|
|
11
11
|
ContentWarningLevel,
|
|
12
|
+
ForumLayout,
|
|
13
|
+
ForumSortOrder,
|
|
14
|
+
ForumTagSetting,
|
|
12
15
|
GatewayOpcodes as GatewayOpcodes3,
|
|
13
16
|
GuildMemberProfileFlags,
|
|
14
17
|
GuildNSFWLevel as GuildNSFWLevel2,
|
|
@@ -21,9 +24,11 @@ import {
|
|
|
21
24
|
OverwriteType as OverwriteType2,
|
|
22
25
|
PublicUserFlags,
|
|
23
26
|
RelationshipType,
|
|
24
|
-
Routes as
|
|
27
|
+
Routes as Routes38,
|
|
25
28
|
SplashCardAlignment,
|
|
26
|
-
SystemChannelFlags
|
|
29
|
+
SystemChannelFlags,
|
|
30
|
+
ThreadAutoArchiveDuration,
|
|
31
|
+
ThreadMemberFlags
|
|
27
32
|
} from "@fluxerjs/types";
|
|
28
33
|
import {
|
|
29
34
|
createLogger as createLogger2,
|
|
@@ -181,10 +186,10 @@ var CacheController = class {
|
|
|
181
186
|
|
|
182
187
|
// src/ClientCore/ChannelManager.ts
|
|
183
188
|
import { LimitedCollection } from "@fluxerjs/collection";
|
|
184
|
-
import { Routes as
|
|
189
|
+
import { Routes as Routes22 } from "@fluxerjs/types";
|
|
185
190
|
|
|
186
191
|
// src/Domain/Channel/Base.ts
|
|
187
|
-
import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
|
|
192
|
+
import { ChannelType as ChannelType3, Routes as Routes7 } from "@fluxerjs/types";
|
|
188
193
|
import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
|
|
189
194
|
|
|
190
195
|
// src/ClientCore/MessageManager.ts
|
|
@@ -265,7 +270,132 @@ function toAttachmentUploadPlanResponse(data) {
|
|
|
265
270
|
}
|
|
266
271
|
|
|
267
272
|
// src/ClientCore/SdkOptions/Channels.ts
|
|
273
|
+
import { ChannelType as ChannelType2 } from "@fluxerjs/types";
|
|
268
274
|
import { resolvePermissionsToBitfield } from "@fluxerjs/util";
|
|
275
|
+
|
|
276
|
+
// src/ClientCore/SdkOptions/Threads.ts
|
|
277
|
+
import {
|
|
278
|
+
ChannelType
|
|
279
|
+
} from "@fluxerjs/types";
|
|
280
|
+
function toThreadEditBody(type, options) {
|
|
281
|
+
const body = {};
|
|
282
|
+
if (options.name !== void 0) body.name = options.name;
|
|
283
|
+
if (options.archived !== void 0) body.archived = options.archived;
|
|
284
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
285
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
286
|
+
}
|
|
287
|
+
if (options.locked !== void 0) body.locked = options.locked;
|
|
288
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
289
|
+
if (options.flags !== void 0) body.flags = options.flags;
|
|
290
|
+
if (options.appliedTags !== void 0 && type !== ChannelType.PrivateThread) {
|
|
291
|
+
body.applied_tags = options.appliedTags;
|
|
292
|
+
}
|
|
293
|
+
if (options.invitable !== void 0 && type === ChannelType.PrivateThread) {
|
|
294
|
+
body.invitable = options.invitable;
|
|
295
|
+
}
|
|
296
|
+
return body;
|
|
297
|
+
}
|
|
298
|
+
function toThreadParentEditBody(options) {
|
|
299
|
+
const body = {};
|
|
300
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
301
|
+
body.default_auto_archive_duration = options.autoArchiveDuration;
|
|
302
|
+
}
|
|
303
|
+
if (options.rateLimitPerUser !== void 0) {
|
|
304
|
+
body.default_thread_rate_limit_per_user = options.rateLimitPerUser;
|
|
305
|
+
}
|
|
306
|
+
return body;
|
|
307
|
+
}
|
|
308
|
+
function toStartThreadBody(channelType, options) {
|
|
309
|
+
const type = options.type ?? (channelType === ChannelType.GuildAnnouncement ? ChannelType.AnnouncementThread : ChannelType.PublicThread);
|
|
310
|
+
const body = { name: options.name, type };
|
|
311
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
312
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
313
|
+
}
|
|
314
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
315
|
+
if (options.invitable !== void 0) body.invitable = options.invitable;
|
|
316
|
+
return body;
|
|
317
|
+
}
|
|
318
|
+
function toStartThreadFromMessageBody(options) {
|
|
319
|
+
const body = { name: options.name };
|
|
320
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
321
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
322
|
+
}
|
|
323
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
324
|
+
return body;
|
|
325
|
+
}
|
|
326
|
+
function toForumThreadMessage(body) {
|
|
327
|
+
const message = {};
|
|
328
|
+
if (body.content !== void 0) message.content = body.content;
|
|
329
|
+
if (body.embeds !== void 0) message.embeds = body.embeds;
|
|
330
|
+
if (body.attachments !== void 0) message.attachments = body.attachments;
|
|
331
|
+
if (body.allowed_mentions !== void 0) message.allowed_mentions = body.allowed_mentions;
|
|
332
|
+
if (body.flags !== void 0) message.flags = body.flags;
|
|
333
|
+
if (body.sticker_ids !== void 0) message.sticker_ids = body.sticker_ids;
|
|
334
|
+
return message;
|
|
335
|
+
}
|
|
336
|
+
function toForumTagBody(options) {
|
|
337
|
+
const body = { name: options.name };
|
|
338
|
+
if ("id" in options && options.id !== void 0) body.id = options.id;
|
|
339
|
+
if (options.moderated !== void 0) body.moderated = options.moderated;
|
|
340
|
+
if (options.emojiId !== void 0) body.emoji_id = options.emojiId;
|
|
341
|
+
if (options.emojiName !== void 0) body.emoji_name = options.emojiName;
|
|
342
|
+
return body;
|
|
343
|
+
}
|
|
344
|
+
function forumParentWire(options, includeLayout) {
|
|
345
|
+
const body = {};
|
|
346
|
+
if (options.availableTags !== void 0) {
|
|
347
|
+
body.available_tags = options.availableTags.map((tag) => toForumTagBody(tag));
|
|
348
|
+
}
|
|
349
|
+
if (options.defaultReactionEmoji !== void 0) {
|
|
350
|
+
body.default_reaction_emoji = options.defaultReactionEmoji === null ? null : reactionEmojiWire(options.defaultReactionEmoji);
|
|
351
|
+
}
|
|
352
|
+
if (options.defaultSortOrder !== void 0) body.default_sort_order = options.defaultSortOrder;
|
|
353
|
+
if (options.defaultTagSetting !== void 0) body.default_tag_setting = options.defaultTagSetting;
|
|
354
|
+
if (options.flags !== void 0) body.flags = options.flags;
|
|
355
|
+
if (options.defaultAutoArchiveDuration !== void 0) {
|
|
356
|
+
body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
|
|
357
|
+
}
|
|
358
|
+
if (options.defaultThreadRateLimitPerUser !== void 0) {
|
|
359
|
+
body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
|
|
360
|
+
}
|
|
361
|
+
if (includeLayout && options.defaultForumLayout !== void 0) {
|
|
362
|
+
body.default_forum_layout = options.defaultForumLayout;
|
|
363
|
+
}
|
|
364
|
+
return body;
|
|
365
|
+
}
|
|
366
|
+
function reactionEmojiWire(emoji) {
|
|
367
|
+
const body = {};
|
|
368
|
+
if (emoji.emojiId !== void 0) body.emoji_id = emoji.emojiId;
|
|
369
|
+
if (emoji.emojiName !== void 0) body.emoji_name = emoji.emojiName;
|
|
370
|
+
return body;
|
|
371
|
+
}
|
|
372
|
+
function toThreadMemberSettingsBody(options) {
|
|
373
|
+
const body = {};
|
|
374
|
+
if (options.flags !== void 0) body.flags = options.flags;
|
|
375
|
+
if (options.muted !== void 0) body.muted = options.muted;
|
|
376
|
+
if (options.muteConfig !== void 0) {
|
|
377
|
+
body.mute_config = options.muteConfig === null ? null : {
|
|
378
|
+
...options.muteConfig.endTime !== void 0 ? { end_time: options.muteConfig.endTime } : {},
|
|
379
|
+
selected_time_window: options.muteConfig.selectedTimeWindow
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return body;
|
|
383
|
+
}
|
|
384
|
+
function withQuery(path, params) {
|
|
385
|
+
const query = new URLSearchParams();
|
|
386
|
+
for (const [key, value] of Object.entries(params)) {
|
|
387
|
+
if (value === void 0) continue;
|
|
388
|
+
if (Array.isArray(value)) {
|
|
389
|
+
for (const item of value) query.append(key, item);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
query.set(key, String(value));
|
|
393
|
+
}
|
|
394
|
+
const text = query.toString();
|
|
395
|
+
return text ? `${path}?${text}` : path;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/ClientCore/SdkOptions/Channels.ts
|
|
269
399
|
function toOverwriteWire(overwrite) {
|
|
270
400
|
return {
|
|
271
401
|
id: overwrite.id,
|
|
@@ -326,6 +456,16 @@ function toChannelCreateBody(options) {
|
|
|
326
456
|
body.content_warning_text = options.contentWarningText;
|
|
327
457
|
}
|
|
328
458
|
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
459
|
+
if (options.defaultAutoArchiveDuration !== void 0) {
|
|
460
|
+
body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
|
|
461
|
+
}
|
|
462
|
+
if (options.defaultThreadRateLimitPerUser !== void 0) {
|
|
463
|
+
body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
|
|
464
|
+
}
|
|
465
|
+
const forumParent = options.type === ChannelType2.GuildForum || options.type === ChannelType2.GuildMedia;
|
|
466
|
+
if (forumParent) {
|
|
467
|
+
Object.assign(body, forumParentWire(options, options.type === ChannelType2.GuildForum));
|
|
468
|
+
}
|
|
329
469
|
return body;
|
|
330
470
|
}
|
|
331
471
|
function toChannelInviteBody(options) {
|
|
@@ -1017,6 +1157,14 @@ var Events = {
|
|
|
1017
1157
|
ChannelCreate: "channelCreate",
|
|
1018
1158
|
ChannelUpdate: "channelUpdate",
|
|
1019
1159
|
ChannelDelete: "channelDelete",
|
|
1160
|
+
ThreadCreate: "threadCreate",
|
|
1161
|
+
ThreadUpdate: "threadUpdate",
|
|
1162
|
+
ThreadDelete: "threadDelete",
|
|
1163
|
+
ThreadListSync: "threadListSync",
|
|
1164
|
+
ThreadMemberUpdate: "threadMemberUpdate",
|
|
1165
|
+
ThreadMembersUpdate: "threadMembersUpdate",
|
|
1166
|
+
ThreadMemberListUpdate: "threadMemberListUpdate",
|
|
1167
|
+
ForumUnreads: "forumUnreads",
|
|
1020
1168
|
ChannelPinsUpdate: "channelPinsUpdate",
|
|
1021
1169
|
ChannelRecipientAdd: "channelRecipientAdd",
|
|
1022
1170
|
ChannelRecipientRemove: "channelRecipientRemove",
|
|
@@ -1154,6 +1302,30 @@ var ReactionCollector = class _ReactionCollector extends EventEmitter {
|
|
|
1154
1302
|
}
|
|
1155
1303
|
};
|
|
1156
1304
|
|
|
1305
|
+
// src/Domain/Channel/ThreadCache.ts
|
|
1306
|
+
function cacheThread(client, data) {
|
|
1307
|
+
const existing = client.channels.get(data.id);
|
|
1308
|
+
if (existing?.isThread() && existing.type === data.type) {
|
|
1309
|
+
existing._patch(data);
|
|
1310
|
+
placeThread(client, existing);
|
|
1311
|
+
return existing;
|
|
1312
|
+
}
|
|
1313
|
+
const created = Channel.from(client, data);
|
|
1314
|
+
if (!created.isThread()) {
|
|
1315
|
+
throw new FluxerError(`Channel ${data.id} is not a thread`, {
|
|
1316
|
+
code: ErrorCodes.InvalidChannelType
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
placeThread(client, created);
|
|
1320
|
+
return created;
|
|
1321
|
+
}
|
|
1322
|
+
function placeThread(client, thread) {
|
|
1323
|
+
client.channels.set(thread.id, thread);
|
|
1324
|
+
if (!thread.guildId) return;
|
|
1325
|
+
const guild = client.guilds.get(thread.guildId);
|
|
1326
|
+
if (guild) guild.channels.set(thread.id, thread);
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1157
1329
|
// src/Domain/Message/Attachment.ts
|
|
1158
1330
|
function toMessageAttachment(data) {
|
|
1159
1331
|
return {
|
|
@@ -1625,6 +1797,8 @@ var Message = class _Message extends Base {
|
|
|
1625
1797
|
nonce;
|
|
1626
1798
|
/** IDs of custom emojis in the message classified as explicit. */
|
|
1627
1799
|
nsfwEmojis;
|
|
1800
|
+
/** Thread started from this message, when the payload included one. */
|
|
1801
|
+
thread;
|
|
1628
1802
|
/**
|
|
1629
1803
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1630
1804
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1700,6 +1874,7 @@ var Message = class _Message extends Base {
|
|
|
1700
1874
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1701
1875
|
this.nonce = data.nonce ?? null;
|
|
1702
1876
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1877
|
+
this.thread = data.thread ? cacheThread(client, data.thread) : null;
|
|
1703
1878
|
}
|
|
1704
1879
|
/**
|
|
1705
1880
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
@@ -1733,6 +1908,7 @@ var Message = class _Message extends Base {
|
|
|
1733
1908
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1734
1909
|
this.nonce = data.nonce ?? null;
|
|
1735
1910
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1911
|
+
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1736
1912
|
}
|
|
1737
1913
|
/**
|
|
1738
1914
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1811,6 +1987,23 @@ var Message = class _Message extends Base {
|
|
|
1811
1987
|
awaitReactions(options) {
|
|
1812
1988
|
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1813
1989
|
}
|
|
1990
|
+
/**
|
|
1991
|
+
* Start a thread from this message.
|
|
1992
|
+
* Fluxer chooses a public or announcement thread from the parent channel.
|
|
1993
|
+
*/
|
|
1994
|
+
async startThread(options) {
|
|
1995
|
+
const data = await this.client.rest.post(
|
|
1996
|
+
Routes4.channelMessageThreads(this.channelId, this.id),
|
|
1997
|
+
{
|
|
1998
|
+
body: toStartThreadFromMessageBody(options),
|
|
1999
|
+
auth: true,
|
|
2000
|
+
...auditReasonHeaders(options.reason)
|
|
2001
|
+
}
|
|
2002
|
+
);
|
|
2003
|
+
const thread = cacheThread(this.client, data);
|
|
2004
|
+
this.thread = thread;
|
|
2005
|
+
return thread;
|
|
2006
|
+
}
|
|
1814
2007
|
/** Fetch the latest version of this message from the API. */
|
|
1815
2008
|
async fetch() {
|
|
1816
2009
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
@@ -2278,43 +2471,56 @@ var Channel = class extends Base {
|
|
|
2278
2471
|
throw new Error("Channel.createDM not initialized");
|
|
2279
2472
|
}
|
|
2280
2473
|
/**
|
|
2281
|
-
* Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
|
|
2474
|
+
* Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
|
|
2475
|
+
* Forum and media channels contain threads and do not accept `send`.
|
|
2282
2476
|
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
2283
2477
|
*/
|
|
2284
2478
|
isTextBased() {
|
|
2285
|
-
return this.type ===
|
|
2479
|
+
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
|
|
2286
2480
|
}
|
|
2287
|
-
/** Check if this is a guild channel
|
|
2481
|
+
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
2288
2482
|
isGuild() {
|
|
2289
|
-
return this.type ===
|
|
2483
|
+
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildCategory || this.type === ChannelType3.GuildLink || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread || this.type === ChannelType3.GuildForum || this.type === ChannelType3.GuildMedia;
|
|
2484
|
+
}
|
|
2485
|
+
/** Check if this is a thread (public, private, or announcement). */
|
|
2486
|
+
isThread() {
|
|
2487
|
+
return this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
|
|
2488
|
+
}
|
|
2489
|
+
/** Check if this is a forum channel. */
|
|
2490
|
+
isForum() {
|
|
2491
|
+
return this.type === ChannelType3.GuildForum;
|
|
2492
|
+
}
|
|
2493
|
+
/** Check if this is a media channel. */
|
|
2494
|
+
isMedia() {
|
|
2495
|
+
return this.type === ChannelType3.GuildMedia;
|
|
2290
2496
|
}
|
|
2291
2497
|
/** Check if this is a guild text channel. */
|
|
2292
2498
|
isText() {
|
|
2293
|
-
return this.type ===
|
|
2499
|
+
return this.type === ChannelType3.GuildText;
|
|
2294
2500
|
}
|
|
2295
2501
|
/** Check if this is a guild announcement channel. */
|
|
2296
2502
|
isAnnouncement() {
|
|
2297
|
-
return this.type ===
|
|
2503
|
+
return this.type === ChannelType3.GuildAnnouncement;
|
|
2298
2504
|
}
|
|
2299
2505
|
/** Check if this is a category channel. */
|
|
2300
2506
|
isCategory() {
|
|
2301
|
-
return this.type ===
|
|
2507
|
+
return this.type === ChannelType3.GuildCategory;
|
|
2302
2508
|
}
|
|
2303
2509
|
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
2304
2510
|
isDM() {
|
|
2305
|
-
return this.type ===
|
|
2511
|
+
return this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes;
|
|
2306
2512
|
}
|
|
2307
2513
|
/** Check if this is a personal notes channel. */
|
|
2308
2514
|
isPersonalNotes() {
|
|
2309
|
-
return this.type ===
|
|
2515
|
+
return this.type === ChannelType3.DMPersonalNotes;
|
|
2310
2516
|
}
|
|
2311
2517
|
/** Check if this is a voice channel. */
|
|
2312
2518
|
isVoice() {
|
|
2313
|
-
return this.type ===
|
|
2519
|
+
return this.type === ChannelType3.GuildVoice;
|
|
2314
2520
|
}
|
|
2315
2521
|
/** Check if this is a link channel. */
|
|
2316
2522
|
isLink() {
|
|
2317
|
-
return this.type ===
|
|
2523
|
+
return this.type === ChannelType3.GuildLink;
|
|
2318
2524
|
}
|
|
2319
2525
|
/**
|
|
2320
2526
|
* Delete recent messages or an explicit ID list.
|
|
@@ -2486,7 +2692,7 @@ var Channel = class extends Base {
|
|
|
2486
2692
|
};
|
|
2487
2693
|
|
|
2488
2694
|
// src/Domain/Channel/Dm.ts
|
|
2489
|
-
import { ChannelType as
|
|
2695
|
+
import { ChannelType as ChannelType4, Routes as Routes9 } from "@fluxerjs/types";
|
|
2490
2696
|
|
|
2491
2697
|
// src/Domain/Channel/TextCapable.ts
|
|
2492
2698
|
import { Routes as Routes8 } from "@fluxerjs/types";
|
|
@@ -2578,7 +2784,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2578
2784
|
* Notes-only; bots usually skip this.
|
|
2579
2785
|
*/
|
|
2580
2786
|
async purgeMessages() {
|
|
2581
|
-
if (this.type !==
|
|
2787
|
+
if (this.type !== ChannelType4.DMPersonalNotes) {
|
|
2582
2788
|
throw new FluxerError("purgeMessages is only available on personal notes channels", {
|
|
2583
2789
|
code: ErrorCodes.InvalidChannelType
|
|
2584
2790
|
});
|
|
@@ -2621,6 +2827,12 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2621
2827
|
}
|
|
2622
2828
|
};
|
|
2623
2829
|
|
|
2830
|
+
// src/Domain/Channel/Forum.ts
|
|
2831
|
+
import {
|
|
2832
|
+
ChannelType as ChannelType7,
|
|
2833
|
+
Routes as Routes16
|
|
2834
|
+
} from "@fluxerjs/types";
|
|
2835
|
+
|
|
2624
2836
|
// src/Domain/Channel/Guild.ts
|
|
2625
2837
|
import { Routes as Routes13 } from "@fluxerjs/types";
|
|
2626
2838
|
import { PermissionFlags } from "@fluxerjs/util";
|
|
@@ -2932,7 +3144,8 @@ var Invite = class _Invite extends Base {
|
|
|
2932
3144
|
// src/Domain/Webhook.ts
|
|
2933
3145
|
import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
|
|
2934
3146
|
import {
|
|
2935
|
-
Routes as Routes11
|
|
3147
|
+
Routes as Routes11,
|
|
3148
|
+
WebhookType
|
|
2936
3149
|
} from "@fluxerjs/types";
|
|
2937
3150
|
import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
|
|
2938
3151
|
var Webhook = class _Webhook extends Base {
|
|
@@ -2952,6 +3165,8 @@ var Webhook = class _Webhook extends Base {
|
|
|
2952
3165
|
token;
|
|
2953
3166
|
/** The user that created this webhook. */
|
|
2954
3167
|
user;
|
|
3168
|
+
/** Incoming or channel-follower webhook. */
|
|
3169
|
+
type;
|
|
2955
3170
|
constructor(client, data) {
|
|
2956
3171
|
super();
|
|
2957
3172
|
this.client = client;
|
|
@@ -2962,6 +3177,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
2962
3177
|
this.avatar = data.avatar ?? null;
|
|
2963
3178
|
this.token = data.token ?? null;
|
|
2964
3179
|
this.user = client.getOrCreateUser(data.user);
|
|
3180
|
+
this.type = data.type ?? WebhookType.Incoming;
|
|
2965
3181
|
}
|
|
2966
3182
|
avatarURL(options) {
|
|
2967
3183
|
return cdnAvatarURL(this.id, this.avatar, {
|
|
@@ -3072,6 +3288,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
3072
3288
|
name: options?.name ?? "Webhook",
|
|
3073
3289
|
avatar: null,
|
|
3074
3290
|
token,
|
|
3291
|
+
type: WebhookType.Incoming,
|
|
3075
3292
|
user: {
|
|
3076
3293
|
id: "",
|
|
3077
3294
|
username: "webhook",
|
|
@@ -3191,6 +3408,23 @@ var PermissionOverwriteManager = class {
|
|
|
3191
3408
|
}
|
|
3192
3409
|
};
|
|
3193
3410
|
|
|
3411
|
+
// src/Domain/Channel/ThreadBind.ts
|
|
3412
|
+
var factory;
|
|
3413
|
+
var managers = /* @__PURE__ */ new WeakMap();
|
|
3414
|
+
function bindThreadManager(next) {
|
|
3415
|
+
factory = next;
|
|
3416
|
+
}
|
|
3417
|
+
function threadManagerFor(channel) {
|
|
3418
|
+
const existing = managers.get(channel);
|
|
3419
|
+
if (existing) return existing;
|
|
3420
|
+
if (!factory) {
|
|
3421
|
+
throw new Error("ThreadManager is not initialized");
|
|
3422
|
+
}
|
|
3423
|
+
const created = factory(channel);
|
|
3424
|
+
managers.set(channel, created);
|
|
3425
|
+
return created;
|
|
3426
|
+
}
|
|
3427
|
+
|
|
3194
3428
|
// src/Domain/Channel/Guild.ts
|
|
3195
3429
|
var GuildChannel = class extends Channel {
|
|
3196
3430
|
/** Guild ID this channel belongs to, or null if missing from the payload. */
|
|
@@ -3311,6 +3545,10 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3311
3545
|
contentWarningLevel;
|
|
3312
3546
|
/** Custom content warning text. */
|
|
3313
3547
|
contentWarningText;
|
|
3548
|
+
/** Default auto-archive duration in minutes for new threads. */
|
|
3549
|
+
defaultAutoArchiveDuration;
|
|
3550
|
+
/** Slowmode in seconds copied onto new threads. */
|
|
3551
|
+
defaultThreadRateLimitPerUser;
|
|
3314
3552
|
constructor(client, data) {
|
|
3315
3553
|
super(client, data);
|
|
3316
3554
|
this.topic = data.topic ?? null;
|
|
@@ -3320,6 +3558,12 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3320
3558
|
this.lastMessageId = data.last_message_id ?? null;
|
|
3321
3559
|
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3322
3560
|
this.contentWarningText = data.content_warning_text ?? null;
|
|
3561
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
3562
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
3563
|
+
}
|
|
3564
|
+
/** Create, list, and search threads in this channel. */
|
|
3565
|
+
get threads() {
|
|
3566
|
+
return threadManagerFor(this);
|
|
3323
3567
|
}
|
|
3324
3568
|
/**
|
|
3325
3569
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3340,6 +3584,25 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3340
3584
|
if ("content_warning_text" in data) {
|
|
3341
3585
|
this.contentWarningText = data.content_warning_text ?? null;
|
|
3342
3586
|
}
|
|
3587
|
+
if ("default_auto_archive_duration" in data) {
|
|
3588
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
3589
|
+
}
|
|
3590
|
+
if ("default_thread_rate_limit_per_user" in data) {
|
|
3591
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
/**
|
|
3595
|
+
* Set the auto-archive and slowmode defaults copied onto new threads.
|
|
3596
|
+
* Sends only those fields. The thread-parent update body does not accept a channel rename.
|
|
3597
|
+
*/
|
|
3598
|
+
async editThreadDefaults(options) {
|
|
3599
|
+
const data = await this.client.rest.patch(Routes13.channel(this.id), {
|
|
3600
|
+
body: toThreadParentEditBody(options),
|
|
3601
|
+
auth: true,
|
|
3602
|
+
...auditReasonHeaders(options.reason)
|
|
3603
|
+
});
|
|
3604
|
+
this._patch(data);
|
|
3605
|
+
return this;
|
|
3343
3606
|
}
|
|
3344
3607
|
};
|
|
3345
3608
|
var AnnouncementChannel = class extends TextChannel {
|
|
@@ -3422,26 +3685,522 @@ var LinkChannel = class extends GuildChannel {
|
|
|
3422
3685
|
}
|
|
3423
3686
|
};
|
|
3424
3687
|
|
|
3688
|
+
// src/Domain/Channel/ThreadManager.ts
|
|
3689
|
+
import { ChannelType as ChannelType6, Routes as Routes15 } from "@fluxerjs/types";
|
|
3690
|
+
|
|
3691
|
+
// src/Domain/Channel/ThreadChannel.ts
|
|
3692
|
+
import { ChannelType as ChannelType5, Routes as Routes14 } from "@fluxerjs/types";
|
|
3693
|
+
var ThreadMember = class {
|
|
3694
|
+
/** Thread ID. */
|
|
3695
|
+
id;
|
|
3696
|
+
/** User ID. */
|
|
3697
|
+
userId;
|
|
3698
|
+
/** When the user last joined the thread. */
|
|
3699
|
+
joinedAt;
|
|
3700
|
+
/** Thread member flags bitfield. */
|
|
3701
|
+
flags;
|
|
3702
|
+
/** Whether the current user has muted the thread. */
|
|
3703
|
+
muted;
|
|
3704
|
+
/** ISO-8601 timestamp when the mute expires, if set. */
|
|
3705
|
+
muteEndTime;
|
|
3706
|
+
/** Selected mute duration in seconds, if set. */
|
|
3707
|
+
muteWindow;
|
|
3708
|
+
constructor(data) {
|
|
3709
|
+
this.id = data.id ?? null;
|
|
3710
|
+
this.userId = data.user_id ?? data.member?.user?.id ?? null;
|
|
3711
|
+
this.joinedAt = new Date(data.join_timestamp);
|
|
3712
|
+
this.flags = data.flags;
|
|
3713
|
+
this.muted = data.muted ?? null;
|
|
3714
|
+
this.muteEndTime = data.mute_config?.end_time ?? null;
|
|
3715
|
+
this.muteWindow = data.mute_config?.selected_time_window ?? null;
|
|
3716
|
+
}
|
|
3717
|
+
};
|
|
3718
|
+
function threadEditFields(options) {
|
|
3719
|
+
const source = options;
|
|
3720
|
+
return {
|
|
3721
|
+
name: typeof source.name === "string" ? source.name : void 0,
|
|
3722
|
+
archived: source.archived,
|
|
3723
|
+
autoArchiveDuration: source.autoArchiveDuration,
|
|
3724
|
+
locked: source.locked,
|
|
3725
|
+
rateLimitPerUser: source.rateLimitPerUser,
|
|
3726
|
+
flags: source.flags,
|
|
3727
|
+
appliedTags: source.appliedTags,
|
|
3728
|
+
invitable: source.invitable,
|
|
3729
|
+
reason: source.reason
|
|
3730
|
+
};
|
|
3731
|
+
}
|
|
3732
|
+
function readMetadata(data) {
|
|
3733
|
+
return {
|
|
3734
|
+
archived: data?.archived ?? false,
|
|
3735
|
+
autoArchiveDuration: data?.auto_archive_duration ?? 0,
|
|
3736
|
+
archiveTimestamp: data?.archive_timestamp ?? null,
|
|
3737
|
+
locked: data?.locked ?? false,
|
|
3738
|
+
invitable: data?.invitable ?? null
|
|
3739
|
+
};
|
|
3740
|
+
}
|
|
3741
|
+
var ThreadChannel = class extends TextCapable(GuildChannel) {
|
|
3742
|
+
/** User who created the thread. */
|
|
3743
|
+
ownerId;
|
|
3744
|
+
/** Whether the thread is archived. */
|
|
3745
|
+
archived;
|
|
3746
|
+
/** Minutes of inactivity before the thread archives. */
|
|
3747
|
+
autoArchiveDuration;
|
|
3748
|
+
/** ISO-8601 timestamp when the archive status last changed. */
|
|
3749
|
+
archiveTimestamp;
|
|
3750
|
+
/** Whether only moderators can unarchive the thread. */
|
|
3751
|
+
locked;
|
|
3752
|
+
/** Whether non-moderators can add other non-moderators. Private threads only. */
|
|
3753
|
+
invitable;
|
|
3754
|
+
/** Slowmode in seconds. */
|
|
3755
|
+
rateLimitPerUser;
|
|
3756
|
+
/** ID of the last message sent in this thread. */
|
|
3757
|
+
lastMessageId;
|
|
3758
|
+
/** Messages in the thread, excluding the starter and deleted messages. */
|
|
3759
|
+
messageCount;
|
|
3760
|
+
/** Messages ever sent in the thread. This count is never decremented. */
|
|
3761
|
+
totalMessageSent;
|
|
3762
|
+
/** Approximate member count, capped at 50. */
|
|
3763
|
+
memberCount;
|
|
3764
|
+
/** Tag IDs applied to a forum or media post. */
|
|
3765
|
+
appliedTags;
|
|
3766
|
+
/** Channel flags bitfield. */
|
|
3767
|
+
flags;
|
|
3768
|
+
/** The current user's membership, when the payload included it. */
|
|
3769
|
+
member;
|
|
3770
|
+
/** Add, remove, and list members of this thread. */
|
|
3771
|
+
members;
|
|
3772
|
+
constructor(client, data) {
|
|
3773
|
+
super(client, data);
|
|
3774
|
+
const metadata = readMetadata(data.thread_metadata);
|
|
3775
|
+
this.ownerId = data.owner_id ?? null;
|
|
3776
|
+
this.archived = metadata.archived;
|
|
3777
|
+
this.autoArchiveDuration = metadata.autoArchiveDuration;
|
|
3778
|
+
this.archiveTimestamp = metadata.archiveTimestamp;
|
|
3779
|
+
this.locked = metadata.locked;
|
|
3780
|
+
this.invitable = metadata.invitable;
|
|
3781
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3782
|
+
this.lastMessageId = data.last_message_id ?? null;
|
|
3783
|
+
this.messageCount = data.message_count ?? 0;
|
|
3784
|
+
this.totalMessageSent = data.total_message_sent ?? 0;
|
|
3785
|
+
this.memberCount = data.member_count ?? 0;
|
|
3786
|
+
this.appliedTags = data.applied_tags ?? [];
|
|
3787
|
+
this.flags = data.flags ?? 0;
|
|
3788
|
+
this.member = data.member ? new ThreadMember(data.member) : null;
|
|
3789
|
+
this.members = new ThreadMemberManager(this);
|
|
3790
|
+
}
|
|
3791
|
+
/** @internal */
|
|
3792
|
+
_patch(data) {
|
|
3793
|
+
super._patch(data);
|
|
3794
|
+
if (data.owner_id !== void 0) this.ownerId = data.owner_id ?? null;
|
|
3795
|
+
if (data.thread_metadata) {
|
|
3796
|
+
const metadata = readMetadata(data.thread_metadata);
|
|
3797
|
+
this.archived = metadata.archived;
|
|
3798
|
+
this.autoArchiveDuration = metadata.autoArchiveDuration;
|
|
3799
|
+
this.archiveTimestamp = metadata.archiveTimestamp;
|
|
3800
|
+
this.locked = metadata.locked;
|
|
3801
|
+
this.invitable = metadata.invitable;
|
|
3802
|
+
}
|
|
3803
|
+
if ("rate_limit_per_user" in data && data.rate_limit_per_user !== void 0) {
|
|
3804
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3805
|
+
}
|
|
3806
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3807
|
+
if (data.message_count !== void 0) this.messageCount = data.message_count;
|
|
3808
|
+
if (data.total_message_sent !== void 0) this.totalMessageSent = data.total_message_sent;
|
|
3809
|
+
if (data.member_count !== void 0) this.memberCount = data.member_count;
|
|
3810
|
+
if (data.applied_tags !== void 0) this.appliedTags = data.applied_tags ?? [];
|
|
3811
|
+
if (data.flags !== void 0) this.flags = data.flags;
|
|
3812
|
+
if (data.member !== void 0) this.member = data.member ? new ThreadMember(data.member) : null;
|
|
3813
|
+
}
|
|
3814
|
+
/**
|
|
3815
|
+
* Edit this thread. Requires Manage Threads on public threads, or ownership on private ones.
|
|
3816
|
+
* `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
|
|
3817
|
+
*/
|
|
3818
|
+
async edit(options) {
|
|
3819
|
+
const data = await this.client.rest.patch(Routes14.channel(this.id), {
|
|
3820
|
+
body: toThreadEditBody(this.type, threadEditFields(options)),
|
|
3821
|
+
auth: true,
|
|
3822
|
+
...auditReasonHeaders(options.reason)
|
|
3823
|
+
});
|
|
3824
|
+
this._patch(data);
|
|
3825
|
+
return this;
|
|
3826
|
+
}
|
|
3827
|
+
/** Archive or unarchive this thread. */
|
|
3828
|
+
async setArchived(archived, reason) {
|
|
3829
|
+
return this.edit({ archived, reason });
|
|
3830
|
+
}
|
|
3831
|
+
/** Lock or unlock this thread. Locked threads can only be unarchived by moderators. */
|
|
3832
|
+
async setLocked(locked, reason) {
|
|
3833
|
+
return this.edit({ locked, reason });
|
|
3834
|
+
}
|
|
3835
|
+
/** Join this thread. */
|
|
3836
|
+
async join() {
|
|
3837
|
+
await this.client.rest.put(Routes14.channelThreadMemberMe(this.id), { auth: true });
|
|
3838
|
+
}
|
|
3839
|
+
/** Leave this thread. */
|
|
3840
|
+
async leave() {
|
|
3841
|
+
await this.client.rest.delete(Routes14.channelThreadMemberMe(this.id), { auth: true });
|
|
3842
|
+
}
|
|
3843
|
+
/** Update the current user's notification settings for this thread. */
|
|
3844
|
+
async editSelf(options) {
|
|
3845
|
+
const data = await this.client.rest.patch(
|
|
3846
|
+
Routes14.channelThreadMemberMeSettings(this.id),
|
|
3847
|
+
{ body: toThreadMemberSettingsBody(options), auth: true }
|
|
3848
|
+
);
|
|
3849
|
+
this.member = data ? new ThreadMember(data) : null;
|
|
3850
|
+
return this.member;
|
|
3851
|
+
}
|
|
3852
|
+
};
|
|
3853
|
+
var ThreadMemberManager = class {
|
|
3854
|
+
constructor(thread) {
|
|
3855
|
+
this.thread = thread;
|
|
3856
|
+
}
|
|
3857
|
+
/** List members of this thread. */
|
|
3858
|
+
async fetch(options) {
|
|
3859
|
+
const data = await this.thread.client.rest.get(
|
|
3860
|
+
withQuery(Routes14.channelThreadMembers(this.thread.id), {
|
|
3861
|
+
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
|
|
3862
|
+
after: options?.after,
|
|
3863
|
+
limit: options?.limit
|
|
3864
|
+
})
|
|
3865
|
+
);
|
|
3866
|
+
return data.map((member) => new ThreadMember(member));
|
|
3867
|
+
}
|
|
3868
|
+
/** Fetch one member of this thread. */
|
|
3869
|
+
async fetchOne(userId, options) {
|
|
3870
|
+
const data = await this.thread.client.rest.get(
|
|
3871
|
+
withQuery(Routes14.channelThreadMember(this.thread.id, userId), {
|
|
3872
|
+
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
|
|
3873
|
+
})
|
|
3874
|
+
);
|
|
3875
|
+
return new ThreadMember(data);
|
|
3876
|
+
}
|
|
3877
|
+
/** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
|
|
3878
|
+
async add(userId) {
|
|
3879
|
+
await this.thread.client.rest.put(Routes14.channelThreadMember(this.thread.id, userId), {
|
|
3880
|
+
auth: true
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3883
|
+
/** Remove a user from this thread. */
|
|
3884
|
+
async remove(userId) {
|
|
3885
|
+
await this.thread.client.rest.delete(Routes14.channelThreadMember(this.thread.id, userId), {
|
|
3886
|
+
auth: true
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3889
|
+
};
|
|
3890
|
+
function isThreadType(type) {
|
|
3891
|
+
return type === ChannelType5.AnnouncementThread || type === ChannelType5.PublicThread || type === ChannelType5.PrivateThread;
|
|
3892
|
+
}
|
|
3893
|
+
|
|
3894
|
+
// src/Domain/Channel/ThreadManager.ts
|
|
3895
|
+
var ThreadManager = class {
|
|
3896
|
+
constructor(channel) {
|
|
3897
|
+
this.channel = channel;
|
|
3898
|
+
}
|
|
3899
|
+
/**
|
|
3900
|
+
* Start a thread in a text or announcement channel.
|
|
3901
|
+
* Forum and media channels must use {@link createPost}.
|
|
3902
|
+
*/
|
|
3903
|
+
async create(options) {
|
|
3904
|
+
if (this.channel.type === ChannelType6.GuildForum || this.channel.type === ChannelType6.GuildMedia) {
|
|
3905
|
+
throw new FluxerError("Forum and media channels start posts with createPost", {
|
|
3906
|
+
code: ErrorCodes.InvalidChannelType
|
|
3907
|
+
});
|
|
3908
|
+
}
|
|
3909
|
+
const data = await this.channel.client.rest.post(
|
|
3910
|
+
Routes15.channelThreads(this.channel.id),
|
|
3911
|
+
{
|
|
3912
|
+
body: toStartThreadBody(this.channel.type, options),
|
|
3913
|
+
auth: true,
|
|
3914
|
+
...auditReasonHeaders(options.reason)
|
|
3915
|
+
}
|
|
3916
|
+
);
|
|
3917
|
+
return cacheThread(this.channel.client, data);
|
|
3918
|
+
}
|
|
3919
|
+
/**
|
|
3920
|
+
* Start a post in a forum or media channel.
|
|
3921
|
+
* The post is a public thread. `message` is its first message.
|
|
3922
|
+
*/
|
|
3923
|
+
async createPost(options) {
|
|
3924
|
+
if (this.channel.type !== ChannelType6.GuildForum && this.channel.type !== ChannelType6.GuildMedia) {
|
|
3925
|
+
throw new FluxerError("createPost is for forum and media channels", {
|
|
3926
|
+
code: ErrorCodes.InvalidChannelType
|
|
3927
|
+
});
|
|
3928
|
+
}
|
|
3929
|
+
const prepared = await prepareMessagePostPayload(options.message, {
|
|
3930
|
+
defaultAllowedMentions: this.channel.client.options.defaultAllowedMentions
|
|
3931
|
+
});
|
|
3932
|
+
const body = {
|
|
3933
|
+
name: options.name,
|
|
3934
|
+
type: ChannelType6.PublicThread,
|
|
3935
|
+
message: toForumThreadMessage(prepared.body)
|
|
3936
|
+
};
|
|
3937
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
3938
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
3939
|
+
}
|
|
3940
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
3941
|
+
if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
|
|
3942
|
+
const data = await this.channel.client.rest.post(
|
|
3943
|
+
Routes15.channelThreads(this.channel.id),
|
|
3944
|
+
{
|
|
3945
|
+
body,
|
|
3946
|
+
files: prepared.files,
|
|
3947
|
+
auth: true,
|
|
3948
|
+
...auditReasonHeaders(options.reason)
|
|
3949
|
+
}
|
|
3950
|
+
);
|
|
3951
|
+
const thread = cacheThread(this.channel.client, data);
|
|
3952
|
+
if (data.message) {
|
|
3953
|
+
this.channel.client._addMessageToCache(data.message.channel_id, data.message);
|
|
3954
|
+
}
|
|
3955
|
+
return thread;
|
|
3956
|
+
}
|
|
3957
|
+
/**
|
|
3958
|
+
* List archived threads in this channel.
|
|
3959
|
+
* `before` is an ISO-8601 archive timestamp.
|
|
3960
|
+
*/
|
|
3961
|
+
async fetchArchived(options) {
|
|
3962
|
+
const path = options.type === "private" ? Routes15.channelThreadsArchivedPrivate(this.channel.id) : Routes15.channelThreadsArchivedPublic(this.channel.id);
|
|
3963
|
+
const data = await this.channel.client.rest.get(
|
|
3964
|
+
withQuery(path, { before: options.before, limit: options.limit })
|
|
3965
|
+
);
|
|
3966
|
+
return fetchedThreadsFrom(this.channel.client, data);
|
|
3967
|
+
}
|
|
3968
|
+
/**
|
|
3969
|
+
* List private archived threads in this channel that the current user has joined.
|
|
3970
|
+
* `before` is a thread snowflake.
|
|
3971
|
+
*/
|
|
3972
|
+
async fetchJoinedPrivateArchived(options) {
|
|
3973
|
+
const data = await this.channel.client.rest.get(
|
|
3974
|
+
withQuery(Routes15.channelJoinedArchivedPrivateThreads(this.channel.id), {
|
|
3975
|
+
before: options?.before,
|
|
3976
|
+
limit: options?.limit
|
|
3977
|
+
})
|
|
3978
|
+
);
|
|
3979
|
+
return fetchedThreadsFrom(this.channel.client, data);
|
|
3980
|
+
}
|
|
3981
|
+
/**
|
|
3982
|
+
* Search threads in this channel.
|
|
3983
|
+
* Returns `{ indexing: true }` while the search index is still building.
|
|
3984
|
+
*/
|
|
3985
|
+
async search(options) {
|
|
3986
|
+
const data = await this.channel.client.rest.get(
|
|
3987
|
+
withQuery(Routes15.channelThreadSearch(this.channel.id), {
|
|
3988
|
+
name: options?.name,
|
|
3989
|
+
tag: options?.tag,
|
|
3990
|
+
tag_setting: options?.tagSetting,
|
|
3991
|
+
archived: options?.archived === void 0 ? void 0 : String(options.archived),
|
|
3992
|
+
sort_by: options?.sortBy,
|
|
3993
|
+
sort_order: options?.sortOrder,
|
|
3994
|
+
limit: options?.limit,
|
|
3995
|
+
offset: options?.offset,
|
|
3996
|
+
max_id: options?.maxId,
|
|
3997
|
+
min_id: options?.minId
|
|
3998
|
+
})
|
|
3999
|
+
);
|
|
4000
|
+
if (isSearchNotReady(data)) {
|
|
4001
|
+
return { indexing: true, retryAfter: data.retry_after, message: data.message };
|
|
4002
|
+
}
|
|
4003
|
+
const page = fetchedThreadsFrom(this.channel.client, data);
|
|
4004
|
+
return {
|
|
4005
|
+
...page,
|
|
4006
|
+
hasMore: data.has_more,
|
|
4007
|
+
totalResults: data.total_results,
|
|
4008
|
+
firstMessages: (data.first_messages ?? []).map(
|
|
4009
|
+
(message) => new Message(this.channel.client, message)
|
|
4010
|
+
)
|
|
4011
|
+
};
|
|
4012
|
+
}
|
|
4013
|
+
/** Set the auto-archive and slowmode defaults copied onto new threads. */
|
|
4014
|
+
async editDefaults(options) {
|
|
4015
|
+
return this.channel.client.rest.patch(Routes15.channel(this.channel.id), {
|
|
4016
|
+
body: toThreadParentEditBody(options),
|
|
4017
|
+
auth: true,
|
|
4018
|
+
...auditReasonHeaders(options.reason)
|
|
4019
|
+
});
|
|
4020
|
+
}
|
|
4021
|
+
};
|
|
4022
|
+
function fetchedThreadsFrom(client, data) {
|
|
4023
|
+
return {
|
|
4024
|
+
threads: (data.threads ?? []).map((thread) => cacheThread(client, thread)),
|
|
4025
|
+
members: (data.members ?? []).map((member) => new ThreadMember(member)),
|
|
4026
|
+
hasMore: data.has_more ?? false
|
|
4027
|
+
};
|
|
4028
|
+
}
|
|
4029
|
+
function isSearchNotReady(data) {
|
|
4030
|
+
return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
|
|
4031
|
+
}
|
|
4032
|
+
async function fetchActiveThreads(client, guildId) {
|
|
4033
|
+
const data = await client.rest.get(Routes15.guildActiveThreads(guildId));
|
|
4034
|
+
return fetchedThreadsFrom(client, data);
|
|
4035
|
+
}
|
|
4036
|
+
|
|
4037
|
+
// src/Domain/Channel/Forum.ts
|
|
4038
|
+
function tagsFrom(data) {
|
|
4039
|
+
return data ?? [];
|
|
4040
|
+
}
|
|
4041
|
+
var ThreadOnlyChannel = class extends GuildChannel {
|
|
4042
|
+
/** Tags that can be applied to posts. */
|
|
4043
|
+
availableTags;
|
|
4044
|
+
/** Default reaction for new posts. */
|
|
4045
|
+
defaultReactionEmoji;
|
|
4046
|
+
/** Default sort order for posts. */
|
|
4047
|
+
defaultSortOrder;
|
|
4048
|
+
/** How posts are filtered when searching by several tags. */
|
|
4049
|
+
defaultTagSetting;
|
|
4050
|
+
/** Default auto-archive duration in minutes for new posts. */
|
|
4051
|
+
defaultAutoArchiveDuration;
|
|
4052
|
+
/** Slowmode in seconds copied onto new posts. */
|
|
4053
|
+
defaultThreadRateLimitPerUser;
|
|
4054
|
+
/** Channel flags bitfield. */
|
|
4055
|
+
flags;
|
|
4056
|
+
/** Create, list, and search posts in this channel. */
|
|
4057
|
+
threads;
|
|
4058
|
+
constructor(client, data) {
|
|
4059
|
+
super(client, data);
|
|
4060
|
+
this.availableTags = tagsFrom(data.available_tags);
|
|
4061
|
+
this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
|
|
4062
|
+
this.defaultSortOrder = data.default_sort_order ?? null;
|
|
4063
|
+
this.defaultTagSetting = data.default_tag_setting ?? null;
|
|
4064
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
4065
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
4066
|
+
this.flags = data.flags ?? 0;
|
|
4067
|
+
this.threads = new ThreadManager(this);
|
|
4068
|
+
}
|
|
4069
|
+
/** @internal */
|
|
4070
|
+
_patch(data) {
|
|
4071
|
+
super._patch(data);
|
|
4072
|
+
if (data.available_tags !== void 0) this.availableTags = tagsFrom(data.available_tags);
|
|
4073
|
+
if ("default_reaction_emoji" in data) {
|
|
4074
|
+
this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
|
|
4075
|
+
}
|
|
4076
|
+
if ("default_sort_order" in data) this.defaultSortOrder = data.default_sort_order ?? null;
|
|
4077
|
+
if ("default_tag_setting" in data) this.defaultTagSetting = data.default_tag_setting ?? null;
|
|
4078
|
+
if ("default_auto_archive_duration" in data) {
|
|
4079
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
4080
|
+
}
|
|
4081
|
+
if ("default_thread_rate_limit_per_user" in data) {
|
|
4082
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
4083
|
+
}
|
|
4084
|
+
if (data.flags !== void 0) this.flags = data.flags;
|
|
4085
|
+
}
|
|
4086
|
+
/**
|
|
4087
|
+
* Edit this channel.
|
|
4088
|
+
* Tag, sort, reaction, and thread-default fields are sent with the usual channel fields.
|
|
4089
|
+
* `defaultForumLayout` is sent only for forum channels.
|
|
4090
|
+
*/
|
|
4091
|
+
async edit(options) {
|
|
4092
|
+
const data = await this.client.rest.patch(Routes16.channel(this.id), {
|
|
4093
|
+
body: {
|
|
4094
|
+
...toChannelEditBody(options),
|
|
4095
|
+
...forumParentWire(options, this.type === ChannelType7.GuildForum)
|
|
4096
|
+
},
|
|
4097
|
+
auth: true,
|
|
4098
|
+
...auditReasonHeaders(options.reason)
|
|
4099
|
+
});
|
|
4100
|
+
this._patch(data);
|
|
4101
|
+
return this;
|
|
4102
|
+
}
|
|
4103
|
+
/** Replace the tags that can be applied to posts (max 20). */
|
|
4104
|
+
async setAvailableTags(tags, reason) {
|
|
4105
|
+
return this.edit({ availableTags: tags, reason });
|
|
4106
|
+
}
|
|
4107
|
+
/** Set or clear the default reaction on new posts. */
|
|
4108
|
+
async setDefaultReactionEmoji(emoji, reason) {
|
|
4109
|
+
return this.edit({ defaultReactionEmoji: emoji, reason });
|
|
4110
|
+
}
|
|
4111
|
+
/** Set or clear the default post sort order. */
|
|
4112
|
+
async setDefaultSortOrder(order, reason) {
|
|
4113
|
+
return this.edit({ defaultSortOrder: order, reason });
|
|
4114
|
+
}
|
|
4115
|
+
/** Set or clear how posts match when several tags are selected. */
|
|
4116
|
+
async setDefaultTagSetting(setting, reason) {
|
|
4117
|
+
return this.edit({ defaultTagSetting: setting, reason });
|
|
4118
|
+
}
|
|
4119
|
+
/** Set the auto-archive and slowmode defaults copied onto new posts. */
|
|
4120
|
+
async editThreadDefaults(options) {
|
|
4121
|
+
const data = await this.client.rest.patch(Routes16.channel(this.id), {
|
|
4122
|
+
body: toThreadParentEditBody(options),
|
|
4123
|
+
auth: true,
|
|
4124
|
+
...auditReasonHeaders(options.reason)
|
|
4125
|
+
});
|
|
4126
|
+
this._patch(data);
|
|
4127
|
+
return this;
|
|
4128
|
+
}
|
|
4129
|
+
/** Create a tag. The response replaces {@link availableTags}. */
|
|
4130
|
+
async createTag(options) {
|
|
4131
|
+
const data = await this.client.rest.post(Routes16.channelTags(this.id), {
|
|
4132
|
+
body: toForumTagBody(options),
|
|
4133
|
+
auth: true,
|
|
4134
|
+
...auditReasonHeaders(options.reason)
|
|
4135
|
+
});
|
|
4136
|
+
this._patch(data);
|
|
4137
|
+
return this;
|
|
4138
|
+
}
|
|
4139
|
+
/** Replace a tag. The response replaces {@link availableTags}. */
|
|
4140
|
+
async editTag(tagId, options) {
|
|
4141
|
+
const data = await this.client.rest.put(Routes16.channelTag(this.id, tagId), {
|
|
4142
|
+
body: toForumTagBody(options),
|
|
4143
|
+
auth: true,
|
|
4144
|
+
...auditReasonHeaders(options.reason)
|
|
4145
|
+
});
|
|
4146
|
+
this._patch(data);
|
|
4147
|
+
return this;
|
|
4148
|
+
}
|
|
4149
|
+
/** Delete a tag. The response replaces {@link availableTags}. */
|
|
4150
|
+
async deleteTag(tagId, reason) {
|
|
4151
|
+
const data = await this.client.rest.delete(Routes16.channelTag(this.id, tagId), {
|
|
4152
|
+
auth: true,
|
|
4153
|
+
...auditReasonHeaders(reason)
|
|
4154
|
+
});
|
|
4155
|
+
this._patch(data);
|
|
4156
|
+
return this;
|
|
4157
|
+
}
|
|
4158
|
+
};
|
|
4159
|
+
var ForumChannel = class extends ThreadOnlyChannel {
|
|
4160
|
+
/** Default layout for posts. */
|
|
4161
|
+
defaultForumLayout;
|
|
4162
|
+
/** Set or clear the default post layout. */
|
|
4163
|
+
async setDefaultForumLayout(layout, reason) {
|
|
4164
|
+
return this.edit({ defaultForumLayout: layout, reason });
|
|
4165
|
+
}
|
|
4166
|
+
constructor(client, data) {
|
|
4167
|
+
super(client, data);
|
|
4168
|
+
this.defaultForumLayout = data.default_forum_layout ?? null;
|
|
4169
|
+
}
|
|
4170
|
+
/** @internal */
|
|
4171
|
+
_patch(data) {
|
|
4172
|
+
super._patch(data);
|
|
4173
|
+
if ("default_forum_layout" in data) this.defaultForumLayout = data.default_forum_layout ?? null;
|
|
4174
|
+
}
|
|
4175
|
+
};
|
|
4176
|
+
var MediaChannel = class extends ThreadOnlyChannel {
|
|
4177
|
+
};
|
|
4178
|
+
|
|
3425
4179
|
// src/Domain/Channel/Factory.ts
|
|
3426
|
-
import { ChannelType as
|
|
4180
|
+
import { ChannelType as ChannelType8 } from "@fluxerjs/types";
|
|
3427
4181
|
var GUILD_FACTORIES = {
|
|
3428
|
-
[
|
|
3429
|
-
[
|
|
3430
|
-
[
|
|
3431
|
-
[
|
|
3432
|
-
[
|
|
4182
|
+
[ChannelType8.GuildText]: (c, d) => new TextChannel(c, d),
|
|
4183
|
+
[ChannelType8.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
|
|
4184
|
+
[ChannelType8.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
4185
|
+
[ChannelType8.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
4186
|
+
[ChannelType8.GuildLink]: (c, d) => new LinkChannel(c, d),
|
|
4187
|
+
[ChannelType8.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
|
|
4188
|
+
[ChannelType8.PublicThread]: (c, d) => new ThreadChannel(c, d),
|
|
4189
|
+
[ChannelType8.PrivateThread]: (c, d) => new ThreadChannel(c, d),
|
|
4190
|
+
[ChannelType8.GuildForum]: (c, d) => new ForumChannel(c, d),
|
|
4191
|
+
[ChannelType8.GuildMedia]: (c, d) => new MediaChannel(c, d)
|
|
3433
4192
|
};
|
|
3434
4193
|
var DM_TYPES = /* @__PURE__ */ new Set([
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
4194
|
+
ChannelType8.DM,
|
|
4195
|
+
ChannelType8.GroupDM,
|
|
4196
|
+
ChannelType8.DMPersonalNotes
|
|
3438
4197
|
]);
|
|
3439
4198
|
function createDM(client, data) {
|
|
3440
4199
|
return new DMChannel(client, data);
|
|
3441
4200
|
}
|
|
3442
4201
|
function channelFrom(client, data) {
|
|
3443
|
-
const
|
|
3444
|
-
return
|
|
4202
|
+
const factory2 = GUILD_FACTORIES[data.type ?? 0];
|
|
4203
|
+
return factory2 ? factory2(client, data) : new GuildChannel(client, data);
|
|
3445
4204
|
}
|
|
3446
4205
|
function channelFromOrCreate(client, data) {
|
|
3447
4206
|
return DM_TYPES.has(data.type ?? 0) ? createDM(client, data) : channelFrom(client, data);
|
|
@@ -3451,9 +4210,13 @@ function channelFromOrCreate(client, data) {
|
|
|
3451
4210
|
Channel.from = channelFrom;
|
|
3452
4211
|
Channel.fromOrCreate = channelFromOrCreate;
|
|
3453
4212
|
Channel.createDM = createDM;
|
|
4213
|
+
bindThreadManager((channel) => new ThreadManager(channel));
|
|
4214
|
+
|
|
4215
|
+
// src/Domain/Guild/Cache.ts
|
|
4216
|
+
import { ChannelType as ChannelType9 } from "@fluxerjs/types";
|
|
3454
4217
|
|
|
3455
4218
|
// src/Domain/Guild/GuildEmoji.ts
|
|
3456
|
-
import { Routes as
|
|
4219
|
+
import { Routes as Routes17 } from "@fluxerjs/types";
|
|
3457
4220
|
import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
|
|
3458
4221
|
var GuildEmoji = class extends Base {
|
|
3459
4222
|
client;
|
|
@@ -3502,7 +4265,7 @@ var GuildEmoji = class extends Base {
|
|
|
3502
4265
|
}
|
|
3503
4266
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
3504
4267
|
async delete(reason) {
|
|
3505
|
-
await this.client.rest.delete(
|
|
4268
|
+
await this.client.rest.delete(Routes17.guildEmoji(this.guildId, this.id), {
|
|
3506
4269
|
auth: true,
|
|
3507
4270
|
...auditReasonHeaders(reason)
|
|
3508
4271
|
});
|
|
@@ -3515,7 +4278,7 @@ var GuildEmoji = class extends Base {
|
|
|
3515
4278
|
*/
|
|
3516
4279
|
async edit(options) {
|
|
3517
4280
|
const { reason, name } = options;
|
|
3518
|
-
const data = await this.client.rest.patch(
|
|
4281
|
+
const data = await this.client.rest.patch(Routes17.guildEmoji(this.guildId, this.id), {
|
|
3519
4282
|
body: { name },
|
|
3520
4283
|
auth: true,
|
|
3521
4284
|
...auditReasonHeaders(reason)
|
|
@@ -3526,7 +4289,7 @@ var GuildEmoji = class extends Base {
|
|
|
3526
4289
|
};
|
|
3527
4290
|
|
|
3528
4291
|
// src/Domain/Guild/GuildMember.ts
|
|
3529
|
-
import { Routes as
|
|
4292
|
+
import { Routes as Routes19 } from "@fluxerjs/types";
|
|
3530
4293
|
import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
|
|
3531
4294
|
|
|
3532
4295
|
// src/Helpers/Permissions.ts
|
|
@@ -3550,7 +4313,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
3550
4313
|
|
|
3551
4314
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
3552
4315
|
import { Collection as Collection7 } from "@fluxerjs/collection";
|
|
3553
|
-
import { Routes as
|
|
4316
|
+
import { Routes as Routes18 } from "@fluxerjs/types";
|
|
3554
4317
|
function roleId(roleOrId) {
|
|
3555
4318
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
3556
4319
|
}
|
|
@@ -3579,7 +4342,7 @@ var GuildMemberRoleManager = class {
|
|
|
3579
4342
|
const id = roleId(roleOrId);
|
|
3580
4343
|
if (this.ids.includes(id)) return;
|
|
3581
4344
|
await this.member.client.rest.put(
|
|
3582
|
-
|
|
4345
|
+
Routes18.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
3583
4346
|
);
|
|
3584
4347
|
this.ids.push(id);
|
|
3585
4348
|
}
|
|
@@ -3588,13 +4351,13 @@ var GuildMemberRoleManager = class {
|
|
|
3588
4351
|
const idx = this.ids.indexOf(id);
|
|
3589
4352
|
if (idx === -1) return;
|
|
3590
4353
|
await this.member.client.rest.delete(
|
|
3591
|
-
|
|
4354
|
+
Routes18.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
3592
4355
|
);
|
|
3593
4356
|
this.ids.splice(idx, 1);
|
|
3594
4357
|
}
|
|
3595
4358
|
async set(roleIds) {
|
|
3596
4359
|
const data = await this.member.client.rest.patch(
|
|
3597
|
-
|
|
4360
|
+
Routes18.guildMember(this.member.guild.id, this.member.id),
|
|
3598
4361
|
{ body: { roles: roleIds }, auth: true }
|
|
3599
4362
|
);
|
|
3600
4363
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -3748,7 +4511,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3748
4511
|
*/
|
|
3749
4512
|
async edit(options) {
|
|
3750
4513
|
const isMe = this.client.user?.id === this.id;
|
|
3751
|
-
const route = isMe ?
|
|
4514
|
+
const route = isMe ? Routes19.guildMemberMe(this.guild.id) : Routes19.guildMember(this.guild.id, this.id);
|
|
3752
4515
|
const data = await this.client.rest.patch(route, {
|
|
3753
4516
|
body: toMemberEditBody(options),
|
|
3754
4517
|
auth: true,
|
|
@@ -3861,7 +4624,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3861
4624
|
};
|
|
3862
4625
|
|
|
3863
4626
|
// src/Domain/Guild/GuildSticker.ts
|
|
3864
|
-
import { Routes as
|
|
4627
|
+
import { Routes as Routes20 } from "@fluxerjs/types";
|
|
3865
4628
|
import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
|
|
3866
4629
|
var GuildSticker = class extends Base {
|
|
3867
4630
|
client;
|
|
@@ -3912,7 +4675,7 @@ var GuildSticker = class extends Base {
|
|
|
3912
4675
|
}
|
|
3913
4676
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3914
4677
|
async delete(reason) {
|
|
3915
|
-
await this.client.rest.delete(
|
|
4678
|
+
await this.client.rest.delete(Routes20.guildSticker(this.guildId, this.id), {
|
|
3916
4679
|
auth: true,
|
|
3917
4680
|
...auditReasonHeaders(reason)
|
|
3918
4681
|
});
|
|
@@ -3925,7 +4688,7 @@ var GuildSticker = class extends Base {
|
|
|
3925
4688
|
*/
|
|
3926
4689
|
async edit(options) {
|
|
3927
4690
|
const { reason, ...body } = options;
|
|
3928
|
-
const data = await this.client.rest.patch(
|
|
4691
|
+
const data = await this.client.rest.patch(Routes20.guildSticker(this.guildId, this.id), {
|
|
3929
4692
|
body,
|
|
3930
4693
|
auth: true,
|
|
3931
4694
|
...auditReasonHeaders(reason)
|
|
@@ -3938,7 +4701,7 @@ var GuildSticker = class extends Base {
|
|
|
3938
4701
|
};
|
|
3939
4702
|
|
|
3940
4703
|
// src/Domain/Guild/Role.ts
|
|
3941
|
-
import { Routes as
|
|
4704
|
+
import { Routes as Routes21 } from "@fluxerjs/types";
|
|
3942
4705
|
import {
|
|
3943
4706
|
ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
|
|
3944
4707
|
PermissionFlags as PermissionFlags4,
|
|
@@ -4053,7 +4816,7 @@ var Role = class _Role extends Base {
|
|
|
4053
4816
|
*/
|
|
4054
4817
|
async edit(options) {
|
|
4055
4818
|
const body = toRoleEditBody(options);
|
|
4056
|
-
const data = await this.client.rest.patch(
|
|
4819
|
+
const data = await this.client.rest.patch(Routes21.guildRole(this.guildId, this.id), {
|
|
4057
4820
|
body: Object.keys(body).length ? body : void 0,
|
|
4058
4821
|
auth: true,
|
|
4059
4822
|
...auditReasonHeaders(options.reason)
|
|
@@ -4066,7 +4829,7 @@ var Role = class _Role extends Base {
|
|
|
4066
4829
|
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
4067
4830
|
*/
|
|
4068
4831
|
async delete(reason) {
|
|
4069
|
-
await this.client.rest.delete(
|
|
4832
|
+
await this.client.rest.delete(Routes21.guildRole(this.guildId, this.id), {
|
|
4070
4833
|
auth: true,
|
|
4071
4834
|
...auditReasonHeaders(reason)
|
|
4072
4835
|
});
|
|
@@ -4161,11 +4924,30 @@ function syncChannels(guild, channels) {
|
|
|
4161
4924
|
const keep = new Set(channels.map((c) => c.id));
|
|
4162
4925
|
for (const data of channels) cacheChannel(guild, data);
|
|
4163
4926
|
for (const [id, channel] of [...guild.channels.entries()]) {
|
|
4164
|
-
if (keep.has(id)) continue;
|
|
4927
|
+
if (keep.has(id) || channel.isThread()) continue;
|
|
4165
4928
|
Map.prototype.delete.call(guild.channels, id);
|
|
4166
4929
|
guild.client.cache.cascadeChannel(channel, "guild");
|
|
4167
4930
|
}
|
|
4168
4931
|
}
|
|
4932
|
+
function isThreadChannelType(type) {
|
|
4933
|
+
return type === ChannelType9.AnnouncementThread || type === ChannelType9.PublicThread || type === ChannelType9.PrivateThread;
|
|
4934
|
+
}
|
|
4935
|
+
function syncThreads(guild, threads, alsoKeep = /* @__PURE__ */ new Set()) {
|
|
4936
|
+
const keep = new Set(alsoKeep);
|
|
4937
|
+
for (const data of threads) {
|
|
4938
|
+
if (!isThreadChannelType(data.type)) continue;
|
|
4939
|
+
const withGuild = data.guild_id ? data : { ...data, guild_id: guild.id };
|
|
4940
|
+
cacheThread(guild.client, withGuild);
|
|
4941
|
+
keep.add(data.id);
|
|
4942
|
+
}
|
|
4943
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4944
|
+
for (const channel of [...guild.channels.values(), ...guild.client.channels.values()]) {
|
|
4945
|
+
if (seen.has(channel.id)) continue;
|
|
4946
|
+
seen.add(channel.id);
|
|
4947
|
+
if (!channel.isThread() || channel.guildId !== guild.id || keep.has(channel.id)) continue;
|
|
4948
|
+
guild.client.cache.cascadeChannel(channel);
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4169
4951
|
function mergeMembers(guild, members) {
|
|
4170
4952
|
for (const m of members) {
|
|
4171
4953
|
if (!m.user?.id) continue;
|
|
@@ -4229,7 +5011,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4229
5011
|
const cached = this.get(channelId);
|
|
4230
5012
|
if (cached && !options?.force) return cached;
|
|
4231
5013
|
try {
|
|
4232
|
-
const data = await this.client.rest.get(
|
|
5014
|
+
const data = await this.client.rest.get(Routes22.channel(channelId));
|
|
4233
5015
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
4234
5016
|
if (guildId) {
|
|
4235
5017
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -4274,7 +5056,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4274
5056
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
4275
5057
|
});
|
|
4276
5058
|
const data = await this.client.rest.post(
|
|
4277
|
-
|
|
5059
|
+
Routes22.channelMessages(channelId),
|
|
4278
5060
|
postPayload
|
|
4279
5061
|
);
|
|
4280
5062
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -4285,11 +5067,11 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4285
5067
|
// src/ClientCore/Client.ts
|
|
4286
5068
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
4287
5069
|
import { REST } from "@fluxerjs/rest";
|
|
4288
|
-
import { GatewayOpcodes as GatewayOpcodes2, Routes as
|
|
5070
|
+
import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes37 } from "@fluxerjs/types";
|
|
4289
5071
|
import { createLogger } from "@fluxerjs/util";
|
|
4290
5072
|
|
|
4291
5073
|
// src/Domain/User.ts
|
|
4292
|
-
import { Routes as
|
|
5074
|
+
import { Routes as Routes23 } from "@fluxerjs/types";
|
|
4293
5075
|
import { SnowflakeUtil as SnowflakeUtil8 } from "@fluxerjs/util";
|
|
4294
5076
|
var User = class extends Base {
|
|
4295
5077
|
/** Parent client instance. */
|
|
@@ -4388,7 +5170,7 @@ var User = class extends Base {
|
|
|
4388
5170
|
* @returns DM channel instance (cached if already open)
|
|
4389
5171
|
*/
|
|
4390
5172
|
async createDM() {
|
|
4391
|
-
const data = await this.client.rest.post(
|
|
5173
|
+
const data = await this.client.rest.post(Routes23.userMeChannels(), {
|
|
4392
5174
|
body: { recipient_id: this.id },
|
|
4393
5175
|
auth: true
|
|
4394
5176
|
});
|
|
@@ -4466,7 +5248,7 @@ function resolveCacheLimits(input) {
|
|
|
4466
5248
|
|
|
4467
5249
|
// src/ClientCore/ClientEmoji.ts
|
|
4468
5250
|
import { Collection as Collection8 } from "@fluxerjs/collection";
|
|
4469
|
-
import { Routes as
|
|
5251
|
+
import { Routes as Routes24 } from "@fluxerjs/types";
|
|
4470
5252
|
import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
|
|
4471
5253
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
4472
5254
|
if (typeof emoji === "object" && emoji.id) {
|
|
@@ -4485,7 +5267,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4485
5267
|
const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
|
|
4486
5268
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
4487
5269
|
if (guildId) {
|
|
4488
|
-
const emojis = await client.rest.get(
|
|
5270
|
+
const emojis = await client.rest.get(Routes24.guildEmojis(guildId));
|
|
4489
5271
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
4490
5272
|
if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
|
|
4491
5273
|
throw new FluxerError(
|
|
@@ -4502,26 +5284,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4502
5284
|
return parsed.name;
|
|
4503
5285
|
}
|
|
4504
5286
|
async function fetchInstance(client) {
|
|
4505
|
-
const raw = await client.rest.get(
|
|
5287
|
+
const raw = await client.rest.get(Routes24.instanceDiscovery(), {
|
|
4506
5288
|
auth: false,
|
|
4507
5289
|
unversioned: true
|
|
4508
5290
|
});
|
|
4509
5291
|
return parseInstanceDiscovery(raw);
|
|
4510
5292
|
}
|
|
4511
5293
|
function fetchGatewayInfo(client) {
|
|
4512
|
-
return client.rest.get(
|
|
5294
|
+
return client.rest.get(Routes24.gatewayBot());
|
|
4513
5295
|
}
|
|
4514
5296
|
function fetchEmojiMetadata(client, emojiId) {
|
|
4515
|
-
return client.rest.get(
|
|
5297
|
+
return client.rest.get(Routes24.emojiMetadata(emojiId), { auth: true });
|
|
4516
5298
|
}
|
|
4517
5299
|
function fetchStickerMetadata(client, stickerId) {
|
|
4518
|
-
return client.rest.get(
|
|
5300
|
+
return client.rest.get(Routes24.stickerMetadata(stickerId), { auth: true });
|
|
4519
5301
|
}
|
|
4520
5302
|
function fetchApplication(client) {
|
|
4521
|
-
return client.rest.get(
|
|
5303
|
+
return client.rest.get(Routes24.applicationsMe(), { auth: true });
|
|
4522
5304
|
}
|
|
4523
5305
|
async function fetchOAuthApplications(client) {
|
|
4524
|
-
const data = await client.rest.get(
|
|
5306
|
+
const data = await client.rest.get(Routes24.oauth2ApplicationsMe(), { auth: true });
|
|
4525
5307
|
if (Array.isArray(data)) return data;
|
|
4526
5308
|
if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
|
|
4527
5309
|
return data.applications;
|
|
@@ -4540,14 +5322,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
4540
5322
|
}
|
|
4541
5323
|
function preloadMessages(client, channelIds) {
|
|
4542
5324
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
4543
|
-
return client.rest.post(
|
|
5325
|
+
return client.rest.post(Routes24.preloadMessages(), {
|
|
4544
5326
|
body: { channels: channelIds },
|
|
4545
5327
|
auth: true
|
|
4546
5328
|
});
|
|
4547
5329
|
}
|
|
4548
5330
|
function preloadMessagesAlt(client, channelIds) {
|
|
4549
5331
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
4550
|
-
return client.rest.post(
|
|
5332
|
+
return client.rest.post(Routes24.preloadMessagesAlt(), {
|
|
4551
5333
|
body: { channels: channelIds },
|
|
4552
5334
|
auth: true
|
|
4553
5335
|
});
|
|
@@ -4555,7 +5337,7 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
4555
5337
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
4556
5338
|
validateBulkMessageFetchRequests(requests);
|
|
4557
5339
|
const wire = toBulkFetchWire(requests);
|
|
4558
|
-
const data = await client.rest.post(
|
|
5340
|
+
const data = await client.rest.post(Routes24.channelsMessagesBulk(), {
|
|
4559
5341
|
body: { requests: wire },
|
|
4560
5342
|
auth: true
|
|
4561
5343
|
});
|
|
@@ -4572,7 +5354,7 @@ async function bulkFetchMessages(client, requests, options = {}) {
|
|
|
4572
5354
|
};
|
|
4573
5355
|
}
|
|
4574
5356
|
async function searchMessages(client, options = {}) {
|
|
4575
|
-
const data = await client.rest.post(
|
|
5357
|
+
const data = await client.rest.post(Routes24.searchMessages(), {
|
|
4576
5358
|
body: toMessageSearchBody(options),
|
|
4577
5359
|
auth: true
|
|
4578
5360
|
});
|
|
@@ -4602,7 +5384,7 @@ import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
|
|
|
4602
5384
|
|
|
4603
5385
|
// src/ClientCore/GuildMemberManager.ts
|
|
4604
5386
|
import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
|
|
4605
|
-
import { Routes as
|
|
5387
|
+
import { Routes as Routes25 } from "@fluxerjs/types";
|
|
4606
5388
|
var GuildMemberManager = class extends LimitedCollection2 {
|
|
4607
5389
|
constructor(guild) {
|
|
4608
5390
|
super({ maxSize: guild.client.cache.limits.members });
|
|
@@ -4659,7 +5441,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
4659
5441
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
4660
5442
|
if (options?.after) params.set("after", options.after);
|
|
4661
5443
|
const qs2 = params.toString();
|
|
4662
|
-
const url =
|
|
5444
|
+
const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
4663
5445
|
const data = await this.guild.client.rest.get(url, { auth: true });
|
|
4664
5446
|
const members = [];
|
|
4665
5447
|
for (const m of data) {
|
|
@@ -4682,7 +5464,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
4682
5464
|
*/
|
|
4683
5465
|
async search(options = {}) {
|
|
4684
5466
|
const data = await this.guild.client.rest.post(
|
|
4685
|
-
|
|
5467
|
+
Routes25.guildMembersSearch(this.guild.id),
|
|
4686
5468
|
{ body: toMemberSearchBody(options), auth: true }
|
|
4687
5469
|
);
|
|
4688
5470
|
const offset = options.offset ?? 0;
|
|
@@ -4708,7 +5490,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
4708
5490
|
};
|
|
4709
5491
|
|
|
4710
5492
|
// src/Domain/Guild/Admin.ts
|
|
4711
|
-
import { Routes as
|
|
5493
|
+
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
4712
5494
|
function toAuditLogEntryPayload(entry, guildId) {
|
|
4713
5495
|
return {
|
|
4714
5496
|
id: entry.id,
|
|
@@ -4729,7 +5511,7 @@ function toVanityPayload(data) {
|
|
|
4729
5511
|
return { code: data.code ?? null, uses: data.uses };
|
|
4730
5512
|
}
|
|
4731
5513
|
async function fetchAuditLogs(guild, options) {
|
|
4732
|
-
const url =
|
|
5514
|
+
const url = Routes26.guildAuditLogs(guild.id) + qs({
|
|
4733
5515
|
limit: options?.limit,
|
|
4734
5516
|
before: options?.before,
|
|
4735
5517
|
after: options?.after,
|
|
@@ -4753,7 +5535,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
4753
5535
|
};
|
|
4754
5536
|
}
|
|
4755
5537
|
async function editGuild(guild, options) {
|
|
4756
|
-
const data = await guild.client.rest.patch(
|
|
5538
|
+
const data = await guild.client.rest.patch(Routes26.guild(guild.id), {
|
|
4757
5539
|
body: toGuildEditBody(options),
|
|
4758
5540
|
auth: true
|
|
4759
5541
|
});
|
|
@@ -4761,13 +5543,13 @@ async function editGuild(guild, options) {
|
|
|
4761
5543
|
return guild;
|
|
4762
5544
|
}
|
|
4763
5545
|
async function fetchVanityURL(guild) {
|
|
4764
|
-
const data = await guild.client.rest.get(
|
|
5546
|
+
const data = await guild.client.rest.get(Routes26.guildVanityUrl(guild.id), {
|
|
4765
5547
|
auth: true
|
|
4766
5548
|
});
|
|
4767
5549
|
return toVanityPayload(data);
|
|
4768
5550
|
}
|
|
4769
5551
|
async function editVanityURL(guild, code) {
|
|
4770
|
-
const data = await guild.client.rest.patch(
|
|
5552
|
+
const data = await guild.client.rest.patch(Routes26.guildVanityUrl(guild.id), {
|
|
4771
5553
|
body: { code },
|
|
4772
5554
|
auth: true
|
|
4773
5555
|
});
|
|
@@ -4775,14 +5557,14 @@ async function editVanityURL(guild, code) {
|
|
|
4775
5557
|
return toVanityPayload(data);
|
|
4776
5558
|
}
|
|
4777
5559
|
async function fetchDiscoveryStatus(guild) {
|
|
4778
|
-
const data = await guild.client.rest.get(
|
|
5560
|
+
const data = await guild.client.rest.get(Routes26.guildDiscovery(guild.id), {
|
|
4779
5561
|
auth: true
|
|
4780
5562
|
});
|
|
4781
5563
|
return toDiscoveryStatusPayload(data);
|
|
4782
5564
|
}
|
|
4783
5565
|
async function applyForDiscovery(guild, options) {
|
|
4784
5566
|
const data = await guild.client.rest.post(
|
|
4785
|
-
|
|
5567
|
+
Routes26.guildDiscovery(guild.id),
|
|
4786
5568
|
{
|
|
4787
5569
|
body: toDiscoveryBody(options),
|
|
4788
5570
|
auth: true
|
|
@@ -4792,7 +5574,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
4792
5574
|
}
|
|
4793
5575
|
async function editDiscoveryApplication(guild, options) {
|
|
4794
5576
|
const data = await guild.client.rest.patch(
|
|
4795
|
-
|
|
5577
|
+
Routes26.guildDiscovery(guild.id),
|
|
4796
5578
|
{
|
|
4797
5579
|
body: toDiscoveryBody(options),
|
|
4798
5580
|
auth: true
|
|
@@ -4801,34 +5583,34 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
4801
5583
|
return toDiscoveryApplicationPayload(data);
|
|
4802
5584
|
}
|
|
4803
5585
|
async function withdrawDiscoveryApplication(guild) {
|
|
4804
|
-
await guild.client.rest.delete(
|
|
5586
|
+
await guild.client.rest.delete(Routes26.guildDiscovery(guild.id), { auth: true });
|
|
4805
5587
|
}
|
|
4806
5588
|
async function deleteGuild(guild, options) {
|
|
4807
5589
|
const body = options ? toSudoBody(options) : {};
|
|
4808
|
-
await guild.client.rest.post(
|
|
5590
|
+
await guild.client.rest.post(Routes26.guildDelete(guild.id), {
|
|
4809
5591
|
body,
|
|
4810
5592
|
auth: true
|
|
4811
5593
|
});
|
|
4812
5594
|
guild.client.guilds.delete(guild.id);
|
|
4813
5595
|
}
|
|
4814
5596
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
4815
|
-
await guild.client.rest.post(
|
|
5597
|
+
await guild.client.rest.post(Routes26.guildTransferOwnership(guild.id), {
|
|
4816
5598
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
4817
5599
|
auth: true
|
|
4818
5600
|
});
|
|
4819
5601
|
}
|
|
4820
5602
|
|
|
4821
5603
|
// src/Domain/Guild/Channels.ts
|
|
4822
|
-
import { Routes as
|
|
5604
|
+
import { Routes as Routes27 } from "@fluxerjs/types";
|
|
4823
5605
|
async function createChannel(guild, options) {
|
|
4824
|
-
const created = await guild.client.rest.post(
|
|
5606
|
+
const created = await guild.client.rest.post(Routes27.guildChannels(guild.id), {
|
|
4825
5607
|
body: toChannelCreateBody(options),
|
|
4826
5608
|
auth: true
|
|
4827
5609
|
});
|
|
4828
5610
|
return cacheChannel(guild, created);
|
|
4829
5611
|
}
|
|
4830
5612
|
async function fetchChannels(guild) {
|
|
4831
|
-
const data = await guild.client.rest.get(
|
|
5613
|
+
const data = await guild.client.rest.get(Routes27.guildChannels(guild.id));
|
|
4832
5614
|
const channels = [];
|
|
4833
5615
|
for (const ch of data) {
|
|
4834
5616
|
const channel = cacheChannel(guild, ch);
|
|
@@ -4837,17 +5619,17 @@ async function fetchChannels(guild) {
|
|
|
4837
5619
|
return channels;
|
|
4838
5620
|
}
|
|
4839
5621
|
async function setChannelPositions(guild, updates) {
|
|
4840
|
-
await guild.client.rest.patch(
|
|
5622
|
+
await guild.client.rest.patch(Routes27.guildChannels(guild.id), {
|
|
4841
5623
|
body: toChannelPositionBody(updates),
|
|
4842
5624
|
auth: true
|
|
4843
5625
|
});
|
|
4844
5626
|
}
|
|
4845
5627
|
async function fetchWebhooks(guild) {
|
|
4846
|
-
const data = await guild.client.rest.get(
|
|
5628
|
+
const data = await guild.client.rest.get(Routes27.guildWebhooks(guild.id));
|
|
4847
5629
|
return data.map((w) => new Webhook(guild.client, w));
|
|
4848
5630
|
}
|
|
4849
5631
|
async function fetchInvites(guild) {
|
|
4850
|
-
const data = await guild.client.rest.get(
|
|
5632
|
+
const data = await guild.client.rest.get(Routes27.guildInvites(guild.id));
|
|
4851
5633
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
4852
5634
|
}
|
|
4853
5635
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -4867,14 +5649,14 @@ function resolveGuildOnlineCount(data) {
|
|
|
4867
5649
|
}
|
|
4868
5650
|
|
|
4869
5651
|
// src/Domain/Guild/Emojis.ts
|
|
4870
|
-
import { Routes as
|
|
5652
|
+
import { Routes as Routes28 } from "@fluxerjs/types";
|
|
4871
5653
|
async function fetchEmojis(guild) {
|
|
4872
|
-
const data = await guild.client.rest.get(
|
|
5654
|
+
const data = await guild.client.rest.get(Routes28.guildEmojis(guild.id));
|
|
4873
5655
|
return data.map((e) => cacheEmoji(guild, e));
|
|
4874
5656
|
}
|
|
4875
5657
|
async function fetchEmoji(guild, emojiId) {
|
|
4876
5658
|
try {
|
|
4877
|
-
const data = await guild.client.rest.get(
|
|
5659
|
+
const data = await guild.client.rest.get(Routes28.guildEmoji(guild.id, emojiId));
|
|
4878
5660
|
return cacheEmoji(guild, data);
|
|
4879
5661
|
} catch (err) {
|
|
4880
5662
|
rethrowMapped(err, {
|
|
@@ -4885,7 +5667,7 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
4885
5667
|
}
|
|
4886
5668
|
async function createEmoji(guild, options) {
|
|
4887
5669
|
const { reason, ...body } = options;
|
|
4888
|
-
const data = await guild.client.rest.post(
|
|
5670
|
+
const data = await guild.client.rest.post(Routes28.guildEmojis(guild.id), {
|
|
4889
5671
|
body,
|
|
4890
5672
|
auth: true,
|
|
4891
5673
|
...auditReasonHeaders(reason)
|
|
@@ -4893,7 +5675,7 @@ async function createEmoji(guild, options) {
|
|
|
4893
5675
|
return cacheEmoji(guild, data);
|
|
4894
5676
|
}
|
|
4895
5677
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
4896
|
-
const data = await guild.client.rest.post(
|
|
5678
|
+
const data = await guild.client.rest.post(Routes28.guildEmojisClone(guild.id), {
|
|
4897
5679
|
body: { source_emoji_id: sourceEmojiId },
|
|
4898
5680
|
auth: true
|
|
4899
5681
|
});
|
|
@@ -4901,7 +5683,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
4901
5683
|
}
|
|
4902
5684
|
async function createEmojisBulk(guild, emojis) {
|
|
4903
5685
|
const data = await guild.client.rest.post(
|
|
4904
|
-
|
|
5686
|
+
Routes28.guildEmojisBulk(guild.id),
|
|
4905
5687
|
{ body: { emojis }, auth: true }
|
|
4906
5688
|
);
|
|
4907
5689
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
@@ -4921,11 +5703,11 @@ var GuildRoleManager = class extends LimitedCollection3 {
|
|
|
4921
5703
|
};
|
|
4922
5704
|
|
|
4923
5705
|
// src/Domain/Guild/MemberHttp.ts
|
|
4924
|
-
import { Routes as
|
|
5706
|
+
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
4925
5707
|
async function fetchMember(guild, userId) {
|
|
4926
5708
|
try {
|
|
4927
5709
|
const data = await guild.client.rest.get(
|
|
4928
|
-
|
|
5710
|
+
Routes29.guildMember(guild.id, userId)
|
|
4929
5711
|
);
|
|
4930
5712
|
return cacheMember(guild, data);
|
|
4931
5713
|
} catch (err) {
|
|
@@ -4940,17 +5722,17 @@ async function fetchMember(guild, userId) {
|
|
|
4940
5722
|
}
|
|
4941
5723
|
async function fetchMe(guild) {
|
|
4942
5724
|
const data = await guild.client.rest.get(
|
|
4943
|
-
|
|
5725
|
+
Routes29.guildMemberMe(guild.id),
|
|
4944
5726
|
{ auth: true }
|
|
4945
5727
|
);
|
|
4946
5728
|
return cacheMember(guild, data);
|
|
4947
5729
|
}
|
|
4948
5730
|
|
|
4949
5731
|
// src/Domain/Guild/Moderation.ts
|
|
4950
|
-
import { Routes as
|
|
5732
|
+
import { Routes as Routes31 } from "@fluxerjs/types";
|
|
4951
5733
|
|
|
4952
5734
|
// src/Domain/Guild/GuildBan.ts
|
|
4953
|
-
import { Routes as
|
|
5735
|
+
import { Routes as Routes30 } from "@fluxerjs/types";
|
|
4954
5736
|
function parseOptionalDate2(value) {
|
|
4955
5737
|
if (value == null || value === "") return null;
|
|
4956
5738
|
const date = new Date(value);
|
|
@@ -4977,7 +5759,7 @@ var GuildBan = class extends Base {
|
|
|
4977
5759
|
* Requires Ban Members permission.
|
|
4978
5760
|
*/
|
|
4979
5761
|
async unban(reason) {
|
|
4980
|
-
await this.client.rest.delete(
|
|
5762
|
+
await this.client.rest.delete(Routes30.guildBan(this.guildId, this.user.id), {
|
|
4981
5763
|
auth: true,
|
|
4982
5764
|
...auditReasonHeaders(reason)
|
|
4983
5765
|
});
|
|
@@ -4987,35 +5769,35 @@ var GuildBan = class extends Base {
|
|
|
4987
5769
|
// src/Domain/Guild/Moderation.ts
|
|
4988
5770
|
async function ban(guild, userId, options) {
|
|
4989
5771
|
const body = options ? toGuildBanBody(options) : {};
|
|
4990
|
-
await guild.client.rest.put(
|
|
5772
|
+
await guild.client.rest.put(Routes31.guildBan(guild.id, userId), {
|
|
4991
5773
|
body: Object.keys(body).length ? body : void 0,
|
|
4992
5774
|
auth: true,
|
|
4993
5775
|
...auditReasonHeaders(options?.reason)
|
|
4994
5776
|
});
|
|
4995
5777
|
}
|
|
4996
5778
|
async function fetchBans(guild) {
|
|
4997
|
-
const data = await guild.client.rest.get(
|
|
5779
|
+
const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
|
|
4998
5780
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
4999
5781
|
}
|
|
5000
5782
|
async function unban(guild, userId, reason) {
|
|
5001
|
-
await guild.client.rest.delete(
|
|
5783
|
+
await guild.client.rest.delete(Routes31.guildBan(guild.id, userId), {
|
|
5002
5784
|
auth: true,
|
|
5003
5785
|
...auditReasonHeaders(reason)
|
|
5004
5786
|
});
|
|
5005
5787
|
}
|
|
5006
5788
|
async function kick(guild, userId, reason) {
|
|
5007
|
-
await guild.client.rest.delete(
|
|
5789
|
+
await guild.client.rest.delete(Routes31.guildMember(guild.id, userId), {
|
|
5008
5790
|
auth: true,
|
|
5009
5791
|
...auditReasonHeaders(reason)
|
|
5010
5792
|
});
|
|
5011
5793
|
}
|
|
5012
5794
|
|
|
5013
5795
|
// src/Domain/Guild/Roles.ts
|
|
5014
|
-
import { Routes as
|
|
5796
|
+
import { Routes as Routes32 } from "@fluxerjs/types";
|
|
5015
5797
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
5016
5798
|
async function createRole(guild, options = {}) {
|
|
5017
5799
|
const body = toRoleCreateBody(options);
|
|
5018
|
-
const data = await guild.client.rest.post(
|
|
5800
|
+
const data = await guild.client.rest.post(Routes32.guildRoles(guild.id), {
|
|
5019
5801
|
body: Object.keys(body).length ? body : void 0,
|
|
5020
5802
|
auth: true,
|
|
5021
5803
|
...auditReasonHeaders(options.reason)
|
|
@@ -5023,12 +5805,12 @@ async function createRole(guild, options = {}) {
|
|
|
5023
5805
|
return cacheRole(guild, data);
|
|
5024
5806
|
}
|
|
5025
5807
|
async function fetchRoles(guild) {
|
|
5026
|
-
const data = await guild.client.rest.get(
|
|
5808
|
+
const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
|
|
5027
5809
|
return data.map((r) => cacheRole(guild, r));
|
|
5028
5810
|
}
|
|
5029
5811
|
async function fetchRole(guild, roleId2) {
|
|
5030
5812
|
try {
|
|
5031
|
-
const data = await guild.client.rest.get(
|
|
5813
|
+
const data = await guild.client.rest.get(Routes32.guildRole(guild.id, roleId2));
|
|
5032
5814
|
return cacheRole(guild, data);
|
|
5033
5815
|
} catch (err) {
|
|
5034
5816
|
rethrowMapped(err, {
|
|
@@ -5045,7 +5827,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
5045
5827
|
const needle = trimmed.toLowerCase();
|
|
5046
5828
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
5047
5829
|
if (cached) return cached.id;
|
|
5048
|
-
const roles = await guild.client.rest.get(
|
|
5830
|
+
const roles = await guild.client.rest.get(Routes32.guildRoles(guild.id));
|
|
5049
5831
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
5050
5832
|
if (!role) return null;
|
|
5051
5833
|
cacheRole(guild, role);
|
|
@@ -5054,7 +5836,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
5054
5836
|
async function setRolePositions(guild, updates) {
|
|
5055
5837
|
return replaceRoles(
|
|
5056
5838
|
guild,
|
|
5057
|
-
await guild.client.rest.patch(
|
|
5839
|
+
await guild.client.rest.patch(Routes32.guildRoles(guild.id), {
|
|
5058
5840
|
body: updates,
|
|
5059
5841
|
auth: true
|
|
5060
5842
|
})
|
|
@@ -5063,7 +5845,7 @@ async function setRolePositions(guild, updates) {
|
|
|
5063
5845
|
async function setRoleHoistPositions(guild, updates) {
|
|
5064
5846
|
return replaceRoles(
|
|
5065
5847
|
guild,
|
|
5066
|
-
await guild.client.rest.patch(
|
|
5848
|
+
await guild.client.rest.patch(Routes32.guildRolesHoistPositions(guild.id), {
|
|
5067
5849
|
body: updates.map((u) => ({
|
|
5068
5850
|
id: u.id,
|
|
5069
5851
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -5075,17 +5857,17 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
5075
5857
|
async function resetRoleHoistPositions(guild) {
|
|
5076
5858
|
return replaceRoles(
|
|
5077
5859
|
guild,
|
|
5078
|
-
await guild.client.rest.delete(
|
|
5860
|
+
await guild.client.rest.delete(Routes32.guildRolesHoistPositions(guild.id), {
|
|
5079
5861
|
auth: true
|
|
5080
5862
|
})
|
|
5081
5863
|
);
|
|
5082
5864
|
}
|
|
5083
5865
|
|
|
5084
5866
|
// src/Domain/Guild/Stickers.ts
|
|
5085
|
-
import { Routes as
|
|
5867
|
+
import { Routes as Routes33 } from "@fluxerjs/types";
|
|
5086
5868
|
async function createSticker(guild, options) {
|
|
5087
5869
|
const { reason, ...body } = options;
|
|
5088
|
-
const data = await guild.client.rest.post(
|
|
5870
|
+
const data = await guild.client.rest.post(Routes33.guildStickers(guild.id), {
|
|
5089
5871
|
body,
|
|
5090
5872
|
auth: true,
|
|
5091
5873
|
...auditReasonHeaders(reason)
|
|
@@ -5093,7 +5875,7 @@ async function createSticker(guild, options) {
|
|
|
5093
5875
|
return cacheSticker(guild, data);
|
|
5094
5876
|
}
|
|
5095
5877
|
async function cloneSticker(guild, sourceStickerId) {
|
|
5096
|
-
const data = await guild.client.rest.post(
|
|
5878
|
+
const data = await guild.client.rest.post(Routes33.guildStickersClone(guild.id), {
|
|
5097
5879
|
body: { source_sticker_id: sourceStickerId },
|
|
5098
5880
|
auth: true
|
|
5099
5881
|
});
|
|
@@ -5101,17 +5883,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
5101
5883
|
}
|
|
5102
5884
|
async function createStickersBulk(guild, stickers) {
|
|
5103
5885
|
const data = await guild.client.rest.post(
|
|
5104
|
-
|
|
5886
|
+
Routes33.guildStickersBulk(guild.id),
|
|
5105
5887
|
{ body: { stickers }, auth: true }
|
|
5106
5888
|
);
|
|
5107
5889
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
5108
5890
|
}
|
|
5109
5891
|
async function fetchStickers(guild) {
|
|
5110
|
-
const data = await guild.client.rest.get(
|
|
5892
|
+
const data = await guild.client.rest.get(Routes33.guildStickers(guild.id));
|
|
5111
5893
|
return data.map((s) => cacheSticker(guild, s));
|
|
5112
5894
|
}
|
|
5113
5895
|
async function fetchSticker(guild, stickerId) {
|
|
5114
|
-
const data = await guild.client.rest.get(
|
|
5896
|
+
const data = await guild.client.rest.get(Routes33.guildSticker(guild.id, stickerId));
|
|
5115
5897
|
return cacheSticker(guild, data);
|
|
5116
5898
|
}
|
|
5117
5899
|
|
|
@@ -5343,7 +6125,7 @@ var Guild = class extends Base {
|
|
|
5343
6125
|
});
|
|
5344
6126
|
}
|
|
5345
6127
|
/**
|
|
5346
|
-
* Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
|
|
6128
|
+
* Create a channel. `type`: 0=text, 2=voice, 4=category, 5=announcement, 15=forum, 16=media, 998=link (set `url`).
|
|
5347
6129
|
* Requires Manage Channels.
|
|
5348
6130
|
*/
|
|
5349
6131
|
createChannel(options) {
|
|
@@ -5353,6 +6135,10 @@ var Guild = class extends Base {
|
|
|
5353
6135
|
fetchChannels() {
|
|
5354
6136
|
return fetchChannels(this);
|
|
5355
6137
|
}
|
|
6138
|
+
/** Fetch active threads in this guild. */
|
|
6139
|
+
fetchActiveThreads() {
|
|
6140
|
+
return fetchActiveThreads(this.client, this.id);
|
|
6141
|
+
}
|
|
5356
6142
|
/** Update channel positions (reordering). */
|
|
5357
6143
|
setChannelPositions(updates) {
|
|
5358
6144
|
return setChannelPositions(this, updates);
|
|
@@ -5583,6 +6369,13 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
5583
6369
|
client.guilds.set(guild.id, guild);
|
|
5584
6370
|
if (resources.roles !== void 0) syncRoles(guild, resources.roles);
|
|
5585
6371
|
if (resources.channels !== void 0) syncChannels(guild, resources.channels);
|
|
6372
|
+
if (resources.threads !== void 0) {
|
|
6373
|
+
syncThreads(
|
|
6374
|
+
guild,
|
|
6375
|
+
resources.threads,
|
|
6376
|
+
new Set((resources.channels ?? []).map((channel) => channel.id))
|
|
6377
|
+
);
|
|
6378
|
+
}
|
|
5586
6379
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
5587
6380
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
5588
6381
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
@@ -5597,7 +6390,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
5597
6390
|
channels: g.channels,
|
|
5598
6391
|
members: g.members,
|
|
5599
6392
|
emojis: g.emojis,
|
|
5600
|
-
stickers: g.stickers
|
|
6393
|
+
stickers: g.stickers,
|
|
6394
|
+
// A channel list without `threads` means this session has no viewable threads.
|
|
6395
|
+
threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
|
|
5601
6396
|
});
|
|
5602
6397
|
if (g.voice_states?.length) {
|
|
5603
6398
|
client.emit(Events.VoiceStatesSync, {
|
|
@@ -5609,7 +6404,7 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
5609
6404
|
}
|
|
5610
6405
|
|
|
5611
6406
|
// src/ClientCore/ClientUser.ts
|
|
5612
|
-
import { GatewayOpcodes, Routes as
|
|
6407
|
+
import { GatewayOpcodes, Routes as Routes34 } from "@fluxerjs/types";
|
|
5613
6408
|
var ClientUser = class extends User {
|
|
5614
6409
|
/** Broadcast presence (gateway opcode 3) on all shards. */
|
|
5615
6410
|
setPresence(presence) {
|
|
@@ -5619,13 +6414,13 @@ var ClientUser = class extends User {
|
|
|
5619
6414
|
}
|
|
5620
6415
|
/** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
|
|
5621
6416
|
async fetch() {
|
|
5622
|
-
const data = await this.client.rest.get(
|
|
6417
|
+
const data = await this.client.rest.get(Routes34.currentUser(), { auth: true });
|
|
5623
6418
|
this._patch(data);
|
|
5624
6419
|
return this;
|
|
5625
6420
|
}
|
|
5626
6421
|
/** GET /users/@me/guilds — returns camelCase partial guilds. */
|
|
5627
6422
|
async fetchGuilds(options) {
|
|
5628
|
-
const path =
|
|
6423
|
+
const path = Routes34.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
|
|
5629
6424
|
const data = await this.client.rest.get(path, { auth: true });
|
|
5630
6425
|
return data.map((g) => ({
|
|
5631
6426
|
id: g.id,
|
|
@@ -5649,7 +6444,7 @@ var ClientUser = class extends User {
|
|
|
5649
6444
|
*/
|
|
5650
6445
|
async leaveGuild(guildId, options) {
|
|
5651
6446
|
const body = options ? toSudoBody(options) : void 0;
|
|
5652
|
-
await this.client.rest.delete(
|
|
6447
|
+
await this.client.rest.delete(Routes34.leaveGuild(guildId), {
|
|
5653
6448
|
body: body && Object.keys(body).length ? body : void 0,
|
|
5654
6449
|
auth: true
|
|
5655
6450
|
});
|
|
@@ -5657,7 +6452,7 @@ var ClientUser = class extends User {
|
|
|
5657
6452
|
/** Delete every message authored by the caller across a guild (sudo). */
|
|
5658
6453
|
async bulkDeleteMyMessagesInGuild(guildId, options) {
|
|
5659
6454
|
const body = options ? toSudoBody(options) : void 0;
|
|
5660
|
-
await this.client.rest.post(
|
|
6455
|
+
await this.client.rest.post(Routes34.guildBulkDeleteMine(guildId), {
|
|
5661
6456
|
body: body && Object.keys(body).length ? body : void 0,
|
|
5662
6457
|
auth: true
|
|
5663
6458
|
});
|
|
@@ -5692,6 +6487,7 @@ var channelHandlers = {
|
|
|
5692
6487
|
if (!ch) return;
|
|
5693
6488
|
indexChannel(client, ch);
|
|
5694
6489
|
client.emit(Events.ChannelCreate, ch);
|
|
6490
|
+
if (ch.isThread()) client.emit(Events.ThreadCreate, ch);
|
|
5695
6491
|
},
|
|
5696
6492
|
CHANNEL_UPDATE(client, d) {
|
|
5697
6493
|
const data = d;
|
|
@@ -5704,12 +6500,14 @@ var channelHandlers = {
|
|
|
5704
6500
|
existing._patch(data);
|
|
5705
6501
|
indexChannel(client, existing);
|
|
5706
6502
|
client.emit(Events.ChannelUpdate, oldCh, existing);
|
|
6503
|
+
if (existing.isThread()) client.emit(Events.ThreadUpdate, oldCh, existing);
|
|
5707
6504
|
return;
|
|
5708
6505
|
}
|
|
5709
6506
|
const newCh = Channel.from(client, data);
|
|
5710
6507
|
if (!newCh) return;
|
|
5711
6508
|
indexChannel(client, newCh);
|
|
5712
6509
|
client.emit(Events.ChannelUpdate, existing ?? newCh, newCh);
|
|
6510
|
+
if (newCh.isThread()) client.emit(Events.ThreadUpdate, existing ?? newCh, newCh);
|
|
5713
6511
|
},
|
|
5714
6512
|
CHANNEL_UPDATE_BULK(client, d) {
|
|
5715
6513
|
const data = d;
|
|
@@ -5731,7 +6529,11 @@ var channelHandlers = {
|
|
|
5731
6529
|
}
|
|
5732
6530
|
if (!channel) return;
|
|
5733
6531
|
client.channels.delete(id);
|
|
6532
|
+
if (channel.isGuild() && channel.guildId) {
|
|
6533
|
+
client.guilds.get(channel.guildId)?.channels.delete(id);
|
|
6534
|
+
}
|
|
5734
6535
|
client.emit(Events.ChannelDelete, channel);
|
|
6536
|
+
if (channel.isThread()) client.emit(Events.ThreadDelete, channel);
|
|
5735
6537
|
},
|
|
5736
6538
|
CHANNEL_PINS_UPDATE(client, d) {
|
|
5737
6539
|
const data = d;
|
|
@@ -5921,6 +6723,10 @@ var guildHandlers = {
|
|
|
5921
6723
|
}
|
|
5922
6724
|
client._onGuildReceived(guild.id);
|
|
5923
6725
|
},
|
|
6726
|
+
/** Same snapshot as Guild Create, including `threads`. Cache only: this is not a join. */
|
|
6727
|
+
GUILD_SYNC(client, d) {
|
|
6728
|
+
applyGuildSnapshotFromGateway(client, d);
|
|
6729
|
+
},
|
|
5924
6730
|
GUILD_UPDATE(client, d) {
|
|
5925
6731
|
const guildData = normalizeGuildUpdatePayload(d);
|
|
5926
6732
|
if (!guildData) return;
|
|
@@ -5970,7 +6776,7 @@ var guildHandlers = {
|
|
|
5970
6776
|
|
|
5971
6777
|
// src/ClientCore/EventHandlers/Invites.ts
|
|
5972
6778
|
import {
|
|
5973
|
-
ChannelType as
|
|
6779
|
+
ChannelType as ChannelType10,
|
|
5974
6780
|
InviteType as InviteType2
|
|
5975
6781
|
} from "@fluxerjs/types";
|
|
5976
6782
|
function normalizeInviteCreate(client, payload) {
|
|
@@ -5995,11 +6801,11 @@ function normalizeInviteCreate(client, payload) {
|
|
|
5995
6801
|
const guildId = str(guildObj?.id) ?? str(raw.guild_id) ?? "0";
|
|
5996
6802
|
const channelId = str(channelObj?.id) ?? str(raw.channel_id) ?? "0";
|
|
5997
6803
|
const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
|
|
5998
|
-
const
|
|
6804
|
+
const cachedChannel2 = channelId !== "0" ? client.channels.get(channelId) : null;
|
|
5999
6805
|
const channel = {
|
|
6000
6806
|
id: channelId,
|
|
6001
|
-
type: num(channelObj?.type) ??
|
|
6002
|
-
name: str(channelObj?.name) ??
|
|
6807
|
+
type: num(channelObj?.type) ?? cachedChannel2?.type ?? ChannelType10.GuildText,
|
|
6808
|
+
name: str(channelObj?.name) ?? cachedChannel2?.name ?? null,
|
|
6003
6809
|
icon: channelObj?.icon ?? null
|
|
6004
6810
|
};
|
|
6005
6811
|
if (type === InviteType2.GroupDM) return { ...shared, type, channel };
|
|
@@ -6403,6 +7209,107 @@ var passthroughHandlers = {
|
|
|
6403
7209
|
WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
|
|
6404
7210
|
};
|
|
6405
7211
|
|
|
7212
|
+
// src/ClientCore/EventHandlers/Threads.ts
|
|
7213
|
+
function cachedChannel(client, id) {
|
|
7214
|
+
const direct = client.channels.get(id);
|
|
7215
|
+
if (direct) return direct;
|
|
7216
|
+
for (const guild of client.guilds.values()) {
|
|
7217
|
+
const nested = guild.channels.get(id);
|
|
7218
|
+
if (nested) return nested;
|
|
7219
|
+
}
|
|
7220
|
+
return null;
|
|
7221
|
+
}
|
|
7222
|
+
var threadHandlers = {
|
|
7223
|
+
THREAD_CREATE(client, d) {
|
|
7224
|
+
channelHandlers.CHANNEL_CREATE(client, d);
|
|
7225
|
+
},
|
|
7226
|
+
THREAD_UPDATE(client, d) {
|
|
7227
|
+
channelHandlers.CHANNEL_UPDATE(client, d);
|
|
7228
|
+
},
|
|
7229
|
+
THREAD_DELETE(client, d) {
|
|
7230
|
+
const data = d;
|
|
7231
|
+
const existing = data.id ? cachedChannel(client, data.id) : null;
|
|
7232
|
+
if (existing?.isThread()) {
|
|
7233
|
+
channelHandlers.CHANNEL_DELETE(client, data);
|
|
7234
|
+
return;
|
|
7235
|
+
}
|
|
7236
|
+
if (!data.id || !isThreadType(data.type)) return;
|
|
7237
|
+
const thread = Channel.from(client, {
|
|
7238
|
+
id: data.id,
|
|
7239
|
+
type: data.type,
|
|
7240
|
+
guild_id: data.guild_id,
|
|
7241
|
+
parent_id: data.parent_id
|
|
7242
|
+
});
|
|
7243
|
+
if (!thread.isThread()) return;
|
|
7244
|
+
client.emit(Events.ChannelDelete, thread);
|
|
7245
|
+
client.emit(Events.ThreadDelete, thread);
|
|
7246
|
+
},
|
|
7247
|
+
THREAD_LIST_SYNC(client, d) {
|
|
7248
|
+
const data = d;
|
|
7249
|
+
const { threads } = fetchedThreadsFrom(client, {
|
|
7250
|
+
threads: data.threads ?? [],
|
|
7251
|
+
members: data.members ?? []
|
|
7252
|
+
});
|
|
7253
|
+
const payload = {
|
|
7254
|
+
guildId: data.guild_id,
|
|
7255
|
+
channelIds: data.channel_ids ?? [],
|
|
7256
|
+
threads
|
|
7257
|
+
};
|
|
7258
|
+
client.emit(Events.ThreadListSync, payload);
|
|
7259
|
+
},
|
|
7260
|
+
THREAD_MEMBER_UPDATE(client, d) {
|
|
7261
|
+
const data = d;
|
|
7262
|
+
const member = new ThreadMember(data);
|
|
7263
|
+
const thread = member.id ? client.channels.get(member.id) : void 0;
|
|
7264
|
+
if (thread?.isThread() && member.userId && member.userId === client.user?.id) {
|
|
7265
|
+
thread.member = member;
|
|
7266
|
+
}
|
|
7267
|
+
client.emit(Events.ThreadMemberUpdate, member);
|
|
7268
|
+
},
|
|
7269
|
+
THREAD_MEMBERS_UPDATE(client, d) {
|
|
7270
|
+
const data = d;
|
|
7271
|
+
const thread = client.channels.get(data.id);
|
|
7272
|
+
if (thread?.isThread()) thread.memberCount = data.member_count;
|
|
7273
|
+
const payload = {
|
|
7274
|
+
id: data.id,
|
|
7275
|
+
guildId: data.guild_id,
|
|
7276
|
+
memberCount: data.member_count,
|
|
7277
|
+
addedMembers: (data.added_members ?? []).map((member) => new ThreadMember(member)),
|
|
7278
|
+
removedMemberIds: data.removed_member_ids ?? []
|
|
7279
|
+
};
|
|
7280
|
+
client.emit(Events.ThreadMembersUpdate, payload);
|
|
7281
|
+
},
|
|
7282
|
+
THREAD_MEMBER_LIST_UPDATE(client, d) {
|
|
7283
|
+
const data = d;
|
|
7284
|
+
const guild = data.guild_id ? client.guilds.get(data.guild_id) : void 0;
|
|
7285
|
+
const payload = {
|
|
7286
|
+
guildId: data.guild_id,
|
|
7287
|
+
threadId: data.thread_id,
|
|
7288
|
+
members: (data.members ?? []).map((entry) => ({
|
|
7289
|
+
userId: entry.user_id,
|
|
7290
|
+
joinTimestamp: entry.join_timestamp,
|
|
7291
|
+
flags: entry.flags,
|
|
7292
|
+
member: guild && entry.member?.user?.id ? cacheMember(guild, entry.member) : null,
|
|
7293
|
+
presence: entry.presence ? { status: entry.presence.status ?? null } : null
|
|
7294
|
+
}))
|
|
7295
|
+
};
|
|
7296
|
+
client.emit(Events.ThreadMemberListUpdate, payload);
|
|
7297
|
+
},
|
|
7298
|
+
FORUM_UNREADS(client, d) {
|
|
7299
|
+
const data = d;
|
|
7300
|
+
const payload = {
|
|
7301
|
+
guildId: data.guild_id,
|
|
7302
|
+
channelId: data.channel_id,
|
|
7303
|
+
threads: (data.threads ?? []).map((entry) => ({
|
|
7304
|
+
threadId: entry.thread_id,
|
|
7305
|
+
count: entry.count ?? null,
|
|
7306
|
+
missing: entry.missing === true
|
|
7307
|
+
}))
|
|
7308
|
+
};
|
|
7309
|
+
client.emit(Events.ForumUnreads, payload);
|
|
7310
|
+
}
|
|
7311
|
+
};
|
|
7312
|
+
|
|
6406
7313
|
// src/ClientCore/EventHandlers/index.ts
|
|
6407
7314
|
var eventHandlers = buildRegistry(
|
|
6408
7315
|
messageHandlers,
|
|
@@ -6411,7 +7318,8 @@ var eventHandlers = buildRegistry(
|
|
|
6411
7318
|
memberHandlers,
|
|
6412
7319
|
inviteHandlers,
|
|
6413
7320
|
guildResourceHandlers,
|
|
6414
|
-
passthroughHandlers
|
|
7321
|
+
passthroughHandlers,
|
|
7322
|
+
threadHandlers
|
|
6415
7323
|
);
|
|
6416
7324
|
|
|
6417
7325
|
// src/ClientCore/GatewayDispatch.ts
|
|
@@ -6637,7 +7545,7 @@ async function connectClientGateway(client, token, signal) {
|
|
|
6637
7545
|
|
|
6638
7546
|
// src/ClientCore/GuildManager.ts
|
|
6639
7547
|
import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
|
|
6640
|
-
import { Routes as
|
|
7548
|
+
import { Routes as Routes35 } from "@fluxerjs/types";
|
|
6641
7549
|
var GuildManager = class extends LimitedCollection5 {
|
|
6642
7550
|
constructor(client) {
|
|
6643
7551
|
super({
|
|
@@ -6676,7 +7584,7 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
6676
7584
|
const cached = this.get(guildId);
|
|
6677
7585
|
if (cached && !options?.force) return cached;
|
|
6678
7586
|
try {
|
|
6679
|
-
const data = await this.client.rest.get(
|
|
7587
|
+
const data = await this.client.rest.get(Routes35.guild(guildId));
|
|
6680
7588
|
if (cached) {
|
|
6681
7589
|
cached._patch(data);
|
|
6682
7590
|
return cached;
|
|
@@ -6764,7 +7672,7 @@ var MessageCache = class {
|
|
|
6764
7672
|
// src/ClientCore/UserManager.ts
|
|
6765
7673
|
import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
|
|
6766
7674
|
import {
|
|
6767
|
-
Routes as
|
|
7675
|
+
Routes as Routes36
|
|
6768
7676
|
} from "@fluxerjs/types";
|
|
6769
7677
|
var soft = (p) => p.catch(() => null);
|
|
6770
7678
|
var UserManager = class extends LimitedCollection6 {
|
|
@@ -6789,7 +7697,7 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
6789
7697
|
async fetch(userId, options) {
|
|
6790
7698
|
const cached = this.get(userId);
|
|
6791
7699
|
if (cached && !options?.force) return cached;
|
|
6792
|
-
const data = await this.client.rest.get(
|
|
7700
|
+
const data = await this.client.rest.get(Routes36.user(userId));
|
|
6793
7701
|
return this.client.getOrCreateUser(data);
|
|
6794
7702
|
}
|
|
6795
7703
|
/** Return a cached user, otherwise {@link fetch}. */
|
|
@@ -6807,10 +7715,10 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
6807
7715
|
async fetchWithProfile(userId, options) {
|
|
6808
7716
|
const guildId = options?.guildId ?? void 0;
|
|
6809
7717
|
const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
|
|
6810
|
-
this.client.rest.get(
|
|
6811
|
-
soft(this.client.rest.get(
|
|
6812
|
-
guildId ? soft(this.client.rest.get(
|
|
6813
|
-
guildId ? soft(this.client.rest.get(
|
|
7718
|
+
this.client.rest.get(Routes36.user(userId)),
|
|
7719
|
+
soft(this.client.rest.get(Routes36.userProfile(userId))),
|
|
7720
|
+
guildId ? soft(this.client.rest.get(Routes36.userProfile(userId, guildId))) : null,
|
|
7721
|
+
guildId ? soft(this.client.rest.get(Routes36.guildMember(guildId, userId))) : null
|
|
6814
7722
|
]);
|
|
6815
7723
|
const user = this.client.getOrCreateUser(userData);
|
|
6816
7724
|
let member = null;
|
|
@@ -7189,6 +8097,72 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7189
8097
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
7190
8098
|
this._sendToAllShards({ op: GatewayOpcodes2.RequestChannelMemberCounts, d: data });
|
|
7191
8099
|
}
|
|
8100
|
+
/**
|
|
8101
|
+
* Request unread counts for posts in one forum or media channel (opcode 28).
|
|
8102
|
+
* Listen for `forumUnreads`. The gateway keeps at most 40 posts and ignores a channel the session cannot view.
|
|
8103
|
+
*/
|
|
8104
|
+
requestForumUnreads(options) {
|
|
8105
|
+
if (!options.guildId || !options.channelId) {
|
|
8106
|
+
throw new FluxerError("requestForumUnreads requires guildId and channelId", {
|
|
8107
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8108
|
+
});
|
|
8109
|
+
}
|
|
8110
|
+
const threads = [];
|
|
8111
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8112
|
+
for (const thread of options.threads) {
|
|
8113
|
+
if (!thread.threadId || seen.has(thread.threadId)) continue;
|
|
8114
|
+
seen.add(thread.threadId);
|
|
8115
|
+
const entry = { thread_id: thread.threadId };
|
|
8116
|
+
if (thread.ackMessageId !== void 0) entry.ack_message_id = thread.ackMessageId;
|
|
8117
|
+
threads.push(entry);
|
|
8118
|
+
}
|
|
8119
|
+
if (!threads.length) {
|
|
8120
|
+
throw new FluxerError("requestForumUnreads requires at least one thread", {
|
|
8121
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8122
|
+
});
|
|
8123
|
+
}
|
|
8124
|
+
if (threads.length > 40) {
|
|
8125
|
+
throw new FluxerError("requestForumUnreads accepts at most 40 threads", {
|
|
8126
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8127
|
+
});
|
|
8128
|
+
}
|
|
8129
|
+
const data = {
|
|
8130
|
+
guild_id: options.guildId,
|
|
8131
|
+
channel_id: options.channelId,
|
|
8132
|
+
threads
|
|
8133
|
+
};
|
|
8134
|
+
this._sendToAllShards({ op: GatewayOpcodes2.RequestForumUnreads, d: data });
|
|
8135
|
+
}
|
|
8136
|
+
/**
|
|
8137
|
+
* Subscribe to thread traffic in a guild (opcode 14).
|
|
8138
|
+
* `threads: true` receives every thread event in the guild.
|
|
8139
|
+
* `threadIds` (at most 10) subscribes to those member lists. Each one arrives as `threadMemberListUpdate`.
|
|
8140
|
+
*/
|
|
8141
|
+
subscribeThreads(options) {
|
|
8142
|
+
if (!options.guildId) {
|
|
8143
|
+
throw new FluxerError("subscribeThreads requires guildId", {
|
|
8144
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8145
|
+
});
|
|
8146
|
+
}
|
|
8147
|
+
if (options.threads === void 0 && options.threadIds === void 0) {
|
|
8148
|
+
throw new FluxerError("subscribeThreads requires threads or threadIds", {
|
|
8149
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8150
|
+
});
|
|
8151
|
+
}
|
|
8152
|
+
const subscription = {};
|
|
8153
|
+
if (options.threads !== void 0) subscription.threads = options.threads;
|
|
8154
|
+
if (options.threadIds !== void 0) {
|
|
8155
|
+
const threadIds = [...new Set(options.threadIds.filter(Boolean))];
|
|
8156
|
+
if (threadIds.length > 10) {
|
|
8157
|
+
throw new FluxerError("subscribeThreads accepts at most 10 threadIds", {
|
|
8158
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8159
|
+
});
|
|
8160
|
+
}
|
|
8161
|
+
subscription.thread_member_lists = threadIds;
|
|
8162
|
+
}
|
|
8163
|
+
const data = { subscriptions: { [options.guildId]: subscription } };
|
|
8164
|
+
this._sendToAllShards({ op: GatewayOpcodes2.LazyRequest, d: data });
|
|
8165
|
+
}
|
|
7192
8166
|
/**
|
|
7193
8167
|
* Broadcast a gateway payload to all shards.
|
|
7194
8168
|
* @param payload - Gateway send payload
|
|
@@ -7292,7 +8266,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7292
8266
|
* @see {@link Routes}
|
|
7293
8267
|
*/
|
|
7294
8268
|
static get Routes() {
|
|
7295
|
-
return
|
|
8269
|
+
return Routes37;
|
|
7296
8270
|
}
|
|
7297
8271
|
};
|
|
7298
8272
|
|
|
@@ -7645,7 +8619,7 @@ export {
|
|
|
7645
8619
|
CategoryChannel,
|
|
7646
8620
|
Channel,
|
|
7647
8621
|
ChannelManager,
|
|
7648
|
-
|
|
8622
|
+
ChannelType11 as ChannelType,
|
|
7649
8623
|
Client,
|
|
7650
8624
|
ClientCluster,
|
|
7651
8625
|
ClientClusterEvents,
|
|
@@ -7658,6 +8632,10 @@ export {
|
|
|
7658
8632
|
ErrorCodes,
|
|
7659
8633
|
Events,
|
|
7660
8634
|
FluxerError,
|
|
8635
|
+
ForumChannel,
|
|
8636
|
+
ForumLayout,
|
|
8637
|
+
ForumSortOrder,
|
|
8638
|
+
ForumTagSetting,
|
|
7661
8639
|
GatewayOpcodes3 as GatewayOpcodes,
|
|
7662
8640
|
Guild,
|
|
7663
8641
|
GuildBan,
|
|
@@ -7676,6 +8654,7 @@ export {
|
|
|
7676
8654
|
Invite,
|
|
7677
8655
|
InviteType3 as InviteType,
|
|
7678
8656
|
LinkChannel,
|
|
8657
|
+
MediaChannel,
|
|
7679
8658
|
Message,
|
|
7680
8659
|
MessageAttachmentFlags2 as MessageAttachmentFlags,
|
|
7681
8660
|
MessageCollector,
|
|
@@ -7700,11 +8679,17 @@ export {
|
|
|
7700
8679
|
ReactionCollector,
|
|
7701
8680
|
RelationshipType,
|
|
7702
8681
|
Role,
|
|
7703
|
-
|
|
8682
|
+
Routes38 as Routes,
|
|
7704
8683
|
STATIC_CDN_URL,
|
|
7705
8684
|
SplashCardAlignment,
|
|
7706
8685
|
SystemChannelFlags,
|
|
7707
8686
|
TextChannel,
|
|
8687
|
+
ThreadAutoArchiveDuration,
|
|
8688
|
+
ThreadChannel,
|
|
8689
|
+
ThreadManager,
|
|
8690
|
+
ThreadMember,
|
|
8691
|
+
ThreadMemberFlags,
|
|
8692
|
+
ThreadMemberManager,
|
|
7708
8693
|
User,
|
|
7709
8694
|
UserFlagsBitField,
|
|
7710
8695
|
UserFlagsBits,
|
|
@@ -7721,6 +8706,7 @@ export {
|
|
|
7721
8706
|
cdnMemberBannerURL,
|
|
7722
8707
|
cdnStickerURL,
|
|
7723
8708
|
createLogger2 as createLogger,
|
|
8709
|
+
fetchActiveThreads,
|
|
7724
8710
|
instanceDiscoveryUrl,
|
|
7725
8711
|
inviteUrl,
|
|
7726
8712
|
normalizeApiOrigin,
|