@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/message.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/Domain/Message/Message.ts
|
|
2
2
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
3
|
-
import { Collection as
|
|
3
|
+
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
4
4
|
import {
|
|
5
5
|
MessageType,
|
|
6
6
|
Routes as Routes4
|
|
7
7
|
} from "@fluxerjs/types";
|
|
8
|
+
import { MessageFlagsBitField } from "@fluxerjs/util";
|
|
8
9
|
|
|
9
10
|
// src/ClientCore/SdkOptions/Attachments.ts
|
|
10
11
|
function toMessageAttachmentEditWire(attachments) {
|
|
@@ -21,9 +22,16 @@ function toMessageAttachmentEditWire(attachments) {
|
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
// src/Helpers/AuditReason.ts
|
|
26
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
27
|
+
function auditReasonHeaders(reason) {
|
|
28
|
+
if (reason == null || reason === "") return {};
|
|
29
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
// src/Helpers/MessageUtils/Body.ts
|
|
25
|
-
import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
26
|
-
import { MessageReferenceType } from "@fluxerjs/types";
|
|
33
|
+
import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
34
|
+
import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
|
|
27
35
|
|
|
28
36
|
// src/LibErrors/ErrorCodes.ts
|
|
29
37
|
import { ErrorCodes } from "@fluxerjs/util";
|
|
@@ -92,6 +100,37 @@ function applyReplyPingSuppression(body) {
|
|
|
92
100
|
function assignIfDefined(target, key, value) {
|
|
93
101
|
if (value !== void 0) target[key] = value;
|
|
94
102
|
}
|
|
103
|
+
function normalizeSendFiles(files) {
|
|
104
|
+
if (!files?.length) return void 0;
|
|
105
|
+
const normalized = [];
|
|
106
|
+
const metaFromBuilders = [];
|
|
107
|
+
let anyBuilderMeta = false;
|
|
108
|
+
for (let i = 0; i < files.length; i++) {
|
|
109
|
+
const file = files[i];
|
|
110
|
+
if (!file) continue;
|
|
111
|
+
if (file instanceof AttachmentBuilder) {
|
|
112
|
+
normalized.push(file.toFileData());
|
|
113
|
+
const meta = {
|
|
114
|
+
id: i,
|
|
115
|
+
filename: file.filename,
|
|
116
|
+
...file.description != null ? { description: file.description } : {},
|
|
117
|
+
...file.spoiler ? { flags: MessageAttachmentFlags.IS_SPOILER } : {}
|
|
118
|
+
};
|
|
119
|
+
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
120
|
+
metaFromBuilders.push(meta);
|
|
121
|
+
} else {
|
|
122
|
+
normalized.push(file);
|
|
123
|
+
metaFromBuilders.push({
|
|
124
|
+
id: i,
|
|
125
|
+
filename: file.filename ?? file.name
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
files: normalized,
|
|
131
|
+
metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
|
|
132
|
+
};
|
|
133
|
+
}
|
|
95
134
|
function buildSendBody(options) {
|
|
96
135
|
const body = typeof options === "string" ? { content: options } : options;
|
|
97
136
|
const result = {};
|
|
@@ -99,16 +138,17 @@ function buildSendBody(options) {
|
|
|
99
138
|
if (body.embeds?.length) {
|
|
100
139
|
result.embeds = body.embeds.map((e) => e instanceof EmbedBuilder ? e.toJSON() : e);
|
|
101
140
|
}
|
|
141
|
+
const normalizedFiles = normalizeSendFiles(body.files);
|
|
102
142
|
if (body.uploadedAttachments?.length) {
|
|
103
143
|
result.attachments = body.uploadedAttachments;
|
|
104
|
-
} else if (
|
|
144
|
+
} else if (normalizedFiles?.files.length) {
|
|
105
145
|
result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
|
|
106
146
|
id: a.id,
|
|
107
147
|
filename: a.filename,
|
|
108
148
|
...a.title != null && { title: a.title },
|
|
109
149
|
...a.description != null && { description: a.description },
|
|
110
150
|
...a.flags != null && { flags: a.flags }
|
|
111
|
-
})) :
|
|
151
|
+
})) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
|
|
112
152
|
}
|
|
113
153
|
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
114
154
|
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
@@ -202,9 +242,10 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
202
242
|
} else if (allowedMentions?.repliedUser === false) {
|
|
203
243
|
applyReplyPingSuppression(body);
|
|
204
244
|
}
|
|
245
|
+
const resolvedFiles = normalizeSendFiles(files);
|
|
205
246
|
return {
|
|
206
247
|
body,
|
|
207
|
-
files: !uploadedAttachments?.length && files
|
|
248
|
+
files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
|
|
208
249
|
};
|
|
209
250
|
}
|
|
210
251
|
|
|
@@ -250,13 +291,17 @@ var Base = class {
|
|
|
250
291
|
};
|
|
251
292
|
|
|
252
293
|
// src/Domain/Message/MessageReaction.ts
|
|
253
|
-
var MessageReaction = class extends Base {
|
|
294
|
+
var MessageReaction = class _MessageReaction extends Base {
|
|
254
295
|
client;
|
|
255
296
|
messageId;
|
|
256
297
|
channelId;
|
|
257
298
|
guildId;
|
|
258
299
|
emoji;
|
|
259
|
-
/**
|
|
300
|
+
/** Total count when hydrated from a message payload; `1` for gateway add events. */
|
|
301
|
+
count;
|
|
302
|
+
/** Whether the current user reacted (message payload); false for gateway remove. */
|
|
303
|
+
me;
|
|
304
|
+
/** Raw gateway payload for low-level access (null when built from a message aggregate). */
|
|
260
305
|
_data;
|
|
261
306
|
constructor(client, data) {
|
|
262
307
|
super();
|
|
@@ -270,6 +315,26 @@ var MessageReaction = class extends Base {
|
|
|
270
315
|
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
271
316
|
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
272
317
|
};
|
|
318
|
+
this.count = 1;
|
|
319
|
+
this.me = false;
|
|
320
|
+
}
|
|
321
|
+
/** Build a reaction aggregate from a message's `reactions` array entry. */
|
|
322
|
+
static fromMessage(message, data) {
|
|
323
|
+
const reaction = new _MessageReaction(message.client, {
|
|
324
|
+
user_id: message.client.user?.id ?? "0",
|
|
325
|
+
message_id: message.id,
|
|
326
|
+
channel_id: message.channelId,
|
|
327
|
+
guild_id: message.guildId ?? void 0,
|
|
328
|
+
emoji: {
|
|
329
|
+
name: data.emoji.name,
|
|
330
|
+
id: data.emoji.id ?? void 0,
|
|
331
|
+
animated: data.emoji.animated ?? void 0
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
Object.defineProperty(reaction, "_data", { value: null });
|
|
335
|
+
reaction.count = data.count;
|
|
336
|
+
reaction.me = data.me ?? false;
|
|
337
|
+
return reaction;
|
|
273
338
|
}
|
|
274
339
|
/** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
|
|
275
340
|
get emojiIdentifier() {
|
|
@@ -279,12 +344,23 @@ var MessageReaction = class extends Base {
|
|
|
279
344
|
get guild() {
|
|
280
345
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
281
346
|
}
|
|
347
|
+
/** Cached message this reaction belongs to, or null if the message was not cached. */
|
|
348
|
+
get message() {
|
|
349
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
|
|
350
|
+
return cached ? new Message(this.client, cached) : null;
|
|
351
|
+
}
|
|
352
|
+
/** Cached text-capable channel, or null if uncached / not text-based. */
|
|
353
|
+
get channel() {
|
|
354
|
+
const channel = this.client.channels.get(this.channelId);
|
|
355
|
+
return channel?.isTextBased() ? channel : null;
|
|
356
|
+
}
|
|
282
357
|
/**
|
|
283
|
-
* Fetch the message this reaction belongs to.
|
|
284
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
358
|
+
* Fetch the message this reaction belongs to (cache first, then REST).
|
|
285
359
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
286
360
|
*/
|
|
287
361
|
async fetchMessage() {
|
|
362
|
+
const cached = this.message;
|
|
363
|
+
if (cached) return cached;
|
|
288
364
|
try {
|
|
289
365
|
const data = await this.client.rest.get(
|
|
290
366
|
Routes.channelMessage(this.channelId, this.messageId)
|
|
@@ -355,11 +431,17 @@ var Events = {
|
|
|
355
431
|
WebhooksUpdate: "webhooksUpdate",
|
|
356
432
|
Resumed: "resumed",
|
|
357
433
|
Error: "error",
|
|
358
|
-
Debug: "debug"
|
|
434
|
+
Debug: "debug",
|
|
435
|
+
ShardReady: "shardReady",
|
|
436
|
+
ShardResumed: "shardResumed",
|
|
437
|
+
ShardDisconnect: "shardDisconnect",
|
|
438
|
+
ShardReconnecting: "shardReconnecting",
|
|
439
|
+
ShardError: "shardError",
|
|
440
|
+
ShardingRequired: "shardingRequired"
|
|
359
441
|
};
|
|
360
442
|
|
|
361
443
|
// src/Helpers/ReactionCollector.ts
|
|
362
|
-
var ReactionCollector = class extends EventEmitter {
|
|
444
|
+
var ReactionCollector = class _ReactionCollector extends EventEmitter {
|
|
363
445
|
client;
|
|
364
446
|
messageId;
|
|
365
447
|
channelId;
|
|
@@ -402,15 +484,17 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
402
484
|
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
403
485
|
}
|
|
404
486
|
});
|
|
405
|
-
const
|
|
487
|
+
const cached = this.client.users.get(entry.userId);
|
|
488
|
+
const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
|
|
489
|
+
{
|
|
406
490
|
id: entry.userId,
|
|
407
491
|
username: "Unknown",
|
|
408
492
|
discriminator: "0",
|
|
409
|
-
|
|
493
|
+
globalName: null,
|
|
410
494
|
avatar: null,
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
495
|
+
bot: false,
|
|
496
|
+
system: false
|
|
497
|
+
};
|
|
414
498
|
this._collect(reaction, user, entry.userId);
|
|
415
499
|
}
|
|
416
500
|
};
|
|
@@ -442,6 +526,21 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
442
526
|
}
|
|
443
527
|
this.emit("end", this.collected, reason);
|
|
444
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* One-shot helper used by {@link Message.awaitReactions}.
|
|
531
|
+
* Resolves with the collected reactions when the collector ends.
|
|
532
|
+
* Rejects if `options.errors` includes the end reason.
|
|
533
|
+
*/
|
|
534
|
+
static awaitReactions(client, messageId, channelId, options) {
|
|
535
|
+
const errors = options?.errors ?? [];
|
|
536
|
+
return new Promise((resolve, reject) => {
|
|
537
|
+
const collector = new _ReactionCollector(client, messageId, channelId, options);
|
|
538
|
+
collector.on("end", (collected, reason) => {
|
|
539
|
+
if (errors.includes(reason)) reject(collected);
|
|
540
|
+
else resolve(collected);
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
}
|
|
445
544
|
on(event, listener) {
|
|
446
545
|
return super.on(event, listener);
|
|
447
546
|
}
|
|
@@ -450,70 +549,242 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
450
549
|
}
|
|
451
550
|
};
|
|
452
551
|
|
|
453
|
-
// src/Domain/Message/
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
552
|
+
// src/Domain/Message/Attachment.ts
|
|
553
|
+
function toMessageAttachment(data) {
|
|
554
|
+
return {
|
|
555
|
+
id: data.id,
|
|
556
|
+
filename: data.filename,
|
|
557
|
+
title: data.title ?? null,
|
|
558
|
+
description: data.description ?? null,
|
|
559
|
+
contentType: data.content_type ?? null,
|
|
560
|
+
contentHash: data.content_hash ?? null,
|
|
561
|
+
size: data.size,
|
|
562
|
+
url: data.url ?? null,
|
|
563
|
+
proxyUrl: data.proxy_url ?? null,
|
|
564
|
+
width: data.width ?? null,
|
|
565
|
+
height: data.height ?? null,
|
|
566
|
+
placeholder: data.placeholder ?? null,
|
|
567
|
+
flags: data.flags ?? 0,
|
|
568
|
+
nsfw: data.nsfw ?? false,
|
|
569
|
+
duration: data.duration ?? null,
|
|
570
|
+
waveform: data.waveform ?? null,
|
|
571
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
572
|
+
expired: data.expired ?? false
|
|
573
|
+
};
|
|
458
574
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
575
|
+
|
|
576
|
+
// src/Domain/Message/Embed.ts
|
|
577
|
+
function toMessageEmbedAuthor(data) {
|
|
578
|
+
return {
|
|
579
|
+
name: data.name ?? null,
|
|
580
|
+
url: data.url ?? null,
|
|
581
|
+
iconUrl: data.icon_url ?? null,
|
|
582
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function toMessageEmbedFooter(data) {
|
|
586
|
+
return {
|
|
587
|
+
text: data.text,
|
|
588
|
+
iconUrl: data.icon_url ?? null,
|
|
589
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
function toMessageEmbedMedia(data) {
|
|
593
|
+
return {
|
|
594
|
+
url: data.url,
|
|
595
|
+
proxyUrl: data.proxy_url ?? null,
|
|
596
|
+
contentType: data.content_type ?? null,
|
|
597
|
+
contentHash: data.content_hash ?? null,
|
|
598
|
+
width: data.width ?? null,
|
|
599
|
+
height: data.height ?? null,
|
|
600
|
+
description: data.description ?? null,
|
|
601
|
+
placeholder: data.placeholder ?? null,
|
|
602
|
+
duration: data.duration ?? null,
|
|
603
|
+
flags: data.flags ?? null
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function toMessageEmbed(data) {
|
|
607
|
+
const full = data;
|
|
608
|
+
return {
|
|
609
|
+
type: data.type ?? "rich",
|
|
610
|
+
url: data.url ?? null,
|
|
611
|
+
title: data.title ?? null,
|
|
612
|
+
color: data.color ?? null,
|
|
613
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
614
|
+
description: data.description ?? null,
|
|
615
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
616
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
617
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
618
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
619
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
620
|
+
name: f.name,
|
|
621
|
+
value: f.value,
|
|
622
|
+
inline: f.inline ?? false
|
|
623
|
+
})),
|
|
624
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
625
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
626
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
627
|
+
nsfw: data.nsfw ?? false,
|
|
628
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
629
|
+
html: full.html ?? null,
|
|
630
|
+
htmlWidth: full.html_width ?? null,
|
|
631
|
+
htmlHeight: full.html_height ?? null
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
636
|
+
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
637
|
+
var MessageReactionManager = class {
|
|
638
|
+
constructor(message) {
|
|
639
|
+
this.message = message;
|
|
466
640
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
641
|
+
_cache = new Collection2();
|
|
642
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
643
|
+
get cache() {
|
|
644
|
+
return this._cache;
|
|
470
645
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return {
|
|
474
|
-
name: parsed.name,
|
|
475
|
-
id: parsed.id,
|
|
476
|
-
...parsed.animated ? { animated: true } : {}
|
|
477
|
-
};
|
|
646
|
+
get size() {
|
|
647
|
+
return this._cache.size;
|
|
478
648
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (!user) return;
|
|
489
|
-
const emojiPayload = toReactionEmoji(wireOrInput);
|
|
490
|
-
const reaction = new MessageReaction(message.client, {
|
|
491
|
-
user_id: user.id,
|
|
492
|
-
channel_id: message.channelId,
|
|
493
|
-
message_id: message.id,
|
|
494
|
-
guild_id: message.guildId ?? void 0,
|
|
495
|
-
emoji: {
|
|
496
|
-
name: emojiPayload.name,
|
|
497
|
-
...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
|
|
498
|
-
...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
|
|
649
|
+
[Symbol.iterator]() {
|
|
650
|
+
return this._cache.values();
|
|
651
|
+
}
|
|
652
|
+
/** @internal Sync from an API message payload. */
|
|
653
|
+
_patch(reactions) {
|
|
654
|
+
this._cache.clear();
|
|
655
|
+
for (const data of reactions ?? []) {
|
|
656
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
657
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
499
658
|
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// src/Domain/Message/MessageSticker.ts
|
|
663
|
+
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
664
|
+
|
|
665
|
+
// src/Helpers/Constants.ts
|
|
666
|
+
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
667
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
668
|
+
|
|
669
|
+
// src/Helpers/Cdn.ts
|
|
670
|
+
var CDN_SIZE_LADDER = [
|
|
671
|
+
16,
|
|
672
|
+
20,
|
|
673
|
+
22,
|
|
674
|
+
24,
|
|
675
|
+
28,
|
|
676
|
+
32,
|
|
677
|
+
40,
|
|
678
|
+
44,
|
|
679
|
+
48,
|
|
680
|
+
56,
|
|
681
|
+
60,
|
|
682
|
+
64,
|
|
683
|
+
80,
|
|
684
|
+
96,
|
|
685
|
+
100,
|
|
686
|
+
128,
|
|
687
|
+
160,
|
|
688
|
+
240,
|
|
689
|
+
256,
|
|
690
|
+
300,
|
|
691
|
+
320,
|
|
692
|
+
480,
|
|
693
|
+
512,
|
|
694
|
+
600,
|
|
695
|
+
640,
|
|
696
|
+
1024,
|
|
697
|
+
1280,
|
|
698
|
+
1536,
|
|
699
|
+
2048,
|
|
700
|
+
3072,
|
|
701
|
+
4096,
|
|
702
|
+
8192,
|
|
703
|
+
16384
|
|
704
|
+
];
|
|
705
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
706
|
+
icon: { min: 128, max: 1024 },
|
|
707
|
+
banner: { min: 480, max: 2400 },
|
|
708
|
+
emoji: { min: 32, max: 512 },
|
|
709
|
+
sticker: { min: 128, max: 512 }
|
|
710
|
+
};
|
|
711
|
+
function nearestSize(requested, candidates) {
|
|
712
|
+
let best = candidates[0];
|
|
713
|
+
let bestDist = Math.abs(requested - best);
|
|
714
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
715
|
+
const step = candidates[i];
|
|
716
|
+
const dist = Math.abs(requested - step);
|
|
717
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
718
|
+
best = step;
|
|
719
|
+
bestDist = dist;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return best;
|
|
723
|
+
}
|
|
724
|
+
function snapCdnSize(requested, assetClass) {
|
|
725
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
726
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
727
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
728
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
729
|
+
return nearestSize(clamped, allowed);
|
|
730
|
+
}
|
|
731
|
+
function mediaBase(options) {
|
|
732
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
733
|
+
}
|
|
734
|
+
function appendSize(options, assetClass) {
|
|
735
|
+
const size = options?.size;
|
|
736
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
737
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
738
|
+
}
|
|
739
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
740
|
+
const ext = animated ? "gif" : "png";
|
|
741
|
+
const size = appendSize(options, "sticker");
|
|
742
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// src/Domain/Message/MessageSticker.ts
|
|
746
|
+
var MessageSticker = class extends Base {
|
|
747
|
+
client;
|
|
748
|
+
id;
|
|
749
|
+
name;
|
|
750
|
+
description;
|
|
751
|
+
tags;
|
|
752
|
+
animated;
|
|
753
|
+
constructor(client, data) {
|
|
754
|
+
super();
|
|
755
|
+
this.client = client;
|
|
756
|
+
this.id = data.id;
|
|
757
|
+
this.name = data.name;
|
|
758
|
+
this.description = data.description ?? "";
|
|
759
|
+
this.tags = data.tags ?? [];
|
|
760
|
+
this.animated = data.animated ?? false;
|
|
761
|
+
}
|
|
762
|
+
/** CDN URL for this sticker image. */
|
|
763
|
+
get url() {
|
|
764
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
765
|
+
mediaBase: this.client.instance.endpoints.media
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
769
|
+
get createdTimestamp() {
|
|
770
|
+
return SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
771
|
+
}
|
|
772
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
773
|
+
get createdAt() {
|
|
774
|
+
return SnowflakeUtil.dateFromSnowflake(this.id);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// src/Domain/Message/Reactions.ts
|
|
779
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
780
|
+
async function emojiPath(message, emoji) {
|
|
781
|
+
return message.client.resolveEmoji(emoji, message.guildId);
|
|
510
782
|
}
|
|
511
783
|
async function reactToMessage(message, emoji) {
|
|
512
784
|
const wire = await emojiPath(message, emoji);
|
|
513
785
|
await message.client.rest.put(
|
|
514
786
|
Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
515
787
|
);
|
|
516
|
-
emitOwnReactionAdd(message, wire);
|
|
517
788
|
}
|
|
518
789
|
async function removeMessageReaction(message, emoji, userId) {
|
|
519
790
|
const e = await emojiPath(message, emoji);
|
|
@@ -619,7 +890,33 @@ async function replyToMessage(message, options, replyOptions) {
|
|
|
619
890
|
}
|
|
620
891
|
|
|
621
892
|
// src/Domain/Message/Message.ts
|
|
893
|
+
function toMessageCall(data) {
|
|
894
|
+
return {
|
|
895
|
+
participants: data.participants,
|
|
896
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
function toMessageSnapshot(client, data) {
|
|
900
|
+
return {
|
|
901
|
+
content: data.content ?? null,
|
|
902
|
+
createdAt: new Date(data.timestamp),
|
|
903
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
904
|
+
mentionUserIds: data.mentions ?? [],
|
|
905
|
+
mentionRoles: data.mention_roles ?? [],
|
|
906
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
907
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
908
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
909
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
function resolveMessageFlags(flags) {
|
|
913
|
+
if (flags === void 0) return void 0;
|
|
914
|
+
if (typeof flags === "number") return flags;
|
|
915
|
+
return Number(MessageFlagsBitField.resolve(flags));
|
|
916
|
+
}
|
|
622
917
|
var Message = class _Message extends Base {
|
|
918
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
919
|
+
partial = false;
|
|
623
920
|
/** The {@link Client} that instantiated this message. */
|
|
624
921
|
client;
|
|
625
922
|
/** Snowflake ID of this message. */
|
|
@@ -648,7 +945,7 @@ var Message = class _Message extends Base {
|
|
|
648
945
|
mentionEveryone;
|
|
649
946
|
/** Whether this is a text-to-speech message. */
|
|
650
947
|
tts;
|
|
651
|
-
/** Embedded content (
|
|
948
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
652
949
|
embeds;
|
|
653
950
|
/** Stickers sent with the message. */
|
|
654
951
|
stickers;
|
|
@@ -670,26 +967,43 @@ var Message = class _Message extends Base {
|
|
|
670
967
|
mentionRoles;
|
|
671
968
|
/** Client-side nonce for deduplication. */
|
|
672
969
|
nonce;
|
|
673
|
-
/**
|
|
970
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
971
|
+
nsfwEmojis;
|
|
972
|
+
/**
|
|
973
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
974
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
975
|
+
*/
|
|
674
976
|
get channel() {
|
|
675
|
-
|
|
977
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
978
|
+
return channel?.isTextBased() ? channel : null;
|
|
676
979
|
}
|
|
677
980
|
/** Cached guild, or null for DMs / uncached. */
|
|
678
981
|
get guild() {
|
|
679
982
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
680
983
|
}
|
|
681
|
-
/**
|
|
984
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
985
|
+
get member() {
|
|
986
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
990
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
991
|
+
* @example
|
|
992
|
+
* const channel = await message.resolveChannel();
|
|
993
|
+
* await channel.delete();
|
|
994
|
+
*/
|
|
682
995
|
async resolveChannel() {
|
|
683
996
|
return this.client.channels.resolve(this.channelId);
|
|
684
997
|
}
|
|
685
|
-
/**
|
|
998
|
+
/**
|
|
999
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
1000
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
1001
|
+
* @example
|
|
1002
|
+
* const guild = await message.resolveGuild();
|
|
1003
|
+
*/
|
|
686
1004
|
async resolveGuild() {
|
|
687
1005
|
if (!this.guildId) return null;
|
|
688
|
-
|
|
689
|
-
return await this.client.guilds.resolve(this.guildId);
|
|
690
|
-
} catch {
|
|
691
|
-
return null;
|
|
692
|
-
}
|
|
1006
|
+
return this.client.guilds.resolve(this.guildId);
|
|
693
1007
|
}
|
|
694
1008
|
/**
|
|
695
1009
|
* Construct a message from API data.
|
|
@@ -706,29 +1020,75 @@ var Message = class _Message extends Base {
|
|
|
706
1020
|
this.createdAt = new Date(data.timestamp);
|
|
707
1021
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
708
1022
|
this.pinned = data.pinned;
|
|
709
|
-
this.attachments = new
|
|
710
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
1023
|
+
this.attachments = new Collection3();
|
|
1024
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
711
1025
|
this.type = data.type ?? MessageType.Default;
|
|
712
|
-
this.flags = data.flags ?? 0;
|
|
1026
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
713
1027
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
714
1028
|
this.tts = data.tts ?? false;
|
|
715
|
-
this.embeds = data.embeds ?? [];
|
|
716
|
-
this.stickers = data.stickers ?? [];
|
|
717
|
-
this.reactions =
|
|
718
|
-
this.
|
|
719
|
-
this.
|
|
720
|
-
|
|
1029
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1030
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
1031
|
+
this.reactions = new MessageReactionManager(this);
|
|
1032
|
+
this.reactions._patch(data.reactions);
|
|
1033
|
+
this.messageReference = data.message_reference ? {
|
|
1034
|
+
channelId: data.message_reference.channel_id,
|
|
1035
|
+
messageId: data.message_reference.message_id,
|
|
1036
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1037
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1038
|
+
} : null;
|
|
1039
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
1040
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
721
1041
|
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
722
1042
|
this.webhookId = data.webhook_id ?? null;
|
|
723
1043
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
724
1044
|
this.mentionRoles = data.mention_roles ?? [];
|
|
725
1045
|
this.nonce = data.nonce ?? null;
|
|
1046
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
726
1047
|
}
|
|
727
|
-
/**
|
|
1048
|
+
/**
|
|
1049
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
1050
|
+
* @internal
|
|
1051
|
+
*/
|
|
1052
|
+
_patch(data) {
|
|
1053
|
+
this.content = data.content;
|
|
1054
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1055
|
+
this.pinned = data.pinned;
|
|
1056
|
+
this.attachments.clear();
|
|
1057
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1058
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1059
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1060
|
+
this.tts = data.tts ?? false;
|
|
1061
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1062
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1063
|
+
this.reactions._patch(data.reactions);
|
|
1064
|
+
this.messageReference = data.message_reference ? {
|
|
1065
|
+
channelId: data.message_reference.channel_id,
|
|
1066
|
+
messageId: data.message_reference.message_id,
|
|
1067
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1068
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1069
|
+
} : null;
|
|
1070
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1071
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1072
|
+
);
|
|
1073
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1074
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1075
|
+
this.webhookId = data.webhook_id ?? null;
|
|
1076
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1077
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
1078
|
+
this.nonce = data.nonce ?? null;
|
|
1079
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Send a standalone message in this channel (not a reply).
|
|
1083
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
1084
|
+
*/
|
|
728
1085
|
async send(options) {
|
|
729
1086
|
return sendMessage(this, options);
|
|
730
1087
|
}
|
|
731
|
-
/**
|
|
1088
|
+
/**
|
|
1089
|
+
* Send a message to another channel by ID.
|
|
1090
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
1091
|
+
*/
|
|
732
1092
|
async sendTo(channelId, options) {
|
|
733
1093
|
return sendMessageTo(this, channelId, options);
|
|
734
1094
|
}
|
|
@@ -742,6 +1102,16 @@ var Message = class _Message extends Base {
|
|
|
742
1102
|
async reply(options, replyOptions) {
|
|
743
1103
|
return replyToMessage(this, options, replyOptions);
|
|
744
1104
|
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Hydrate a partial message, or return the message as-is.
|
|
1107
|
+
* @example
|
|
1108
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
1109
|
+
* const message = await Message.resolve(msg);
|
|
1110
|
+
* });
|
|
1111
|
+
*/
|
|
1112
|
+
static async resolve(message) {
|
|
1113
|
+
return message.partial ? message.fetch() : message;
|
|
1114
|
+
}
|
|
745
1115
|
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
746
1116
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
747
1117
|
return createMessageBody(content, referenced_message, ping);
|
|
@@ -754,7 +1124,7 @@ var Message = class _Message extends Base {
|
|
|
754
1124
|
async edit(options) {
|
|
755
1125
|
const body = {};
|
|
756
1126
|
if (options.content !== void 0) body.content = options.content;
|
|
757
|
-
if (options.embeds
|
|
1127
|
+
if (options.embeds !== void 0) {
|
|
758
1128
|
body.embeds = options.embeds.map(
|
|
759
1129
|
(e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
|
|
760
1130
|
);
|
|
@@ -762,7 +1132,8 @@ var Message = class _Message extends Base {
|
|
|
762
1132
|
if (options.allowedMentions) {
|
|
763
1133
|
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
764
1134
|
}
|
|
765
|
-
|
|
1135
|
+
const flags = resolveMessageFlags(options.flags);
|
|
1136
|
+
if (flags !== void 0) body.flags = flags;
|
|
766
1137
|
if (options.attachments !== void 0) {
|
|
767
1138
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
768
1139
|
}
|
|
@@ -777,13 +1148,22 @@ var Message = class _Message extends Base {
|
|
|
777
1148
|
createReactionCollector(options) {
|
|
778
1149
|
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
779
1150
|
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
1153
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1154
|
+
*/
|
|
1155
|
+
awaitReactions(options) {
|
|
1156
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1157
|
+
}
|
|
780
1158
|
/** Fetch the latest version of this message from the API. */
|
|
781
1159
|
async fetch() {
|
|
782
1160
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
783
1161
|
}
|
|
784
1162
|
/** Delete this message. */
|
|
785
|
-
async delete() {
|
|
786
|
-
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id)
|
|
1163
|
+
async delete(reason) {
|
|
1164
|
+
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
|
|
1165
|
+
...auditReasonHeaders(reason)
|
|
1166
|
+
});
|
|
787
1167
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
788
1168
|
}
|
|
789
1169
|
/** Delete a specific attachment from this message. */
|
|
@@ -829,6 +1209,58 @@ var Message = class _Message extends Base {
|
|
|
829
1209
|
return fetchMessageReactionUsersPage(this, emoji, options);
|
|
830
1210
|
}
|
|
831
1211
|
};
|
|
1212
|
+
|
|
1213
|
+
// src/Domain/Message/PartialMessage.ts
|
|
1214
|
+
import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
|
|
1215
|
+
var PartialMessage = class {
|
|
1216
|
+
partial = true;
|
|
1217
|
+
client;
|
|
1218
|
+
id;
|
|
1219
|
+
channelId;
|
|
1220
|
+
guildId;
|
|
1221
|
+
content;
|
|
1222
|
+
authorId;
|
|
1223
|
+
author;
|
|
1224
|
+
createdAt;
|
|
1225
|
+
constructor(client, data) {
|
|
1226
|
+
this.client = client;
|
|
1227
|
+
this.id = data.id;
|
|
1228
|
+
this.channelId = data.channelId;
|
|
1229
|
+
this.guildId = data.guildId ?? null;
|
|
1230
|
+
this.content = data.content ?? null;
|
|
1231
|
+
this.authorId = data.authorId ?? null;
|
|
1232
|
+
this.author = data.author ?? null;
|
|
1233
|
+
this.createdAt = data.createdAt ?? (SnowflakeUtil2.isValid(data.id) ? SnowflakeUtil2.dateFromSnowflake(data.id) : null);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
1237
|
+
* Same contract as {@link Message.channel}.
|
|
1238
|
+
*/
|
|
1239
|
+
get channel() {
|
|
1240
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1241
|
+
return channel?.isTextBased() ? channel : null;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1245
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1246
|
+
* @example
|
|
1247
|
+
* const channel = await message.resolveChannel();
|
|
1248
|
+
* await channel.delete();
|
|
1249
|
+
*/
|
|
1250
|
+
async resolveChannel() {
|
|
1251
|
+
return this.client.channels.resolve(this.channelId);
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Fetch the full message from the API.
|
|
1255
|
+
* @example
|
|
1256
|
+
* const message = await partial.fetch();
|
|
1257
|
+
* await message.reply('Pong!');
|
|
1258
|
+
*/
|
|
1259
|
+
async fetch() {
|
|
1260
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
832
1263
|
export {
|
|
833
|
-
Message
|
|
1264
|
+
Message,
|
|
1265
|
+
PartialMessage
|
|
834
1266
|
};
|