@fluxerjs/core 2.2.0 → 3.1.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/README.md +21 -9
- package/dist/Expressions-Bdgo72qI.d.mts +34 -0
- package/dist/Expressions-Bdgo72qI.d.ts +34 -0
- package/dist/{SubpathMessage-D70lAT7N.d.mts → SubpathMessage-Cj_U0V19.d.mts} +1446 -1117
- package/dist/{SubpathMessage-D70lAT7N.d.ts → SubpathMessage-DaimQAd9.d.ts} +1446 -1117
- package/dist/Sudo-fOKSPbxN.d.mts +461 -0
- package/dist/Sudo-fOKSPbxN.d.ts +461 -0
- package/dist/client.d.mts +4 -3
- package/dist/client.d.ts +4 -3
- package/dist/client.js +2219 -1051
- package/dist/client.mjs +2103 -938
- package/dist/cluster.d.mts +5 -4
- package/dist/cluster.d.ts +5 -4
- package/dist/cluster.js +2134 -966
- package/dist/cluster.mjs +2097 -932
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2199 -1053
- package/dist/index.mjs +2035 -877
- package/dist/internal.d.mts +12 -0
- package/dist/internal.d.ts +12 -0
- package/dist/internal.js +449 -0
- package/dist/internal.mjs +398 -0
- package/dist/message.d.mts +4 -3
- package/dist/message.d.ts +4 -3
- package/dist/message.js +528 -95
- package/dist/message.mjs +528 -96
- package/package.json +13 -9
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AttachmentBuilder as AttachmentBuilder2,
|
|
4
|
+
AttachmentMeta,
|
|
5
|
+
EmbedBuilder as EmbedBuilder4,
|
|
6
|
+
MessagePayload as MessagePayload2
|
|
7
|
+
} from "@fluxerjs/builders";
|
|
3
8
|
import {
|
|
4
9
|
AuditLogActionType,
|
|
5
10
|
ChannelType as ChannelType5,
|
|
@@ -9,7 +14,7 @@ import {
|
|
|
9
14
|
GuildNSFWLevel as GuildNSFWLevel2,
|
|
10
15
|
GuildOperations,
|
|
11
16
|
InviteType as InviteType3,
|
|
12
|
-
MessageAttachmentFlags,
|
|
17
|
+
MessageAttachmentFlags as MessageAttachmentFlags2,
|
|
13
18
|
MessageFlags,
|
|
14
19
|
MessageReferenceType as MessageReferenceType2,
|
|
15
20
|
MessageType as MessageType2,
|
|
@@ -22,14 +27,14 @@ import {
|
|
|
22
27
|
} from "@fluxerjs/types";
|
|
23
28
|
import {
|
|
24
29
|
createLogger as createLogger2,
|
|
25
|
-
MessageFlagsBitField,
|
|
30
|
+
MessageFlagsBitField as MessageFlagsBitField2,
|
|
26
31
|
MessageFlagsBits,
|
|
27
|
-
PermissionFlags as
|
|
28
|
-
PermissionsBitField as
|
|
32
|
+
PermissionFlags as PermissionFlags5,
|
|
33
|
+
PermissionsBitField as PermissionsBitField4,
|
|
29
34
|
parsePrefixCommand,
|
|
30
35
|
parseUserMention,
|
|
31
36
|
resolveKlipyToImageUrl,
|
|
32
|
-
resolvePermissionsToBitfield as
|
|
37
|
+
resolvePermissionsToBitfield as resolvePermissionsToBitfield4,
|
|
33
38
|
serializeError,
|
|
34
39
|
UserFlagsBitField,
|
|
35
40
|
UserFlagsBits
|
|
@@ -74,6 +79,9 @@ var CacheController = class {
|
|
|
74
79
|
stickers
|
|
75
80
|
};
|
|
76
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Sweep cached messages. Filter receives a hydrated {@link Message} (`createdAt`).
|
|
84
|
+
*/
|
|
77
85
|
sweepMessages(filter, channelId) {
|
|
78
86
|
return this.client.sweepMessages(filter, channelId);
|
|
79
87
|
}
|
|
@@ -142,7 +150,7 @@ var CacheController = class {
|
|
|
142
150
|
* @internal
|
|
143
151
|
*/
|
|
144
152
|
cascadeChannel(channel, from = "both") {
|
|
145
|
-
const guildId =
|
|
153
|
+
const guildId = typeof channel.isGuild === "function" && channel.isGuild() ? channel.guildId : void 0;
|
|
146
154
|
const dropFromGuild = () => {
|
|
147
155
|
if (!guildId) return;
|
|
148
156
|
const guildChannels = this.client.guilds.get(guildId)?.channels;
|
|
@@ -173,23 +181,24 @@ var CacheController = class {
|
|
|
173
181
|
|
|
174
182
|
// src/ClientCore/ChannelManager.ts
|
|
175
183
|
import { LimitedCollection } from "@fluxerjs/collection";
|
|
176
|
-
import { Routes as
|
|
184
|
+
import { Routes as Routes19 } from "@fluxerjs/types";
|
|
177
185
|
|
|
178
186
|
// src/Domain/Channel/Base.ts
|
|
179
187
|
import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
|
|
180
|
-
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
188
|
+
import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
|
|
181
189
|
|
|
182
190
|
// src/ClientCore/MessageManager.ts
|
|
183
|
-
import { Collection as
|
|
191
|
+
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
184
192
|
import { Routes as Routes5 } from "@fluxerjs/types";
|
|
185
193
|
|
|
186
194
|
// src/Domain/Message/Message.ts
|
|
187
195
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
188
|
-
import { Collection as
|
|
196
|
+
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
189
197
|
import {
|
|
190
198
|
MessageType,
|
|
191
199
|
Routes as Routes4
|
|
192
200
|
} from "@fluxerjs/types";
|
|
201
|
+
import { MessageFlagsBitField } from "@fluxerjs/util";
|
|
193
202
|
|
|
194
203
|
// src/ClientCore/SdkOptions/Attachments.ts
|
|
195
204
|
function toMessageAttachmentEditWire(attachments) {
|
|
@@ -256,21 +265,66 @@ function toAttachmentUploadPlanResponse(data) {
|
|
|
256
265
|
}
|
|
257
266
|
|
|
258
267
|
// src/ClientCore/SdkOptions/Channels.ts
|
|
268
|
+
import { resolvePermissionsToBitfield } from "@fluxerjs/util";
|
|
269
|
+
function toOverwriteWire(overwrite) {
|
|
270
|
+
return {
|
|
271
|
+
id: overwrite.id,
|
|
272
|
+
type: overwrite.type,
|
|
273
|
+
allow: overwrite.allow !== void 0 ? resolvePermissionsToBitfield(overwrite.allow) : "0",
|
|
274
|
+
deny: overwrite.deny !== void 0 ? resolvePermissionsToBitfield(overwrite.deny) : "0"
|
|
275
|
+
};
|
|
276
|
+
}
|
|
259
277
|
function toChannelEditBody(options) {
|
|
260
278
|
const body = {};
|
|
261
279
|
if (options.name !== void 0) body.name = options.name;
|
|
262
280
|
if (options.topic !== void 0) body.topic = options.topic;
|
|
281
|
+
if (options.url !== void 0) body.url = options.url;
|
|
263
282
|
if (options.parentId !== void 0) body.parent_id = options.parentId;
|
|
264
283
|
if (options.bitrate !== void 0) body.bitrate = options.bitrate;
|
|
265
284
|
if (options.userLimit !== void 0) body.user_limit = options.userLimit;
|
|
285
|
+
if (options.voiceConnectionLimit !== void 0) {
|
|
286
|
+
body.voice_connection_limit = options.voiceConnectionLimit;
|
|
287
|
+
}
|
|
266
288
|
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
289
|
+
if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
|
|
290
|
+
if (options.contentWarningLevel !== void 0) {
|
|
291
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
292
|
+
}
|
|
293
|
+
if (options.contentWarningText !== void 0) {
|
|
294
|
+
body.content_warning_text = options.contentWarningText;
|
|
295
|
+
}
|
|
267
296
|
if (options.rateLimitPerUser !== void 0) {
|
|
268
297
|
body.rate_limit_per_user = options.rateLimitPerUser;
|
|
269
298
|
}
|
|
270
299
|
if (options.rtcRegion !== void 0) body.rtc_region = options.rtcRegion;
|
|
300
|
+
if (options.icon !== void 0) body.icon = options.icon;
|
|
301
|
+
if (options.permissionOverwrites !== void 0) {
|
|
302
|
+
body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
|
|
303
|
+
}
|
|
304
|
+
return body;
|
|
305
|
+
}
|
|
306
|
+
function toChannelCreateBody(options) {
|
|
307
|
+
const body = { name: options.name, type: options.type };
|
|
308
|
+
if (options.topic !== void 0) body.topic = options.topic;
|
|
309
|
+
if (options.url !== void 0) body.url = options.url;
|
|
310
|
+
if (options.parentId !== void 0) body.parent_id = options.parentId;
|
|
311
|
+
if (options.bitrate !== void 0) body.bitrate = options.bitrate;
|
|
312
|
+
if (options.userLimit !== void 0) body.user_limit = options.userLimit;
|
|
313
|
+
if (options.voiceConnectionLimit !== void 0) {
|
|
314
|
+
body.voice_connection_limit = options.voiceConnectionLimit;
|
|
315
|
+
}
|
|
271
316
|
if (options.permissionOverwrites !== void 0) {
|
|
272
|
-
body.permission_overwrites = options.permissionOverwrites;
|
|
317
|
+
body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
|
|
318
|
+
}
|
|
319
|
+
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
320
|
+
if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
|
|
321
|
+
if (options.contentWarningLevel !== void 0) {
|
|
322
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
273
323
|
}
|
|
324
|
+
if (options.contentWarningText !== void 0) {
|
|
325
|
+
body.content_warning_text = options.contentWarningText;
|
|
326
|
+
}
|
|
327
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
274
328
|
return body;
|
|
275
329
|
}
|
|
276
330
|
function toChannelInviteBody(options) {
|
|
@@ -281,6 +335,13 @@ function toChannelInviteBody(options) {
|
|
|
281
335
|
if (options.temporary !== void 0) body.temporary = options.temporary;
|
|
282
336
|
return body;
|
|
283
337
|
}
|
|
338
|
+
function toGroupDmEditBody(options) {
|
|
339
|
+
const body = { type: 3 };
|
|
340
|
+
if (options.name !== void 0) body.name = options.name;
|
|
341
|
+
if (options.icon !== void 0) body.icon = options.icon;
|
|
342
|
+
if (options.nicks !== void 0) body.nicks = options.nicks;
|
|
343
|
+
return body;
|
|
344
|
+
}
|
|
284
345
|
|
|
285
346
|
// src/ClientCore/SdkOptions/Discovery.ts
|
|
286
347
|
function toDiscoveryBody(options) {
|
|
@@ -316,32 +377,8 @@ function toDiscoveryStatusPayload(data) {
|
|
|
316
377
|
};
|
|
317
378
|
}
|
|
318
379
|
|
|
319
|
-
// src/ClientCore/SdkOptions/Expressions.ts
|
|
320
|
-
function toEmojiCreateBody(options) {
|
|
321
|
-
return { name: options.name, image: options.image };
|
|
322
|
-
}
|
|
323
|
-
function toEmojiEditBody(options) {
|
|
324
|
-
return { name: options.name };
|
|
325
|
-
}
|
|
326
|
-
function toStickerCreateBody(options) {
|
|
327
|
-
const body = {
|
|
328
|
-
name: options.name,
|
|
329
|
-
image: options.file
|
|
330
|
-
};
|
|
331
|
-
if (options.description !== void 0) body.description = options.description;
|
|
332
|
-
if (options.tags !== void 0) body.tags = options.tags;
|
|
333
|
-
return body;
|
|
334
|
-
}
|
|
335
|
-
function toStickerEditBody(options) {
|
|
336
|
-
const body = {};
|
|
337
|
-
if (options.name !== void 0) body.name = options.name;
|
|
338
|
-
if (options.description !== void 0) body.description = options.description;
|
|
339
|
-
if (options.tags !== void 0) body.tags = options.tags;
|
|
340
|
-
return body;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
380
|
// src/ClientCore/SdkOptions/Guild.ts
|
|
344
|
-
import { resolvePermissionsToBitfield } from "@fluxerjs/util";
|
|
381
|
+
import { resolvePermissionsToBitfield as resolvePermissionsToBitfield2 } from "@fluxerjs/util";
|
|
345
382
|
function toGuildEditBody(options) {
|
|
346
383
|
const body = {};
|
|
347
384
|
if (options.name !== void 0) body.name = options.name;
|
|
@@ -369,6 +406,16 @@ function toGuildEditBody(options) {
|
|
|
369
406
|
body.splash_card_alignment = options.splashCardAlignment;
|
|
370
407
|
}
|
|
371
408
|
if (options.nsfwLevel !== void 0) body.nsfw_level = options.nsfwLevel;
|
|
409
|
+
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
410
|
+
if (options.contentWarningLevel !== void 0) {
|
|
411
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
412
|
+
}
|
|
413
|
+
if (options.contentWarningText !== void 0) {
|
|
414
|
+
body.content_warning_text = options.contentWarningText;
|
|
415
|
+
}
|
|
416
|
+
if (options.messageHistoryCutoff !== void 0) {
|
|
417
|
+
body.message_history_cutoff = options.messageHistoryCutoff;
|
|
418
|
+
}
|
|
372
419
|
if (options.features !== void 0) body.features = options.features;
|
|
373
420
|
return body;
|
|
374
421
|
}
|
|
@@ -378,6 +425,9 @@ function toGuildBanBody(options) {
|
|
|
378
425
|
if (options.deleteMessageDays !== void 0) {
|
|
379
426
|
body.delete_message_days = options.deleteMessageDays;
|
|
380
427
|
}
|
|
428
|
+
if (options.deleteMessageSeconds !== void 0) {
|
|
429
|
+
body.delete_message_seconds = options.deleteMessageSeconds;
|
|
430
|
+
}
|
|
381
431
|
if (options.banDurationSeconds !== void 0) {
|
|
382
432
|
body.ban_duration_seconds = options.banDurationSeconds;
|
|
383
433
|
}
|
|
@@ -392,18 +442,26 @@ function toChannelPositionBody(updates) {
|
|
|
392
442
|
return row;
|
|
393
443
|
});
|
|
394
444
|
}
|
|
395
|
-
function
|
|
445
|
+
function toRolePermissionsBody(options) {
|
|
396
446
|
const body = {};
|
|
447
|
+
if (options.permissions !== void 0) {
|
|
448
|
+
body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield2(options.permissions);
|
|
449
|
+
}
|
|
450
|
+
return body;
|
|
451
|
+
}
|
|
452
|
+
function toRoleCreateBody(options) {
|
|
453
|
+
const body = { ...toRolePermissionsBody(options) };
|
|
454
|
+
if (options.name !== void 0) body.name = options.name;
|
|
455
|
+
if (options.color !== void 0) body.color = options.color;
|
|
456
|
+
return body;
|
|
457
|
+
}
|
|
458
|
+
function toRoleEditBody(options) {
|
|
459
|
+
const body = { ...toRolePermissionsBody(options) };
|
|
397
460
|
if (options.name !== void 0) body.name = options.name;
|
|
398
461
|
if (options.color !== void 0) body.color = options.color;
|
|
399
462
|
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
400
463
|
if (options.mentionable !== void 0) body.mentionable = options.mentionable;
|
|
401
|
-
if (options.unicodeEmoji !== void 0) body.unicode_emoji = options.unicodeEmoji;
|
|
402
|
-
if (options.position !== void 0) body.position = options.position;
|
|
403
464
|
if (options.hoistPosition !== void 0) body.hoist_position = options.hoistPosition;
|
|
404
|
-
if (options.permissions !== void 0) {
|
|
405
|
-
body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield(options.permissions);
|
|
406
|
-
}
|
|
407
465
|
return body;
|
|
408
466
|
}
|
|
409
467
|
|
|
@@ -421,6 +479,8 @@ function toMemberSearchBody(options) {
|
|
|
421
479
|
if (options.userCreatedAtLte !== void 0) body.user_created_at_lte = options.userCreatedAtLte;
|
|
422
480
|
if (options.sortBy !== void 0) body.sort_by = options.sortBy;
|
|
423
481
|
if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
|
|
482
|
+
if (options.joinSourceType !== void 0) body.join_source_type = options.joinSourceType;
|
|
483
|
+
if (options.sourceInviteCode !== void 0) body.source_invite_code = options.sourceInviteCode;
|
|
424
484
|
return body;
|
|
425
485
|
}
|
|
426
486
|
function toMemberEditBody(options) {
|
|
@@ -433,6 +493,7 @@ function toMemberEditBody(options) {
|
|
|
433
493
|
if (options.pronouns !== void 0) body.pronouns = options.pronouns;
|
|
434
494
|
if (options.accentColor !== void 0) body.accent_color = options.accentColor;
|
|
435
495
|
if (options.profileFlags !== void 0) body.profile_flags = options.profileFlags;
|
|
496
|
+
if (options.mentionFlags !== void 0) body.mention_flags = options.mentionFlags;
|
|
436
497
|
if (options.mute !== void 0) body.mute = options.mute;
|
|
437
498
|
if (options.deaf !== void 0) body.deaf = options.deaf;
|
|
438
499
|
if (options.communicationDisabledUntil !== void 0) {
|
|
@@ -454,15 +515,54 @@ function toBulkFetchWire(requests) {
|
|
|
454
515
|
...r.around !== void 0 ? { around: r.around } : {}
|
|
455
516
|
}));
|
|
456
517
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (options.
|
|
462
|
-
if (options.
|
|
463
|
-
|
|
518
|
+
function toMessageSearchBody(options = {}) {
|
|
519
|
+
const body = { scope: "current" };
|
|
520
|
+
if (options.content !== void 0) body.content = options.content;
|
|
521
|
+
if (options.contents !== void 0) body.contents = options.contents;
|
|
522
|
+
if (options.exactPhrases !== void 0) body.exact_phrases = options.exactPhrases;
|
|
523
|
+
if (options.channelIds !== void 0) {
|
|
524
|
+
body.channel_id = options.channelIds;
|
|
525
|
+
body.channel_ids = options.channelIds;
|
|
526
|
+
}
|
|
527
|
+
if (options.excludeChannelIds !== void 0) body.exclude_channel_id = options.excludeChannelIds;
|
|
528
|
+
if (options.contextGuildId !== void 0) body.context_guild_id = options.contextGuildId;
|
|
529
|
+
if (options.contextChannelId !== void 0) body.context_channel_id = options.contextChannelId;
|
|
530
|
+
if (options.hitsPerPage !== void 0) body.hits_per_page = options.hitsPerPage;
|
|
531
|
+
if (options.page !== void 0) body.page = options.page;
|
|
532
|
+
if (options.cursor !== void 0) body.cursor = options.cursor;
|
|
533
|
+
if (options.minId !== void 0) body.min_id = options.minId;
|
|
534
|
+
if (options.maxId !== void 0) body.max_id = options.maxId;
|
|
535
|
+
if (options.authorIds !== void 0) body.author_id = options.authorIds;
|
|
536
|
+
if (options.excludeAuthorIds !== void 0) body.exclude_author_id = options.excludeAuthorIds;
|
|
537
|
+
if (options.authorType !== void 0) body.author_type = options.authorType;
|
|
538
|
+
if (options.excludeAuthorType !== void 0) body.exclude_author_type = options.excludeAuthorType;
|
|
539
|
+
if (options.mentions !== void 0) body.mentions = options.mentions;
|
|
540
|
+
if (options.excludeMentions !== void 0) body.exclude_mentions = options.excludeMentions;
|
|
541
|
+
if (options.mentionEveryone !== void 0) body.mention_everyone = options.mentionEveryone;
|
|
542
|
+
if (options.pinned !== void 0) body.pinned = options.pinned;
|
|
543
|
+
if (options.includeNsfw !== void 0) body.include_nsfw = options.includeNsfw;
|
|
544
|
+
if (options.has !== void 0) body.has = options.has;
|
|
545
|
+
if (options.excludeHas !== void 0) body.exclude_has = options.excludeHas;
|
|
546
|
+
if (options.sortBy !== void 0) body.sort_by = options.sortBy;
|
|
547
|
+
if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
|
|
464
548
|
return body;
|
|
465
549
|
}
|
|
550
|
+
function isMessageSearchIndexing(data) {
|
|
551
|
+
return "indexing" in data && data.indexing === true;
|
|
552
|
+
}
|
|
553
|
+
function toMessageSearchResponse(data) {
|
|
554
|
+
if (isMessageSearchIndexing(data)) {
|
|
555
|
+
return { indexing: true };
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
messages: data.messages,
|
|
559
|
+
channels: data.channels,
|
|
560
|
+
total: data.total,
|
|
561
|
+
hitsPerPage: data.hits_per_page,
|
|
562
|
+
page: data.page,
|
|
563
|
+
...data.cursor !== void 0 ? { cursor: data.cursor } : {}
|
|
564
|
+
};
|
|
565
|
+
}
|
|
466
566
|
|
|
467
567
|
// src/ClientCore/SdkOptions/Presence.ts
|
|
468
568
|
function toPresenceWire(options) {
|
|
@@ -511,9 +611,16 @@ function toSudoBody(options) {
|
|
|
511
611
|
return body;
|
|
512
612
|
}
|
|
513
613
|
|
|
614
|
+
// src/Helpers/AuditReason.ts
|
|
615
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
616
|
+
function auditReasonHeaders(reason) {
|
|
617
|
+
if (reason == null || reason === "") return {};
|
|
618
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
619
|
+
}
|
|
620
|
+
|
|
514
621
|
// src/Helpers/MessageUtils/Body.ts
|
|
515
|
-
import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
516
|
-
import { MessageReferenceType } from "@fluxerjs/types";
|
|
622
|
+
import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
623
|
+
import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
|
|
517
624
|
|
|
518
625
|
// src/LibErrors/ErrorCodes.ts
|
|
519
626
|
import { ErrorCodes } from "@fluxerjs/util";
|
|
@@ -582,6 +689,37 @@ function applyReplyPingSuppression(body) {
|
|
|
582
689
|
function assignIfDefined(target, key, value) {
|
|
583
690
|
if (value !== void 0) target[key] = value;
|
|
584
691
|
}
|
|
692
|
+
function normalizeSendFiles(files) {
|
|
693
|
+
if (!files?.length) return void 0;
|
|
694
|
+
const normalized = [];
|
|
695
|
+
const metaFromBuilders = [];
|
|
696
|
+
let anyBuilderMeta = false;
|
|
697
|
+
for (let i = 0; i < files.length; i++) {
|
|
698
|
+
const file = files[i];
|
|
699
|
+
if (!file) continue;
|
|
700
|
+
if (file instanceof AttachmentBuilder) {
|
|
701
|
+
normalized.push(file.toFileData());
|
|
702
|
+
const meta = {
|
|
703
|
+
id: i,
|
|
704
|
+
filename: file.filename,
|
|
705
|
+
...file.description != null ? { description: file.description } : {},
|
|
706
|
+
...file.spoiler ? { flags: MessageAttachmentFlags.IS_SPOILER } : {}
|
|
707
|
+
};
|
|
708
|
+
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
709
|
+
metaFromBuilders.push(meta);
|
|
710
|
+
} else {
|
|
711
|
+
normalized.push(file);
|
|
712
|
+
metaFromBuilders.push({
|
|
713
|
+
id: i,
|
|
714
|
+
filename: file.filename ?? file.name
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return {
|
|
719
|
+
files: normalized,
|
|
720
|
+
metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
|
|
721
|
+
};
|
|
722
|
+
}
|
|
585
723
|
function buildSendBody(options) {
|
|
586
724
|
const body = typeof options === "string" ? { content: options } : options;
|
|
587
725
|
const result = {};
|
|
@@ -589,16 +727,17 @@ function buildSendBody(options) {
|
|
|
589
727
|
if (body.embeds?.length) {
|
|
590
728
|
result.embeds = body.embeds.map((e) => e instanceof EmbedBuilder ? e.toJSON() : e);
|
|
591
729
|
}
|
|
730
|
+
const normalizedFiles = normalizeSendFiles(body.files);
|
|
592
731
|
if (body.uploadedAttachments?.length) {
|
|
593
732
|
result.attachments = body.uploadedAttachments;
|
|
594
|
-
} else if (
|
|
733
|
+
} else if (normalizedFiles?.files.length) {
|
|
595
734
|
result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
|
|
596
735
|
id: a.id,
|
|
597
736
|
filename: a.filename,
|
|
598
737
|
...a.title != null && { title: a.title },
|
|
599
738
|
...a.description != null && { description: a.description },
|
|
600
739
|
...a.flags != null && { flags: a.flags }
|
|
601
|
-
})) :
|
|
740
|
+
})) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
|
|
602
741
|
}
|
|
603
742
|
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
604
743
|
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
@@ -692,9 +831,10 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
692
831
|
} else if (allowedMentions?.repliedUser === false) {
|
|
693
832
|
applyReplyPingSuppression(body);
|
|
694
833
|
}
|
|
834
|
+
const resolvedFiles = normalizeSendFiles(files);
|
|
695
835
|
return {
|
|
696
836
|
body,
|
|
697
|
-
files: !uploadedAttachments?.length && files
|
|
837
|
+
files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
|
|
698
838
|
};
|
|
699
839
|
}
|
|
700
840
|
|
|
@@ -755,13 +895,17 @@ var Base = class {
|
|
|
755
895
|
};
|
|
756
896
|
|
|
757
897
|
// src/Domain/Message/MessageReaction.ts
|
|
758
|
-
var MessageReaction = class extends Base {
|
|
898
|
+
var MessageReaction = class _MessageReaction extends Base {
|
|
759
899
|
client;
|
|
760
900
|
messageId;
|
|
761
901
|
channelId;
|
|
762
902
|
guildId;
|
|
763
903
|
emoji;
|
|
764
|
-
/**
|
|
904
|
+
/** Total count when hydrated from a message payload; `1` for gateway add events. */
|
|
905
|
+
count;
|
|
906
|
+
/** Whether the current user reacted (message payload); false for gateway remove. */
|
|
907
|
+
me;
|
|
908
|
+
/** Raw gateway payload for low-level access (null when built from a message aggregate). */
|
|
765
909
|
_data;
|
|
766
910
|
constructor(client, data) {
|
|
767
911
|
super();
|
|
@@ -775,6 +919,26 @@ var MessageReaction = class extends Base {
|
|
|
775
919
|
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
776
920
|
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
777
921
|
};
|
|
922
|
+
this.count = 1;
|
|
923
|
+
this.me = false;
|
|
924
|
+
}
|
|
925
|
+
/** Build a reaction aggregate from a message's `reactions` array entry. */
|
|
926
|
+
static fromMessage(message, data) {
|
|
927
|
+
const reaction = new _MessageReaction(message.client, {
|
|
928
|
+
user_id: message.client.user?.id ?? "0",
|
|
929
|
+
message_id: message.id,
|
|
930
|
+
channel_id: message.channelId,
|
|
931
|
+
guild_id: message.guildId ?? void 0,
|
|
932
|
+
emoji: {
|
|
933
|
+
name: data.emoji.name,
|
|
934
|
+
id: data.emoji.id ?? void 0,
|
|
935
|
+
animated: data.emoji.animated ?? void 0
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
Object.defineProperty(reaction, "_data", { value: null });
|
|
939
|
+
reaction.count = data.count;
|
|
940
|
+
reaction.me = data.me ?? false;
|
|
941
|
+
return reaction;
|
|
778
942
|
}
|
|
779
943
|
/** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
|
|
780
944
|
get emojiIdentifier() {
|
|
@@ -784,12 +948,23 @@ var MessageReaction = class extends Base {
|
|
|
784
948
|
get guild() {
|
|
785
949
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
786
950
|
}
|
|
951
|
+
/** Cached message this reaction belongs to, or null if the message was not cached. */
|
|
952
|
+
get message() {
|
|
953
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
|
|
954
|
+
return cached ? new Message(this.client, cached) : null;
|
|
955
|
+
}
|
|
956
|
+
/** Cached text-capable channel, or null if uncached / not text-based. */
|
|
957
|
+
get channel() {
|
|
958
|
+
const channel = this.client.channels.get(this.channelId);
|
|
959
|
+
return channel?.isTextBased() ? channel : null;
|
|
960
|
+
}
|
|
787
961
|
/**
|
|
788
|
-
* Fetch the message this reaction belongs to.
|
|
789
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
962
|
+
* Fetch the message this reaction belongs to (cache first, then REST).
|
|
790
963
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
791
964
|
*/
|
|
792
965
|
async fetchMessage() {
|
|
966
|
+
const cached = this.message;
|
|
967
|
+
if (cached) return cached;
|
|
793
968
|
try {
|
|
794
969
|
const data = await this.client.rest.get(
|
|
795
970
|
Routes.channelMessage(this.channelId, this.messageId)
|
|
@@ -860,11 +1035,17 @@ var Events = {
|
|
|
860
1035
|
WebhooksUpdate: "webhooksUpdate",
|
|
861
1036
|
Resumed: "resumed",
|
|
862
1037
|
Error: "error",
|
|
863
|
-
Debug: "debug"
|
|
1038
|
+
Debug: "debug",
|
|
1039
|
+
ShardReady: "shardReady",
|
|
1040
|
+
ShardResumed: "shardResumed",
|
|
1041
|
+
ShardDisconnect: "shardDisconnect",
|
|
1042
|
+
ShardReconnecting: "shardReconnecting",
|
|
1043
|
+
ShardError: "shardError",
|
|
1044
|
+
ShardingRequired: "shardingRequired"
|
|
864
1045
|
};
|
|
865
1046
|
|
|
866
1047
|
// src/Helpers/ReactionCollector.ts
|
|
867
|
-
var ReactionCollector = class extends EventEmitter {
|
|
1048
|
+
var ReactionCollector = class _ReactionCollector extends EventEmitter {
|
|
868
1049
|
client;
|
|
869
1050
|
messageId;
|
|
870
1051
|
channelId;
|
|
@@ -907,15 +1088,17 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
907
1088
|
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
908
1089
|
}
|
|
909
1090
|
});
|
|
910
|
-
const
|
|
1091
|
+
const cached = this.client.users.get(entry.userId);
|
|
1092
|
+
const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
|
|
1093
|
+
{
|
|
911
1094
|
id: entry.userId,
|
|
912
1095
|
username: "Unknown",
|
|
913
1096
|
discriminator: "0",
|
|
914
|
-
|
|
1097
|
+
globalName: null,
|
|
915
1098
|
avatar: null,
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
}
|
|
1099
|
+
bot: false,
|
|
1100
|
+
system: false
|
|
1101
|
+
};
|
|
919
1102
|
this._collect(reaction, user, entry.userId);
|
|
920
1103
|
}
|
|
921
1104
|
};
|
|
@@ -947,6 +1130,21 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
947
1130
|
}
|
|
948
1131
|
this.emit("end", this.collected, reason);
|
|
949
1132
|
}
|
|
1133
|
+
/**
|
|
1134
|
+
* One-shot helper used by {@link Message.awaitReactions}.
|
|
1135
|
+
* Resolves with the collected reactions when the collector ends.
|
|
1136
|
+
* Rejects if `options.errors` includes the end reason.
|
|
1137
|
+
*/
|
|
1138
|
+
static awaitReactions(client, messageId, channelId, options) {
|
|
1139
|
+
const errors = options?.errors ?? [];
|
|
1140
|
+
return new Promise((resolve, reject) => {
|
|
1141
|
+
const collector = new _ReactionCollector(client, messageId, channelId, options);
|
|
1142
|
+
collector.on("end", (collected, reason) => {
|
|
1143
|
+
if (errors.includes(reason)) reject(collected);
|
|
1144
|
+
else resolve(collected);
|
|
1145
|
+
});
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
950
1148
|
on(event, listener) {
|
|
951
1149
|
return super.on(event, listener);
|
|
952
1150
|
}
|
|
@@ -955,70 +1153,293 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
955
1153
|
}
|
|
956
1154
|
};
|
|
957
1155
|
|
|
958
|
-
// src/Domain/Message/
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1156
|
+
// src/Domain/Message/Attachment.ts
|
|
1157
|
+
function toMessageAttachment(data) {
|
|
1158
|
+
return {
|
|
1159
|
+
id: data.id,
|
|
1160
|
+
filename: data.filename,
|
|
1161
|
+
title: data.title ?? null,
|
|
1162
|
+
description: data.description ?? null,
|
|
1163
|
+
contentType: data.content_type ?? null,
|
|
1164
|
+
contentHash: data.content_hash ?? null,
|
|
1165
|
+
size: data.size,
|
|
1166
|
+
url: data.url ?? null,
|
|
1167
|
+
proxyUrl: data.proxy_url ?? null,
|
|
1168
|
+
width: data.width ?? null,
|
|
1169
|
+
height: data.height ?? null,
|
|
1170
|
+
placeholder: data.placeholder ?? null,
|
|
1171
|
+
flags: data.flags ?? 0,
|
|
1172
|
+
nsfw: data.nsfw ?? false,
|
|
1173
|
+
duration: data.duration ?? null,
|
|
1174
|
+
waveform: data.waveform ?? null,
|
|
1175
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
1176
|
+
expired: data.expired ?? false
|
|
1177
|
+
};
|
|
963
1178
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1179
|
+
|
|
1180
|
+
// src/Domain/Message/Embed.ts
|
|
1181
|
+
function toMessageEmbedAuthor(data) {
|
|
1182
|
+
return {
|
|
1183
|
+
name: data.name ?? null,
|
|
1184
|
+
url: data.url ?? null,
|
|
1185
|
+
iconUrl: data.icon_url ?? null,
|
|
1186
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
function toMessageEmbedFooter(data) {
|
|
1190
|
+
return {
|
|
1191
|
+
text: data.text,
|
|
1192
|
+
iconUrl: data.icon_url ?? null,
|
|
1193
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
function toMessageEmbedMedia(data) {
|
|
1197
|
+
return {
|
|
1198
|
+
url: data.url,
|
|
1199
|
+
proxyUrl: data.proxy_url ?? null,
|
|
1200
|
+
contentType: data.content_type ?? null,
|
|
1201
|
+
contentHash: data.content_hash ?? null,
|
|
1202
|
+
width: data.width ?? null,
|
|
1203
|
+
height: data.height ?? null,
|
|
1204
|
+
description: data.description ?? null,
|
|
1205
|
+
placeholder: data.placeholder ?? null,
|
|
1206
|
+
duration: data.duration ?? null,
|
|
1207
|
+
flags: data.flags ?? null
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
function toMessageEmbed(data) {
|
|
1211
|
+
const full = data;
|
|
1212
|
+
return {
|
|
1213
|
+
type: data.type ?? "rich",
|
|
1214
|
+
url: data.url ?? null,
|
|
1215
|
+
title: data.title ?? null,
|
|
1216
|
+
color: data.color ?? null,
|
|
1217
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
1218
|
+
description: data.description ?? null,
|
|
1219
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
1220
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
1221
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
1222
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
1223
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
1224
|
+
name: f.name,
|
|
1225
|
+
value: f.value,
|
|
1226
|
+
inline: f.inline ?? false
|
|
1227
|
+
})),
|
|
1228
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
1229
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
1230
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
1231
|
+
nsfw: data.nsfw ?? false,
|
|
1232
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
1233
|
+
html: full.html ?? null,
|
|
1234
|
+
htmlWidth: full.html_width ?? null,
|
|
1235
|
+
htmlHeight: full.html_height ?? null
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
1240
|
+
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
1241
|
+
var MessageReactionManager = class {
|
|
1242
|
+
constructor(message) {
|
|
1243
|
+
this.message = message;
|
|
1244
|
+
}
|
|
1245
|
+
_cache = new Collection2();
|
|
1246
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
1247
|
+
get cache() {
|
|
1248
|
+
return this._cache;
|
|
971
1249
|
}
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
return { name: animatedWire[1], id: animatedWire[2], animated: true };
|
|
1250
|
+
get size() {
|
|
1251
|
+
return this._cache.size;
|
|
975
1252
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
return {
|
|
979
|
-
name: parsed.name,
|
|
980
|
-
id: parsed.id,
|
|
981
|
-
...parsed.animated ? { animated: true } : {}
|
|
982
|
-
};
|
|
1253
|
+
[Symbol.iterator]() {
|
|
1254
|
+
return this._cache.values();
|
|
983
1255
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
}
|
|
991
|
-
function emitOwnReactionAdd(message, wireOrInput) {
|
|
992
|
-
const user = message.client.user;
|
|
993
|
-
if (!user) return;
|
|
994
|
-
const emojiPayload = toReactionEmoji(wireOrInput);
|
|
995
|
-
const reaction = new MessageReaction(message.client, {
|
|
996
|
-
user_id: user.id,
|
|
997
|
-
channel_id: message.channelId,
|
|
998
|
-
message_id: message.id,
|
|
999
|
-
guild_id: message.guildId ?? void 0,
|
|
1000
|
-
emoji: {
|
|
1001
|
-
name: emojiPayload.name,
|
|
1002
|
-
...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
|
|
1003
|
-
...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
|
|
1256
|
+
/** @internal Sync from an API message payload. */
|
|
1257
|
+
_patch(reactions) {
|
|
1258
|
+
this._cache.clear();
|
|
1259
|
+
for (const data of reactions ?? []) {
|
|
1260
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
1261
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
1004
1262
|
}
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1266
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1267
|
+
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
1268
|
+
|
|
1269
|
+
// src/Helpers/Constants.ts
|
|
1270
|
+
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
1271
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
1272
|
+
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1273
|
+
|
|
1274
|
+
// src/Helpers/Cdn.ts
|
|
1275
|
+
var CDN_SIZE_LADDER = [
|
|
1276
|
+
16,
|
|
1277
|
+
20,
|
|
1278
|
+
22,
|
|
1279
|
+
24,
|
|
1280
|
+
28,
|
|
1281
|
+
32,
|
|
1282
|
+
40,
|
|
1283
|
+
44,
|
|
1284
|
+
48,
|
|
1285
|
+
56,
|
|
1286
|
+
60,
|
|
1287
|
+
64,
|
|
1288
|
+
80,
|
|
1289
|
+
96,
|
|
1290
|
+
100,
|
|
1291
|
+
128,
|
|
1292
|
+
160,
|
|
1293
|
+
240,
|
|
1294
|
+
256,
|
|
1295
|
+
300,
|
|
1296
|
+
320,
|
|
1297
|
+
480,
|
|
1298
|
+
512,
|
|
1299
|
+
600,
|
|
1300
|
+
640,
|
|
1301
|
+
1024,
|
|
1302
|
+
1280,
|
|
1303
|
+
1536,
|
|
1304
|
+
2048,
|
|
1305
|
+
3072,
|
|
1306
|
+
4096,
|
|
1307
|
+
8192,
|
|
1308
|
+
16384
|
|
1309
|
+
];
|
|
1310
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
1311
|
+
icon: { min: 128, max: 1024 },
|
|
1312
|
+
banner: { min: 480, max: 2400 },
|
|
1313
|
+
emoji: { min: 32, max: 512 },
|
|
1314
|
+
sticker: { min: 128, max: 512 }
|
|
1315
|
+
};
|
|
1316
|
+
function nearestSize(requested, candidates) {
|
|
1317
|
+
let best = candidates[0];
|
|
1318
|
+
let bestDist = Math.abs(requested - best);
|
|
1319
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
1320
|
+
const step = candidates[i];
|
|
1321
|
+
const dist = Math.abs(requested - step);
|
|
1322
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1323
|
+
best = step;
|
|
1324
|
+
bestDist = dist;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
return best;
|
|
1328
|
+
}
|
|
1329
|
+
function snapCdnSize(requested, assetClass) {
|
|
1330
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1331
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1332
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1333
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1334
|
+
return nearestSize(clamped, allowed);
|
|
1335
|
+
}
|
|
1336
|
+
function mediaBase(options) {
|
|
1337
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1338
|
+
}
|
|
1339
|
+
function staticBase(options) {
|
|
1340
|
+
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
1341
|
+
}
|
|
1342
|
+
function getExtension(hash, options) {
|
|
1343
|
+
const ext = options?.extension ?? "png";
|
|
1344
|
+
if (hash?.startsWith("a_")) return "gif";
|
|
1345
|
+
return ext;
|
|
1346
|
+
}
|
|
1347
|
+
function appendSize(options, assetClass) {
|
|
1348
|
+
const size = options?.size;
|
|
1349
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1350
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1351
|
+
}
|
|
1352
|
+
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1353
|
+
if (!avatarHash) return null;
|
|
1354
|
+
const ext = getExtension(avatarHash, options);
|
|
1355
|
+
const size = appendSize(options, "icon");
|
|
1356
|
+
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1357
|
+
}
|
|
1358
|
+
function cdnDisplayAvatarURL(userId, avatarHash, options) {
|
|
1359
|
+
return cdnAvatarURL(userId, avatarHash, options) ?? cdnDefaultAvatarURL(userId, options);
|
|
1360
|
+
}
|
|
1361
|
+
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1362
|
+
if (!bannerHash) return null;
|
|
1363
|
+
const ext = getExtension(bannerHash, options);
|
|
1364
|
+
const size = appendSize(options, "banner");
|
|
1365
|
+
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1366
|
+
}
|
|
1367
|
+
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1368
|
+
if (!avatarHash) return null;
|
|
1369
|
+
const ext = getExtension(avatarHash, options);
|
|
1370
|
+
const size = appendSize(options, "icon");
|
|
1371
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1372
|
+
}
|
|
1373
|
+
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1374
|
+
if (!bannerHash) return null;
|
|
1375
|
+
const ext = getExtension(bannerHash, options);
|
|
1376
|
+
const size = appendSize(options, "banner");
|
|
1377
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1378
|
+
}
|
|
1379
|
+
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
1380
|
+
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
1381
|
+
return `${staticBase(options)}/avatars/${index}.png`;
|
|
1382
|
+
}
|
|
1383
|
+
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1384
|
+
if (!hash) return null;
|
|
1385
|
+
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1386
|
+
const size = appendSize(options, assetClass);
|
|
1387
|
+
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1388
|
+
}
|
|
1389
|
+
function cdnEmojiURL(emojiId, animated, options) {
|
|
1390
|
+
const ext = animated ? "gif" : "png";
|
|
1391
|
+
const size = appendSize(options, "emoji");
|
|
1392
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1393
|
+
}
|
|
1394
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
1395
|
+
const ext = animated ? "gif" : "png";
|
|
1396
|
+
const size = appendSize(options, "sticker");
|
|
1397
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1401
|
+
var MessageSticker = class extends Base {
|
|
1402
|
+
client;
|
|
1403
|
+
id;
|
|
1404
|
+
name;
|
|
1405
|
+
description;
|
|
1406
|
+
tags;
|
|
1407
|
+
animated;
|
|
1408
|
+
constructor(client, data) {
|
|
1409
|
+
super();
|
|
1410
|
+
this.client = client;
|
|
1411
|
+
this.id = data.id;
|
|
1412
|
+
this.name = data.name;
|
|
1413
|
+
this.description = data.description ?? "";
|
|
1414
|
+
this.tags = data.tags ?? [];
|
|
1415
|
+
this.animated = data.animated ?? false;
|
|
1416
|
+
}
|
|
1417
|
+
/** CDN URL for this sticker image. */
|
|
1418
|
+
get url() {
|
|
1419
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
1420
|
+
mediaBase: this.client.instance.endpoints.media
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
1424
|
+
get createdTimestamp() {
|
|
1425
|
+
return SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1426
|
+
}
|
|
1427
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
1428
|
+
get createdAt() {
|
|
1429
|
+
return SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
// src/Domain/Message/Reactions.ts
|
|
1434
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
1435
|
+
async function emojiPath(message, emoji) {
|
|
1436
|
+
return message.client.resolveEmoji(emoji, message.guildId);
|
|
1015
1437
|
}
|
|
1016
1438
|
async function reactToMessage(message, emoji) {
|
|
1017
1439
|
const wire = await emojiPath(message, emoji);
|
|
1018
1440
|
await message.client.rest.put(
|
|
1019
1441
|
Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
1020
1442
|
);
|
|
1021
|
-
emitOwnReactionAdd(message, wire);
|
|
1022
1443
|
}
|
|
1023
1444
|
async function removeMessageReaction(message, emoji, userId) {
|
|
1024
1445
|
const e = await emojiPath(message, emoji);
|
|
@@ -1124,7 +1545,33 @@ async function replyToMessage(message, options, replyOptions) {
|
|
|
1124
1545
|
}
|
|
1125
1546
|
|
|
1126
1547
|
// src/Domain/Message/Message.ts
|
|
1548
|
+
function toMessageCall(data) {
|
|
1549
|
+
return {
|
|
1550
|
+
participants: data.participants,
|
|
1551
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
function toMessageSnapshot(client, data) {
|
|
1555
|
+
return {
|
|
1556
|
+
content: data.content ?? null,
|
|
1557
|
+
createdAt: new Date(data.timestamp),
|
|
1558
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
1559
|
+
mentionUserIds: data.mentions ?? [],
|
|
1560
|
+
mentionRoles: data.mention_roles ?? [],
|
|
1561
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
1562
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
1563
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
1564
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
function resolveMessageFlags(flags) {
|
|
1568
|
+
if (flags === void 0) return void 0;
|
|
1569
|
+
if (typeof flags === "number") return flags;
|
|
1570
|
+
return Number(MessageFlagsBitField.resolve(flags));
|
|
1571
|
+
}
|
|
1127
1572
|
var Message = class _Message extends Base {
|
|
1573
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
1574
|
+
partial = false;
|
|
1128
1575
|
/** The {@link Client} that instantiated this message. */
|
|
1129
1576
|
client;
|
|
1130
1577
|
/** Snowflake ID of this message. */
|
|
@@ -1153,7 +1600,7 @@ var Message = class _Message extends Base {
|
|
|
1153
1600
|
mentionEveryone;
|
|
1154
1601
|
/** Whether this is a text-to-speech message. */
|
|
1155
1602
|
tts;
|
|
1156
|
-
/** Embedded content (
|
|
1603
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
1157
1604
|
embeds;
|
|
1158
1605
|
/** Stickers sent with the message. */
|
|
1159
1606
|
stickers;
|
|
@@ -1175,26 +1622,43 @@ var Message = class _Message extends Base {
|
|
|
1175
1622
|
mentionRoles;
|
|
1176
1623
|
/** Client-side nonce for deduplication. */
|
|
1177
1624
|
nonce;
|
|
1178
|
-
/**
|
|
1625
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
1626
|
+
nsfwEmojis;
|
|
1627
|
+
/**
|
|
1628
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1629
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
1630
|
+
*/
|
|
1179
1631
|
get channel() {
|
|
1180
|
-
|
|
1632
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1633
|
+
return channel?.isTextBased() ? channel : null;
|
|
1181
1634
|
}
|
|
1182
1635
|
/** Cached guild, or null for DMs / uncached. */
|
|
1183
1636
|
get guild() {
|
|
1184
1637
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
1185
1638
|
}
|
|
1186
|
-
/**
|
|
1639
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
1640
|
+
get member() {
|
|
1641
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1645
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1646
|
+
* @example
|
|
1647
|
+
* const channel = await message.resolveChannel();
|
|
1648
|
+
* await channel.delete();
|
|
1649
|
+
*/
|
|
1187
1650
|
async resolveChannel() {
|
|
1188
1651
|
return this.client.channels.resolve(this.channelId);
|
|
1189
1652
|
}
|
|
1190
|
-
/**
|
|
1653
|
+
/**
|
|
1654
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
1655
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
1656
|
+
* @example
|
|
1657
|
+
* const guild = await message.resolveGuild();
|
|
1658
|
+
*/
|
|
1191
1659
|
async resolveGuild() {
|
|
1192
1660
|
if (!this.guildId) return null;
|
|
1193
|
-
|
|
1194
|
-
return await this.client.guilds.resolve(this.guildId);
|
|
1195
|
-
} catch {
|
|
1196
|
-
return null;
|
|
1197
|
-
}
|
|
1661
|
+
return this.client.guilds.resolve(this.guildId);
|
|
1198
1662
|
}
|
|
1199
1663
|
/**
|
|
1200
1664
|
* Construct a message from API data.
|
|
@@ -1211,29 +1675,75 @@ var Message = class _Message extends Base {
|
|
|
1211
1675
|
this.createdAt = new Date(data.timestamp);
|
|
1212
1676
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1213
1677
|
this.pinned = data.pinned;
|
|
1214
|
-
this.attachments = new
|
|
1215
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
1678
|
+
this.attachments = new Collection3();
|
|
1679
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1216
1680
|
this.type = data.type ?? MessageType.Default;
|
|
1217
|
-
this.flags = data.flags ?? 0;
|
|
1681
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1218
1682
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1219
1683
|
this.tts = data.tts ?? false;
|
|
1220
|
-
this.embeds = data.embeds ?? [];
|
|
1221
|
-
this.stickers = data.stickers ?? [];
|
|
1222
|
-
this.reactions =
|
|
1223
|
-
this.
|
|
1224
|
-
this.
|
|
1225
|
-
|
|
1684
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1685
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
1686
|
+
this.reactions = new MessageReactionManager(this);
|
|
1687
|
+
this.reactions._patch(data.reactions);
|
|
1688
|
+
this.messageReference = data.message_reference ? {
|
|
1689
|
+
channelId: data.message_reference.channel_id,
|
|
1690
|
+
messageId: data.message_reference.message_id,
|
|
1691
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1692
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1693
|
+
} : null;
|
|
1694
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
1695
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1226
1696
|
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
1227
1697
|
this.webhookId = data.webhook_id ?? null;
|
|
1228
1698
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1229
1699
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1230
1700
|
this.nonce = data.nonce ?? null;
|
|
1701
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
1705
|
+
* @internal
|
|
1706
|
+
*/
|
|
1707
|
+
_patch(data) {
|
|
1708
|
+
this.content = data.content;
|
|
1709
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1710
|
+
this.pinned = data.pinned;
|
|
1711
|
+
this.attachments.clear();
|
|
1712
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1713
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1714
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1715
|
+
this.tts = data.tts ?? false;
|
|
1716
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1717
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1718
|
+
this.reactions._patch(data.reactions);
|
|
1719
|
+
this.messageReference = data.message_reference ? {
|
|
1720
|
+
channelId: data.message_reference.channel_id,
|
|
1721
|
+
messageId: data.message_reference.message_id,
|
|
1722
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1723
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1724
|
+
} : null;
|
|
1725
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1726
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1727
|
+
);
|
|
1728
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1729
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1730
|
+
this.webhookId = data.webhook_id ?? null;
|
|
1731
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1732
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
1733
|
+
this.nonce = data.nonce ?? null;
|
|
1734
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1231
1735
|
}
|
|
1232
|
-
/**
|
|
1736
|
+
/**
|
|
1737
|
+
* Send a standalone message in this channel (not a reply).
|
|
1738
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
1739
|
+
*/
|
|
1233
1740
|
async send(options) {
|
|
1234
1741
|
return sendMessage(this, options);
|
|
1235
1742
|
}
|
|
1236
|
-
/**
|
|
1743
|
+
/**
|
|
1744
|
+
* Send a message to another channel by ID.
|
|
1745
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
1746
|
+
*/
|
|
1237
1747
|
async sendTo(channelId, options) {
|
|
1238
1748
|
return sendMessageTo(this, channelId, options);
|
|
1239
1749
|
}
|
|
@@ -1247,6 +1757,16 @@ var Message = class _Message extends Base {
|
|
|
1247
1757
|
async reply(options, replyOptions) {
|
|
1248
1758
|
return replyToMessage(this, options, replyOptions);
|
|
1249
1759
|
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Hydrate a partial message, or return the message as-is.
|
|
1762
|
+
* @example
|
|
1763
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
1764
|
+
* const message = await Message.resolve(msg);
|
|
1765
|
+
* });
|
|
1766
|
+
*/
|
|
1767
|
+
static async resolve(message) {
|
|
1768
|
+
return message.partial ? message.fetch() : message;
|
|
1769
|
+
}
|
|
1250
1770
|
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
1251
1771
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
1252
1772
|
return createMessageBody(content, referenced_message, ping);
|
|
@@ -1259,7 +1779,7 @@ var Message = class _Message extends Base {
|
|
|
1259
1779
|
async edit(options) {
|
|
1260
1780
|
const body = {};
|
|
1261
1781
|
if (options.content !== void 0) body.content = options.content;
|
|
1262
|
-
if (options.embeds
|
|
1782
|
+
if (options.embeds !== void 0) {
|
|
1263
1783
|
body.embeds = options.embeds.map(
|
|
1264
1784
|
(e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
|
|
1265
1785
|
);
|
|
@@ -1267,7 +1787,8 @@ var Message = class _Message extends Base {
|
|
|
1267
1787
|
if (options.allowedMentions) {
|
|
1268
1788
|
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
1269
1789
|
}
|
|
1270
|
-
|
|
1790
|
+
const flags = resolveMessageFlags(options.flags);
|
|
1791
|
+
if (flags !== void 0) body.flags = flags;
|
|
1271
1792
|
if (options.attachments !== void 0) {
|
|
1272
1793
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
1273
1794
|
}
|
|
@@ -1282,13 +1803,22 @@ var Message = class _Message extends Base {
|
|
|
1282
1803
|
createReactionCollector(options) {
|
|
1283
1804
|
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
1284
1805
|
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
1808
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1809
|
+
*/
|
|
1810
|
+
awaitReactions(options) {
|
|
1811
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1812
|
+
}
|
|
1285
1813
|
/** Fetch the latest version of this message from the API. */
|
|
1286
1814
|
async fetch() {
|
|
1287
1815
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1288
1816
|
}
|
|
1289
1817
|
/** Delete this message. */
|
|
1290
|
-
async delete() {
|
|
1291
|
-
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id)
|
|
1818
|
+
async delete(reason) {
|
|
1819
|
+
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
|
|
1820
|
+
...auditReasonHeaders(reason)
|
|
1821
|
+
});
|
|
1292
1822
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
1293
1823
|
}
|
|
1294
1824
|
/** Delete a specific attachment from this message. */
|
|
@@ -1335,6 +1865,57 @@ var Message = class _Message extends Base {
|
|
|
1335
1865
|
}
|
|
1336
1866
|
};
|
|
1337
1867
|
|
|
1868
|
+
// src/Domain/Message/PartialMessage.ts
|
|
1869
|
+
import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
|
|
1870
|
+
var PartialMessage = class {
|
|
1871
|
+
partial = true;
|
|
1872
|
+
client;
|
|
1873
|
+
id;
|
|
1874
|
+
channelId;
|
|
1875
|
+
guildId;
|
|
1876
|
+
content;
|
|
1877
|
+
authorId;
|
|
1878
|
+
author;
|
|
1879
|
+
createdAt;
|
|
1880
|
+
constructor(client, data) {
|
|
1881
|
+
this.client = client;
|
|
1882
|
+
this.id = data.id;
|
|
1883
|
+
this.channelId = data.channelId;
|
|
1884
|
+
this.guildId = data.guildId ?? null;
|
|
1885
|
+
this.content = data.content ?? null;
|
|
1886
|
+
this.authorId = data.authorId ?? null;
|
|
1887
|
+
this.author = data.author ?? null;
|
|
1888
|
+
this.createdAt = data.createdAt ?? (SnowflakeUtil2.isValid(data.id) ? SnowflakeUtil2.dateFromSnowflake(data.id) : null);
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
1892
|
+
* Same contract as {@link Message.channel}.
|
|
1893
|
+
*/
|
|
1894
|
+
get channel() {
|
|
1895
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1896
|
+
return channel?.isTextBased() ? channel : null;
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1900
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1901
|
+
* @example
|
|
1902
|
+
* const channel = await message.resolveChannel();
|
|
1903
|
+
* await channel.delete();
|
|
1904
|
+
*/
|
|
1905
|
+
async resolveChannel() {
|
|
1906
|
+
return this.client.channels.resolve(this.channelId);
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* Fetch the full message from the API.
|
|
1910
|
+
* @example
|
|
1911
|
+
* const message = await partial.fetch();
|
|
1912
|
+
* await message.reply('Pong!');
|
|
1913
|
+
*/
|
|
1914
|
+
async fetch() {
|
|
1915
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1338
1919
|
// src/ClientCore/MessageManager.ts
|
|
1339
1920
|
var BULK = {
|
|
1340
1921
|
requests: { min: 1, max: 25 },
|
|
@@ -1369,19 +1950,40 @@ var MessageManager = class {
|
|
|
1369
1950
|
this.client = client;
|
|
1370
1951
|
this.channelId = channelId;
|
|
1371
1952
|
}
|
|
1953
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1954
|
+
_structures = new Collection4();
|
|
1372
1955
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1373
1956
|
get(messageId) {
|
|
1374
1957
|
const data = this.client._getMessageCache(this.channelId)?.get(messageId);
|
|
1375
|
-
|
|
1958
|
+
if (!data) {
|
|
1959
|
+
this._structures.delete(messageId);
|
|
1960
|
+
return void 0;
|
|
1961
|
+
}
|
|
1962
|
+
const existing = this._structures.get(messageId);
|
|
1963
|
+
if (existing) return existing;
|
|
1964
|
+
const message = new Message(this.client, data);
|
|
1965
|
+
this._structures.set(messageId, message);
|
|
1966
|
+
return message;
|
|
1967
|
+
}
|
|
1968
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1969
|
+
async resolve(messageId) {
|
|
1970
|
+
return this.get(messageId) ?? this.fetch(messageId);
|
|
1376
1971
|
}
|
|
1377
1972
|
async fetch(idOrOptions) {
|
|
1378
1973
|
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1379
1974
|
}
|
|
1380
|
-
/** Cache API data and return a {@link Message}
|
|
1975
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1381
1976
|
wrap(data) {
|
|
1382
1977
|
this.client._addMessageToCache(this.channelId, data);
|
|
1383
1978
|
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
1384
|
-
|
|
1979
|
+
const existing = this._structures.get(data.id);
|
|
1980
|
+
if (existing) {
|
|
1981
|
+
existing._patch(cached);
|
|
1982
|
+
return existing;
|
|
1983
|
+
}
|
|
1984
|
+
const message = new Message(this.client, cached);
|
|
1985
|
+
this._structures.set(data.id, message);
|
|
1986
|
+
return message;
|
|
1385
1987
|
}
|
|
1386
1988
|
/** Fetch a single message from the API. */
|
|
1387
1989
|
async fetchOne(messageId) {
|
|
@@ -1414,14 +2016,135 @@ var MessageManager = class {
|
|
|
1414
2016
|
}
|
|
1415
2017
|
const base = Routes5.channelMessages(this.channelId);
|
|
1416
2018
|
const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
|
|
1417
|
-
const collection = new
|
|
2019
|
+
const collection = new Collection4();
|
|
1418
2020
|
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
1419
2021
|
return collection;
|
|
1420
2022
|
}
|
|
1421
2023
|
};
|
|
1422
2024
|
|
|
2025
|
+
// src/Helpers/MessageCollector.ts
|
|
2026
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
2027
|
+
import { Collection as Collection5 } from "@fluxerjs/collection";
|
|
2028
|
+
function requireCollectorBounds(options) {
|
|
2029
|
+
const time = options.time ?? 0;
|
|
2030
|
+
const max = options.max ?? 0;
|
|
2031
|
+
if (time <= 0 && max <= 0) {
|
|
2032
|
+
throw new FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
2033
|
+
code: ErrorCodes.CollectorOptionsRequired
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
var MessageCollector = class _MessageCollector extends EventEmitter2 {
|
|
2038
|
+
client;
|
|
2039
|
+
channelId;
|
|
2040
|
+
options;
|
|
2041
|
+
collected = new Collection5();
|
|
2042
|
+
_timeout = null;
|
|
2043
|
+
_ended = false;
|
|
2044
|
+
_listener;
|
|
2045
|
+
constructor(client, channelId, options = {}) {
|
|
2046
|
+
super();
|
|
2047
|
+
requireCollectorBounds(options);
|
|
2048
|
+
this.client = client;
|
|
2049
|
+
this.channelId = channelId;
|
|
2050
|
+
this.options = {
|
|
2051
|
+
filter: options.filter ?? (() => true),
|
|
2052
|
+
time: options.time ?? 0,
|
|
2053
|
+
max: options.max ?? 0
|
|
2054
|
+
};
|
|
2055
|
+
this._listener = (message) => {
|
|
2056
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
2057
|
+
if (!this.options.filter(message)) return;
|
|
2058
|
+
this.collected.set(message.id, message);
|
|
2059
|
+
this.emit("collect", message);
|
|
2060
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
2061
|
+
this.stop("limit");
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
2065
|
+
if (this.options.time > 0) {
|
|
2066
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
stop(reason = "user") {
|
|
2070
|
+
if (this._ended) return;
|
|
2071
|
+
this._ended = true;
|
|
2072
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
2073
|
+
if (this._timeout) {
|
|
2074
|
+
clearTimeout(this._timeout);
|
|
2075
|
+
this._timeout = null;
|
|
2076
|
+
}
|
|
2077
|
+
this.emit("end", this.collected, reason);
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
2081
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
2082
|
+
* the end reason is not listed in `errors`).
|
|
2083
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
2084
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
2085
|
+
*/
|
|
2086
|
+
static awaitMessages(client, channelId, options) {
|
|
2087
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
2088
|
+
return new Promise((resolve, reject) => {
|
|
2089
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
2090
|
+
collector.on("end", (collected, reason) => {
|
|
2091
|
+
if (!errors.includes(reason)) {
|
|
2092
|
+
resolve(collected);
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
if (reason === "time") {
|
|
2096
|
+
reject(
|
|
2097
|
+
new FluxerError("Message collector timed out", {
|
|
2098
|
+
code: ErrorCodes.CollectorIdle
|
|
2099
|
+
})
|
|
2100
|
+
);
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
if (reason === "limit") {
|
|
2104
|
+
reject(
|
|
2105
|
+
new FluxerError("Message collector reached max", {
|
|
2106
|
+
code: ErrorCodes.CollectorMax
|
|
2107
|
+
})
|
|
2108
|
+
);
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
reject(collected);
|
|
2112
|
+
});
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
on(event, listener) {
|
|
2116
|
+
return super.on(event, listener);
|
|
2117
|
+
}
|
|
2118
|
+
emit(event, ...args) {
|
|
2119
|
+
return super.emit(event, ...args);
|
|
2120
|
+
}
|
|
2121
|
+
};
|
|
2122
|
+
|
|
1423
2123
|
// src/Domain/Channel/Attachments.ts
|
|
1424
2124
|
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
2125
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
2126
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
2127
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
2128
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
2129
|
+
if (!rules?.length) return null;
|
|
2130
|
+
const snapshot = {};
|
|
2131
|
+
for (const rule of rules) {
|
|
2132
|
+
Object.assign(snapshot, rule.overrides);
|
|
2133
|
+
}
|
|
2134
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
2135
|
+
}
|
|
2136
|
+
function assertBotAttachmentLimits(client, files) {
|
|
2137
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
2138
|
+
for (const file of files) {
|
|
2139
|
+
const size = file.data.byteLength;
|
|
2140
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
2141
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
2142
|
+
throw new FluxerError(
|
|
2143
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
2144
|
+
{ code: ErrorCodes.AttachmentTooLarge }
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
1425
2148
|
function asBytes(data) {
|
|
1426
2149
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
1427
2150
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -1441,6 +2164,7 @@ async function putBlob(url, body, contentType) {
|
|
|
1441
2164
|
}
|
|
1442
2165
|
}
|
|
1443
2166
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
2167
|
+
assertBotAttachmentLimits(client, files);
|
|
1444
2168
|
const plan = await client.rest.post(
|
|
1445
2169
|
Routes6.channelAttachments(channelId),
|
|
1446
2170
|
{
|
|
@@ -1498,6 +2222,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1498
2222
|
|
|
1499
2223
|
// src/Domain/Channel/Base.ts
|
|
1500
2224
|
var Channel = class extends Base {
|
|
2225
|
+
#messages;
|
|
1501
2226
|
/** The {@link Client} that instantiated this channel. */
|
|
1502
2227
|
client;
|
|
1503
2228
|
/** Snowflake ID of this channel. */
|
|
@@ -1521,11 +2246,11 @@ var Channel = class extends Base {
|
|
|
1521
2246
|
}
|
|
1522
2247
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1523
2248
|
get createdTimestamp() {
|
|
1524
|
-
return
|
|
2249
|
+
return SnowflakeUtil3.timestampFromSnowflake(this.id);
|
|
1525
2250
|
}
|
|
1526
2251
|
/** Date when this channel was created, derived from its snowflake ID. */
|
|
1527
2252
|
get createdAt() {
|
|
1528
|
-
return
|
|
2253
|
+
return SnowflakeUtil3.dateFromSnowflake(this.id);
|
|
1529
2254
|
}
|
|
1530
2255
|
/**
|
|
1531
2256
|
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
@@ -1539,19 +2264,36 @@ var Channel = class extends Base {
|
|
|
1539
2264
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1540
2265
|
}
|
|
1541
2266
|
}
|
|
1542
|
-
/**
|
|
2267
|
+
/** @internal Factory wired after subclasses load. */
|
|
1543
2268
|
static from(_c, _d) {
|
|
1544
2269
|
throw new Error("Channel.from not initialized");
|
|
1545
2270
|
}
|
|
2271
|
+
/** @internal Factory wired after subclasses load. */
|
|
1546
2272
|
static fromOrCreate(_c, _d) {
|
|
1547
2273
|
throw new Error("Channel.fromOrCreate not initialized");
|
|
1548
2274
|
}
|
|
2275
|
+
/** @internal Factory wired after subclasses load. */
|
|
1549
2276
|
static createDM(_c, _d) {
|
|
1550
2277
|
throw new Error("Channel.createDM not initialized");
|
|
1551
2278
|
}
|
|
1552
|
-
/**
|
|
2279
|
+
/**
|
|
2280
|
+
* Whether this channel type can carry messages (text, voice, DM, group DM, notes).
|
|
2281
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
2282
|
+
*/
|
|
1553
2283
|
isTextBased() {
|
|
1554
|
-
return
|
|
2284
|
+
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
|
|
2285
|
+
}
|
|
2286
|
+
/** Check if this is a guild channel (text, voice, category, or link). */
|
|
2287
|
+
isGuild() {
|
|
2288
|
+
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
|
|
2289
|
+
}
|
|
2290
|
+
/** Check if this is a guild text channel. */
|
|
2291
|
+
isText() {
|
|
2292
|
+
return this.type === ChannelType.GuildText;
|
|
2293
|
+
}
|
|
2294
|
+
/** Check if this is a category channel. */
|
|
2295
|
+
isCategory() {
|
|
2296
|
+
return this.type === ChannelType.GuildCategory;
|
|
1555
2297
|
}
|
|
1556
2298
|
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1557
2299
|
isDM() {
|
|
@@ -1563,11 +2305,11 @@ var Channel = class extends Base {
|
|
|
1563
2305
|
}
|
|
1564
2306
|
/** Check if this is a voice channel. */
|
|
1565
2307
|
isVoice() {
|
|
1566
|
-
return
|
|
2308
|
+
return this.type === ChannelType.GuildVoice;
|
|
1567
2309
|
}
|
|
1568
2310
|
/** Check if this is a link channel. */
|
|
1569
2311
|
isLink() {
|
|
1570
|
-
return
|
|
2312
|
+
return this.type === ChannelType.GuildLink;
|
|
1571
2313
|
}
|
|
1572
2314
|
/**
|
|
1573
2315
|
* Delete recent messages or an explicit ID list.
|
|
@@ -1606,7 +2348,7 @@ var Channel = class extends Base {
|
|
|
1606
2348
|
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1607
2349
|
return ids;
|
|
1608
2350
|
}
|
|
1609
|
-
/** Delete all messages sent by the bot in this channel
|
|
2351
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1610
2352
|
async bulkDeleteMyMessages(options) {
|
|
1611
2353
|
const body = options ? toSudoBody(options) : void 0;
|
|
1612
2354
|
await this.client.rest.post(Routes7.channelBulkDeleteMine(this.id), {
|
|
@@ -1614,11 +2356,17 @@ var Channel = class extends Base {
|
|
|
1614
2356
|
auth: true
|
|
1615
2357
|
});
|
|
1616
2358
|
}
|
|
1617
|
-
/**
|
|
2359
|
+
/**
|
|
2360
|
+
* Mark all pinned messages as read in this channel.
|
|
2361
|
+
* Session-token helper; bots usually skip this.
|
|
2362
|
+
*/
|
|
1618
2363
|
async acknowledgePins() {
|
|
1619
2364
|
await this.client.rest.post(Routes7.channelPinsAck(this.id), { auth: true });
|
|
1620
2365
|
}
|
|
1621
|
-
/**
|
|
2366
|
+
/**
|
|
2367
|
+
* Clear the read state for this channel.
|
|
2368
|
+
* Session-token helper; bots usually skip this.
|
|
2369
|
+
*/
|
|
1622
2370
|
async clearReadState() {
|
|
1623
2371
|
await this.client.rest.delete(Routes7.channelMessagesAck(this.id), { auth: true });
|
|
1624
2372
|
}
|
|
@@ -1654,7 +2402,11 @@ var Channel = class extends Base {
|
|
|
1654
2402
|
async sendTyping() {
|
|
1655
2403
|
await this.client.rest.post(Routes7.channelTyping(this.id), { auth: true });
|
|
1656
2404
|
}
|
|
1657
|
-
/**
|
|
2405
|
+
/**
|
|
2406
|
+
* Fetch available RTC regions for voice channels.
|
|
2407
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
2408
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
2409
|
+
*/
|
|
1658
2410
|
async fetchRtcRegions() {
|
|
1659
2411
|
const data = await this.client.rest.get(Routes7.channelRtcRegions(this.id), {
|
|
1660
2412
|
auth: true
|
|
@@ -1673,71 +2425,66 @@ var Channel = class extends Base {
|
|
|
1673
2425
|
nextSendAllowedAt: data.next_send_allowed_at
|
|
1674
2426
|
};
|
|
1675
2427
|
}
|
|
1676
|
-
/**
|
|
2428
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1677
2429
|
canSendMessage() {
|
|
1678
|
-
return this.
|
|
2430
|
+
return this.isTextBased();
|
|
1679
2431
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
// src/Domain/Channel/TextCapable.ts
|
|
1686
|
-
import { Routes as Routes8 } from "@fluxerjs/types";
|
|
1687
|
-
|
|
1688
|
-
// src/Helpers/MessageCollector.ts
|
|
1689
|
-
import { EventEmitter as EventEmitter2 } from "events";
|
|
1690
|
-
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
1691
|
-
var MessageCollector = class extends EventEmitter2 {
|
|
1692
|
-
client;
|
|
1693
|
-
channelId;
|
|
1694
|
-
options;
|
|
1695
|
-
collected = new Collection4();
|
|
1696
|
-
_timeout = null;
|
|
1697
|
-
_ended = false;
|
|
1698
|
-
_listener;
|
|
1699
|
-
constructor(client, channelId, options = {}) {
|
|
1700
|
-
super();
|
|
1701
|
-
this.client = client;
|
|
1702
|
-
this.channelId = channelId;
|
|
1703
|
-
this.options = {
|
|
1704
|
-
filter: options.filter ?? (() => true),
|
|
1705
|
-
time: options.time ?? 0,
|
|
1706
|
-
max: options.max ?? 0
|
|
1707
|
-
};
|
|
1708
|
-
this._listener = (message) => {
|
|
1709
|
-
if (this._ended || message.channelId !== this.channelId) return;
|
|
1710
|
-
if (!this.options.filter(message)) return;
|
|
1711
|
-
this.collected.set(message.id, message);
|
|
1712
|
-
this.emit("collect", message);
|
|
1713
|
-
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
1714
|
-
this.stop("limit");
|
|
1715
|
-
}
|
|
1716
|
-
};
|
|
1717
|
-
this.client.on(Events.MessageCreate, this._listener);
|
|
1718
|
-
if (this.options.time > 0) {
|
|
1719
|
-
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
2432
|
+
/** Per-channel message cache + fetch. */
|
|
2433
|
+
get messages() {
|
|
2434
|
+
if (!this.#messages) {
|
|
2435
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1720
2436
|
}
|
|
2437
|
+
return this.#messages;
|
|
1721
2438
|
}
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
this.
|
|
1725
|
-
this.client.off(Events.MessageCreate, this._listener);
|
|
1726
|
-
if (this._timeout) {
|
|
1727
|
-
clearTimeout(this._timeout);
|
|
1728
|
-
this._timeout = null;
|
|
1729
|
-
}
|
|
1730
|
-
this.emit("end", this.collected, reason);
|
|
2439
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
2440
|
+
createMessageCollector(options) {
|
|
2441
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1731
2442
|
}
|
|
1732
|
-
|
|
1733
|
-
|
|
2443
|
+
/**
|
|
2444
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
2445
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
2446
|
+
* @example
|
|
2447
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
2448
|
+
*/
|
|
2449
|
+
awaitMessages(options) {
|
|
2450
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
1734
2451
|
}
|
|
1735
|
-
|
|
1736
|
-
|
|
2452
|
+
/**
|
|
2453
|
+
* Delete this channel (or close it if it is a DM).
|
|
2454
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
2455
|
+
* @example
|
|
2456
|
+
* const channel = await client.channels.fetch(channelId);
|
|
2457
|
+
* await channel.delete();
|
|
2458
|
+
*/
|
|
2459
|
+
async delete(options) {
|
|
2460
|
+
const params = new URLSearchParams();
|
|
2461
|
+
if (options?.silent) params.set("silent", "true");
|
|
2462
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2463
|
+
const qs2 = params.toString();
|
|
2464
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
2465
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2466
|
+
await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2467
|
+
body,
|
|
2468
|
+
auth: true,
|
|
2469
|
+
...auditReasonHeaders(_reason)
|
|
2470
|
+
});
|
|
2471
|
+
this.client.channels.delete(this.id);
|
|
2472
|
+
this.client._clearMessageCache(this.id);
|
|
2473
|
+
if (this.isGuild() && this.guildId) {
|
|
2474
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
/** Channel mention (`<#id>`). */
|
|
2478
|
+
toString() {
|
|
2479
|
+
return `<#${this.id}>`;
|
|
1737
2480
|
}
|
|
1738
2481
|
};
|
|
1739
2482
|
|
|
2483
|
+
// src/Domain/Channel/Dm.ts
|
|
2484
|
+
import { ChannelType as ChannelType2, Routes as Routes9 } from "@fluxerjs/types";
|
|
2485
|
+
|
|
1740
2486
|
// src/Domain/Channel/TextCapable.ts
|
|
2487
|
+
import { Routes as Routes8 } from "@fluxerjs/types";
|
|
1741
2488
|
async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
1742
2489
|
const params = new URLSearchParams();
|
|
1743
2490
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
@@ -1755,27 +2502,19 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
|
1755
2502
|
}
|
|
1756
2503
|
function TextCapable(Base2) {
|
|
1757
2504
|
class TextCapableChannel extends Base2 {
|
|
1758
|
-
|
|
2505
|
+
/**
|
|
2506
|
+
* Send a message in this channel.
|
|
2507
|
+
* @example
|
|
2508
|
+
* await channel.send('hi');
|
|
2509
|
+
*/
|
|
1759
2510
|
async send(options) {
|
|
1760
|
-
|
|
1761
|
-
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
1762
|
-
});
|
|
1763
|
-
const data = await this.client.rest.post(Routes8.channelMessages(this.id), payload);
|
|
1764
|
-
this.client._addMessageToCache(this.id, data);
|
|
1765
|
-
return new Message(this.client, data);
|
|
1766
|
-
}
|
|
1767
|
-
get messages() {
|
|
1768
|
-
if (!this.#messages) {
|
|
1769
|
-
this.#messages = new MessageManager(this.client, this.id);
|
|
1770
|
-
}
|
|
1771
|
-
return this.#messages;
|
|
1772
|
-
}
|
|
1773
|
-
createMessageCollector(options) {
|
|
1774
|
-
return new MessageCollector(this.client, this.id, options);
|
|
2511
|
+
return this.client.channels.send(this.id, options);
|
|
1775
2512
|
}
|
|
2513
|
+
/** Fetch pinned messages in this channel. */
|
|
1776
2514
|
async fetchPinnedMessages(options) {
|
|
1777
2515
|
return (await this.fetchPinnedMessagesPage(options)).messages;
|
|
1778
2516
|
}
|
|
2517
|
+
/** Fetch a page of pinned messages plus pagination metadata. */
|
|
1779
2518
|
async fetchPinnedMessagesPage(options) {
|
|
1780
2519
|
return fetchPinnedMessagesPageFor(this.client, this.id, options);
|
|
1781
2520
|
}
|
|
@@ -1801,7 +2540,38 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1801
2540
|
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
1802
2541
|
this.nicks = full.nicks ?? {};
|
|
1803
2542
|
}
|
|
1804
|
-
/**
|
|
2543
|
+
/**
|
|
2544
|
+
* Apply DM/group-DM fields in place.
|
|
2545
|
+
* @internal
|
|
2546
|
+
*/
|
|
2547
|
+
_patch(data) {
|
|
2548
|
+
super._patch(data);
|
|
2549
|
+
const full = data;
|
|
2550
|
+
if ("last_message_id" in full && full.last_message_id !== void 0) {
|
|
2551
|
+
this.lastMessageId = full.last_message_id ?? null;
|
|
2552
|
+
}
|
|
2553
|
+
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2554
|
+
if ("recipients" in full && full.recipients !== void 0) {
|
|
2555
|
+
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2556
|
+
}
|
|
2557
|
+
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Edit this group DM (name, icon, nicks).
|
|
2561
|
+
* Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
|
|
2562
|
+
*/
|
|
2563
|
+
async edit(options) {
|
|
2564
|
+
const data = await this.client.rest.patch(Routes9.channel(this.id), {
|
|
2565
|
+
body: toGroupDmEditBody(options),
|
|
2566
|
+
auth: true
|
|
2567
|
+
});
|
|
2568
|
+
this._patch(data);
|
|
2569
|
+
return this;
|
|
2570
|
+
}
|
|
2571
|
+
/**
|
|
2572
|
+
* Purge all messages from personal notes. Only works on personal notes channels.
|
|
2573
|
+
* Notes-only; bots usually skip this.
|
|
2574
|
+
*/
|
|
1805
2575
|
async purgeMessages() {
|
|
1806
2576
|
if (this.type !== ChannelType2.DMPersonalNotes) {
|
|
1807
2577
|
throw new FluxerError("purgeMessages is only available on personal notes channels", {
|
|
@@ -1814,15 +2584,24 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1814
2584
|
);
|
|
1815
2585
|
return data.deleted_count;
|
|
1816
2586
|
}
|
|
1817
|
-
/**
|
|
2587
|
+
/**
|
|
2588
|
+
* Pin this DM channel to the top of the DM list.
|
|
2589
|
+
* Session-token helper; bots usually skip this.
|
|
2590
|
+
*/
|
|
1818
2591
|
async pinInList() {
|
|
1819
2592
|
await this.client.rest.put(Routes9.userMeChannelPin(this.id), { auth: true });
|
|
1820
2593
|
}
|
|
1821
|
-
/**
|
|
2594
|
+
/**
|
|
2595
|
+
* Unpin this DM channel from the DM list.
|
|
2596
|
+
* Session-token helper; bots usually skip this.
|
|
2597
|
+
*/
|
|
1822
2598
|
async unpinFromList() {
|
|
1823
2599
|
await this.client.rest.delete(Routes9.userMeChannelPin(this.id), { auth: true });
|
|
1824
2600
|
}
|
|
1825
|
-
/**
|
|
2601
|
+
/**
|
|
2602
|
+
* Add a user to this group DM.
|
|
2603
|
+
* Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
|
|
2604
|
+
*/
|
|
1826
2605
|
async addRecipient(userId) {
|
|
1827
2606
|
await this.client.rest.put(Routes9.channelRecipient(this.id, userId), { auth: true });
|
|
1828
2607
|
const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
|
|
@@ -1838,7 +2617,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1838
2617
|
};
|
|
1839
2618
|
|
|
1840
2619
|
// src/Domain/Channel/Guild.ts
|
|
1841
|
-
import { Routes as
|
|
2620
|
+
import { Routes as Routes13 } from "@fluxerjs/types";
|
|
1842
2621
|
import { PermissionFlags } from "@fluxerjs/util";
|
|
1843
2622
|
|
|
1844
2623
|
// src/Domain/Invite.ts
|
|
@@ -1846,21 +2625,13 @@ import {
|
|
|
1846
2625
|
InviteType,
|
|
1847
2626
|
isGroupDmInvite,
|
|
1848
2627
|
isGuildInvite,
|
|
1849
|
-
isPackInvite,
|
|
1850
2628
|
Routes as Routes10
|
|
1851
2629
|
} from "@fluxerjs/types";
|
|
1852
2630
|
|
|
1853
2631
|
// src/Helpers/Instance.ts
|
|
1854
2632
|
import { isRecord } from "@fluxerjs/util";
|
|
1855
|
-
|
|
1856
|
-
// src/Helpers/Constants.ts
|
|
1857
|
-
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
1858
|
-
var CDN_URL = "https://fluxerusercontent.com";
|
|
1859
|
-
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1860
|
-
|
|
1861
|
-
// src/Helpers/Instance.ts
|
|
1862
2633
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
1863
|
-
api: "https://
|
|
2634
|
+
api: "https://web.fluxer.app/api",
|
|
1864
2635
|
api_client: "https://web.fluxer.app/api",
|
|
1865
2636
|
api_public: "https://api.fluxer.app",
|
|
1866
2637
|
gateway: "wss://gateway.fluxer.app",
|
|
@@ -1894,6 +2665,10 @@ function requireString(obj, key, path) {
|
|
|
1894
2665
|
}
|
|
1895
2666
|
return value;
|
|
1896
2667
|
}
|
|
2668
|
+
var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
|
|
2669
|
+
function instanceDiscoveryUrl(origin) {
|
|
2670
|
+
return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
|
|
2671
|
+
}
|
|
1897
2672
|
function normalizeApiOrigin(api) {
|
|
1898
2673
|
const trimmed = api.trim().replace(/\/+$/, "");
|
|
1899
2674
|
return trimmed.replace(/\/v\d+$/i, "");
|
|
@@ -1922,6 +2697,8 @@ function parseInstanceDiscovery(raw) {
|
|
|
1922
2697
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
1923
2698
|
}
|
|
1924
2699
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2700
|
+
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2701
|
+
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
1925
2702
|
endpoints.invite = normalizeInviteBase(endpoints.invite);
|
|
1926
2703
|
endpoints.media = endpoints.media.replace(/\/+$/, "");
|
|
1927
2704
|
endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
|
|
@@ -1999,6 +2776,11 @@ function resolveInstanceEndpoints(input) {
|
|
|
1999
2776
|
}
|
|
2000
2777
|
}
|
|
2001
2778
|
merged.api = normalizeApiOrigin(merged.api);
|
|
2779
|
+
merged.api_client = normalizeApiOrigin(merged.api_client);
|
|
2780
|
+
merged.api_public = normalizeApiOrigin(merged.api_public);
|
|
2781
|
+
if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
|
|
2782
|
+
merged.api_public = merged.api;
|
|
2783
|
+
}
|
|
2002
2784
|
merged.invite = normalizeInviteBase(merged.invite);
|
|
2003
2785
|
merged.media = merged.media.replace(/\/+$/, "");
|
|
2004
2786
|
merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
|
|
@@ -2007,13 +2789,13 @@ function resolveInstanceEndpoints(input) {
|
|
|
2007
2789
|
discovery: null
|
|
2008
2790
|
});
|
|
2009
2791
|
}
|
|
2010
|
-
function resolveRestApi(
|
|
2011
|
-
const fromInstance = normalizeApiOrigin(
|
|
2792
|
+
function resolveRestApi(instanceApiPublic, restApi) {
|
|
2793
|
+
const fromInstance = normalizeApiOrigin(instanceApiPublic);
|
|
2012
2794
|
if (restApi === void 0) return fromInstance;
|
|
2013
2795
|
const fromRest = normalizeApiOrigin(restApi);
|
|
2014
2796
|
if (fromRest !== fromInstance) {
|
|
2015
2797
|
throw new FluxerError(
|
|
2016
|
-
`Conflicting API hosts: instance.
|
|
2798
|
+
`Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
|
|
2017
2799
|
{ code: ErrorCodes.ConflictingInstanceConfig }
|
|
2018
2800
|
);
|
|
2019
2801
|
}
|
|
@@ -2049,13 +2831,36 @@ function parseInviteCode(codeOrUrl) {
|
|
|
2049
2831
|
}
|
|
2050
2832
|
return code;
|
|
2051
2833
|
}
|
|
2834
|
+
function parseOptionalDate(value) {
|
|
2835
|
+
if (value == null || value === "") return null;
|
|
2836
|
+
const date = new Date(value);
|
|
2837
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
2838
|
+
}
|
|
2839
|
+
function toInviteGuild(data) {
|
|
2840
|
+
return {
|
|
2841
|
+
id: data.id,
|
|
2842
|
+
name: data.name,
|
|
2843
|
+
icon: data.icon ?? null,
|
|
2844
|
+
banner: data.banner ?? null,
|
|
2845
|
+
splash: data.splash ?? null,
|
|
2846
|
+
features: data.features ?? []
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
function toInviteChannel(data) {
|
|
2850
|
+
return {
|
|
2851
|
+
id: data.id,
|
|
2852
|
+
name: data.name ?? null,
|
|
2853
|
+
type: data.type,
|
|
2854
|
+
icon: data.icon ?? null,
|
|
2855
|
+
parentId: data.parent_id ?? null
|
|
2856
|
+
};
|
|
2857
|
+
}
|
|
2052
2858
|
var Invite = class _Invite extends Base {
|
|
2053
2859
|
client;
|
|
2054
2860
|
code;
|
|
2055
2861
|
type;
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
pack;
|
|
2862
|
+
guildSnapshot;
|
|
2863
|
+
channelSnapshot;
|
|
2059
2864
|
inviter;
|
|
2060
2865
|
memberCount;
|
|
2061
2866
|
presenceCount;
|
|
@@ -2070,15 +2875,14 @@ var Invite = class _Invite extends Base {
|
|
|
2070
2875
|
this.client = client;
|
|
2071
2876
|
this.code = data.code;
|
|
2072
2877
|
this.type = data.type;
|
|
2073
|
-
this.
|
|
2074
|
-
this.
|
|
2075
|
-
this.pack = isPackInvite(data) ? data.pack : null;
|
|
2878
|
+
this.guildSnapshot = isGuildInvite(data) ? toInviteGuild(data.guild) : null;
|
|
2879
|
+
this.channelSnapshot = isGuildInvite(data) || isGroupDmInvite(data) ? toInviteChannel(data.channel) : null;
|
|
2076
2880
|
this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
|
|
2077
|
-
this.memberCount =
|
|
2881
|
+
this.memberCount = data.member_count ?? null;
|
|
2078
2882
|
this.presenceCount = isGuildInvite(data) ? data.presence_count ?? null : null;
|
|
2079
|
-
this.expiresAt = data.expires_at
|
|
2883
|
+
this.expiresAt = parseOptionalDate(data.expires_at);
|
|
2080
2884
|
this.temporary = data.temporary ?? null;
|
|
2081
|
-
this.createdAt = data.created_at
|
|
2885
|
+
this.createdAt = parseOptionalDate(data.created_at);
|
|
2082
2886
|
this.uses = data.uses ?? null;
|
|
2083
2887
|
this.maxUses = data.max_uses ?? null;
|
|
2084
2888
|
this.maxAge = data.max_age ?? null;
|
|
@@ -2089,16 +2893,25 @@ var Invite = class _Invite extends Base {
|
|
|
2089
2893
|
isGroupDM() {
|
|
2090
2894
|
return this.type === InviteType.GroupDM;
|
|
2091
2895
|
}
|
|
2092
|
-
isPack() {
|
|
2093
|
-
return this.type === InviteType.EmojiPack || this.type === InviteType.StickerPack;
|
|
2094
|
-
}
|
|
2095
2896
|
/** Full invite URL (uses this client's instance invite base). */
|
|
2096
2897
|
get url() {
|
|
2097
2898
|
return inviteUrl(this.client.instance.endpoints.invite, this.code);
|
|
2098
2899
|
}
|
|
2099
|
-
/**
|
|
2100
|
-
|
|
2101
|
-
|
|
2900
|
+
/**
|
|
2901
|
+
* Resolve the cached/fetched {@link Guild} for this invite, or null.
|
|
2902
|
+
* `guildSnapshot` is metadata only.
|
|
2903
|
+
*/
|
|
2904
|
+
async resolveGuild() {
|
|
2905
|
+
if (!this.guildSnapshot?.id) return null;
|
|
2906
|
+
return this.client.guilds.resolve(this.guildSnapshot.id);
|
|
2907
|
+
}
|
|
2908
|
+
/**
|
|
2909
|
+
* Resolve the cached/fetched {@link Channel} for this invite, or null.
|
|
2910
|
+
* `channelSnapshot` is metadata only.
|
|
2911
|
+
*/
|
|
2912
|
+
async resolveChannel() {
|
|
2913
|
+
if (!this.channelSnapshot?.id) return null;
|
|
2914
|
+
return this.client.channels.resolve(this.channelSnapshot.id);
|
|
2102
2915
|
}
|
|
2103
2916
|
/** Fetch invite metadata by code or URL (does not join). */
|
|
2104
2917
|
static async fetch(client, codeOrUrl) {
|
|
@@ -2116,69 +2929,7 @@ import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
|
|
|
2116
2929
|
import {
|
|
2117
2930
|
Routes as Routes11
|
|
2118
2931
|
} from "@fluxerjs/types";
|
|
2119
|
-
import { SnowflakeUtil as
|
|
2120
|
-
|
|
2121
|
-
// src/Helpers/Cdn.ts
|
|
2122
|
-
function mediaBase(options) {
|
|
2123
|
-
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
2124
|
-
}
|
|
2125
|
-
function staticBase(options) {
|
|
2126
|
-
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
2127
|
-
}
|
|
2128
|
-
function getExtension(hash, options) {
|
|
2129
|
-
const ext = options?.extension ?? "png";
|
|
2130
|
-
if (hash?.startsWith("a_")) return "gif";
|
|
2131
|
-
return ext;
|
|
2132
|
-
}
|
|
2133
|
-
function appendSize(options) {
|
|
2134
|
-
return options?.size ? `?size=${options.size}` : "";
|
|
2135
|
-
}
|
|
2136
|
-
function cdnAvatarURL(userId, avatarHash, options) {
|
|
2137
|
-
if (!avatarHash) return null;
|
|
2138
|
-
const ext = getExtension(avatarHash, options);
|
|
2139
|
-
const size = appendSize(options);
|
|
2140
|
-
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
2141
|
-
}
|
|
2142
|
-
function cdnDisplayAvatarURL(userId, avatarHash, options) {
|
|
2143
|
-
return cdnAvatarURL(userId, avatarHash, options) ?? cdnDefaultAvatarURL(userId, options);
|
|
2144
|
-
}
|
|
2145
|
-
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
2146
|
-
if (!bannerHash) return null;
|
|
2147
|
-
const ext = getExtension(bannerHash, options);
|
|
2148
|
-
const size = appendSize(options);
|
|
2149
|
-
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
2150
|
-
}
|
|
2151
|
-
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
2152
|
-
if (!avatarHash) return null;
|
|
2153
|
-
const ext = getExtension(avatarHash, options);
|
|
2154
|
-
const size = appendSize(options);
|
|
2155
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
2156
|
-
}
|
|
2157
|
-
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
2158
|
-
if (!bannerHash) return null;
|
|
2159
|
-
const ext = getExtension(bannerHash, options);
|
|
2160
|
-
const size = appendSize(options);
|
|
2161
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
2162
|
-
}
|
|
2163
|
-
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
2164
|
-
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
2165
|
-
return `${staticBase(options)}/avatars/${index}.png`;
|
|
2166
|
-
}
|
|
2167
|
-
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
2168
|
-
if (!hash) return null;
|
|
2169
|
-
const size = options?.size ? `?size=${options.size}` : "";
|
|
2170
|
-
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
2171
|
-
}
|
|
2172
|
-
function cdnEmojiURL(emojiId, animated, options) {
|
|
2173
|
-
const ext = animated ? "gif" : "png";
|
|
2174
|
-
return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
|
|
2175
|
-
}
|
|
2176
|
-
function cdnStickerURL(stickerId, animated, options) {
|
|
2177
|
-
const ext = animated ? "gif" : "png";
|
|
2178
|
-
return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
|
-
// src/Domain/Webhook.ts
|
|
2932
|
+
import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
|
|
2182
2933
|
var Webhook = class _Webhook extends Base {
|
|
2183
2934
|
/** Parent client instance. */
|
|
2184
2935
|
client;
|
|
@@ -2215,11 +2966,11 @@ var Webhook = class _Webhook extends Base {
|
|
|
2215
2966
|
}
|
|
2216
2967
|
/** Unix timestamp (ms) when this webhook was created, derived from its snowflake ID. */
|
|
2217
2968
|
get createdTimestamp() {
|
|
2218
|
-
return
|
|
2969
|
+
return SnowflakeUtil4.timestampFromSnowflake(this.id);
|
|
2219
2970
|
}
|
|
2220
2971
|
/** Date when this webhook was created, derived from its snowflake ID. */
|
|
2221
2972
|
get createdAt() {
|
|
2222
|
-
return
|
|
2973
|
+
return SnowflakeUtil4.dateFromSnowflake(this.id);
|
|
2223
2974
|
}
|
|
2224
2975
|
/** Delete this webhook (token auth when available, otherwise bot auth). */
|
|
2225
2976
|
async delete() {
|
|
@@ -2341,9 +3092,103 @@ var Webhook = class _Webhook extends Base {
|
|
|
2341
3092
|
}
|
|
2342
3093
|
};
|
|
2343
3094
|
|
|
3095
|
+
// src/Domain/Channel/PermissionOverwriteManager.ts
|
|
3096
|
+
import { Collection as Collection6 } from "@fluxerjs/collection";
|
|
3097
|
+
import { Routes as Routes12 } from "@fluxerjs/types";
|
|
3098
|
+
import { resolvePermissionsToBitfield as resolvePermissionsToBitfield3 } from "@fluxerjs/util";
|
|
3099
|
+
|
|
3100
|
+
// src/Domain/Channel/PermissionOverwrite.ts
|
|
3101
|
+
import { PermissionsBitField } from "@fluxerjs/util";
|
|
3102
|
+
var PermissionOverwrite = class {
|
|
3103
|
+
id;
|
|
3104
|
+
type;
|
|
3105
|
+
/** @internal Raw allow bitfield string. */
|
|
3106
|
+
_allow;
|
|
3107
|
+
/** @internal Raw deny bitfield string. */
|
|
3108
|
+
_deny;
|
|
3109
|
+
constructor(data) {
|
|
3110
|
+
this.id = data.id;
|
|
3111
|
+
this.type = data.type;
|
|
3112
|
+
this._allow = data.allow ?? "0";
|
|
3113
|
+
this._deny = data.deny ?? "0";
|
|
3114
|
+
}
|
|
3115
|
+
/** Allowed permissions for this overwrite. */
|
|
3116
|
+
get allow() {
|
|
3117
|
+
return new PermissionsBitField(BigInt(this._allow || "0"));
|
|
3118
|
+
}
|
|
3119
|
+
/** Denied permissions for this overwrite. */
|
|
3120
|
+
get deny() {
|
|
3121
|
+
return new PermissionsBitField(BigInt(this._deny || "0"));
|
|
3122
|
+
}
|
|
3123
|
+
/** Wire shape for permission computation / REST. */
|
|
3124
|
+
toJSON() {
|
|
3125
|
+
return {
|
|
3126
|
+
id: this.id,
|
|
3127
|
+
type: this.type,
|
|
3128
|
+
allow: this._allow,
|
|
3129
|
+
deny: this._deny
|
|
3130
|
+
};
|
|
3131
|
+
}
|
|
3132
|
+
};
|
|
3133
|
+
|
|
3134
|
+
// src/Domain/Channel/PermissionOverwriteManager.ts
|
|
3135
|
+
var PermissionOverwriteManager = class {
|
|
3136
|
+
constructor(channel, initial = []) {
|
|
3137
|
+
this.channel = channel;
|
|
3138
|
+
this._patch(initial);
|
|
3139
|
+
}
|
|
3140
|
+
_cache = new Collection6();
|
|
3141
|
+
/** Cached overwrites keyed by role/member ID. */
|
|
3142
|
+
get cache() {
|
|
3143
|
+
return this._cache;
|
|
3144
|
+
}
|
|
3145
|
+
get size() {
|
|
3146
|
+
return this._cache.size;
|
|
3147
|
+
}
|
|
3148
|
+
[Symbol.iterator]() {
|
|
3149
|
+
return this._cache.values();
|
|
3150
|
+
}
|
|
3151
|
+
/** Wire-shaped overwrites for permission computation. */
|
|
3152
|
+
toJSON() {
|
|
3153
|
+
return [...this._cache.values()].map((o) => o.toJSON());
|
|
3154
|
+
}
|
|
3155
|
+
/** Edit or create a permission overwrite. */
|
|
3156
|
+
async edit(overwriteId, options) {
|
|
3157
|
+
const allow = options.allow !== void 0 ? resolvePermissionsToBitfield3(options.allow) : "0";
|
|
3158
|
+
const deny = options.deny !== void 0 ? resolvePermissionsToBitfield3(options.deny) : "0";
|
|
3159
|
+
await this.channel.client.rest.put(Routes12.channelPermission(this.channel.id, overwriteId), {
|
|
3160
|
+
body: { type: options.type, allow, deny },
|
|
3161
|
+
auth: true
|
|
3162
|
+
});
|
|
3163
|
+
this._cache.set(
|
|
3164
|
+
overwriteId,
|
|
3165
|
+
new PermissionOverwrite({
|
|
3166
|
+
id: overwriteId,
|
|
3167
|
+
type: options.type,
|
|
3168
|
+
allow,
|
|
3169
|
+
deny
|
|
3170
|
+
})
|
|
3171
|
+
);
|
|
3172
|
+
}
|
|
3173
|
+
/** Delete a permission overwrite. */
|
|
3174
|
+
async delete(overwriteId) {
|
|
3175
|
+
await this.channel.client.rest.delete(Routes12.channelPermission(this.channel.id, overwriteId), {
|
|
3176
|
+
auth: true
|
|
3177
|
+
});
|
|
3178
|
+
this._cache.delete(overwriteId);
|
|
3179
|
+
}
|
|
3180
|
+
/** @internal Sync from an API channel payload. */
|
|
3181
|
+
_patch(overwrites) {
|
|
3182
|
+
this._cache.clear();
|
|
3183
|
+
for (const entry of overwrites ?? []) {
|
|
3184
|
+
this._cache.set(entry.id, new PermissionOverwrite(entry));
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
};
|
|
3188
|
+
|
|
2344
3189
|
// src/Domain/Channel/Guild.ts
|
|
2345
3190
|
var GuildChannel = class extends Channel {
|
|
2346
|
-
/** Guild ID this channel belongs to. */
|
|
3191
|
+
/** Guild ID this channel belongs to, or null if missing from the payload. */
|
|
2347
3192
|
guildId;
|
|
2348
3193
|
/** Position in the channel list. */
|
|
2349
3194
|
position;
|
|
@@ -2353,11 +3198,14 @@ var GuildChannel = class extends Channel {
|
|
|
2353
3198
|
permissionOverwrites;
|
|
2354
3199
|
constructor(client, data) {
|
|
2355
3200
|
super(client, data);
|
|
2356
|
-
this.guildId = data.guild_id ??
|
|
3201
|
+
this.guildId = data.guild_id ?? null;
|
|
2357
3202
|
this.name = data.name ?? null;
|
|
2358
3203
|
this.position = data.position;
|
|
2359
3204
|
this.parentId = data.parent_id ?? null;
|
|
2360
|
-
this.permissionOverwrites =
|
|
3205
|
+
this.permissionOverwrites = new PermissionOverwriteManager(
|
|
3206
|
+
this,
|
|
3207
|
+
data.permission_overwrites ?? []
|
|
3208
|
+
);
|
|
2361
3209
|
}
|
|
2362
3210
|
/**
|
|
2363
3211
|
* Apply guild-channel fields in place.
|
|
@@ -2369,13 +3217,13 @@ var GuildChannel = class extends Channel {
|
|
|
2369
3217
|
if (data.position !== void 0) this.position = data.position;
|
|
2370
3218
|
if (data.parent_id !== void 0) this.parentId = data.parent_id ?? null;
|
|
2371
3219
|
if (data.permission_overwrites !== void 0) {
|
|
2372
|
-
this.permissionOverwrites
|
|
3220
|
+
this.permissionOverwrites._patch(data.permission_overwrites ?? []);
|
|
2373
3221
|
}
|
|
2374
3222
|
this.applyEditPatch(data);
|
|
2375
3223
|
}
|
|
2376
3224
|
/** Create a webhook for this channel. Requires Manage Webhooks. */
|
|
2377
3225
|
async createWebhook(options) {
|
|
2378
|
-
const data = await this.client.rest.post(
|
|
3226
|
+
const data = await this.client.rest.post(Routes13.channelWebhooks(this.id), {
|
|
2379
3227
|
body: options,
|
|
2380
3228
|
auth: true
|
|
2381
3229
|
});
|
|
@@ -2383,13 +3231,13 @@ var GuildChannel = class extends Channel {
|
|
|
2383
3231
|
}
|
|
2384
3232
|
/** Fetch all webhooks in this channel. Requires Manage Webhooks. */
|
|
2385
3233
|
async fetchWebhooks() {
|
|
2386
|
-
const data = await this.client.rest.get(
|
|
3234
|
+
const data = await this.client.rest.get(Routes13.channelWebhooks(this.id));
|
|
2387
3235
|
return data.map((w) => new Webhook(this.client, w));
|
|
2388
3236
|
}
|
|
2389
3237
|
/** Create an invite for this channel. Requires Create Instant Invite. */
|
|
2390
3238
|
async createInvite(options) {
|
|
2391
3239
|
const body = options ? toChannelInviteBody(options) : {};
|
|
2392
|
-
const data = await this.client.rest.post(
|
|
3240
|
+
const data = await this.client.rest.post(Routes13.channelInvites(this.id), {
|
|
2393
3241
|
body: Object.keys(body).length ? body : void 0,
|
|
2394
3242
|
auth: true
|
|
2395
3243
|
});
|
|
@@ -2397,109 +3245,161 @@ var GuildChannel = class extends Channel {
|
|
|
2397
3245
|
}
|
|
2398
3246
|
/** Fetch all invites for this channel. Requires Manage Channels. */
|
|
2399
3247
|
async fetchInvites() {
|
|
2400
|
-
const data = await this.client.rest.get(
|
|
3248
|
+
const data = await this.client.rest.get(Routes13.channelInvites(this.id));
|
|
2401
3249
|
return data.map((i) => new Invite(this.client, i));
|
|
2402
3250
|
}
|
|
2403
|
-
/**
|
|
2404
|
-
async editPermission(overwriteId, options) {
|
|
2405
|
-
await this.client.rest.put(Routes12.channelPermission(this.id, overwriteId), {
|
|
2406
|
-
body: options,
|
|
2407
|
-
auth: true
|
|
2408
|
-
});
|
|
2409
|
-
const entry = {
|
|
2410
|
-
id: overwriteId,
|
|
2411
|
-
type: options.type,
|
|
2412
|
-
allow: options.allow ?? "0",
|
|
2413
|
-
deny: options.deny ?? "0"
|
|
2414
|
-
};
|
|
2415
|
-
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
2416
|
-
if (idx >= 0) this.permissionOverwrites[idx] = entry;
|
|
2417
|
-
else this.permissionOverwrites.push(entry);
|
|
2418
|
-
}
|
|
2419
|
-
/** Delete a permission overwrite. Requires Manage Roles. */
|
|
2420
|
-
async deletePermission(overwriteId) {
|
|
2421
|
-
await this.client.rest.delete(Routes12.channelPermission(this.id, overwriteId), { auth: true });
|
|
2422
|
-
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
2423
|
-
if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
|
|
2424
|
-
}
|
|
2425
|
-
/** Check if the bot can send messages in this channel (with permissions). */
|
|
3251
|
+
/** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
|
|
2426
3252
|
canSendMessage() {
|
|
3253
|
+
if (!this.guildId) return false;
|
|
2427
3254
|
const me = this.client.guilds.get(this.guildId)?.members.me;
|
|
2428
3255
|
if (!me) return false;
|
|
2429
3256
|
const perms = me.permissionsIn(this);
|
|
2430
3257
|
return perms.has(PermissionFlags.ViewChannel) && perms.has(PermissionFlags.SendMessages);
|
|
2431
3258
|
}
|
|
3259
|
+
/**
|
|
3260
|
+
* Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
|
|
3261
|
+
* Returns false when the channel has no guildId.
|
|
3262
|
+
*/
|
|
3263
|
+
async canSend() {
|
|
3264
|
+
if (!this.guildId) return false;
|
|
3265
|
+
const guild = this.client.guilds.get(this.guildId);
|
|
3266
|
+
if (!guild) return false;
|
|
3267
|
+
if (!guild.members.me) {
|
|
3268
|
+
try {
|
|
3269
|
+
await guild.members.fetchMe();
|
|
3270
|
+
} catch {
|
|
3271
|
+
return false;
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
return this.canSendMessage();
|
|
3275
|
+
}
|
|
2432
3276
|
/** Edit this channel's settings. Requires Manage Channels. */
|
|
2433
3277
|
async edit(options) {
|
|
2434
|
-
const data = await this.client.rest.patch(
|
|
3278
|
+
const data = await this.client.rest.patch(Routes13.channel(this.id), {
|
|
2435
3279
|
body: toChannelEditBody(options),
|
|
2436
|
-
auth: true
|
|
3280
|
+
auth: true,
|
|
3281
|
+
...auditReasonHeaders(options.reason)
|
|
2437
3282
|
});
|
|
2438
3283
|
this.name = data.name ?? this.name;
|
|
2439
3284
|
this.parentId = data.parent_id ?? this.parentId;
|
|
2440
|
-
|
|
3285
|
+
if (data.permission_overwrites !== void 0) {
|
|
3286
|
+
this.permissionOverwrites._patch(data.permission_overwrites);
|
|
3287
|
+
}
|
|
2441
3288
|
this.applyEditPatch(data);
|
|
2442
3289
|
return this;
|
|
2443
3290
|
}
|
|
2444
3291
|
applyEditPatch(_data) {
|
|
2445
3292
|
}
|
|
2446
|
-
/** Delete this channel. Requires Manage Channels or channel ownership. */
|
|
2447
|
-
async delete(options) {
|
|
2448
|
-
const params = new URLSearchParams();
|
|
2449
|
-
if (options?.silent) params.set("silent", "true");
|
|
2450
|
-
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2451
|
-
const qs2 = params.toString();
|
|
2452
|
-
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2453
|
-
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2454
|
-
await this.client.rest.delete(Routes12.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2455
|
-
body,
|
|
2456
|
-
auth: true
|
|
2457
|
-
});
|
|
2458
|
-
this.client.channels.delete(this.id);
|
|
2459
|
-
this.client._clearMessageCache(this.id);
|
|
2460
|
-
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
2461
|
-
}
|
|
2462
3293
|
};
|
|
2463
3294
|
var TextChannel = class extends TextCapable(GuildChannel) {
|
|
2464
3295
|
/** Channel topic. */
|
|
2465
3296
|
topic;
|
|
2466
3297
|
/** Whether this channel is marked as NSFW. */
|
|
2467
3298
|
nsfw;
|
|
3299
|
+
/** Per-channel NSFW override (`null` inherits). */
|
|
3300
|
+
nsfwOverride;
|
|
2468
3301
|
/** Slowmode rate limit in seconds. */
|
|
2469
3302
|
rateLimitPerUser;
|
|
2470
3303
|
/** ID of the last message sent in this channel. */
|
|
2471
3304
|
lastMessageId;
|
|
3305
|
+
/** Content warning level. */
|
|
3306
|
+
contentWarningLevel;
|
|
3307
|
+
/** Custom content warning text. */
|
|
3308
|
+
contentWarningText;
|
|
2472
3309
|
constructor(client, data) {
|
|
2473
3310
|
super(client, data);
|
|
2474
3311
|
this.topic = data.topic ?? null;
|
|
2475
3312
|
this.nsfw = data.nsfw ?? false;
|
|
3313
|
+
this.nsfwOverride = data.nsfw_override ?? null;
|
|
2476
3314
|
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
2477
3315
|
this.lastMessageId = data.last_message_id ?? null;
|
|
3316
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3317
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3318
|
+
}
|
|
3319
|
+
/**
|
|
3320
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3321
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3322
|
+
*/
|
|
3323
|
+
async setSlowmode(seconds) {
|
|
3324
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
2478
3325
|
}
|
|
2479
3326
|
applyEditPatch(data) {
|
|
2480
3327
|
if ("topic" in data) this.topic = data.topic ?? null;
|
|
2481
3328
|
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3329
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
2482
3330
|
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3331
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3332
|
+
if ("content_warning_level" in data) {
|
|
3333
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3334
|
+
}
|
|
3335
|
+
if ("content_warning_text" in data) {
|
|
3336
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3337
|
+
}
|
|
2483
3338
|
}
|
|
2484
3339
|
};
|
|
2485
3340
|
var CategoryChannel = class extends GuildChannel {
|
|
2486
3341
|
};
|
|
2487
|
-
var VoiceChannel = class extends GuildChannel {
|
|
3342
|
+
var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
3343
|
+
/** Channel topic. */
|
|
3344
|
+
topic;
|
|
3345
|
+
/** Whether this channel is marked as NSFW. */
|
|
3346
|
+
nsfw;
|
|
3347
|
+
/** Per-channel NSFW override (`null` inherits). */
|
|
3348
|
+
nsfwOverride;
|
|
3349
|
+
/** Slowmode rate limit in seconds. */
|
|
3350
|
+
rateLimitPerUser;
|
|
3351
|
+
/** ID of the last message sent in this channel. */
|
|
3352
|
+
lastMessageId;
|
|
3353
|
+
/** Content warning level. */
|
|
3354
|
+
contentWarningLevel;
|
|
3355
|
+
/** Custom content warning text. */
|
|
3356
|
+
contentWarningText;
|
|
2488
3357
|
/** Voice bitrate. */
|
|
2489
3358
|
bitrate;
|
|
2490
3359
|
/** Maximum number of users allowed. */
|
|
2491
3360
|
userLimit;
|
|
3361
|
+
/** Max active voice connections per user. */
|
|
3362
|
+
voiceConnectionLimit;
|
|
2492
3363
|
/** RTC region override for this channel. */
|
|
2493
3364
|
rtcRegion;
|
|
2494
3365
|
constructor(client, data) {
|
|
2495
3366
|
super(client, data);
|
|
3367
|
+
this.topic = data.topic ?? null;
|
|
3368
|
+
this.nsfw = data.nsfw ?? false;
|
|
3369
|
+
this.nsfwOverride = data.nsfw_override ?? null;
|
|
3370
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3371
|
+
this.lastMessageId = data.last_message_id ?? null;
|
|
3372
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3373
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
2496
3374
|
this.bitrate = data.bitrate ?? null;
|
|
2497
3375
|
this.userLimit = data.user_limit ?? null;
|
|
3376
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
2498
3377
|
this.rtcRegion = data.rtc_region ?? null;
|
|
2499
3378
|
}
|
|
3379
|
+
/**
|
|
3380
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3381
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3382
|
+
*/
|
|
3383
|
+
async setSlowmode(seconds) {
|
|
3384
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
3385
|
+
}
|
|
2500
3386
|
applyEditPatch(data) {
|
|
3387
|
+
if ("topic" in data) this.topic = data.topic ?? null;
|
|
3388
|
+
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3389
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
3390
|
+
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3391
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3392
|
+
if ("content_warning_level" in data) {
|
|
3393
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3394
|
+
}
|
|
3395
|
+
if ("content_warning_text" in data) {
|
|
3396
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3397
|
+
}
|
|
2501
3398
|
if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
|
|
2502
3399
|
if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
|
|
3400
|
+
if ("voice_connection_limit" in data) {
|
|
3401
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3402
|
+
}
|
|
2503
3403
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
2504
3404
|
}
|
|
2505
3405
|
};
|
|
@@ -2510,6 +3410,9 @@ var LinkChannel = class extends GuildChannel {
|
|
|
2510
3410
|
super(client, data);
|
|
2511
3411
|
this.url = data.url ?? null;
|
|
2512
3412
|
}
|
|
3413
|
+
applyEditPatch(data) {
|
|
3414
|
+
if ("url" in data) this.url = data.url ?? null;
|
|
3415
|
+
}
|
|
2513
3416
|
};
|
|
2514
3417
|
|
|
2515
3418
|
// src/Domain/Channel/Factory.ts
|
|
@@ -2542,8 +3445,8 @@ Channel.fromOrCreate = channelFromOrCreate;
|
|
|
2542
3445
|
Channel.createDM = createDM;
|
|
2543
3446
|
|
|
2544
3447
|
// src/Domain/Guild/GuildEmoji.ts
|
|
2545
|
-
import { Routes as
|
|
2546
|
-
import { SnowflakeUtil as
|
|
3448
|
+
import { Routes as Routes14 } from "@fluxerjs/types";
|
|
3449
|
+
import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
|
|
2547
3450
|
var GuildEmoji = class extends Base {
|
|
2548
3451
|
client;
|
|
2549
3452
|
id;
|
|
@@ -2579,20 +3482,21 @@ var GuildEmoji = class extends Base {
|
|
|
2579
3482
|
}
|
|
2580
3483
|
/** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
|
|
2581
3484
|
get createdTimestamp() {
|
|
2582
|
-
return
|
|
3485
|
+
return SnowflakeUtil5.timestampFromSnowflake(this.id);
|
|
2583
3486
|
}
|
|
2584
3487
|
/** Date when this emoji was created, derived from its snowflake ID. */
|
|
2585
3488
|
get createdAt() {
|
|
2586
|
-
return
|
|
3489
|
+
return SnowflakeUtil5.dateFromSnowflake(this.id);
|
|
2587
3490
|
}
|
|
2588
3491
|
/** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
|
|
2589
3492
|
toString() {
|
|
2590
3493
|
return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
|
|
2591
3494
|
}
|
|
2592
3495
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
2593
|
-
async delete() {
|
|
2594
|
-
await this.client.rest.delete(
|
|
2595
|
-
auth: true
|
|
3496
|
+
async delete(reason) {
|
|
3497
|
+
await this.client.rest.delete(Routes14.guildEmoji(this.guildId, this.id), {
|
|
3498
|
+
auth: true,
|
|
3499
|
+
...auditReasonHeaders(reason)
|
|
2596
3500
|
});
|
|
2597
3501
|
const guild = this.client.guilds.get(this.guildId);
|
|
2598
3502
|
if (guild) guild.emojis.delete(this.id);
|
|
@@ -2602,9 +3506,11 @@ var GuildEmoji = class extends Base {
|
|
|
2602
3506
|
* Requires Manage Emojis and Stickers permission.
|
|
2603
3507
|
*/
|
|
2604
3508
|
async edit(options) {
|
|
2605
|
-
const
|
|
2606
|
-
|
|
2607
|
-
|
|
3509
|
+
const { reason, name } = options;
|
|
3510
|
+
const data = await this.client.rest.patch(Routes14.guildEmoji(this.guildId, this.id), {
|
|
3511
|
+
body: { name },
|
|
3512
|
+
auth: true,
|
|
3513
|
+
...auditReasonHeaders(reason)
|
|
2608
3514
|
});
|
|
2609
3515
|
this.name = data.name;
|
|
2610
3516
|
return this;
|
|
@@ -2612,14 +3518,17 @@ var GuildEmoji = class extends Base {
|
|
|
2612
3518
|
};
|
|
2613
3519
|
|
|
2614
3520
|
// src/Domain/Guild/GuildMember.ts
|
|
2615
|
-
import { Routes as
|
|
2616
|
-
import { PermissionsBitField } from "@fluxerjs/util";
|
|
3521
|
+
import { Routes as Routes16 } from "@fluxerjs/types";
|
|
3522
|
+
import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
|
|
2617
3523
|
|
|
2618
3524
|
// src/Helpers/Permissions.ts
|
|
2619
3525
|
import { OverwriteType } from "@fluxerjs/types";
|
|
2620
3526
|
import { ALL_PERMISSIONS_BIGINT, PermissionFlags as PermissionFlags2 } from "@fluxerjs/util";
|
|
2621
3527
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
2622
3528
|
if (isOwner) return ALL_PERMISSIONS_BIGINT;
|
|
3529
|
+
if ((basePermissions & PermissionFlags2.Administrator) !== 0n) {
|
|
3530
|
+
return ALL_PERMISSIONS_BIGINT;
|
|
3531
|
+
}
|
|
2623
3532
|
let perms = basePermissions;
|
|
2624
3533
|
for (const overwrite of overwrites ?? []) {
|
|
2625
3534
|
const applies = overwrite.type === OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === OverwriteType.Member && overwrite.id === memberId;
|
|
@@ -2628,12 +3537,12 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
2628
3537
|
const deny = BigInt(overwrite.deny || "0");
|
|
2629
3538
|
perms = perms & ~deny | allow;
|
|
2630
3539
|
}
|
|
2631
|
-
return
|
|
3540
|
+
return perms;
|
|
2632
3541
|
}
|
|
2633
3542
|
|
|
2634
3543
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
2635
|
-
import { Collection as
|
|
2636
|
-
import { Routes as
|
|
3544
|
+
import { Collection as Collection7 } from "@fluxerjs/collection";
|
|
3545
|
+
import { Routes as Routes15 } from "@fluxerjs/types";
|
|
2637
3546
|
function roleId(roleOrId) {
|
|
2638
3547
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
2639
3548
|
}
|
|
@@ -2651,7 +3560,7 @@ var GuildMemberRoleManager = class {
|
|
|
2651
3560
|
}
|
|
2652
3561
|
/** Live Role objects from `guild.roles` for this member's role IDs. */
|
|
2653
3562
|
get cache() {
|
|
2654
|
-
const out = new
|
|
3563
|
+
const out = new Collection7();
|
|
2655
3564
|
for (const id of this.ids) {
|
|
2656
3565
|
const role = this.member.guild.roles.get(id);
|
|
2657
3566
|
if (role) out.set(id, role);
|
|
@@ -2662,7 +3571,7 @@ var GuildMemberRoleManager = class {
|
|
|
2662
3571
|
const id = roleId(roleOrId);
|
|
2663
3572
|
if (this.ids.includes(id)) return;
|
|
2664
3573
|
await this.member.client.rest.put(
|
|
2665
|
-
|
|
3574
|
+
Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2666
3575
|
);
|
|
2667
3576
|
this.ids.push(id);
|
|
2668
3577
|
}
|
|
@@ -2671,13 +3580,13 @@ var GuildMemberRoleManager = class {
|
|
|
2671
3580
|
const idx = this.ids.indexOf(id);
|
|
2672
3581
|
if (idx === -1) return;
|
|
2673
3582
|
await this.member.client.rest.delete(
|
|
2674
|
-
|
|
3583
|
+
Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2675
3584
|
);
|
|
2676
3585
|
this.ids.splice(idx, 1);
|
|
2677
3586
|
}
|
|
2678
3587
|
async set(roleIds) {
|
|
2679
3588
|
const data = await this.member.client.rest.patch(
|
|
2680
|
-
|
|
3589
|
+
Routes15.guildMember(this.member.guild.id, this.member.id),
|
|
2681
3590
|
{ body: { roles: roleIds }, auth: true }
|
|
2682
3591
|
);
|
|
2683
3592
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -2690,6 +3599,8 @@ var GuildMemberRoleManager = class {
|
|
|
2690
3599
|
|
|
2691
3600
|
// src/Domain/Guild/GuildMember.ts
|
|
2692
3601
|
var GuildMember = class _GuildMember extends Base {
|
|
3602
|
+
/** Discriminant vs {@link PartialGuildMember}: always `false` on a hydrated member. */
|
|
3603
|
+
partial = false;
|
|
2693
3604
|
/** Parent client instance. */
|
|
2694
3605
|
client;
|
|
2695
3606
|
/** User ID (same as `user.id`). */
|
|
@@ -2718,6 +3629,12 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2718
3629
|
accentColor;
|
|
2719
3630
|
/** Guild-specific profile flags. */
|
|
2720
3631
|
profileFlags;
|
|
3632
|
+
/** Per-guild reply mention preference override. */
|
|
3633
|
+
mentionFlags;
|
|
3634
|
+
/** Guild-specific bio (set from member edit; not always on GET member). */
|
|
3635
|
+
bio;
|
|
3636
|
+
/** Guild-specific pronouns (set from member edit; not always on GET member). */
|
|
3637
|
+
pronouns;
|
|
2721
3638
|
constructor(client, data, guild) {
|
|
2722
3639
|
super();
|
|
2723
3640
|
this.client = client;
|
|
@@ -2734,6 +3651,9 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2734
3651
|
this.banner = data.banner ?? null;
|
|
2735
3652
|
this.accentColor = data.accent_color ?? null;
|
|
2736
3653
|
this.profileFlags = data.profile_flags ?? null;
|
|
3654
|
+
this.mentionFlags = data.mention_flags ?? null;
|
|
3655
|
+
this.bio = data.bio ?? null;
|
|
3656
|
+
this.pronouns = data.pronouns ?? null;
|
|
2737
3657
|
}
|
|
2738
3658
|
/**
|
|
2739
3659
|
* Apply an API member payload in place (gateway GUILD_MEMBER_UPDATE / REST edit).
|
|
@@ -2752,6 +3672,9 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2752
3672
|
if (data.banner !== void 0) this.banner = data.banner ?? null;
|
|
2753
3673
|
if (data.accent_color !== void 0) this.accentColor = data.accent_color ?? null;
|
|
2754
3674
|
if (data.profile_flags !== void 0) this.profileFlags = data.profile_flags ?? null;
|
|
3675
|
+
if (data.mention_flags !== void 0) this.mentionFlags = data.mention_flags ?? null;
|
|
3676
|
+
if (data.bio !== void 0) this.bio = data.bio ?? null;
|
|
3677
|
+
if (data.pronouns !== void 0) this.pronouns = data.pronouns ?? null;
|
|
2755
3678
|
}
|
|
2756
3679
|
/**
|
|
2757
3680
|
* Snapshot for `guildMemberUpdate` old-member arg (before in-place patch).
|
|
@@ -2780,7 +3703,10 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2780
3703
|
avatar: this.avatar,
|
|
2781
3704
|
banner: this.banner,
|
|
2782
3705
|
accent_color: this.accentColor,
|
|
2783
|
-
profile_flags: this.profileFlags ?? void 0
|
|
3706
|
+
profile_flags: this.profileFlags ?? void 0,
|
|
3707
|
+
mention_flags: this.mentionFlags,
|
|
3708
|
+
bio: this.bio,
|
|
3709
|
+
pronouns: this.pronouns
|
|
2784
3710
|
},
|
|
2785
3711
|
this.guild
|
|
2786
3712
|
);
|
|
@@ -2807,15 +3733,23 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2807
3733
|
mediaBase: this.client.instance.endpoints.media
|
|
2808
3734
|
});
|
|
2809
3735
|
}
|
|
2810
|
-
/**
|
|
3736
|
+
/**
|
|
3737
|
+
* PATCH member (`/members/@me` when editing the bot).
|
|
3738
|
+
* @example
|
|
3739
|
+
* await member.edit({ nick: 'Ada' });
|
|
3740
|
+
*/
|
|
2811
3741
|
async edit(options) {
|
|
2812
3742
|
const isMe = this.client.user?.id === this.id;
|
|
2813
|
-
const route = isMe ?
|
|
3743
|
+
const route = isMe ? Routes16.guildMemberMe(this.guild.id) : Routes16.guildMember(this.guild.id, this.id);
|
|
2814
3744
|
const data = await this.client.rest.patch(route, {
|
|
2815
3745
|
body: toMemberEditBody(options),
|
|
2816
|
-
auth: true
|
|
3746
|
+
auth: true,
|
|
3747
|
+
...auditReasonHeaders(options.reason ?? options.timeoutReason)
|
|
2817
3748
|
});
|
|
2818
3749
|
this._patch(data);
|
|
3750
|
+
if (options.bio !== void 0) this.bio = options.bio;
|
|
3751
|
+
if (options.pronouns !== void 0) this.pronouns = options.pronouns;
|
|
3752
|
+
if (options.mentionFlags !== void 0) this.mentionFlags = options.mentionFlags;
|
|
2819
3753
|
return this;
|
|
2820
3754
|
}
|
|
2821
3755
|
/**
|
|
@@ -2823,7 +3757,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2823
3757
|
* @see {@link permissionsIn} for channel-specific permissions
|
|
2824
3758
|
*/
|
|
2825
3759
|
get permissions() {
|
|
2826
|
-
return new
|
|
3760
|
+
return new PermissionsBitField2(this._effectivePermissions([], []));
|
|
2827
3761
|
}
|
|
2828
3762
|
/**
|
|
2829
3763
|
* Effective permissions in a channel (roles + overwrites).
|
|
@@ -2831,8 +3765,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2831
3765
|
* @returns Computed permissions bitfield
|
|
2832
3766
|
*/
|
|
2833
3767
|
permissionsIn(channel) {
|
|
2834
|
-
return new
|
|
2835
|
-
this._effectivePermissions(channel.permissionOverwrites, [...this.roles.roleIds])
|
|
3768
|
+
return new PermissionsBitField2(
|
|
3769
|
+
this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
|
|
2836
3770
|
);
|
|
2837
3771
|
}
|
|
2838
3772
|
/**
|
|
@@ -2843,6 +3777,63 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2843
3777
|
async move(channelId, connectionId) {
|
|
2844
3778
|
await this.edit({ channelId, connectionId });
|
|
2845
3779
|
}
|
|
3780
|
+
/** Kick this member. Requires Kick Members. */
|
|
3781
|
+
async kick(reason) {
|
|
3782
|
+
await this.guild.kick(this.id, reason);
|
|
3783
|
+
}
|
|
3784
|
+
/** Ban this member. Requires Ban Members. */
|
|
3785
|
+
async ban(options) {
|
|
3786
|
+
await this.guild.ban(this.id, options);
|
|
3787
|
+
}
|
|
3788
|
+
/**
|
|
3789
|
+
* Whether the bot can kick this member (cache-only; needs `members.me`).
|
|
3790
|
+
* False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
|
|
3791
|
+
*/
|
|
3792
|
+
get kickable() {
|
|
3793
|
+
return this._moderatableWith(PermissionFlags3.KickMembers);
|
|
3794
|
+
}
|
|
3795
|
+
/**
|
|
3796
|
+
* Whether the bot can ban this member (cache-only; needs `members.me`).
|
|
3797
|
+
*/
|
|
3798
|
+
get bannable() {
|
|
3799
|
+
return this._moderatableWith(PermissionFlags3.BanMembers);
|
|
3800
|
+
}
|
|
3801
|
+
/**
|
|
3802
|
+
* Whether the bot can timeout this member (cache-only; needs `members.me`).
|
|
3803
|
+
*/
|
|
3804
|
+
get moderatable() {
|
|
3805
|
+
return this._moderatableWith(PermissionFlags3.ModerateMembers);
|
|
3806
|
+
}
|
|
3807
|
+
_moderatableWith(flag) {
|
|
3808
|
+
const me = this.guild.members.me;
|
|
3809
|
+
if (!me) return false;
|
|
3810
|
+
if (this.id === me.id) return false;
|
|
3811
|
+
if (this.guild.ownerId != null && String(this.guild.ownerId) === String(this.id)) return false;
|
|
3812
|
+
if (!me.permissions.has(flag)) return false;
|
|
3813
|
+
return this._compareRolePosition(me) < 0;
|
|
3814
|
+
}
|
|
3815
|
+
/** Negative when this member's highest role is below `other`'s. */
|
|
3816
|
+
_compareRolePosition(other) {
|
|
3817
|
+
const highest = (m) => {
|
|
3818
|
+
let pos = -1;
|
|
3819
|
+
for (const role of m.roles.cache.values()) {
|
|
3820
|
+
if (role.position > pos) pos = role.position;
|
|
3821
|
+
}
|
|
3822
|
+
return pos;
|
|
3823
|
+
};
|
|
3824
|
+
return highest(this) - highest(other);
|
|
3825
|
+
}
|
|
3826
|
+
/**
|
|
3827
|
+
* Timeout this member for `durationMs` milliseconds, or pass `null` to clear.
|
|
3828
|
+
* Requires Moderate Members.
|
|
3829
|
+
*/
|
|
3830
|
+
async timeout(durationMs, reason) {
|
|
3831
|
+
const communicationDisabledUntil = durationMs == null || durationMs <= 0 ? null : new Date(Date.now() + durationMs).toISOString();
|
|
3832
|
+
return this.edit({
|
|
3833
|
+
communicationDisabledUntil,
|
|
3834
|
+
...reason !== void 0 ? { timeoutReason: reason } : {}
|
|
3835
|
+
});
|
|
3836
|
+
}
|
|
2846
3837
|
_effectivePermissions(overwrites, roleIds) {
|
|
2847
3838
|
const ownerId = this.guild.ownerId;
|
|
2848
3839
|
const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
|
|
@@ -2862,8 +3853,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2862
3853
|
};
|
|
2863
3854
|
|
|
2864
3855
|
// src/Domain/Guild/GuildSticker.ts
|
|
2865
|
-
import { Routes as
|
|
2866
|
-
import { SnowflakeUtil as
|
|
3856
|
+
import { Routes as Routes17 } from "@fluxerjs/types";
|
|
3857
|
+
import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
|
|
2867
3858
|
var GuildSticker = class extends Base {
|
|
2868
3859
|
client;
|
|
2869
3860
|
id;
|
|
@@ -2905,16 +3896,17 @@ var GuildSticker = class extends Base {
|
|
|
2905
3896
|
}
|
|
2906
3897
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
2907
3898
|
get createdTimestamp() {
|
|
2908
|
-
return
|
|
3899
|
+
return SnowflakeUtil6.timestampFromSnowflake(this.id);
|
|
2909
3900
|
}
|
|
2910
3901
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
2911
3902
|
get createdAt() {
|
|
2912
|
-
return
|
|
3903
|
+
return SnowflakeUtil6.dateFromSnowflake(this.id);
|
|
2913
3904
|
}
|
|
2914
3905
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
2915
|
-
async delete() {
|
|
2916
|
-
await this.client.rest.delete(
|
|
2917
|
-
auth: true
|
|
3906
|
+
async delete(reason) {
|
|
3907
|
+
await this.client.rest.delete(Routes17.guildSticker(this.guildId, this.id), {
|
|
3908
|
+
auth: true,
|
|
3909
|
+
...auditReasonHeaders(reason)
|
|
2918
3910
|
});
|
|
2919
3911
|
const guild = this.client.guilds.get(this.guildId);
|
|
2920
3912
|
if (guild) guild.stickers.delete(this.id);
|
|
@@ -2924,9 +3916,11 @@ var GuildSticker = class extends Base {
|
|
|
2924
3916
|
* Requires Manage Emojis and Stickers permission.
|
|
2925
3917
|
*/
|
|
2926
3918
|
async edit(options) {
|
|
2927
|
-
const
|
|
2928
|
-
|
|
2929
|
-
|
|
3919
|
+
const { reason, ...body } = options;
|
|
3920
|
+
const data = await this.client.rest.patch(Routes17.guildSticker(this.guildId, this.id), {
|
|
3921
|
+
body,
|
|
3922
|
+
auth: true,
|
|
3923
|
+
...auditReasonHeaders(reason)
|
|
2930
3924
|
});
|
|
2931
3925
|
const s = data;
|
|
2932
3926
|
this.name = s.name;
|
|
@@ -2936,12 +3930,12 @@ var GuildSticker = class extends Base {
|
|
|
2936
3930
|
};
|
|
2937
3931
|
|
|
2938
3932
|
// src/Domain/Guild/Role.ts
|
|
2939
|
-
import { Routes as
|
|
3933
|
+
import { Routes as Routes18 } from "@fluxerjs/types";
|
|
2940
3934
|
import {
|
|
2941
3935
|
ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
|
|
2942
|
-
PermissionFlags as
|
|
2943
|
-
PermissionsBitField as
|
|
2944
|
-
SnowflakeUtil as
|
|
3936
|
+
PermissionFlags as PermissionFlags4,
|
|
3937
|
+
PermissionsBitField as PermissionsBitField3,
|
|
3938
|
+
SnowflakeUtil as SnowflakeUtil7
|
|
2945
3939
|
} from "@fluxerjs/util";
|
|
2946
3940
|
var Role = class _Role extends Base {
|
|
2947
3941
|
/** Parent client instance. */
|
|
@@ -2985,21 +3979,29 @@ var Role = class _Role extends Base {
|
|
|
2985
3979
|
*/
|
|
2986
3980
|
get permissions() {
|
|
2987
3981
|
const bits = BigInt(this._permissions);
|
|
2988
|
-
return new
|
|
2989
|
-
(bits &
|
|
3982
|
+
return new PermissionsBitField3(
|
|
3983
|
+
(bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
|
|
2990
3984
|
);
|
|
2991
3985
|
}
|
|
3986
|
+
/**
|
|
3987
|
+
* Alias of {@link permissions}.has for discord.js-style checks.
|
|
3988
|
+
* @example
|
|
3989
|
+
* if (role.has(PermissionFlags.BanMembers)) { ... }
|
|
3990
|
+
*/
|
|
3991
|
+
has(permission) {
|
|
3992
|
+
return this.permissions.has(permission);
|
|
3993
|
+
}
|
|
2992
3994
|
/**
|
|
2993
3995
|
* Format as a mention string (`<@&id>`).
|
|
2994
3996
|
* @returns Mention syntax
|
|
2995
3997
|
*/
|
|
2996
3998
|
/** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
|
|
2997
3999
|
get createdTimestamp() {
|
|
2998
|
-
return
|
|
4000
|
+
return SnowflakeUtil7.timestampFromSnowflake(this.id);
|
|
2999
4001
|
}
|
|
3000
4002
|
/** Date when this role was created, derived from its snowflake ID. */
|
|
3001
4003
|
get createdAt() {
|
|
3002
|
-
return
|
|
4004
|
+
return SnowflakeUtil7.dateFromSnowflake(this.id);
|
|
3003
4005
|
}
|
|
3004
4006
|
toString() {
|
|
3005
4007
|
return `<@&${this.id}>`;
|
|
@@ -3042,19 +4044,24 @@ var Role = class _Role extends Base {
|
|
|
3042
4044
|
* @returns This role instance (updated in-place)
|
|
3043
4045
|
*/
|
|
3044
4046
|
async edit(options) {
|
|
3045
|
-
const body =
|
|
3046
|
-
const data = await this.client.rest.patch(
|
|
4047
|
+
const body = toRoleEditBody(options);
|
|
4048
|
+
const data = await this.client.rest.patch(Routes18.guildRole(this.guildId, this.id), {
|
|
3047
4049
|
body: Object.keys(body).length ? body : void 0,
|
|
3048
|
-
auth: true
|
|
4050
|
+
auth: true,
|
|
4051
|
+
...auditReasonHeaders(options.reason)
|
|
3049
4052
|
});
|
|
3050
4053
|
this._patch(data);
|
|
3051
4054
|
return this;
|
|
3052
4055
|
}
|
|
3053
4056
|
/**
|
|
3054
4057
|
* DELETE role. Requires Manage Roles.
|
|
4058
|
+
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
3055
4059
|
*/
|
|
3056
|
-
async delete() {
|
|
3057
|
-
await this.client.rest.delete(
|
|
4060
|
+
async delete(reason) {
|
|
4061
|
+
await this.client.rest.delete(Routes18.guildRole(this.guildId, this.id), {
|
|
4062
|
+
auth: true,
|
|
4063
|
+
...auditReasonHeaders(reason)
|
|
4064
|
+
});
|
|
3058
4065
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
3059
4066
|
}
|
|
3060
4067
|
};
|
|
@@ -3062,17 +4069,15 @@ var Role = class _Role extends Base {
|
|
|
3062
4069
|
// src/Domain/Guild/Cache.ts
|
|
3063
4070
|
function putChannel(client, channel, guild) {
|
|
3064
4071
|
client.channels.set(channel.id, channel);
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
return guildId ? client.guilds.get(guildId) : void 0;
|
|
3068
|
-
})();
|
|
4072
|
+
if (!channel.isGuild()) return;
|
|
4073
|
+
const resolvedGuild = guild ?? (channel.guildId ? client.guilds.get(channel.guildId) : void 0);
|
|
3069
4074
|
if (resolvedGuild) {
|
|
3070
4075
|
resolvedGuild.channels.set(channel.id, channel);
|
|
3071
4076
|
}
|
|
3072
4077
|
}
|
|
3073
4078
|
function cacheChannel(guild, data) {
|
|
3074
4079
|
const existing = guild.channels.get(data.id) ?? guild.client.channels.get(data.id);
|
|
3075
|
-
if (existing &&
|
|
4080
|
+
if (existing?.isGuild() && existing.type === data.type) {
|
|
3076
4081
|
existing._patch(data);
|
|
3077
4082
|
putChannel(guild.client, existing, guild);
|
|
3078
4083
|
return existing;
|
|
@@ -3186,6 +4191,10 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3186
4191
|
});
|
|
3187
4192
|
this.client = client;
|
|
3188
4193
|
}
|
|
4194
|
+
/**
|
|
4195
|
+
* Remove a channel from cache. Does not delete it on the API.
|
|
4196
|
+
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
4197
|
+
*/
|
|
3189
4198
|
delete(key) {
|
|
3190
4199
|
const channel = this.get(key);
|
|
3191
4200
|
const deleted = super.delete(key);
|
|
@@ -3199,15 +4208,20 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3199
4208
|
return this.get(channelId) ?? this.fetch(channelId);
|
|
3200
4209
|
}
|
|
3201
4210
|
/**
|
|
3202
|
-
* Fetch a channel by ID.
|
|
3203
|
-
*
|
|
4211
|
+
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
4212
|
+
* and {@link Channel.send} (send throws if the type is not text-based).
|
|
4213
|
+
* Returns the cached channel unless `force` is set.
|
|
4214
|
+
* @example
|
|
4215
|
+
* const channel = await client.channels.fetch(channelId);
|
|
4216
|
+
* await channel.delete();
|
|
4217
|
+
* await channel.send('hi');
|
|
3204
4218
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
3205
4219
|
*/
|
|
3206
4220
|
async fetch(channelId, options) {
|
|
3207
4221
|
const cached = this.get(channelId);
|
|
3208
4222
|
if (cached && !options?.force) return cached;
|
|
3209
4223
|
try {
|
|
3210
|
-
const data = await this.client.rest.get(
|
|
4224
|
+
const data = await this.client.rest.get(Routes19.channel(channelId));
|
|
3211
4225
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
3212
4226
|
if (guildId) {
|
|
3213
4227
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -3243,6 +4257,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3243
4257
|
}
|
|
3244
4258
|
/**
|
|
3245
4259
|
* Send to a channel by ID without resolving it first.
|
|
4260
|
+
* Prefer {@link Channel.send} after {@link fetch} when you want the channel object.
|
|
3246
4261
|
* @example
|
|
3247
4262
|
* await client.channels.send(logChannelId, 'User joined!');
|
|
3248
4263
|
*/
|
|
@@ -3251,7 +4266,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3251
4266
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
3252
4267
|
});
|
|
3253
4268
|
const data = await this.client.rest.post(
|
|
3254
|
-
|
|
4269
|
+
Routes19.channelMessages(channelId),
|
|
3255
4270
|
postPayload
|
|
3256
4271
|
);
|
|
3257
4272
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -3266,8 +4281,8 @@ import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes34 } from "@fluxerjs
|
|
|
3266
4281
|
import { createLogger } from "@fluxerjs/util";
|
|
3267
4282
|
|
|
3268
4283
|
// src/Domain/User.ts
|
|
3269
|
-
import { Routes as
|
|
3270
|
-
import { SnowflakeUtil as
|
|
4284
|
+
import { Routes as Routes20 } from "@fluxerjs/types";
|
|
4285
|
+
import { SnowflakeUtil as SnowflakeUtil8 } from "@fluxerjs/util";
|
|
3271
4286
|
var User = class extends Base {
|
|
3272
4287
|
/** Parent client instance. */
|
|
3273
4288
|
client;
|
|
@@ -3351,11 +4366,11 @@ var User = class extends Base {
|
|
|
3351
4366
|
*/
|
|
3352
4367
|
/** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
|
|
3353
4368
|
get createdTimestamp() {
|
|
3354
|
-
return
|
|
4369
|
+
return SnowflakeUtil8.timestampFromSnowflake(this.id);
|
|
3355
4370
|
}
|
|
3356
4371
|
/** Date when this account was created, derived from its snowflake ID. */
|
|
3357
4372
|
get createdAt() {
|
|
3358
|
-
return
|
|
4373
|
+
return SnowflakeUtil8.dateFromSnowflake(this.id);
|
|
3359
4374
|
}
|
|
3360
4375
|
toString() {
|
|
3361
4376
|
return `<@${this.id}>`;
|
|
@@ -3365,7 +4380,7 @@ var User = class extends Base {
|
|
|
3365
4380
|
* @returns DM channel instance (cached if already open)
|
|
3366
4381
|
*/
|
|
3367
4382
|
async createDM() {
|
|
3368
|
-
const data = await this.client.rest.post(
|
|
4383
|
+
const data = await this.client.rest.post(Routes20.userMeChannels(), {
|
|
3369
4384
|
body: { recipient_id: this.id },
|
|
3370
4385
|
auth: true
|
|
3371
4386
|
});
|
|
@@ -3442,14 +4457,14 @@ function resolveCacheLimits(input) {
|
|
|
3442
4457
|
}
|
|
3443
4458
|
|
|
3444
4459
|
// src/ClientCore/ClientEmoji.ts
|
|
3445
|
-
import { Collection as
|
|
3446
|
-
import { Routes as
|
|
3447
|
-
import { formatEmoji, getUnicodeFromShortcode, parseEmoji
|
|
4460
|
+
import { Collection as Collection8 } from "@fluxerjs/collection";
|
|
4461
|
+
import { Routes as Routes21 } from "@fluxerjs/types";
|
|
4462
|
+
import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
|
|
3448
4463
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
3449
4464
|
if (typeof emoji === "object" && emoji.id) {
|
|
3450
4465
|
return formatEmoji({ name: emoji.name, id: emoji.id, animated: emoji.animated });
|
|
3451
4466
|
}
|
|
3452
|
-
const parsed =
|
|
4467
|
+
const parsed = parseEmoji(
|
|
3453
4468
|
typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
|
|
3454
4469
|
);
|
|
3455
4470
|
if (!parsed) {
|
|
@@ -3462,7 +4477,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
3462
4477
|
const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
|
|
3463
4478
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
3464
4479
|
if (guildId) {
|
|
3465
|
-
const emojis = await client.rest.get(
|
|
4480
|
+
const emojis = await client.rest.get(Routes21.guildEmojis(guildId));
|
|
3466
4481
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
3467
4482
|
if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
|
|
3468
4483
|
throw new FluxerError(
|
|
@@ -3479,28 +4494,34 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
3479
4494
|
return parsed.name;
|
|
3480
4495
|
}
|
|
3481
4496
|
async function fetchInstance(client) {
|
|
3482
|
-
const raw = await client.rest.get(
|
|
4497
|
+
const raw = await client.rest.get(Routes21.instanceDiscovery(), {
|
|
4498
|
+
auth: false,
|
|
4499
|
+
unversioned: true
|
|
4500
|
+
});
|
|
3483
4501
|
return parseInstanceDiscovery(raw);
|
|
3484
4502
|
}
|
|
3485
4503
|
function fetchGatewayInfo(client) {
|
|
3486
|
-
return client.rest.get(
|
|
4504
|
+
return client.rest.get(Routes21.gatewayBot());
|
|
3487
4505
|
}
|
|
3488
4506
|
function fetchEmojiMetadata(client, emojiId) {
|
|
3489
|
-
return client.rest.get(
|
|
4507
|
+
return client.rest.get(Routes21.emojiMetadata(emojiId), { auth: true });
|
|
3490
4508
|
}
|
|
3491
4509
|
function fetchStickerMetadata(client, stickerId) {
|
|
3492
|
-
return client.rest.get(
|
|
4510
|
+
return client.rest.get(Routes21.stickerMetadata(stickerId), { auth: true });
|
|
3493
4511
|
}
|
|
3494
4512
|
function fetchApplication(client) {
|
|
3495
|
-
return client.rest.get(
|
|
4513
|
+
return client.rest.get(Routes21.applicationsMe(), { auth: true });
|
|
3496
4514
|
}
|
|
3497
4515
|
async function fetchOAuthApplications(client) {
|
|
3498
|
-
const data = await client.rest.get(
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
4516
|
+
const data = await client.rest.get(Routes21.oauth2ApplicationsMe(), { auth: true });
|
|
4517
|
+
if (Array.isArray(data)) return data;
|
|
4518
|
+
if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
|
|
4519
|
+
return data.applications;
|
|
4520
|
+
}
|
|
4521
|
+
if (data && typeof data === "object" && "id" in data && typeof data.id === "string") {
|
|
4522
|
+
return [data];
|
|
4523
|
+
}
|
|
4524
|
+
return [];
|
|
3504
4525
|
}
|
|
3505
4526
|
function assertChannelIdBatch(name, channelIds) {
|
|
3506
4527
|
if (channelIds.length < 1 || channelIds.length > 100) {
|
|
@@ -3511,14 +4532,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
3511
4532
|
}
|
|
3512
4533
|
function preloadMessages(client, channelIds) {
|
|
3513
4534
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
3514
|
-
return client.rest.post(
|
|
4535
|
+
return client.rest.post(Routes21.preloadMessages(), {
|
|
3515
4536
|
body: { channels: channelIds },
|
|
3516
4537
|
auth: true
|
|
3517
4538
|
});
|
|
3518
4539
|
}
|
|
3519
4540
|
function preloadMessagesAlt(client, channelIds) {
|
|
3520
4541
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
3521
|
-
return client.rest.post(
|
|
4542
|
+
return client.rest.post(Routes21.preloadMessagesAlt(), {
|
|
3522
4543
|
body: { channels: channelIds },
|
|
3523
4544
|
auth: true
|
|
3524
4545
|
});
|
|
@@ -3526,14 +4547,14 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
3526
4547
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
3527
4548
|
validateBulkMessageFetchRequests(requests);
|
|
3528
4549
|
const wire = toBulkFetchWire(requests);
|
|
3529
|
-
const data = await client.rest.post(
|
|
4550
|
+
const data = await client.rest.post(Routes21.channelsMessagesBulk(), {
|
|
3530
4551
|
body: { requests: wire },
|
|
3531
4552
|
auth: true
|
|
3532
4553
|
});
|
|
3533
4554
|
if (options.hydrate === false) return data;
|
|
3534
4555
|
return {
|
|
3535
4556
|
channels: data.channels.map((entry) => {
|
|
3536
|
-
const collection = new
|
|
4557
|
+
const collection = new Collection8();
|
|
3537
4558
|
for (const msg of entry.messages) {
|
|
3538
4559
|
client._addMessageToCache(entry.channel_id, msg);
|
|
3539
4560
|
collection.set(msg.id, new Message(client, msg));
|
|
@@ -3542,6 +4563,13 @@ async function bulkFetchMessages(client, requests, options = {}) {
|
|
|
3542
4563
|
})
|
|
3543
4564
|
};
|
|
3544
4565
|
}
|
|
4566
|
+
async function searchMessages(client, options = {}) {
|
|
4567
|
+
const data = await client.rest.post(Routes21.searchMessages(), {
|
|
4568
|
+
body: toMessageSearchBody(options),
|
|
4569
|
+
auth: true
|
|
4570
|
+
});
|
|
4571
|
+
return toMessageSearchResponse(data);
|
|
4572
|
+
}
|
|
3545
4573
|
|
|
3546
4574
|
// src/ClientCore/ClientEvents.ts
|
|
3547
4575
|
function createEventMethods(client) {
|
|
@@ -3557,16 +4585,16 @@ function createEventMethods(client) {
|
|
|
3557
4585
|
}
|
|
3558
4586
|
|
|
3559
4587
|
// src/ClientCore/GatewayReady.ts
|
|
3560
|
-
import { WebSocketManager } from "@fluxerjs/ws";
|
|
4588
|
+
import { GatewayCloseCodes, WebSocketManager } from "@fluxerjs/ws";
|
|
3561
4589
|
|
|
3562
4590
|
// src/Domain/Guild/Guild.ts
|
|
3563
|
-
import { LimitedCollection as
|
|
4591
|
+
import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
|
|
3564
4592
|
import { GuildNSFWLevel } from "@fluxerjs/types";
|
|
3565
|
-
import { SnowflakeUtil as
|
|
4593
|
+
import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
|
|
3566
4594
|
|
|
3567
4595
|
// src/ClientCore/GuildMemberManager.ts
|
|
3568
4596
|
import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
|
|
3569
|
-
import { Routes as
|
|
4597
|
+
import { Routes as Routes22 } from "@fluxerjs/types";
|
|
3570
4598
|
var GuildMemberManager = class extends LimitedCollection2 {
|
|
3571
4599
|
constructor(guild) {
|
|
3572
4600
|
super({ maxSize: guild.client.cache.limits.members });
|
|
@@ -3583,7 +4611,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3583
4611
|
* console.log(member.displayName);
|
|
3584
4612
|
*/
|
|
3585
4613
|
async resolve(userId) {
|
|
3586
|
-
return this.get(userId) ?? this.
|
|
4614
|
+
return this.get(userId) ?? this.fetch(userId);
|
|
3587
4615
|
}
|
|
3588
4616
|
/**
|
|
3589
4617
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -3610,17 +4638,20 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3610
4638
|
async fetchMe() {
|
|
3611
4639
|
return this.guild.fetchMe();
|
|
3612
4640
|
}
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
4641
|
+
async fetch(userIdOrOptions, options) {
|
|
4642
|
+
if (typeof userIdOrOptions === "string") {
|
|
4643
|
+
const cached = this.get(userIdOrOptions);
|
|
4644
|
+
if (cached && !options?.force) return cached;
|
|
4645
|
+
return this.guild.fetchMember(userIdOrOptions);
|
|
4646
|
+
}
|
|
4647
|
+
return this.fetchMany(userIdOrOptions);
|
|
4648
|
+
}
|
|
4649
|
+
async fetchMany(options) {
|
|
3619
4650
|
const params = new URLSearchParams();
|
|
3620
4651
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
3621
4652
|
if (options?.after) params.set("after", options.after);
|
|
3622
4653
|
const qs2 = params.toString();
|
|
3623
|
-
const url =
|
|
4654
|
+
const url = Routes22.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
3624
4655
|
const data = await this.guild.client.rest.get(url, { auth: true });
|
|
3625
4656
|
const members = [];
|
|
3626
4657
|
for (const m of data) {
|
|
@@ -3643,7 +4674,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3643
4674
|
*/
|
|
3644
4675
|
async search(options = {}) {
|
|
3645
4676
|
const data = await this.guild.client.rest.post(
|
|
3646
|
-
|
|
4677
|
+
Routes22.guildMembersSearch(this.guild.id),
|
|
3647
4678
|
{ body: toMemberSearchBody(options), auth: true }
|
|
3648
4679
|
);
|
|
3649
4680
|
const offset = options.offset ?? 0;
|
|
@@ -3669,7 +4700,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3669
4700
|
};
|
|
3670
4701
|
|
|
3671
4702
|
// src/Domain/Guild/Admin.ts
|
|
3672
|
-
import { Routes as
|
|
4703
|
+
import { Routes as Routes23 } from "@fluxerjs/types";
|
|
3673
4704
|
function toAuditLogEntryPayload(entry, guildId) {
|
|
3674
4705
|
return {
|
|
3675
4706
|
id: entry.id,
|
|
@@ -3690,7 +4721,7 @@ function toVanityPayload(data) {
|
|
|
3690
4721
|
return { code: data.code ?? null, uses: data.uses };
|
|
3691
4722
|
}
|
|
3692
4723
|
async function fetchAuditLogs(guild, options) {
|
|
3693
|
-
const url =
|
|
4724
|
+
const url = Routes23.guildAuditLogs(guild.id) + qs({
|
|
3694
4725
|
limit: options?.limit,
|
|
3695
4726
|
before: options?.before,
|
|
3696
4727
|
after: options?.after,
|
|
@@ -3714,7 +4745,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
3714
4745
|
};
|
|
3715
4746
|
}
|
|
3716
4747
|
async function editGuild(guild, options) {
|
|
3717
|
-
const data = await guild.client.rest.patch(
|
|
4748
|
+
const data = await guild.client.rest.patch(Routes23.guild(guild.id), {
|
|
3718
4749
|
body: toGuildEditBody(options),
|
|
3719
4750
|
auth: true
|
|
3720
4751
|
});
|
|
@@ -3722,13 +4753,13 @@ async function editGuild(guild, options) {
|
|
|
3722
4753
|
return guild;
|
|
3723
4754
|
}
|
|
3724
4755
|
async function fetchVanityURL(guild) {
|
|
3725
|
-
const data = await guild.client.rest.get(
|
|
4756
|
+
const data = await guild.client.rest.get(Routes23.guildVanityUrl(guild.id), {
|
|
3726
4757
|
auth: true
|
|
3727
4758
|
});
|
|
3728
4759
|
return toVanityPayload(data);
|
|
3729
4760
|
}
|
|
3730
4761
|
async function editVanityURL(guild, code) {
|
|
3731
|
-
const data = await guild.client.rest.patch(
|
|
4762
|
+
const data = await guild.client.rest.patch(Routes23.guildVanityUrl(guild.id), {
|
|
3732
4763
|
body: { code },
|
|
3733
4764
|
auth: true
|
|
3734
4765
|
});
|
|
@@ -3736,14 +4767,14 @@ async function editVanityURL(guild, code) {
|
|
|
3736
4767
|
return toVanityPayload(data);
|
|
3737
4768
|
}
|
|
3738
4769
|
async function fetchDiscoveryStatus(guild) {
|
|
3739
|
-
const data = await guild.client.rest.get(
|
|
4770
|
+
const data = await guild.client.rest.get(Routes23.guildDiscovery(guild.id), {
|
|
3740
4771
|
auth: true
|
|
3741
4772
|
});
|
|
3742
4773
|
return toDiscoveryStatusPayload(data);
|
|
3743
4774
|
}
|
|
3744
4775
|
async function applyForDiscovery(guild, options) {
|
|
3745
4776
|
const data = await guild.client.rest.post(
|
|
3746
|
-
|
|
4777
|
+
Routes23.guildDiscovery(guild.id),
|
|
3747
4778
|
{
|
|
3748
4779
|
body: toDiscoveryBody(options),
|
|
3749
4780
|
auth: true
|
|
@@ -3753,7 +4784,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
3753
4784
|
}
|
|
3754
4785
|
async function editDiscoveryApplication(guild, options) {
|
|
3755
4786
|
const data = await guild.client.rest.patch(
|
|
3756
|
-
|
|
4787
|
+
Routes23.guildDiscovery(guild.id),
|
|
3757
4788
|
{
|
|
3758
4789
|
body: toDiscoveryBody(options),
|
|
3759
4790
|
auth: true
|
|
@@ -3762,34 +4793,34 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
3762
4793
|
return toDiscoveryApplicationPayload(data);
|
|
3763
4794
|
}
|
|
3764
4795
|
async function withdrawDiscoveryApplication(guild) {
|
|
3765
|
-
await guild.client.rest.delete(
|
|
4796
|
+
await guild.client.rest.delete(Routes23.guildDiscovery(guild.id), { auth: true });
|
|
3766
4797
|
}
|
|
3767
4798
|
async function deleteGuild(guild, options) {
|
|
3768
4799
|
const body = options ? toSudoBody(options) : {};
|
|
3769
|
-
await guild.client.rest.post(
|
|
4800
|
+
await guild.client.rest.post(Routes23.guildDelete(guild.id), {
|
|
3770
4801
|
body,
|
|
3771
4802
|
auth: true
|
|
3772
4803
|
});
|
|
3773
4804
|
guild.client.guilds.delete(guild.id);
|
|
3774
4805
|
}
|
|
3775
4806
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
3776
|
-
await guild.client.rest.post(
|
|
4807
|
+
await guild.client.rest.post(Routes23.guildTransferOwnership(guild.id), {
|
|
3777
4808
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
3778
4809
|
auth: true
|
|
3779
4810
|
});
|
|
3780
4811
|
}
|
|
3781
4812
|
|
|
3782
4813
|
// src/Domain/Guild/Channels.ts
|
|
3783
|
-
import { Routes as
|
|
3784
|
-
async function createChannel(guild,
|
|
3785
|
-
const created = await guild.client.rest.post(
|
|
3786
|
-
body:
|
|
4814
|
+
import { Routes as Routes24 } from "@fluxerjs/types";
|
|
4815
|
+
async function createChannel(guild, options) {
|
|
4816
|
+
const created = await guild.client.rest.post(Routes24.guildChannels(guild.id), {
|
|
4817
|
+
body: toChannelCreateBody(options),
|
|
3787
4818
|
auth: true
|
|
3788
4819
|
});
|
|
3789
4820
|
return cacheChannel(guild, created);
|
|
3790
4821
|
}
|
|
3791
4822
|
async function fetchChannels(guild) {
|
|
3792
|
-
const data = await guild.client.rest.get(
|
|
4823
|
+
const data = await guild.client.rest.get(Routes24.guildChannels(guild.id));
|
|
3793
4824
|
const channels = [];
|
|
3794
4825
|
for (const ch of data) {
|
|
3795
4826
|
const channel = cacheChannel(guild, ch);
|
|
@@ -3798,17 +4829,17 @@ async function fetchChannels(guild) {
|
|
|
3798
4829
|
return channels;
|
|
3799
4830
|
}
|
|
3800
4831
|
async function setChannelPositions(guild, updates) {
|
|
3801
|
-
await guild.client.rest.patch(
|
|
4832
|
+
await guild.client.rest.patch(Routes24.guildChannels(guild.id), {
|
|
3802
4833
|
body: toChannelPositionBody(updates),
|
|
3803
4834
|
auth: true
|
|
3804
4835
|
});
|
|
3805
4836
|
}
|
|
3806
4837
|
async function fetchWebhooks(guild) {
|
|
3807
|
-
const data = await guild.client.rest.get(
|
|
4838
|
+
const data = await guild.client.rest.get(Routes24.guildWebhooks(guild.id));
|
|
3808
4839
|
return data.map((w) => new Webhook(guild.client, w));
|
|
3809
4840
|
}
|
|
3810
4841
|
async function fetchInvites(guild) {
|
|
3811
|
-
const data = await guild.client.rest.get(
|
|
4842
|
+
const data = await guild.client.rest.get(Routes24.guildInvites(guild.id));
|
|
3812
4843
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
3813
4844
|
}
|
|
3814
4845
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -3828,14 +4859,14 @@ function resolveGuildOnlineCount(data) {
|
|
|
3828
4859
|
}
|
|
3829
4860
|
|
|
3830
4861
|
// src/Domain/Guild/Emojis.ts
|
|
3831
|
-
import { Routes as
|
|
4862
|
+
import { Routes as Routes25 } from "@fluxerjs/types";
|
|
3832
4863
|
async function fetchEmojis(guild) {
|
|
3833
|
-
const data = await guild.client.rest.get(
|
|
4864
|
+
const data = await guild.client.rest.get(Routes25.guildEmojis(guild.id));
|
|
3834
4865
|
return data.map((e) => cacheEmoji(guild, e));
|
|
3835
4866
|
}
|
|
3836
4867
|
async function fetchEmoji(guild, emojiId) {
|
|
3837
4868
|
try {
|
|
3838
|
-
const data = await guild.client.rest.get(
|
|
4869
|
+
const data = await guild.client.rest.get(Routes25.guildEmoji(guild.id, emojiId));
|
|
3839
4870
|
return cacheEmoji(guild, data);
|
|
3840
4871
|
} catch (err) {
|
|
3841
4872
|
rethrowMapped(err, {
|
|
@@ -3845,14 +4876,16 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
3845
4876
|
}
|
|
3846
4877
|
}
|
|
3847
4878
|
async function createEmoji(guild, options) {
|
|
3848
|
-
const
|
|
3849
|
-
|
|
3850
|
-
|
|
4879
|
+
const { reason, ...body } = options;
|
|
4880
|
+
const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
|
|
4881
|
+
body,
|
|
4882
|
+
auth: true,
|
|
4883
|
+
...auditReasonHeaders(reason)
|
|
3851
4884
|
});
|
|
3852
4885
|
return cacheEmoji(guild, data);
|
|
3853
4886
|
}
|
|
3854
4887
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
3855
|
-
const data = await guild.client.rest.post(
|
|
4888
|
+
const data = await guild.client.rest.post(Routes25.guildEmojisClone(guild.id), {
|
|
3856
4889
|
body: { source_emoji_id: sourceEmojiId },
|
|
3857
4890
|
auth: true
|
|
3858
4891
|
});
|
|
@@ -3860,18 +4893,31 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
3860
4893
|
}
|
|
3861
4894
|
async function createEmojisBulk(guild, emojis) {
|
|
3862
4895
|
const data = await guild.client.rest.post(
|
|
3863
|
-
|
|
4896
|
+
Routes25.guildEmojisBulk(guild.id),
|
|
3864
4897
|
{ body: { emojis }, auth: true }
|
|
3865
4898
|
);
|
|
3866
4899
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
3867
4900
|
}
|
|
3868
4901
|
|
|
4902
|
+
// src/Domain/Guild/GuildRoleManager.ts
|
|
4903
|
+
import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
|
|
4904
|
+
var GuildRoleManager = class extends LimitedCollection3 {
|
|
4905
|
+
constructor(guildId, options) {
|
|
4906
|
+
super(options);
|
|
4907
|
+
this.guildId = guildId;
|
|
4908
|
+
}
|
|
4909
|
+
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4910
|
+
get everyone() {
|
|
4911
|
+
return this.get(this.guildId);
|
|
4912
|
+
}
|
|
4913
|
+
};
|
|
4914
|
+
|
|
3869
4915
|
// src/Domain/Guild/MemberHttp.ts
|
|
3870
|
-
import { Routes as
|
|
4916
|
+
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
3871
4917
|
async function fetchMember(guild, userId) {
|
|
3872
4918
|
try {
|
|
3873
4919
|
const data = await guild.client.rest.get(
|
|
3874
|
-
|
|
4920
|
+
Routes26.guildMember(guild.id, userId)
|
|
3875
4921
|
);
|
|
3876
4922
|
return cacheMember(guild, data);
|
|
3877
4923
|
} catch (err) {
|
|
@@ -3886,23 +4932,28 @@ async function fetchMember(guild, userId) {
|
|
|
3886
4932
|
}
|
|
3887
4933
|
async function fetchMe(guild) {
|
|
3888
4934
|
const data = await guild.client.rest.get(
|
|
3889
|
-
|
|
4935
|
+
Routes26.guildMemberMe(guild.id),
|
|
3890
4936
|
{ auth: true }
|
|
3891
4937
|
);
|
|
3892
4938
|
return cacheMember(guild, data);
|
|
3893
4939
|
}
|
|
3894
4940
|
|
|
3895
4941
|
// src/Domain/Guild/Moderation.ts
|
|
3896
|
-
import { Routes as
|
|
4942
|
+
import { Routes as Routes28 } from "@fluxerjs/types";
|
|
3897
4943
|
|
|
3898
4944
|
// src/Domain/Guild/GuildBan.ts
|
|
3899
|
-
import { Routes as
|
|
4945
|
+
import { Routes as Routes27 } from "@fluxerjs/types";
|
|
4946
|
+
function parseOptionalDate2(value) {
|
|
4947
|
+
if (value == null || value === "") return null;
|
|
4948
|
+
const date = new Date(value);
|
|
4949
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
4950
|
+
}
|
|
3900
4951
|
var GuildBan = class extends Base {
|
|
3901
4952
|
client;
|
|
3902
4953
|
guildId;
|
|
3903
4954
|
user;
|
|
3904
4955
|
reason;
|
|
3905
|
-
/**
|
|
4956
|
+
/** When a temporary ban expires. Null for permanent bans. */
|
|
3906
4957
|
expiresAt;
|
|
3907
4958
|
/** @param data - API ban from GET /guilds/{id}/bans or gateway GUILD_BAN_ADD */
|
|
3908
4959
|
constructor(client, data, guildId) {
|
|
@@ -3911,15 +4962,16 @@ var GuildBan = class extends Base {
|
|
|
3911
4962
|
this.guildId = data.guild_id ?? guildId;
|
|
3912
4963
|
this.user = client.getOrCreateUser(data.user);
|
|
3913
4964
|
this.reason = data.reason ?? null;
|
|
3914
|
-
this.expiresAt = data.expires_at
|
|
4965
|
+
this.expiresAt = parseOptionalDate2(data.expires_at);
|
|
3915
4966
|
}
|
|
3916
4967
|
/**
|
|
3917
4968
|
* Remove this ban (unban the user).
|
|
3918
4969
|
* Requires Ban Members permission.
|
|
3919
4970
|
*/
|
|
3920
|
-
async unban() {
|
|
3921
|
-
await this.client.rest.delete(
|
|
3922
|
-
auth: true
|
|
4971
|
+
async unban(reason) {
|
|
4972
|
+
await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
|
|
4973
|
+
auth: true,
|
|
4974
|
+
...auditReasonHeaders(reason)
|
|
3923
4975
|
});
|
|
3924
4976
|
}
|
|
3925
4977
|
};
|
|
@@ -3927,40 +4979,48 @@ var GuildBan = class extends Base {
|
|
|
3927
4979
|
// src/Domain/Guild/Moderation.ts
|
|
3928
4980
|
async function ban(guild, userId, options) {
|
|
3929
4981
|
const body = options ? toGuildBanBody(options) : {};
|
|
3930
|
-
await guild.client.rest.put(
|
|
4982
|
+
await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
|
|
3931
4983
|
body: Object.keys(body).length ? body : void 0,
|
|
3932
|
-
auth: true
|
|
4984
|
+
auth: true,
|
|
4985
|
+
...auditReasonHeaders(options?.reason)
|
|
3933
4986
|
});
|
|
3934
4987
|
}
|
|
3935
4988
|
async function fetchBans(guild) {
|
|
3936
|
-
const data = await guild.client.rest.get(
|
|
4989
|
+
const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
|
|
3937
4990
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
3938
4991
|
}
|
|
3939
|
-
async function unban(guild, userId) {
|
|
3940
|
-
await guild.client.rest.delete(
|
|
4992
|
+
async function unban(guild, userId, reason) {
|
|
4993
|
+
await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
|
|
4994
|
+
auth: true,
|
|
4995
|
+
...auditReasonHeaders(reason)
|
|
4996
|
+
});
|
|
3941
4997
|
}
|
|
3942
|
-
async function kick(guild, userId) {
|
|
3943
|
-
await guild.client.rest.delete(
|
|
4998
|
+
async function kick(guild, userId, reason) {
|
|
4999
|
+
await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
|
|
5000
|
+
auth: true,
|
|
5001
|
+
...auditReasonHeaders(reason)
|
|
5002
|
+
});
|
|
3944
5003
|
}
|
|
3945
5004
|
|
|
3946
5005
|
// src/Domain/Guild/Roles.ts
|
|
3947
|
-
import { Routes as
|
|
5006
|
+
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
3948
5007
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
3949
5008
|
async function createRole(guild, options = {}) {
|
|
3950
|
-
const body =
|
|
3951
|
-
const data = await guild.client.rest.post(
|
|
5009
|
+
const body = toRoleCreateBody(options);
|
|
5010
|
+
const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
|
|
3952
5011
|
body: Object.keys(body).length ? body : void 0,
|
|
3953
|
-
auth: true
|
|
5012
|
+
auth: true,
|
|
5013
|
+
...auditReasonHeaders(options.reason)
|
|
3954
5014
|
});
|
|
3955
5015
|
return cacheRole(guild, data);
|
|
3956
5016
|
}
|
|
3957
5017
|
async function fetchRoles(guild) {
|
|
3958
|
-
const data = await guild.client.rest.get(
|
|
5018
|
+
const data = await guild.client.rest.get(Routes29.guildRoles(guild.id));
|
|
3959
5019
|
return data.map((r) => cacheRole(guild, r));
|
|
3960
5020
|
}
|
|
3961
5021
|
async function fetchRole(guild, roleId2) {
|
|
3962
5022
|
try {
|
|
3963
|
-
const data = await guild.client.rest.get(
|
|
5023
|
+
const data = await guild.client.rest.get(Routes29.guildRole(guild.id, roleId2));
|
|
3964
5024
|
return cacheRole(guild, data);
|
|
3965
5025
|
} catch (err) {
|
|
3966
5026
|
rethrowMapped(err, {
|
|
@@ -3977,7 +5037,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3977
5037
|
const needle = trimmed.toLowerCase();
|
|
3978
5038
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3979
5039
|
if (cached) return cached.id;
|
|
3980
|
-
const roles = await guild.client.rest.get(
|
|
5040
|
+
const roles = await guild.client.rest.get(Routes29.guildRoles(guild.id));
|
|
3981
5041
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3982
5042
|
if (!role) return null;
|
|
3983
5043
|
cacheRole(guild, role);
|
|
@@ -3986,7 +5046,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3986
5046
|
async function setRolePositions(guild, updates) {
|
|
3987
5047
|
return replaceRoles(
|
|
3988
5048
|
guild,
|
|
3989
|
-
await guild.client.rest.patch(
|
|
5049
|
+
await guild.client.rest.patch(Routes29.guildRoles(guild.id), {
|
|
3990
5050
|
body: updates,
|
|
3991
5051
|
auth: true
|
|
3992
5052
|
})
|
|
@@ -3995,7 +5055,7 @@ async function setRolePositions(guild, updates) {
|
|
|
3995
5055
|
async function setRoleHoistPositions(guild, updates) {
|
|
3996
5056
|
return replaceRoles(
|
|
3997
5057
|
guild,
|
|
3998
|
-
await guild.client.rest.patch(
|
|
5058
|
+
await guild.client.rest.patch(Routes29.guildRolesHoistPositions(guild.id), {
|
|
3999
5059
|
body: updates.map((u) => ({
|
|
4000
5060
|
id: u.id,
|
|
4001
5061
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -4007,23 +5067,25 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
4007
5067
|
async function resetRoleHoistPositions(guild) {
|
|
4008
5068
|
return replaceRoles(
|
|
4009
5069
|
guild,
|
|
4010
|
-
await guild.client.rest.delete(
|
|
5070
|
+
await guild.client.rest.delete(Routes29.guildRolesHoistPositions(guild.id), {
|
|
4011
5071
|
auth: true
|
|
4012
5072
|
})
|
|
4013
5073
|
);
|
|
4014
5074
|
}
|
|
4015
5075
|
|
|
4016
5076
|
// src/Domain/Guild/Stickers.ts
|
|
4017
|
-
import { Routes as
|
|
5077
|
+
import { Routes as Routes30 } from "@fluxerjs/types";
|
|
4018
5078
|
async function createSticker(guild, options) {
|
|
4019
|
-
const
|
|
4020
|
-
|
|
4021
|
-
|
|
5079
|
+
const { reason, ...body } = options;
|
|
5080
|
+
const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
|
|
5081
|
+
body,
|
|
5082
|
+
auth: true,
|
|
5083
|
+
...auditReasonHeaders(reason)
|
|
4022
5084
|
});
|
|
4023
5085
|
return cacheSticker(guild, data);
|
|
4024
5086
|
}
|
|
4025
5087
|
async function cloneSticker(guild, sourceStickerId) {
|
|
4026
|
-
const data = await guild.client.rest.post(
|
|
5088
|
+
const data = await guild.client.rest.post(Routes30.guildStickersClone(guild.id), {
|
|
4027
5089
|
body: { source_sticker_id: sourceStickerId },
|
|
4028
5090
|
auth: true
|
|
4029
5091
|
});
|
|
@@ -4031,17 +5093,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
4031
5093
|
}
|
|
4032
5094
|
async function createStickersBulk(guild, stickers) {
|
|
4033
5095
|
const data = await guild.client.rest.post(
|
|
4034
|
-
|
|
5096
|
+
Routes30.guildStickersBulk(guild.id),
|
|
4035
5097
|
{ body: { stickers }, auth: true }
|
|
4036
5098
|
);
|
|
4037
5099
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
4038
5100
|
}
|
|
4039
5101
|
async function fetchStickers(guild) {
|
|
4040
|
-
const data = await guild.client.rest.get(
|
|
5102
|
+
const data = await guild.client.rest.get(Routes30.guildStickers(guild.id));
|
|
4041
5103
|
return data.map((s) => cacheSticker(guild, s));
|
|
4042
5104
|
}
|
|
4043
5105
|
async function fetchSticker(guild, stickerId) {
|
|
4044
|
-
const data = await guild.client.rest.get(
|
|
5106
|
+
const data = await guild.client.rest.get(Routes30.guildSticker(guild.id, stickerId));
|
|
4045
5107
|
return cacheSticker(guild, data);
|
|
4046
5108
|
}
|
|
4047
5109
|
|
|
@@ -4081,8 +5143,26 @@ var Guild = class extends Base {
|
|
|
4081
5143
|
systemChannelId;
|
|
4082
5144
|
/** Rules channel ID (for Community guilds), or null if none. */
|
|
4083
5145
|
rulesChannelId;
|
|
5146
|
+
/** {@link SystemChannelFlags} bitfield. */
|
|
5147
|
+
systemChannelFlags;
|
|
5148
|
+
/** Splash card alignment. */
|
|
5149
|
+
splashCardAlignment;
|
|
5150
|
+
/** Embed splash hash. */
|
|
5151
|
+
embedSplash;
|
|
4084
5152
|
/** NSFW level for this guild. */
|
|
4085
5153
|
nsfwLevel;
|
|
5154
|
+
/** Whether the guild is marked as adult (18+) content. */
|
|
5155
|
+
nsfw;
|
|
5156
|
+
/** Content warning level. */
|
|
5157
|
+
contentWarningLevel;
|
|
5158
|
+
/** Custom guild-wide content warning text. */
|
|
5159
|
+
contentWarningText;
|
|
5160
|
+
/** {@link GuildOperations} bitfield of disabled operations. */
|
|
5161
|
+
disabledOperations;
|
|
5162
|
+
/** ISO-8601 timestamp before which message history is not available. */
|
|
5163
|
+
messageHistoryCutoff;
|
|
5164
|
+
/** Permissions for the current member in this guild (bitfield string). */
|
|
5165
|
+
permissions;
|
|
4086
5166
|
/** MFA level required for moderation actions. */
|
|
4087
5167
|
mfaLevel;
|
|
4088
5168
|
/** Banner width in pixels. */
|
|
@@ -4116,13 +5196,13 @@ var Guild = class extends Base {
|
|
|
4116
5196
|
this.client = client;
|
|
4117
5197
|
this.id = data.id;
|
|
4118
5198
|
this.members = new GuildMemberManager(this);
|
|
4119
|
-
this.channels = new
|
|
5199
|
+
this.channels = new LimitedCollection4({
|
|
4120
5200
|
maxSize: Number.POSITIVE_INFINITY,
|
|
4121
5201
|
onEvict: (_id, channel) => client.cache.cascadeChannel(channel, "guild")
|
|
4122
5202
|
});
|
|
4123
|
-
this.roles = new
|
|
4124
|
-
this.emojis = new
|
|
4125
|
-
this.stickers = new
|
|
5203
|
+
this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
|
|
5204
|
+
this.emojis = new LimitedCollection4({ maxSize: client.cache.limits.emojis });
|
|
5205
|
+
this.stickers = new LimitedCollection4({ maxSize: client.cache.limits.stickers });
|
|
4126
5206
|
this.name = data.name ?? "";
|
|
4127
5207
|
this.icon = data.icon ?? null;
|
|
4128
5208
|
this.banner = data.banner ?? null;
|
|
@@ -4137,7 +5217,16 @@ var Guild = class extends Base {
|
|
|
4137
5217
|
this.afkTimeout = data.afk_timeout ?? 0;
|
|
4138
5218
|
this.systemChannelId = data.system_channel_id ?? null;
|
|
4139
5219
|
this.rulesChannelId = data.rules_channel_id ?? null;
|
|
5220
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
5221
|
+
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
5222
|
+
this.embedSplash = data.embed_splash ?? null;
|
|
4140
5223
|
this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
|
|
5224
|
+
this.nsfw = data.nsfw ?? false;
|
|
5225
|
+
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
5226
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
5227
|
+
this.disabledOperations = data.disabled_operations ?? 0;
|
|
5228
|
+
this.messageHistoryCutoff = data.message_history_cutoff ?? null;
|
|
5229
|
+
this.permissions = data.permissions ?? null;
|
|
4141
5230
|
this.mfaLevel = data.mfa_level ?? 0;
|
|
4142
5231
|
this.bannerWidth = data.banner_width ?? null;
|
|
4143
5232
|
this.bannerHeight = data.banner_height ?? null;
|
|
@@ -4172,7 +5261,28 @@ var Guild = class extends Base {
|
|
|
4172
5261
|
if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
|
|
4173
5262
|
if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
|
|
4174
5263
|
if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
|
|
5264
|
+
if (data.system_channel_flags !== void 0) {
|
|
5265
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
5266
|
+
}
|
|
5267
|
+
if (data.splash_card_alignment !== void 0) {
|
|
5268
|
+
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
5269
|
+
}
|
|
5270
|
+
if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
|
|
4175
5271
|
if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
|
|
5272
|
+
if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
|
|
5273
|
+
if (data.content_warning_level !== void 0) {
|
|
5274
|
+
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
5275
|
+
}
|
|
5276
|
+
if (data.content_warning_text !== void 0) {
|
|
5277
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
5278
|
+
}
|
|
5279
|
+
if (data.disabled_operations !== void 0) {
|
|
5280
|
+
this.disabledOperations = data.disabled_operations ?? 0;
|
|
5281
|
+
}
|
|
5282
|
+
if (data.message_history_cutoff !== void 0) {
|
|
5283
|
+
this.messageHistoryCutoff = data.message_history_cutoff ?? null;
|
|
5284
|
+
}
|
|
5285
|
+
if (data.permissions !== void 0) this.permissions = data.permissions ?? null;
|
|
4176
5286
|
if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
|
|
4177
5287
|
if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
|
|
4178
5288
|
if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
|
|
@@ -4193,11 +5303,11 @@ var Guild = class extends Base {
|
|
|
4193
5303
|
}
|
|
4194
5304
|
/** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
|
|
4195
5305
|
get createdTimestamp() {
|
|
4196
|
-
return
|
|
5306
|
+
return SnowflakeUtil9.timestampFromSnowflake(this.id);
|
|
4197
5307
|
}
|
|
4198
5308
|
/** Date when this guild was created, derived from its snowflake ID. */
|
|
4199
5309
|
get createdAt() {
|
|
4200
|
-
return
|
|
5310
|
+
return SnowflakeUtil9.dateFromSnowflake(this.id);
|
|
4201
5311
|
}
|
|
4202
5312
|
/** The guild's name. */
|
|
4203
5313
|
toString() {
|
|
@@ -4225,11 +5335,11 @@ var Guild = class extends Base {
|
|
|
4225
5335
|
});
|
|
4226
5336
|
}
|
|
4227
5337
|
/**
|
|
4228
|
-
* Create a channel. `
|
|
5338
|
+
* Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
|
|
4229
5339
|
* Requires Manage Channels.
|
|
4230
5340
|
*/
|
|
4231
|
-
createChannel(
|
|
4232
|
-
return createChannel(this,
|
|
5341
|
+
createChannel(options) {
|
|
5342
|
+
return createChannel(this, options);
|
|
4233
5343
|
}
|
|
4234
5344
|
/** Fetch all channels in this guild from the API. */
|
|
4235
5345
|
fetchChannels() {
|
|
@@ -4291,7 +5401,7 @@ var Guild = class extends Base {
|
|
|
4291
5401
|
resetRoleHoistPositions() {
|
|
4292
5402
|
return resetRoleHoistPositions(this);
|
|
4293
5403
|
}
|
|
4294
|
-
/** Ban a user from the guild. Requires Ban Members. `
|
|
5404
|
+
/** Ban a user from the guild. Requires Ban Members. `banDurationSeconds`: 0 = permanent. */
|
|
4295
5405
|
ban(userId, options) {
|
|
4296
5406
|
return ban(this, userId, options);
|
|
4297
5407
|
}
|
|
@@ -4300,12 +5410,12 @@ var Guild = class extends Base {
|
|
|
4300
5410
|
return fetchBans(this);
|
|
4301
5411
|
}
|
|
4302
5412
|
/** Unban a user from the guild. Requires Ban Members. */
|
|
4303
|
-
unban(userId) {
|
|
4304
|
-
return unban(this, userId);
|
|
5413
|
+
unban(userId, reason) {
|
|
5414
|
+
return unban(this, userId, reason);
|
|
4305
5415
|
}
|
|
4306
5416
|
/** Kick a user from the guild. Requires Kick Members. */
|
|
4307
|
-
kick(userId) {
|
|
4308
|
-
return kick(this, userId);
|
|
5417
|
+
kick(userId, reason) {
|
|
5418
|
+
return kick(this, userId, reason);
|
|
4309
5419
|
}
|
|
4310
5420
|
/** Fetch all emojis in this guild from the API. */
|
|
4311
5421
|
fetchEmojis() {
|
|
@@ -4491,23 +5601,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
4491
5601
|
}
|
|
4492
5602
|
|
|
4493
5603
|
// src/ClientCore/ClientUser.ts
|
|
4494
|
-
import { GatewayOpcodes, Routes as
|
|
5604
|
+
import { GatewayOpcodes, Routes as Routes31 } from "@fluxerjs/types";
|
|
4495
5605
|
var ClientUser = class extends User {
|
|
4496
5606
|
/** Broadcast presence (gateway opcode 3) on all shards. */
|
|
4497
5607
|
setPresence(presence) {
|
|
5608
|
+
this.client.options.presence = presence;
|
|
4498
5609
|
const wire = toPresenceWire(presence);
|
|
4499
|
-
this.client.options.presence = wire;
|
|
4500
5610
|
this.client._sendToAllShards({ op: GatewayOpcodes.PresenceUpdate, d: wire });
|
|
4501
5611
|
}
|
|
4502
5612
|
/** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
|
|
4503
5613
|
async fetch() {
|
|
4504
|
-
const data = await this.client.rest.get(
|
|
5614
|
+
const data = await this.client.rest.get(Routes31.currentUser(), { auth: true });
|
|
4505
5615
|
this._patch(data);
|
|
4506
5616
|
return this;
|
|
4507
5617
|
}
|
|
4508
5618
|
/** GET /users/@me/guilds — returns camelCase partial guilds. */
|
|
4509
5619
|
async fetchGuilds(options) {
|
|
4510
|
-
const path =
|
|
5620
|
+
const path = Routes31.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
|
|
4511
5621
|
const data = await this.client.rest.get(path, { auth: true });
|
|
4512
5622
|
return data.map((g) => ({
|
|
4513
5623
|
id: g.id,
|
|
@@ -4520,10 +5630,18 @@ var ClientUser = class extends User {
|
|
|
4520
5630
|
...g.approximate_presence_count !== void 0 ? { approximatePresenceCount: g.approximate_presence_count } : {}
|
|
4521
5631
|
}));
|
|
4522
5632
|
}
|
|
4523
|
-
/**
|
|
5633
|
+
/**
|
|
5634
|
+
* Leave a guild (`client.user.leaveGuild`).
|
|
5635
|
+
* DELETE /users/@me/guilds/{guild_id}.
|
|
5636
|
+
*
|
|
5637
|
+
* @param guildId - Guild to leave
|
|
5638
|
+
* @param options - Optional sudo / MFA body for user accounts
|
|
5639
|
+
* @example
|
|
5640
|
+
* await client.user.leaveGuild(guildId);
|
|
5641
|
+
*/
|
|
4524
5642
|
async leaveGuild(guildId, options) {
|
|
4525
5643
|
const body = options ? toSudoBody(options) : void 0;
|
|
4526
|
-
await this.client.rest.delete(
|
|
5644
|
+
await this.client.rest.delete(Routes31.leaveGuild(guildId), {
|
|
4527
5645
|
body: body && Object.keys(body).length ? body : void 0,
|
|
4528
5646
|
auth: true
|
|
4529
5647
|
});
|
|
@@ -4531,7 +5649,7 @@ var ClientUser = class extends User {
|
|
|
4531
5649
|
/** Delete every message authored by the caller across a guild (sudo). */
|
|
4532
5650
|
async bulkDeleteMyMessagesInGuild(guildId, options) {
|
|
4533
5651
|
const body = options ? toSudoBody(options) : void 0;
|
|
4534
|
-
await this.client.rest.post(
|
|
5652
|
+
await this.client.rest.post(Routes31.guildBulkDeleteMine(guildId), {
|
|
4535
5653
|
body: body && Object.keys(body).length ? body : void 0,
|
|
4536
5654
|
auth: true
|
|
4537
5655
|
});
|
|
@@ -4698,7 +5816,7 @@ var guildResourceHandlers = {
|
|
|
4698
5816
|
role = new Role(client, data.role, data.guild_id);
|
|
4699
5817
|
guild?.roles.set(role.id, role);
|
|
4700
5818
|
}
|
|
4701
|
-
client.emit(Events.GuildRoleUpdate,
|
|
5819
|
+
client.emit(Events.GuildRoleUpdate, oldRole, role);
|
|
4702
5820
|
},
|
|
4703
5821
|
GUILD_ROLE_UPDATE_BULK(client, d) {
|
|
4704
5822
|
const data = d;
|
|
@@ -4714,11 +5832,7 @@ var guildResourceHandlers = {
|
|
|
4714
5832
|
const guild = client.guilds.get(data.guild_id);
|
|
4715
5833
|
const role = guild?.roles.get(data.role_id) ?? null;
|
|
4716
5834
|
guild?.roles.delete(data.role_id);
|
|
4717
|
-
client.emit(Events.GuildRoleDelete,
|
|
4718
|
-
roleId: data.role_id,
|
|
4719
|
-
guildId: data.guild_id,
|
|
4720
|
-
role
|
|
4721
|
-
});
|
|
5835
|
+
client.emit(Events.GuildRoleDelete, role, data.guild_id, data.role_id);
|
|
4722
5836
|
},
|
|
4723
5837
|
GUILD_BAN_ADD(client, d) {
|
|
4724
5838
|
const data = d;
|
|
@@ -4751,7 +5865,14 @@ function markGuildUnavailable(client, id) {
|
|
|
4751
5865
|
guild.available = false;
|
|
4752
5866
|
client.emit(Events.GuildUnavailable, guild);
|
|
4753
5867
|
}
|
|
5868
|
+
function isStartupGuildHydration(client) {
|
|
5869
|
+
return client._guildStreamSettleTimeout !== null;
|
|
5870
|
+
}
|
|
4754
5871
|
var guildHandlers = {
|
|
5872
|
+
/**
|
|
5873
|
+
* Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
|
|
5874
|
+
* {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
|
|
5875
|
+
*/
|
|
4755
5876
|
GUILD_CREATE(client, d) {
|
|
4756
5877
|
const raw = d;
|
|
4757
5878
|
if (raw.unavailable === true) {
|
|
@@ -4764,11 +5885,32 @@ var guildHandlers = {
|
|
|
4764
5885
|
}
|
|
4765
5886
|
return;
|
|
4766
5887
|
}
|
|
5888
|
+
const startupHydration = isStartupGuildHydration(client);
|
|
5889
|
+
if (startupHydration) {
|
|
5890
|
+
resetGuildStreamSettle(client);
|
|
5891
|
+
}
|
|
4767
5892
|
const result = applyGuildSnapshotFromGateway(client, d);
|
|
4768
5893
|
if (!result) return;
|
|
4769
5894
|
const { guild, recovered } = result;
|
|
4770
|
-
|
|
4771
|
-
|
|
5895
|
+
const legacyStartup = client.options.emitGuildCreateOnStartup === true;
|
|
5896
|
+
const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
|
|
5897
|
+
const isStartupBackfill = wasReadyStub || startupHydration;
|
|
5898
|
+
if (recovered) {
|
|
5899
|
+
guild.available = true;
|
|
5900
|
+
if (legacyStartup && isStartupBackfill) {
|
|
5901
|
+
client.emit(Events.GuildCreate, guild);
|
|
5902
|
+
} else {
|
|
5903
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5904
|
+
}
|
|
5905
|
+
} else if (startupHydration) {
|
|
5906
|
+
if (legacyStartup) {
|
|
5907
|
+
client.emit(Events.GuildCreate, guild);
|
|
5908
|
+
} else {
|
|
5909
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5910
|
+
}
|
|
5911
|
+
} else {
|
|
5912
|
+
client.emit(Events.GuildCreate, guild);
|
|
5913
|
+
}
|
|
4772
5914
|
client._onGuildReceived(guild.id);
|
|
4773
5915
|
},
|
|
4774
5916
|
GUILD_UPDATE(client, d) {
|
|
@@ -4807,6 +5949,7 @@ var guildHandlers = {
|
|
|
4807
5949
|
markGuildUnavailable(client, id);
|
|
4808
5950
|
return;
|
|
4809
5951
|
}
|
|
5952
|
+
client._readyStubGuildIds.delete(id);
|
|
4810
5953
|
const guild = client.guilds.get(id);
|
|
4811
5954
|
if (!guild) return;
|
|
4812
5955
|
client.guilds.delete(id);
|
|
@@ -4827,7 +5970,7 @@ function normalizeInviteCreate(client, payload) {
|
|
|
4827
5970
|
const code = str(raw?.code);
|
|
4828
5971
|
if (!raw || !code) return null;
|
|
4829
5972
|
const typeNum = num(raw.type);
|
|
4830
|
-
const type = typeNum === InviteType2.GroupDM
|
|
5973
|
+
const type = typeNum === InviteType2.GroupDM ? InviteType2.GroupDM : InviteType2.Guild;
|
|
4831
5974
|
const shared = {
|
|
4832
5975
|
code,
|
|
4833
5976
|
inviter: raw.inviter ?? null,
|
|
@@ -4839,11 +5982,6 @@ function normalizeInviteCreate(client, payload) {
|
|
|
4839
5982
|
max_uses: num(raw.max_uses),
|
|
4840
5983
|
max_age: num(raw.max_age)
|
|
4841
5984
|
};
|
|
4842
|
-
if (type === InviteType2.EmojiPack || type === InviteType2.StickerPack) {
|
|
4843
|
-
const pack = asRecord(raw.pack);
|
|
4844
|
-
if (!pack || !str(pack.id) || !str(pack.name)) return null;
|
|
4845
|
-
return { ...shared, type, pack };
|
|
4846
|
-
}
|
|
4847
5985
|
const guildObj = asRecord(raw.guild);
|
|
4848
5986
|
const channelObj = asRecord(raw.channel);
|
|
4849
5987
|
const guildId = str(guildObj?.id) ?? str(raw.guild_id) ?? "0";
|
|
@@ -4895,6 +6033,30 @@ var inviteHandlers = {
|
|
|
4895
6033
|
}
|
|
4896
6034
|
};
|
|
4897
6035
|
|
|
6036
|
+
// src/Domain/Guild/PartialGuildMember.ts
|
|
6037
|
+
var PartialGuildMember = class {
|
|
6038
|
+
partial = true;
|
|
6039
|
+
client;
|
|
6040
|
+
id;
|
|
6041
|
+
user;
|
|
6042
|
+
guildId;
|
|
6043
|
+
guild;
|
|
6044
|
+
constructor(data) {
|
|
6045
|
+
this.client = data.client;
|
|
6046
|
+
this.id = data.id;
|
|
6047
|
+
this.user = data.user;
|
|
6048
|
+
this.guild = data.guild;
|
|
6049
|
+
this.guildId = data.guild.id;
|
|
6050
|
+
}
|
|
6051
|
+
/**
|
|
6052
|
+
* Fetch the full {@link GuildMember} from the API (cache-aware via `guild.members.fetch`).
|
|
6053
|
+
* @throws FluxerError with MEMBER_NOT_FOUND if the user is not in the guild
|
|
6054
|
+
*/
|
|
6055
|
+
async fetch() {
|
|
6056
|
+
return this.guild.members.fetch(this.id);
|
|
6057
|
+
}
|
|
6058
|
+
};
|
|
6059
|
+
|
|
4898
6060
|
// src/ClientCore/EventHandlers/Members.ts
|
|
4899
6061
|
var memberHandlers = {
|
|
4900
6062
|
GUILD_MEMBER_ADD(client, d) {
|
|
@@ -4921,28 +6083,15 @@ var memberHandlers = {
|
|
|
4921
6083
|
const data = d;
|
|
4922
6084
|
const guild = client.guilds.get(data.guild_id);
|
|
4923
6085
|
if (!guild || !data.user?.id) return;
|
|
4924
|
-
|
|
4925
|
-
if (
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
...data.user,
|
|
4934
|
-
username: data.user.username ?? "Unknown",
|
|
4935
|
-
discriminator: data.user.discriminator ?? "0"
|
|
4936
|
-
},
|
|
4937
|
-
roles: [],
|
|
4938
|
-
joined_at: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
4939
|
-
nick: null,
|
|
4940
|
-
mute: false,
|
|
4941
|
-
deaf: false
|
|
4942
|
-
},
|
|
4943
|
-
guild
|
|
4944
|
-
);
|
|
4945
|
-
}
|
|
6086
|
+
const cached = guild.members.get(data.user.id);
|
|
6087
|
+
if (cached) guild.members.delete(data.user.id);
|
|
6088
|
+
const user = client.getOrCreateUser(data.user);
|
|
6089
|
+
const member = cached ?? new PartialGuildMember({
|
|
6090
|
+
client,
|
|
6091
|
+
id: data.user.id,
|
|
6092
|
+
user,
|
|
6093
|
+
guild
|
|
6094
|
+
});
|
|
4946
6095
|
guild.adjustMemberCount(-1);
|
|
4947
6096
|
client.emit(Events.GuildMemberRemove, member);
|
|
4948
6097
|
},
|
|
@@ -4961,7 +6110,7 @@ var memberHandlers = {
|
|
|
4961
6110
|
members,
|
|
4962
6111
|
chunkIndex: data.chunk_index,
|
|
4963
6112
|
chunkCount: data.chunk_count,
|
|
4964
|
-
notFound: [],
|
|
6113
|
+
notFound: data.not_found ?? [],
|
|
4965
6114
|
nonce: data.nonce ?? null
|
|
4966
6115
|
};
|
|
4967
6116
|
client.emit(Events.GuildMembersChunk, payload);
|
|
@@ -4969,7 +6118,35 @@ var memberHandlers = {
|
|
|
4969
6118
|
};
|
|
4970
6119
|
|
|
4971
6120
|
// src/ClientCore/EventHandlers/Messages.ts
|
|
4972
|
-
|
|
6121
|
+
import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
|
|
6122
|
+
function cachedTextChannel(client, channelId) {
|
|
6123
|
+
const channel = client.channels.get(channelId);
|
|
6124
|
+
return channel?.isTextBased() ? channel : null;
|
|
6125
|
+
}
|
|
6126
|
+
function cachedMessage(client, channelId, messageId) {
|
|
6127
|
+
const data = client._getMessageCache(channelId)?.get(messageId);
|
|
6128
|
+
return data ? new Message(client, data) : null;
|
|
6129
|
+
}
|
|
6130
|
+
function isHydratableMessage(data) {
|
|
6131
|
+
return Boolean(data.author?.id && data.timestamp);
|
|
6132
|
+
}
|
|
6133
|
+
function toPartialMessage(client, args) {
|
|
6134
|
+
const cached = args.cached;
|
|
6135
|
+
const authorId = args.authorId ?? cached?.author?.id ?? null;
|
|
6136
|
+
const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
|
|
6137
|
+
const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil10.isValid(args.id) ? SnowflakeUtil10.dateFromSnowflake(args.id) : null;
|
|
6138
|
+
return new PartialMessage(client, {
|
|
6139
|
+
id: args.id,
|
|
6140
|
+
channelId: args.channelId,
|
|
6141
|
+
guildId: args.guildId ?? cached?.guild_id ?? null,
|
|
6142
|
+
channel: cachedTextChannel(client, args.channelId),
|
|
6143
|
+
content: args.content ?? cached?.content ?? null,
|
|
6144
|
+
authorId,
|
|
6145
|
+
author,
|
|
6146
|
+
createdAt
|
|
6147
|
+
});
|
|
6148
|
+
}
|
|
6149
|
+
function toReactionEmoji(emoji) {
|
|
4973
6150
|
return {
|
|
4974
6151
|
name: emoji.name,
|
|
4975
6152
|
...emoji.id !== void 0 ? { id: emoji.id } : {},
|
|
@@ -4986,9 +6163,12 @@ function emitReaction(event) {
|
|
|
4986
6163
|
const payload = {
|
|
4987
6164
|
reaction,
|
|
4988
6165
|
user,
|
|
6166
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6167
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
6168
|
+
member,
|
|
4989
6169
|
messageId: data.message_id,
|
|
4990
6170
|
channelId: data.channel_id,
|
|
4991
|
-
emoji:
|
|
6171
|
+
emoji: toReactionEmoji(data.emoji),
|
|
4992
6172
|
userId: data.user_id
|
|
4993
6173
|
};
|
|
4994
6174
|
client.emit(event, payload);
|
|
@@ -5008,37 +6188,60 @@ var messageHandlers = {
|
|
|
5008
6188
|
},
|
|
5009
6189
|
MESSAGE_UPDATE(client, d) {
|
|
5010
6190
|
const partial = d;
|
|
5011
|
-
const
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
if (
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
mergedData = { ...oldData, ...partial };
|
|
5019
|
-
}
|
|
6191
|
+
const oldData = client._getMessageCache(partial.channel_id)?.get(partial.id);
|
|
6192
|
+
const oldMessage = oldData ? new Message(client, oldData) : null;
|
|
6193
|
+
const mergedData = oldData ? { ...oldData, ...partial } : partial;
|
|
6194
|
+
if (isHydratableMessage(mergedData)) {
|
|
6195
|
+
client._addMessageToCache(partial.channel_id, mergedData);
|
|
6196
|
+
client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
|
|
6197
|
+
return;
|
|
5020
6198
|
}
|
|
5021
|
-
client.
|
|
5022
|
-
|
|
6199
|
+
client.emit(
|
|
6200
|
+
Events.MessageUpdate,
|
|
6201
|
+
oldMessage,
|
|
6202
|
+
toPartialMessage(client, {
|
|
6203
|
+
id: partial.id,
|
|
6204
|
+
channelId: partial.channel_id,
|
|
6205
|
+
guildId: partial.guild_id ?? oldData?.guild_id ?? null,
|
|
6206
|
+
content: partial.content ?? oldData?.content ?? null,
|
|
6207
|
+
authorId: partial.author?.id ?? oldData?.author?.id ?? null,
|
|
6208
|
+
cached: oldData
|
|
6209
|
+
})
|
|
6210
|
+
);
|
|
5023
6211
|
},
|
|
5024
6212
|
MESSAGE_DELETE(client, d) {
|
|
5025
6213
|
const data = d;
|
|
5026
|
-
client.
|
|
5027
|
-
client
|
|
6214
|
+
const cached = client._getMessageCache(data.channel_id)?.get(data.id);
|
|
6215
|
+
const payload = toPartialMessage(client, {
|
|
5028
6216
|
id: data.id,
|
|
5029
6217
|
channelId: data.channel_id,
|
|
5030
|
-
|
|
5031
|
-
content: data.content ?? null,
|
|
5032
|
-
authorId: data.author_id ?? null
|
|
6218
|
+
guildId: data.guild_id ?? cached?.guild_id ?? null,
|
|
6219
|
+
content: data.content ?? cached?.content ?? null,
|
|
6220
|
+
authorId: data.author_id ?? cached?.author?.id ?? null,
|
|
6221
|
+
cached
|
|
5033
6222
|
});
|
|
6223
|
+
client._removeMessageFromCache(data.channel_id, data.id);
|
|
6224
|
+
client.emit(Events.MessageDelete, payload);
|
|
5034
6225
|
},
|
|
5035
6226
|
MESSAGE_DELETE_BULK(client, d) {
|
|
5036
6227
|
const data = d;
|
|
5037
|
-
|
|
6228
|
+
const ids = data.ids ?? [];
|
|
6229
|
+
const cache = client._getMessageCache(data.channel_id);
|
|
6230
|
+
const messages = ids.map(
|
|
6231
|
+
(id) => toPartialMessage(client, {
|
|
6232
|
+
id,
|
|
6233
|
+
channelId: data.channel_id,
|
|
6234
|
+
guildId: data.guild_id ?? cache?.get(id)?.guild_id ?? null,
|
|
6235
|
+
cached: cache?.get(id)
|
|
6236
|
+
})
|
|
6237
|
+
);
|
|
6238
|
+
for (const id of ids) client._removeMessageFromCache(data.channel_id, id);
|
|
5038
6239
|
client.emit(Events.MessageDeleteBulk, {
|
|
5039
|
-
ids
|
|
6240
|
+
ids,
|
|
5040
6241
|
channelId: data.channel_id,
|
|
5041
|
-
guildId: data.guild_id ?? null
|
|
6242
|
+
guildId: data.guild_id ?? null,
|
|
6243
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
6244
|
+
messages
|
|
5042
6245
|
});
|
|
5043
6246
|
},
|
|
5044
6247
|
MESSAGE_REACTION_ADD: emitReaction(Events.MessageReactionAdd),
|
|
@@ -5048,7 +6251,9 @@ var messageHandlers = {
|
|
|
5048
6251
|
const payload = {
|
|
5049
6252
|
messageId: data.message_id,
|
|
5050
6253
|
channelId: data.channel_id,
|
|
5051
|
-
guildId: data.guild_id ?? null
|
|
6254
|
+
guildId: data.guild_id ?? null,
|
|
6255
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6256
|
+
channel: cachedTextChannel(client, data.channel_id)
|
|
5052
6257
|
};
|
|
5053
6258
|
client.emit(Events.MessageReactionRemoveAll, payload);
|
|
5054
6259
|
},
|
|
@@ -5058,7 +6263,9 @@ var messageHandlers = {
|
|
|
5058
6263
|
messageId: data.message_id,
|
|
5059
6264
|
channelId: data.channel_id,
|
|
5060
6265
|
guildId: data.guild_id ?? null,
|
|
5061
|
-
emoji:
|
|
6266
|
+
emoji: toReactionEmoji(data.emoji),
|
|
6267
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6268
|
+
channel: cachedTextChannel(client, data.channel_id)
|
|
5062
6269
|
};
|
|
5063
6270
|
client.emit(Events.MessageReactionRemoveEmoji, payload);
|
|
5064
6271
|
},
|
|
@@ -5077,7 +6284,7 @@ var messageHandlers = {
|
|
|
5077
6284
|
}
|
|
5078
6285
|
reactions.push({
|
|
5079
6286
|
userId: entry.user_id,
|
|
5080
|
-
emoji:
|
|
6287
|
+
emoji: toReactionEmoji(entry.emoji),
|
|
5081
6288
|
member
|
|
5082
6289
|
});
|
|
5083
6290
|
}
|
|
@@ -5085,6 +6292,8 @@ var messageHandlers = {
|
|
|
5085
6292
|
channelId: data.channel_id,
|
|
5086
6293
|
messageId: data.message_id,
|
|
5087
6294
|
guildId: data.guild_id ?? null,
|
|
6295
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6296
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
5088
6297
|
reactions
|
|
5089
6298
|
};
|
|
5090
6299
|
client.emit(Events.MessageReactionAddMany, payload);
|
|
@@ -5259,10 +6468,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
|
|
|
5259
6468
|
for (const g of guilds ?? []) {
|
|
5260
6469
|
if (g.unavailable === true) {
|
|
5261
6470
|
if (typeof g.id === "string") {
|
|
5262
|
-
|
|
5263
|
-
if (
|
|
5264
|
-
|
|
6471
|
+
let guild = client.guilds.get(g.id);
|
|
6472
|
+
if (!guild) {
|
|
6473
|
+
guild = new Guild(client, { id: g.id });
|
|
6474
|
+
guild.available = false;
|
|
6475
|
+
client.guilds.set(g.id, guild);
|
|
6476
|
+
} else if (guild.available !== false) {
|
|
6477
|
+
guild.available = false;
|
|
5265
6478
|
}
|
|
6479
|
+
client._readyStubGuildIds.add(g.id);
|
|
5266
6480
|
if (pending !== null) pending.add(g.id);
|
|
5267
6481
|
}
|
|
5268
6482
|
continue;
|
|
@@ -5290,22 +6504,36 @@ function clearGuildStreamSettle(client) {
|
|
|
5290
6504
|
clearTimeout(client._guildStreamSettleTimeout);
|
|
5291
6505
|
client._guildStreamSettleTimeout = null;
|
|
5292
6506
|
}
|
|
6507
|
+
function resetGuildStreamSettle(client) {
|
|
6508
|
+
clearGuildStreamSettle(client);
|
|
6509
|
+
client._guildStreamSettleTimeout = setTimeout(() => {
|
|
6510
|
+
client._guildStreamSettleTimeout = null;
|
|
6511
|
+
if (client.readyAt === null) finalizeClientReady(client);
|
|
6512
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
6513
|
+
}
|
|
5293
6514
|
function handleReadyPayload(client, data) {
|
|
5294
6515
|
client.user = new ClientUser(client, data.user);
|
|
5295
6516
|
const waitForGuilds = client.options.waitForGuilds === true;
|
|
5296
6517
|
const guilds = data.guilds ?? [];
|
|
5297
6518
|
const pending = hydrateReadyGuilds(client, guilds, waitForGuilds);
|
|
5298
|
-
if (
|
|
5299
|
-
|
|
6519
|
+
if (client.readyAt !== null) {
|
|
6520
|
+
if (pending !== null && pending.size > 0) {
|
|
6521
|
+
const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
|
|
6522
|
+
for (const id of pending) existing.add(id);
|
|
6523
|
+
client._pendingGuildIds = existing;
|
|
6524
|
+
}
|
|
5300
6525
|
return;
|
|
5301
6526
|
}
|
|
5302
|
-
if (
|
|
5303
|
-
client.
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
}, GUILD_STREAM_SETTLE_MS);
|
|
6527
|
+
if (pending !== null && pending.size > 0) {
|
|
6528
|
+
const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
|
|
6529
|
+
for (const id of pending) existing.add(id);
|
|
6530
|
+
client._pendingGuildIds = existing;
|
|
5307
6531
|
return;
|
|
5308
6532
|
}
|
|
6533
|
+
if (guilds.length === 0) {
|
|
6534
|
+
resetGuildStreamSettle(client);
|
|
6535
|
+
if (waitForGuilds) return;
|
|
6536
|
+
}
|
|
5309
6537
|
finalizeClientReady(client);
|
|
5310
6538
|
}
|
|
5311
6539
|
async function connectClientGateway(client, token, signal) {
|
|
@@ -5315,7 +6543,7 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5315
6543
|
const ws = new WebSocketManager({
|
|
5316
6544
|
token,
|
|
5317
6545
|
intents: client.options.intents ?? 0,
|
|
5318
|
-
presence: client.options.presence,
|
|
6546
|
+
presence: client.options.presence ? toPresenceWire(client.options.presence) : void 0,
|
|
5319
6547
|
flags: client.options.identifyFlags,
|
|
5320
6548
|
ignoredEvents: client.options.ignoredEvents,
|
|
5321
6549
|
initialGuildId: client.options.initialGuildId,
|
|
@@ -5324,24 +6552,57 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5324
6552
|
},
|
|
5325
6553
|
version: client.options.rest?.version ?? "1",
|
|
5326
6554
|
debug: client.options.gatewayDebug !== false,
|
|
5327
|
-
WebSocket: client.options.WebSocket
|
|
6555
|
+
WebSocket: client.options.WebSocket,
|
|
6556
|
+
shardCount: client.options.shardCount ?? client.options.totalShards,
|
|
6557
|
+
shardIds: client.options.shardIds ?? client.options.shardList,
|
|
6558
|
+
guildsPerShard: client.options.guildsPerShard,
|
|
6559
|
+
buildStrategy: client.options.buildStrategy,
|
|
6560
|
+
sessionStore: client.options.sessionStore,
|
|
6561
|
+
identifyThrottler: client.options.identifyThrottler
|
|
5328
6562
|
});
|
|
5329
6563
|
ws.on("dispatch", ({ payload }) => {
|
|
5330
6564
|
handleGatewayDispatch(client, payload, client._deferredGatewayDispatches).catch(
|
|
5331
6565
|
(err) => emitClientError(client, err)
|
|
5332
6566
|
);
|
|
5333
6567
|
});
|
|
5334
|
-
ws.on("ready", ({ data }) => {
|
|
5335
|
-
|
|
6568
|
+
ws.on("ready", ({ shardId, data }) => {
|
|
6569
|
+
client.emit(Events.ShardReady, shardId);
|
|
6570
|
+
try {
|
|
6571
|
+
handleReadyPayload(client, data);
|
|
6572
|
+
} catch (err) {
|
|
6573
|
+
emitClientError(client, err);
|
|
6574
|
+
}
|
|
6575
|
+
});
|
|
6576
|
+
ws.on("resumed", (shardId) => {
|
|
6577
|
+
client.emit(Events.ShardResumed, shardId);
|
|
6578
|
+
});
|
|
6579
|
+
ws.on("close", ({ shardId, code }) => {
|
|
6580
|
+
client.emit(Events.ShardDisconnect, shardId, code);
|
|
6581
|
+
if (code === GatewayCloseCodes.AuthenticationFailed) {
|
|
6582
|
+
emitClientError(
|
|
6583
|
+
client,
|
|
6584
|
+
new FluxerError("Gateway authentication failed (4004). Check the bot token.", {
|
|
6585
|
+
code: ErrorCodes.InvalidToken
|
|
6586
|
+
})
|
|
6587
|
+
);
|
|
6588
|
+
}
|
|
5336
6589
|
});
|
|
5337
|
-
ws.on("error", ({ error }) => {
|
|
5338
|
-
|
|
6590
|
+
ws.on("error", ({ shardId, error }) => {
|
|
6591
|
+
if (shardId >= 0) client.emit(Events.ShardError, shardId, error);
|
|
6592
|
+
client.logger.error("gateway error", {
|
|
6593
|
+
error: error.message,
|
|
6594
|
+
name: error.name,
|
|
6595
|
+
shardId
|
|
6596
|
+
});
|
|
5339
6597
|
client.emit(Events.Error, error);
|
|
5340
6598
|
});
|
|
5341
6599
|
ws.on("debug", (msg) => {
|
|
5342
6600
|
client.logger.debug(msg);
|
|
5343
6601
|
client.emit(Events.Debug, msg);
|
|
5344
6602
|
});
|
|
6603
|
+
ws.on("shardingRequired", (payload) => {
|
|
6604
|
+
client.emit(Events.ShardingRequired, payload);
|
|
6605
|
+
});
|
|
5345
6606
|
client._ws = ws;
|
|
5346
6607
|
const onAbort = () => {
|
|
5347
6608
|
ws.destroy();
|
|
@@ -5367,9 +6628,9 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5367
6628
|
}
|
|
5368
6629
|
|
|
5369
6630
|
// src/ClientCore/GuildManager.ts
|
|
5370
|
-
import { LimitedCollection as
|
|
5371
|
-
import { Routes as
|
|
5372
|
-
var GuildManager = class extends
|
|
6631
|
+
import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
|
|
6632
|
+
import { Routes as Routes32 } from "@fluxerjs/types";
|
|
6633
|
+
var GuildManager = class extends LimitedCollection5 {
|
|
5373
6634
|
constructor(client) {
|
|
5374
6635
|
super({
|
|
5375
6636
|
maxSize: client.cache.limits.guilds,
|
|
@@ -5378,8 +6639,8 @@ var GuildManager = class extends LimitedCollection4 {
|
|
|
5378
6639
|
this.client = client;
|
|
5379
6640
|
}
|
|
5380
6641
|
/**
|
|
5381
|
-
* Remove a guild and cascade its channels / message caches.
|
|
5382
|
-
*
|
|
6642
|
+
* Remove a guild from cache and cascade its channels / message caches.
|
|
6643
|
+
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
5383
6644
|
*/
|
|
5384
6645
|
delete(key) {
|
|
5385
6646
|
const guild = this.get(key);
|
|
@@ -5407,7 +6668,7 @@ var GuildManager = class extends LimitedCollection4 {
|
|
|
5407
6668
|
const cached = this.get(guildId);
|
|
5408
6669
|
if (cached && !options?.force) return cached;
|
|
5409
6670
|
try {
|
|
5410
|
-
const data = await this.client.rest.get(
|
|
6671
|
+
const data = await this.client.rest.get(Routes32.guild(guildId));
|
|
5411
6672
|
if (cached) {
|
|
5412
6673
|
cached._patch(data);
|
|
5413
6674
|
return cached;
|
|
@@ -5492,184 +6753,13 @@ var MessageCache = class {
|
|
|
5492
6753
|
}
|
|
5493
6754
|
};
|
|
5494
6755
|
|
|
5495
|
-
// src/ClientCore/PackManager.ts
|
|
5496
|
-
import {
|
|
5497
|
-
Routes as Routes32
|
|
5498
|
-
} from "@fluxerjs/types";
|
|
5499
|
-
function toPackSummaryPayload(data) {
|
|
5500
|
-
return {
|
|
5501
|
-
id: data.id,
|
|
5502
|
-
name: data.name,
|
|
5503
|
-
description: data.description,
|
|
5504
|
-
type: data.type,
|
|
5505
|
-
creatorId: data.creator_id,
|
|
5506
|
-
createdAt: data.created_at,
|
|
5507
|
-
updatedAt: data.updated_at,
|
|
5508
|
-
...data.installed_at !== void 0 ? { installedAt: data.installed_at } : {}
|
|
5509
|
-
};
|
|
5510
|
-
}
|
|
5511
|
-
function toEmojiPayload(data) {
|
|
5512
|
-
return {
|
|
5513
|
-
id: data.id,
|
|
5514
|
-
name: data.name,
|
|
5515
|
-
animated: data.animated
|
|
5516
|
-
};
|
|
5517
|
-
}
|
|
5518
|
-
function toStickerPayload(data) {
|
|
5519
|
-
return {
|
|
5520
|
-
id: data.id,
|
|
5521
|
-
name: data.name,
|
|
5522
|
-
description: data.description,
|
|
5523
|
-
tags: data.tags,
|
|
5524
|
-
animated: data.animated,
|
|
5525
|
-
nsfw: data.nsfw
|
|
5526
|
-
};
|
|
5527
|
-
}
|
|
5528
|
-
function toInvitePayload(data) {
|
|
5529
|
-
return {
|
|
5530
|
-
code: data.code,
|
|
5531
|
-
...data.max_uses !== void 0 ? { maxUses: data.max_uses } : {},
|
|
5532
|
-
...data.max_age !== void 0 ? { maxAge: data.max_age } : {},
|
|
5533
|
-
...data.uses !== void 0 ? { uses: data.uses } : {},
|
|
5534
|
-
...data.temporary !== void 0 ? { temporary: data.temporary } : {},
|
|
5535
|
-
...data.created_at !== void 0 ? { createdAt: data.created_at } : {},
|
|
5536
|
-
...data.expires_at !== void 0 ? { expiresAt: data.expires_at } : {}
|
|
5537
|
-
};
|
|
5538
|
-
}
|
|
5539
|
-
function mapDashboardSection(section) {
|
|
5540
|
-
return {
|
|
5541
|
-
installedLimit: section.installed_limit,
|
|
5542
|
-
createdLimit: section.created_limit,
|
|
5543
|
-
installed: section.installed.map(toPackSummaryPayload),
|
|
5544
|
-
created: section.created.map(toPackSummaryPayload)
|
|
5545
|
-
};
|
|
5546
|
-
}
|
|
5547
|
-
var PackManager = class {
|
|
5548
|
-
constructor(client) {
|
|
5549
|
-
this.client = client;
|
|
5550
|
-
}
|
|
5551
|
-
/** Fetch the current user's pack dashboard (camelCase summaries). */
|
|
5552
|
-
async fetchDashboard() {
|
|
5553
|
-
const data = await this.client.rest.get(Routes32.packs());
|
|
5554
|
-
return {
|
|
5555
|
-
emoji: mapDashboardSection(data.emoji),
|
|
5556
|
-
sticker: mapDashboardSection(data.sticker)
|
|
5557
|
-
};
|
|
5558
|
-
}
|
|
5559
|
-
/** Create a pack. */
|
|
5560
|
-
async create(packType, body) {
|
|
5561
|
-
const data = await this.client.rest.post(Routes32.packsByType(packType), {
|
|
5562
|
-
body
|
|
5563
|
-
});
|
|
5564
|
-
return toPackSummaryPayload(data);
|
|
5565
|
-
}
|
|
5566
|
-
/** Edit a pack. */
|
|
5567
|
-
async edit(packId, body) {
|
|
5568
|
-
const data = await this.client.rest.patch(Routes32.pack(packId), { body });
|
|
5569
|
-
return toPackSummaryPayload(data);
|
|
5570
|
-
}
|
|
5571
|
-
/** Delete a pack. */
|
|
5572
|
-
async delete(packId) {
|
|
5573
|
-
await this.client.rest.delete(Routes32.pack(packId));
|
|
5574
|
-
}
|
|
5575
|
-
/** Install a pack for the current user. */
|
|
5576
|
-
async install(packId) {
|
|
5577
|
-
await this.client.rest.post(Routes32.packInstall(packId));
|
|
5578
|
-
}
|
|
5579
|
-
/** Uninstall a pack for the current user. */
|
|
5580
|
-
async uninstall(packId) {
|
|
5581
|
-
await this.client.rest.delete(Routes32.packInstall(packId));
|
|
5582
|
-
}
|
|
5583
|
-
/** List invites for a pack. */
|
|
5584
|
-
async listInvites(packId) {
|
|
5585
|
-
const data = await this.client.rest.get(Routes32.packInvites(packId));
|
|
5586
|
-
return data.map(toInvitePayload);
|
|
5587
|
-
}
|
|
5588
|
-
/** Create an invite for a pack. */
|
|
5589
|
-
async createInvite(packId, options = {}) {
|
|
5590
|
-
const body = toPackInviteBody(options);
|
|
5591
|
-
const data = await this.client.rest.post(Routes32.packInvites(packId), {
|
|
5592
|
-
body: Object.keys(body).length ? body : void 0
|
|
5593
|
-
});
|
|
5594
|
-
return toInvitePayload(data);
|
|
5595
|
-
}
|
|
5596
|
-
/** List emojis in a pack. */
|
|
5597
|
-
async listEmojis(packId) {
|
|
5598
|
-
const data = await this.client.rest.get(Routes32.packEmojis(packId));
|
|
5599
|
-
return data.map(toEmojiPayload);
|
|
5600
|
-
}
|
|
5601
|
-
/** Create an emoji in a pack. */
|
|
5602
|
-
async createEmoji(packId, options) {
|
|
5603
|
-
const data = await this.client.rest.post(Routes32.packEmojis(packId), {
|
|
5604
|
-
body: toEmojiCreateBody(options)
|
|
5605
|
-
});
|
|
5606
|
-
return toEmojiPayload(data);
|
|
5607
|
-
}
|
|
5608
|
-
/** Bulk-create emojis in a pack. */
|
|
5609
|
-
async createEmojisBulk(packId, emojis) {
|
|
5610
|
-
const data = await this.client.rest.post(
|
|
5611
|
-
Routes32.packEmojisBulk(packId),
|
|
5612
|
-
{ body: { emojis: emojis.map(toEmojiCreateBody) } }
|
|
5613
|
-
);
|
|
5614
|
-
return {
|
|
5615
|
-
success: data.success.map(toEmojiPayload),
|
|
5616
|
-
failed: data.failed
|
|
5617
|
-
};
|
|
5618
|
-
}
|
|
5619
|
-
/** Edit an emoji in a pack. */
|
|
5620
|
-
async editEmoji(packId, emojiId, options) {
|
|
5621
|
-
const data = await this.client.rest.patch(Routes32.packEmoji(packId, emojiId), {
|
|
5622
|
-
body: toEmojiEditBody(options)
|
|
5623
|
-
});
|
|
5624
|
-
return toEmojiPayload(data);
|
|
5625
|
-
}
|
|
5626
|
-
/** Delete an emoji from a pack. */
|
|
5627
|
-
async deleteEmoji(packId, emojiId) {
|
|
5628
|
-
await this.client.rest.delete(Routes32.packEmoji(packId, emojiId));
|
|
5629
|
-
}
|
|
5630
|
-
/** List stickers in a pack. */
|
|
5631
|
-
async listStickers(packId) {
|
|
5632
|
-
const data = await this.client.rest.get(Routes32.packStickers(packId));
|
|
5633
|
-
return data.map(toStickerPayload);
|
|
5634
|
-
}
|
|
5635
|
-
/** Create a sticker in a pack. */
|
|
5636
|
-
async createSticker(packId, options) {
|
|
5637
|
-
const data = await this.client.rest.post(Routes32.packStickers(packId), {
|
|
5638
|
-
body: toStickerCreateBody(options)
|
|
5639
|
-
});
|
|
5640
|
-
return toStickerPayload(data);
|
|
5641
|
-
}
|
|
5642
|
-
/** Bulk-create stickers in a pack. */
|
|
5643
|
-
async createStickersBulk(packId, stickers) {
|
|
5644
|
-
const data = await this.client.rest.post(
|
|
5645
|
-
Routes32.packStickersBulk(packId),
|
|
5646
|
-
{ body: { stickers: stickers.map(toStickerCreateBody) } }
|
|
5647
|
-
);
|
|
5648
|
-
return {
|
|
5649
|
-
success: data.success.map(toStickerPayload),
|
|
5650
|
-
failed: data.failed
|
|
5651
|
-
};
|
|
5652
|
-
}
|
|
5653
|
-
/** Edit a sticker in a pack. */
|
|
5654
|
-
async editSticker(packId, stickerId, options) {
|
|
5655
|
-
const data = await this.client.rest.patch(Routes32.packSticker(packId, stickerId), {
|
|
5656
|
-
body: toStickerEditBody(options)
|
|
5657
|
-
});
|
|
5658
|
-
return toStickerPayload(data);
|
|
5659
|
-
}
|
|
5660
|
-
/** Delete a sticker from a pack. */
|
|
5661
|
-
async deleteSticker(packId, stickerId) {
|
|
5662
|
-
await this.client.rest.delete(Routes32.packSticker(packId, stickerId));
|
|
5663
|
-
}
|
|
5664
|
-
};
|
|
5665
|
-
|
|
5666
6756
|
// src/ClientCore/UserManager.ts
|
|
5667
|
-
import { LimitedCollection as
|
|
6757
|
+
import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
|
|
5668
6758
|
import {
|
|
5669
6759
|
Routes as Routes33
|
|
5670
6760
|
} from "@fluxerjs/types";
|
|
5671
6761
|
var soft = (p) => p.catch(() => null);
|
|
5672
|
-
var UserManager = class extends
|
|
6762
|
+
var UserManager = class extends LimitedCollection6 {
|
|
5673
6763
|
constructor(client) {
|
|
5674
6764
|
super({ maxSize: client.cache.limits.users });
|
|
5675
6765
|
this.client = client;
|
|
@@ -5687,11 +6777,17 @@ var UserManager = class extends LimitedCollection5 {
|
|
|
5687
6777
|
}
|
|
5688
6778
|
return removed;
|
|
5689
6779
|
}
|
|
5690
|
-
/** Fetch a user by ID and update cache. */
|
|
5691
|
-
async fetch(userId) {
|
|
6780
|
+
/** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
|
|
6781
|
+
async fetch(userId, options) {
|
|
6782
|
+
const cached = this.get(userId);
|
|
6783
|
+
if (cached && !options?.force) return cached;
|
|
5692
6784
|
const data = await this.client.rest.get(Routes33.user(userId));
|
|
5693
6785
|
return this.client.getOrCreateUser(data);
|
|
5694
6786
|
}
|
|
6787
|
+
/** Return a cached user, otherwise {@link fetch}. */
|
|
6788
|
+
async resolve(userId) {
|
|
6789
|
+
return this.get(userId) ?? this.fetch(userId);
|
|
6790
|
+
}
|
|
5695
6791
|
/**
|
|
5696
6792
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
5697
6793
|
* @example
|
|
@@ -5751,19 +6847,32 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5751
6847
|
users;
|
|
5752
6848
|
/** Cache limits, stats, sweeps, and cascade entry points. */
|
|
5753
6849
|
cache;
|
|
5754
|
-
/**
|
|
5755
|
-
packs = new PackManager(this);
|
|
5756
|
-
/** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
|
|
6850
|
+
/** Typed event handlers. Prefer `client.on(Events.*, ...)`. */
|
|
5757
6851
|
events;
|
|
5758
6852
|
/** The authenticated bot user. Null until READY is received. */
|
|
5759
6853
|
user = null;
|
|
5760
6854
|
/** Timestamp when the client became ready. Null until READY is received. */
|
|
5761
6855
|
readyAt = null;
|
|
6856
|
+
/**
|
|
6857
|
+
* Milliseconds since {@link readyAt}, or `null` if the client is not ready.
|
|
6858
|
+
* @example
|
|
6859
|
+
* client.on(Events.Ready, () => {
|
|
6860
|
+
* console.log(client.uptime);
|
|
6861
|
+
* });
|
|
6862
|
+
*/
|
|
6863
|
+
get uptime() {
|
|
6864
|
+
return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
|
|
6865
|
+
}
|
|
5762
6866
|
/** @internal WebSocket manager. */
|
|
5763
6867
|
_ws = null;
|
|
5764
6868
|
/** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
|
|
5765
6869
|
_pendingGuildIds = null;
|
|
5766
|
-
/**
|
|
6870
|
+
/** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
|
|
6871
|
+
_readyStubGuildIds = /* @__PURE__ */ new Set();
|
|
6872
|
+
/**
|
|
6873
|
+
* @internal Empty-READY guild stream window.
|
|
6874
|
+
* Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
|
|
6875
|
+
*/
|
|
5767
6876
|
_guildStreamSettleTimeout = null;
|
|
5768
6877
|
/** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
|
|
5769
6878
|
_deferredGatewayDispatches = [];
|
|
@@ -5794,7 +6903,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5794
6903
|
const restApi = options.rest?.api;
|
|
5795
6904
|
if (options.instance !== void 0) {
|
|
5796
6905
|
this.instance = resolveInstanceEndpoints(options.instance);
|
|
5797
|
-
resolveRestApi(this.instance.endpoints.
|
|
6906
|
+
resolveRestApi(this.instance.endpoints.api_public, restApi);
|
|
5798
6907
|
} else {
|
|
5799
6908
|
this.instance = resolveInstanceEndpoints(
|
|
5800
6909
|
restApi !== void 0 ? { api: restApi } : void 0
|
|
@@ -5807,27 +6916,31 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5807
6916
|
}
|
|
5808
6917
|
this.rest = new REST({
|
|
5809
6918
|
...this.options.rest,
|
|
5810
|
-
api: this.instance.endpoints.
|
|
5811
|
-
version: this.options.rest?.version ?? "1"
|
|
6919
|
+
api: this.instance.endpoints.api_public,
|
|
6920
|
+
version: this.options.rest?.version ?? "1",
|
|
6921
|
+
locale: this.options.locale ?? this.options.rest?.locale
|
|
5812
6922
|
});
|
|
5813
6923
|
}
|
|
5814
6924
|
/**
|
|
5815
6925
|
* Create a client from instance discovery (`GET /.well-known/fluxer`).
|
|
5816
|
-
*
|
|
6926
|
+
* Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
|
|
6927
|
+
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
6928
|
+
* Does not log in. Call {@link login} with a token afterward.
|
|
5817
6929
|
*
|
|
5818
|
-
* @param origin -
|
|
5819
|
-
* @param options - Client options (must not conflict with discovered `endpoints.
|
|
6930
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
|
|
6931
|
+
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
5820
6932
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
5821
6933
|
*/
|
|
5822
6934
|
static async fromDiscovery(origin, options = {}, connectOptions) {
|
|
5823
|
-
const
|
|
6935
|
+
const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
|
|
5824
6936
|
const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
|
|
5825
6937
|
const bootstrap = new REST({
|
|
5826
6938
|
...options.rest ?? {},
|
|
5827
|
-
api:
|
|
5828
|
-
version
|
|
6939
|
+
api: bootstrapOrigin,
|
|
6940
|
+
version,
|
|
6941
|
+
locale: options.locale ?? options.rest?.locale
|
|
5829
6942
|
});
|
|
5830
|
-
const raw = await bootstrap.get(
|
|
6943
|
+
const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
|
|
5831
6944
|
auth: false,
|
|
5832
6945
|
...connectOptions?.signal ? { signal: connectOptions.signal } : {}
|
|
5833
6946
|
});
|
|
@@ -5835,7 +6948,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5835
6948
|
const { rest, ...restOptions } = options;
|
|
5836
6949
|
return new _Client({
|
|
5837
6950
|
...restOptions,
|
|
5838
|
-
// Drop rest.api so discovered endpoints.
|
|
6951
|
+
// Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
|
|
5839
6952
|
...rest ? { rest: { ...rest, api: void 0 } } : {},
|
|
5840
6953
|
instance: discovery
|
|
5841
6954
|
});
|
|
@@ -5862,7 +6975,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5862
6975
|
return resolveClientEmoji(this, emoji, guildId);
|
|
5863
6976
|
}
|
|
5864
6977
|
/**
|
|
5865
|
-
* Fetch instance discovery document (
|
|
6978
|
+
* Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
|
|
5866
6979
|
* @returns Instance configuration (endpoints, features, metadata)
|
|
5867
6980
|
*/
|
|
5868
6981
|
fetchInstance() {
|
|
@@ -5899,33 +7012,23 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5899
7012
|
return fetchApplication(this);
|
|
5900
7013
|
}
|
|
5901
7014
|
/**
|
|
5902
|
-
* Fetch OAuth2 applications
|
|
5903
|
-
*
|
|
7015
|
+
* Fetch OAuth2 applications (`GET /oauth2/applications/@me`).
|
|
7016
|
+
* A bot token returns the bot application object (normalized to a one-element array).
|
|
7017
|
+
* A user token returns the owner's application list.
|
|
5904
7018
|
*/
|
|
5905
7019
|
fetchOAuthApplications() {
|
|
5906
7020
|
return fetchOAuthApplications(this);
|
|
5907
7021
|
}
|
|
5908
|
-
/**
|
|
5909
|
-
* Check username#discriminator availability.
|
|
5910
|
-
* @param username - Username to check
|
|
5911
|
-
* @param discriminator - Discriminator to check
|
|
5912
|
-
* @returns Availability result
|
|
5913
|
-
*/
|
|
5914
|
-
checkUsernameTag(username, discriminator) {
|
|
5915
|
-
return checkUsernameTag(this, username, discriminator);
|
|
5916
|
-
}
|
|
5917
7022
|
/**
|
|
5918
7023
|
* Preload recent messages for multiple channels (batch endpoint).
|
|
5919
|
-
* @
|
|
5920
|
-
* @returns Preload response with message counts/timestamps
|
|
7024
|
+
* Prefer this over {@link bulkFetchMessages} for bots (`bulkFetchMessages` is user-account only).
|
|
5921
7025
|
*/
|
|
5922
7026
|
preloadMessages(channelIds) {
|
|
5923
7027
|
return preloadMessages(this, channelIds);
|
|
5924
7028
|
}
|
|
5925
7029
|
/**
|
|
5926
7030
|
* Preload recent messages (alternate endpoint).
|
|
5927
|
-
*
|
|
5928
|
-
* @returns Preload response with message counts/timestamps
|
|
7031
|
+
* Prefer this over {@link bulkFetchMessages} for bots.
|
|
5929
7032
|
*/
|
|
5930
7033
|
preloadMessagesAlt(channelIds) {
|
|
5931
7034
|
return preloadMessagesAlt(this, channelIds);
|
|
@@ -5933,6 +7036,14 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5933
7036
|
bulkFetchMessages(requests, options = {}) {
|
|
5934
7037
|
return bulkFetchMessages(this, requests, options);
|
|
5935
7038
|
}
|
|
7039
|
+
/**
|
|
7040
|
+
* Search messages in the current bot scope (`POST /search/messages`, `scope: current`).
|
|
7041
|
+
* Other scopes are denied for bots (`BOT_SEARCH_SCOPE_UNAVAILABLE`).
|
|
7042
|
+
* Returns camelCase results (`hitsPerPage`) or `{ indexing: true }` while channels are indexed.
|
|
7043
|
+
*/
|
|
7044
|
+
searchMessages(options) {
|
|
7045
|
+
return searchMessages(this, options);
|
|
7046
|
+
}
|
|
5936
7047
|
/** @internal */
|
|
5937
7048
|
_getMessageCache(channelId) {
|
|
5938
7049
|
return this._messageCache.get(channelId);
|
|
@@ -5956,12 +7067,16 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5956
7067
|
/**
|
|
5957
7068
|
* Sweep cached messages (remove entries matching filter).
|
|
5958
7069
|
* Prefer {@link CacheController.sweepMessages} (`client.cache.sweepMessages`).
|
|
7070
|
+
* The filter receives a hydrated {@link Message} (`createdAt`), not the stored wire payload.
|
|
5959
7071
|
* @param filter - Predicate to test each message (return true to remove)
|
|
5960
7072
|
* @param channelId - Optional channel ID to scope sweep
|
|
5961
7073
|
* @returns Count of messages removed
|
|
5962
7074
|
*/
|
|
5963
7075
|
sweepMessages(filter, channelId) {
|
|
5964
|
-
return this._messageCache.sweep(
|
|
7076
|
+
return this._messageCache.sweep(
|
|
7077
|
+
filter ? (data, chId) => filter(new Message(this, data), chId) : void 0,
|
|
7078
|
+
channelId
|
|
7079
|
+
);
|
|
5965
7080
|
}
|
|
5966
7081
|
/**
|
|
5967
7082
|
* Sweep cached members across all guilds (remove entries matching filter).
|
|
@@ -5994,6 +7109,9 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5994
7109
|
}
|
|
5995
7110
|
/**
|
|
5996
7111
|
* The underlying {@link WebSocketManager} (throws if not logged in).
|
|
7112
|
+
* Gateway heartbeat ACK latency: `client.ws.ping` (ms, or `-1` before the first ACK).
|
|
7113
|
+
* @example
|
|
7114
|
+
* console.log(client.ws.ping);
|
|
5997
7115
|
* @throws {@link FluxerError} with {@link ErrorCodes.NotLoggedIn}
|
|
5998
7116
|
*/
|
|
5999
7117
|
get ws() {
|
|
@@ -6032,6 +7150,37 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6032
7150
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
6033
7151
|
this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildMembers, d: data });
|
|
6034
7152
|
}
|
|
7153
|
+
/**
|
|
7154
|
+
* Request guild member/online counts via gateway opcode 15.
|
|
7155
|
+
* Listen for `guildCountsUpdate`. Cached `guild.memberCount` / `guild.onlineCount` update when that event arrives.
|
|
7156
|
+
*/
|
|
7157
|
+
requestGuildCounts(options) {
|
|
7158
|
+
const guildIds = [...new Set(options.guildIds.filter(Boolean))];
|
|
7159
|
+
if (!guildIds.length) {
|
|
7160
|
+
throw new FluxerError("requestGuildCounts requires at least one guildId", {
|
|
7161
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
7162
|
+
});
|
|
7163
|
+
}
|
|
7164
|
+
const data = { guild_ids: guildIds };
|
|
7165
|
+
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
7166
|
+
this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildCounts, d: data });
|
|
7167
|
+
}
|
|
7168
|
+
/**
|
|
7169
|
+
* Request per-channel member counts via gateway opcode 16.
|
|
7170
|
+
* Event-only: listen for `channelMemberCountsUpdate`. There is no `channel.memberCount` field.
|
|
7171
|
+
*/
|
|
7172
|
+
requestChannelMemberCounts(options) {
|
|
7173
|
+
if (!options.guildId) {
|
|
7174
|
+
throw new FluxerError("requestChannelMemberCounts requires guildId", {
|
|
7175
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
7176
|
+
});
|
|
7177
|
+
}
|
|
7178
|
+
const data = { guild_id: options.guildId };
|
|
7179
|
+
if (options.channelId !== void 0) data.channel_id = options.channelId;
|
|
7180
|
+
if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
|
|
7181
|
+
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
7182
|
+
this._sendToAllShards({ op: GatewayOpcodes2.RequestChannelMemberCounts, d: data });
|
|
7183
|
+
}
|
|
6035
7184
|
/**
|
|
6036
7185
|
* Broadcast a gateway payload to all shards.
|
|
6037
7186
|
* @param payload - Gateway send payload
|
|
@@ -6045,9 +7194,13 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6045
7194
|
}
|
|
6046
7195
|
/**
|
|
6047
7196
|
* Connect to the gateway with a bot token.
|
|
7197
|
+
* @example
|
|
7198
|
+
* const client = new Client();
|
|
7199
|
+
* client.on(Events.Ready, () => console.log('Ready!'));
|
|
7200
|
+
* await client.login(process.env.FLUXER_BOT_TOKEN);
|
|
6048
7201
|
* @param token - Bot token from the developer portal
|
|
6049
7202
|
* @param options - Optional abort signal for cancellation
|
|
6050
|
-
* @returns
|
|
7203
|
+
* @returns This client (for chaining)
|
|
6051
7204
|
* @throws {@link FluxerError} if already logged in or token is invalid
|
|
6052
7205
|
*/
|
|
6053
7206
|
async login(token, options) {
|
|
@@ -6062,7 +7215,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6062
7215
|
this.rest.setToken(token);
|
|
6063
7216
|
try {
|
|
6064
7217
|
this._ws = await connectClientGateway(this, token, options?.signal);
|
|
6065
|
-
return
|
|
7218
|
+
return this;
|
|
6066
7219
|
} catch (err) {
|
|
6067
7220
|
this._ws?.destroy();
|
|
6068
7221
|
this._ws = null;
|
|
@@ -6091,6 +7244,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6091
7244
|
this.user = null;
|
|
6092
7245
|
this.readyAt = null;
|
|
6093
7246
|
this._pendingGuildIds = null;
|
|
7247
|
+
this._readyStubGuildIds.clear();
|
|
6094
7248
|
this.guilds.clear();
|
|
6095
7249
|
this.channels.clear();
|
|
6096
7250
|
this.users.clear();
|
|
@@ -6115,6 +7269,20 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6115
7269
|
);
|
|
6116
7270
|
}
|
|
6117
7271
|
}
|
|
7272
|
+
/**
|
|
7273
|
+
* REST path helpers ({@link Routes}). Pass the path to {@link REST client.rest}.
|
|
7274
|
+
* Prefer high-level helpers (`channel.send()`, `guild.members.fetch()`) when they exist.
|
|
7275
|
+
*
|
|
7276
|
+
* @example
|
|
7277
|
+
* const channel = await client.rest.get(Client.Routes.channel(channelId));
|
|
7278
|
+
*
|
|
7279
|
+
* @example
|
|
7280
|
+
* await client.rest.post(Client.Routes.channelMessages(channelId), {
|
|
7281
|
+
* body: { content: 'hello' },
|
|
7282
|
+
* });
|
|
7283
|
+
*
|
|
7284
|
+
* @see {@link Routes}
|
|
7285
|
+
*/
|
|
6118
7286
|
static get Routes() {
|
|
6119
7287
|
return Routes34;
|
|
6120
7288
|
}
|
|
@@ -6458,7 +7626,8 @@ var ClientCluster = class extends EventEmitter4 {
|
|
|
6458
7626
|
};
|
|
6459
7627
|
export {
|
|
6460
7628
|
AllowedMentions,
|
|
6461
|
-
AttachmentBuilder,
|
|
7629
|
+
AttachmentBuilder2 as AttachmentBuilder,
|
|
7630
|
+
AttachmentMeta,
|
|
6462
7631
|
AuditLogActionType,
|
|
6463
7632
|
BETA_CLIENT_CLUSTER_WARNING,
|
|
6464
7633
|
Base,
|
|
@@ -6485,31 +7654,39 @@ export {
|
|
|
6485
7654
|
GuildBan,
|
|
6486
7655
|
GuildChannel,
|
|
6487
7656
|
GuildEmoji,
|
|
7657
|
+
GuildManager,
|
|
6488
7658
|
GuildMember,
|
|
6489
7659
|
GuildMemberManager,
|
|
6490
7660
|
GuildMemberProfileFlags,
|
|
6491
7661
|
GuildMemberRoleManager,
|
|
6492
7662
|
GuildNSFWLevel2 as GuildNSFWLevel,
|
|
6493
7663
|
GuildOperations,
|
|
7664
|
+
GuildRoleManager,
|
|
6494
7665
|
GuildSticker,
|
|
7666
|
+
INSTANCE_DISCOVERY_PATH,
|
|
6495
7667
|
Invite,
|
|
6496
7668
|
InviteType3 as InviteType,
|
|
6497
7669
|
LinkChannel,
|
|
6498
7670
|
Message,
|
|
6499
|
-
MessageAttachmentFlags,
|
|
7671
|
+
MessageAttachmentFlags2 as MessageAttachmentFlags,
|
|
6500
7672
|
MessageCollector,
|
|
6501
7673
|
MessageFlags,
|
|
6502
|
-
MessageFlagsBitField,
|
|
7674
|
+
MessageFlagsBitField2 as MessageFlagsBitField,
|
|
6503
7675
|
MessageFlagsBits,
|
|
6504
7676
|
MessageManager,
|
|
6505
7677
|
MessagePayload2 as MessagePayload,
|
|
6506
7678
|
MessageReaction,
|
|
7679
|
+
MessageReactionManager,
|
|
6507
7680
|
MessageReferenceType2 as MessageReferenceType,
|
|
7681
|
+
MessageSticker,
|
|
6508
7682
|
MessageType2 as MessageType,
|
|
6509
7683
|
OverwriteType2 as OverwriteType,
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
7684
|
+
PartialGuildMember,
|
|
7685
|
+
PartialMessage,
|
|
7686
|
+
PermissionFlags5 as PermissionFlags,
|
|
7687
|
+
PermissionOverwrite,
|
|
7688
|
+
PermissionOverwriteManager,
|
|
7689
|
+
PermissionsBitField4 as PermissionsBitField,
|
|
6513
7690
|
PublicUserFlags,
|
|
6514
7691
|
ReactionCollector,
|
|
6515
7692
|
RelationshipType,
|
|
@@ -6535,6 +7712,7 @@ export {
|
|
|
6535
7712
|
cdnMemberBannerURL,
|
|
6536
7713
|
cdnStickerURL,
|
|
6537
7714
|
createLogger2 as createLogger,
|
|
7715
|
+
instanceDiscoveryUrl,
|
|
6538
7716
|
inviteUrl,
|
|
6539
7717
|
normalizeApiOrigin,
|
|
6540
7718
|
normalizeCacheLimit,
|
|
@@ -6544,26 +7722,6 @@ export {
|
|
|
6544
7722
|
resolveCacheLimits,
|
|
6545
7723
|
resolveInstanceEndpoints,
|
|
6546
7724
|
resolveKlipyToImageUrl,
|
|
6547
|
-
|
|
6548
|
-
serializeError
|
|
6549
|
-
toAttachmentUploadCompleteBody,
|
|
6550
|
-
toAttachmentUploadPlanBody,
|
|
6551
|
-
toBulkFetchWire,
|
|
6552
|
-
toChannelEditBody,
|
|
6553
|
-
toChannelInviteBody,
|
|
6554
|
-
toDiscoveryApplicationPayload,
|
|
6555
|
-
toDiscoveryBody,
|
|
6556
|
-
toDiscoveryStatusPayload,
|
|
6557
|
-
toEmojiCreateBody,
|
|
6558
|
-
toEmojiEditBody,
|
|
6559
|
-
toMemberEditBody,
|
|
6560
|
-
toMemberSearchBody,
|
|
6561
|
-
toMessageAttachmentEditWire,
|
|
6562
|
-
toPackInviteBody,
|
|
6563
|
-
toPackSummaryPayload,
|
|
6564
|
-
toPresenceWire,
|
|
6565
|
-
toProfilePayload,
|
|
6566
|
-
toStickerCreateBody,
|
|
6567
|
-
toStickerEditBody,
|
|
6568
|
-
toSudoBody
|
|
7725
|
+
resolvePermissionsToBitfield4 as resolvePermissionsToBitfield,
|
|
7726
|
+
serializeError
|
|
6569
7727
|
};
|