@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.js
CHANGED
|
@@ -20,14 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/SubpathMessage.ts
|
|
21
21
|
var SubpathMessage_exports = {};
|
|
22
22
|
__export(SubpathMessage_exports, {
|
|
23
|
-
Message: () => Message
|
|
23
|
+
Message: () => Message,
|
|
24
|
+
PartialMessage: () => PartialMessage
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(SubpathMessage_exports);
|
|
26
27
|
|
|
27
28
|
// src/Domain/Message/Message.ts
|
|
28
29
|
var import_builders3 = require("@fluxerjs/builders");
|
|
29
|
-
var
|
|
30
|
+
var import_collection3 = require("@fluxerjs/collection");
|
|
30
31
|
var import_types5 = require("@fluxerjs/types");
|
|
32
|
+
var import_util4 = require("@fluxerjs/util");
|
|
31
33
|
|
|
32
34
|
// src/ClientCore/SdkOptions/Attachments.ts
|
|
33
35
|
function toMessageAttachmentEditWire(attachments) {
|
|
@@ -44,6 +46,13 @@ function toMessageAttachmentEditWire(attachments) {
|
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
// src/Helpers/AuditReason.ts
|
|
50
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
51
|
+
function auditReasonHeaders(reason) {
|
|
52
|
+
if (reason == null || reason === "") return {};
|
|
53
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
// src/Helpers/MessageUtils/Body.ts
|
|
48
57
|
var import_builders = require("@fluxerjs/builders");
|
|
49
58
|
var import_types = require("@fluxerjs/types");
|
|
@@ -115,6 +124,37 @@ function applyReplyPingSuppression(body) {
|
|
|
115
124
|
function assignIfDefined(target, key, value) {
|
|
116
125
|
if (value !== void 0) target[key] = value;
|
|
117
126
|
}
|
|
127
|
+
function normalizeSendFiles(files) {
|
|
128
|
+
if (!files?.length) return void 0;
|
|
129
|
+
const normalized = [];
|
|
130
|
+
const metaFromBuilders = [];
|
|
131
|
+
let anyBuilderMeta = false;
|
|
132
|
+
for (let i = 0; i < files.length; i++) {
|
|
133
|
+
const file = files[i];
|
|
134
|
+
if (!file) continue;
|
|
135
|
+
if (file instanceof import_builders.AttachmentBuilder) {
|
|
136
|
+
normalized.push(file.toFileData());
|
|
137
|
+
const meta = {
|
|
138
|
+
id: i,
|
|
139
|
+
filename: file.filename,
|
|
140
|
+
...file.description != null ? { description: file.description } : {},
|
|
141
|
+
...file.spoiler ? { flags: import_types.MessageAttachmentFlags.IS_SPOILER } : {}
|
|
142
|
+
};
|
|
143
|
+
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
144
|
+
metaFromBuilders.push(meta);
|
|
145
|
+
} else {
|
|
146
|
+
normalized.push(file);
|
|
147
|
+
metaFromBuilders.push({
|
|
148
|
+
id: i,
|
|
149
|
+
filename: file.filename ?? file.name
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
files: normalized,
|
|
155
|
+
metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
|
|
156
|
+
};
|
|
157
|
+
}
|
|
118
158
|
function buildSendBody(options) {
|
|
119
159
|
const body = typeof options === "string" ? { content: options } : options;
|
|
120
160
|
const result = {};
|
|
@@ -122,16 +162,17 @@ function buildSendBody(options) {
|
|
|
122
162
|
if (body.embeds?.length) {
|
|
123
163
|
result.embeds = body.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
|
|
124
164
|
}
|
|
165
|
+
const normalizedFiles = normalizeSendFiles(body.files);
|
|
125
166
|
if (body.uploadedAttachments?.length) {
|
|
126
167
|
result.attachments = body.uploadedAttachments;
|
|
127
|
-
} else if (
|
|
168
|
+
} else if (normalizedFiles?.files.length) {
|
|
128
169
|
result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
|
|
129
170
|
id: a.id,
|
|
130
171
|
filename: a.filename,
|
|
131
172
|
...a.title != null && { title: a.title },
|
|
132
173
|
...a.description != null && { description: a.description },
|
|
133
174
|
...a.flags != null && { flags: a.flags }
|
|
134
|
-
})) :
|
|
175
|
+
})) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
|
|
135
176
|
}
|
|
136
177
|
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
137
178
|
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
@@ -225,9 +266,10 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
225
266
|
} else if (allowedMentions?.repliedUser === false) {
|
|
226
267
|
applyReplyPingSuppression(body);
|
|
227
268
|
}
|
|
269
|
+
const resolvedFiles = normalizeSendFiles(files);
|
|
228
270
|
return {
|
|
229
271
|
body,
|
|
230
|
-
files: !uploadedAttachments?.length && files
|
|
272
|
+
files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
|
|
231
273
|
};
|
|
232
274
|
}
|
|
233
275
|
|
|
@@ -273,13 +315,17 @@ var Base = class {
|
|
|
273
315
|
};
|
|
274
316
|
|
|
275
317
|
// src/Domain/Message/MessageReaction.ts
|
|
276
|
-
var MessageReaction = class extends Base {
|
|
318
|
+
var MessageReaction = class _MessageReaction extends Base {
|
|
277
319
|
client;
|
|
278
320
|
messageId;
|
|
279
321
|
channelId;
|
|
280
322
|
guildId;
|
|
281
323
|
emoji;
|
|
282
|
-
/**
|
|
324
|
+
/** Total count when hydrated from a message payload; `1` for gateway add events. */
|
|
325
|
+
count;
|
|
326
|
+
/** Whether the current user reacted (message payload); false for gateway remove. */
|
|
327
|
+
me;
|
|
328
|
+
/** Raw gateway payload for low-level access (null when built from a message aggregate). */
|
|
283
329
|
_data;
|
|
284
330
|
constructor(client, data) {
|
|
285
331
|
super();
|
|
@@ -293,6 +339,26 @@ var MessageReaction = class extends Base {
|
|
|
293
339
|
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
294
340
|
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
295
341
|
};
|
|
342
|
+
this.count = 1;
|
|
343
|
+
this.me = false;
|
|
344
|
+
}
|
|
345
|
+
/** Build a reaction aggregate from a message's `reactions` array entry. */
|
|
346
|
+
static fromMessage(message, data) {
|
|
347
|
+
const reaction = new _MessageReaction(message.client, {
|
|
348
|
+
user_id: message.client.user?.id ?? "0",
|
|
349
|
+
message_id: message.id,
|
|
350
|
+
channel_id: message.channelId,
|
|
351
|
+
guild_id: message.guildId ?? void 0,
|
|
352
|
+
emoji: {
|
|
353
|
+
name: data.emoji.name,
|
|
354
|
+
id: data.emoji.id ?? void 0,
|
|
355
|
+
animated: data.emoji.animated ?? void 0
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
Object.defineProperty(reaction, "_data", { value: null });
|
|
359
|
+
reaction.count = data.count;
|
|
360
|
+
reaction.me = data.me ?? false;
|
|
361
|
+
return reaction;
|
|
296
362
|
}
|
|
297
363
|
/** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
|
|
298
364
|
get emojiIdentifier() {
|
|
@@ -302,12 +368,23 @@ var MessageReaction = class extends Base {
|
|
|
302
368
|
get guild() {
|
|
303
369
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
304
370
|
}
|
|
371
|
+
/** Cached message this reaction belongs to, or null if the message was not cached. */
|
|
372
|
+
get message() {
|
|
373
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
|
|
374
|
+
return cached ? new Message(this.client, cached) : null;
|
|
375
|
+
}
|
|
376
|
+
/** Cached text-capable channel, or null if uncached / not text-based. */
|
|
377
|
+
get channel() {
|
|
378
|
+
const channel = this.client.channels.get(this.channelId);
|
|
379
|
+
return channel?.isTextBased() ? channel : null;
|
|
380
|
+
}
|
|
305
381
|
/**
|
|
306
|
-
* Fetch the message this reaction belongs to.
|
|
307
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
382
|
+
* Fetch the message this reaction belongs to (cache first, then REST).
|
|
308
383
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
309
384
|
*/
|
|
310
385
|
async fetchMessage() {
|
|
386
|
+
const cached = this.message;
|
|
387
|
+
if (cached) return cached;
|
|
311
388
|
try {
|
|
312
389
|
const data = await this.client.rest.get(
|
|
313
390
|
import_types2.Routes.channelMessage(this.channelId, this.messageId)
|
|
@@ -378,11 +455,17 @@ var Events = {
|
|
|
378
455
|
WebhooksUpdate: "webhooksUpdate",
|
|
379
456
|
Resumed: "resumed",
|
|
380
457
|
Error: "error",
|
|
381
|
-
Debug: "debug"
|
|
458
|
+
Debug: "debug",
|
|
459
|
+
ShardReady: "shardReady",
|
|
460
|
+
ShardResumed: "shardResumed",
|
|
461
|
+
ShardDisconnect: "shardDisconnect",
|
|
462
|
+
ShardReconnecting: "shardReconnecting",
|
|
463
|
+
ShardError: "shardError",
|
|
464
|
+
ShardingRequired: "shardingRequired"
|
|
382
465
|
};
|
|
383
466
|
|
|
384
467
|
// src/Helpers/ReactionCollector.ts
|
|
385
|
-
var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
468
|
+
var ReactionCollector = class _ReactionCollector extends import_node_events.EventEmitter {
|
|
386
469
|
client;
|
|
387
470
|
messageId;
|
|
388
471
|
channelId;
|
|
@@ -425,15 +508,17 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
425
508
|
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
426
509
|
}
|
|
427
510
|
});
|
|
428
|
-
const
|
|
511
|
+
const cached = this.client.users.get(entry.userId);
|
|
512
|
+
const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
|
|
513
|
+
{
|
|
429
514
|
id: entry.userId,
|
|
430
515
|
username: "Unknown",
|
|
431
516
|
discriminator: "0",
|
|
432
|
-
|
|
517
|
+
globalName: null,
|
|
433
518
|
avatar: null,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
519
|
+
bot: false,
|
|
520
|
+
system: false
|
|
521
|
+
};
|
|
437
522
|
this._collect(reaction, user, entry.userId);
|
|
438
523
|
}
|
|
439
524
|
};
|
|
@@ -465,6 +550,21 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
465
550
|
}
|
|
466
551
|
this.emit("end", this.collected, reason);
|
|
467
552
|
}
|
|
553
|
+
/**
|
|
554
|
+
* One-shot helper used by {@link Message.awaitReactions}.
|
|
555
|
+
* Resolves with the collected reactions when the collector ends.
|
|
556
|
+
* Rejects if `options.errors` includes the end reason.
|
|
557
|
+
*/
|
|
558
|
+
static awaitReactions(client, messageId, channelId, options) {
|
|
559
|
+
const errors = options?.errors ?? [];
|
|
560
|
+
return new Promise((resolve, reject) => {
|
|
561
|
+
const collector = new _ReactionCollector(client, messageId, channelId, options);
|
|
562
|
+
collector.on("end", (collected, reason) => {
|
|
563
|
+
if (errors.includes(reason)) reject(collected);
|
|
564
|
+
else resolve(collected);
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
}
|
|
468
568
|
on(event, listener) {
|
|
469
569
|
return super.on(event, listener);
|
|
470
570
|
}
|
|
@@ -473,70 +573,242 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
473
573
|
}
|
|
474
574
|
};
|
|
475
575
|
|
|
476
|
-
// src/Domain/Message/
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
576
|
+
// src/Domain/Message/Attachment.ts
|
|
577
|
+
function toMessageAttachment(data) {
|
|
578
|
+
return {
|
|
579
|
+
id: data.id,
|
|
580
|
+
filename: data.filename,
|
|
581
|
+
title: data.title ?? null,
|
|
582
|
+
description: data.description ?? null,
|
|
583
|
+
contentType: data.content_type ?? null,
|
|
584
|
+
contentHash: data.content_hash ?? null,
|
|
585
|
+
size: data.size,
|
|
586
|
+
url: data.url ?? null,
|
|
587
|
+
proxyUrl: data.proxy_url ?? null,
|
|
588
|
+
width: data.width ?? null,
|
|
589
|
+
height: data.height ?? null,
|
|
590
|
+
placeholder: data.placeholder ?? null,
|
|
591
|
+
flags: data.flags ?? 0,
|
|
592
|
+
nsfw: data.nsfw ?? false,
|
|
593
|
+
duration: data.duration ?? null,
|
|
594
|
+
waveform: data.waveform ?? null,
|
|
595
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
596
|
+
expired: data.expired ?? false
|
|
597
|
+
};
|
|
481
598
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
599
|
+
|
|
600
|
+
// src/Domain/Message/Embed.ts
|
|
601
|
+
function toMessageEmbedAuthor(data) {
|
|
602
|
+
return {
|
|
603
|
+
name: data.name ?? null,
|
|
604
|
+
url: data.url ?? null,
|
|
605
|
+
iconUrl: data.icon_url ?? null,
|
|
606
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
function toMessageEmbedFooter(data) {
|
|
610
|
+
return {
|
|
611
|
+
text: data.text,
|
|
612
|
+
iconUrl: data.icon_url ?? null,
|
|
613
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
function toMessageEmbedMedia(data) {
|
|
617
|
+
return {
|
|
618
|
+
url: data.url,
|
|
619
|
+
proxyUrl: data.proxy_url ?? null,
|
|
620
|
+
contentType: data.content_type ?? null,
|
|
621
|
+
contentHash: data.content_hash ?? null,
|
|
622
|
+
width: data.width ?? null,
|
|
623
|
+
height: data.height ?? null,
|
|
624
|
+
description: data.description ?? null,
|
|
625
|
+
placeholder: data.placeholder ?? null,
|
|
626
|
+
duration: data.duration ?? null,
|
|
627
|
+
flags: data.flags ?? null
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
function toMessageEmbed(data) {
|
|
631
|
+
const full = data;
|
|
632
|
+
return {
|
|
633
|
+
type: data.type ?? "rich",
|
|
634
|
+
url: data.url ?? null,
|
|
635
|
+
title: data.title ?? null,
|
|
636
|
+
color: data.color ?? null,
|
|
637
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
638
|
+
description: data.description ?? null,
|
|
639
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
640
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
641
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
642
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
643
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
644
|
+
name: f.name,
|
|
645
|
+
value: f.value,
|
|
646
|
+
inline: f.inline ?? false
|
|
647
|
+
})),
|
|
648
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
649
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
650
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
651
|
+
nsfw: data.nsfw ?? false,
|
|
652
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
653
|
+
html: full.html ?? null,
|
|
654
|
+
htmlWidth: full.html_width ?? null,
|
|
655
|
+
htmlHeight: full.html_height ?? null
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
660
|
+
var import_collection2 = require("@fluxerjs/collection");
|
|
661
|
+
var MessageReactionManager = class {
|
|
662
|
+
constructor(message) {
|
|
663
|
+
this.message = message;
|
|
489
664
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
665
|
+
_cache = new import_collection2.Collection();
|
|
666
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
667
|
+
get cache() {
|
|
668
|
+
return this._cache;
|
|
493
669
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
return {
|
|
497
|
-
name: parsed.name,
|
|
498
|
-
id: parsed.id,
|
|
499
|
-
...parsed.animated ? { animated: true } : {}
|
|
500
|
-
};
|
|
670
|
+
get size() {
|
|
671
|
+
return this._cache.size;
|
|
501
672
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (!user) return;
|
|
512
|
-
const emojiPayload = toReactionEmoji(wireOrInput);
|
|
513
|
-
const reaction = new MessageReaction(message.client, {
|
|
514
|
-
user_id: user.id,
|
|
515
|
-
channel_id: message.channelId,
|
|
516
|
-
message_id: message.id,
|
|
517
|
-
guild_id: message.guildId ?? void 0,
|
|
518
|
-
emoji: {
|
|
519
|
-
name: emojiPayload.name,
|
|
520
|
-
...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
|
|
521
|
-
...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
|
|
673
|
+
[Symbol.iterator]() {
|
|
674
|
+
return this._cache.values();
|
|
675
|
+
}
|
|
676
|
+
/** @internal Sync from an API message payload. */
|
|
677
|
+
_patch(reactions) {
|
|
678
|
+
this._cache.clear();
|
|
679
|
+
for (const data of reactions ?? []) {
|
|
680
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
681
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
522
682
|
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
// src/Domain/Message/MessageSticker.ts
|
|
687
|
+
var import_util3 = require("@fluxerjs/util");
|
|
688
|
+
|
|
689
|
+
// src/Helpers/Constants.ts
|
|
690
|
+
var import_rest2 = require("@fluxerjs/rest");
|
|
691
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
692
|
+
|
|
693
|
+
// src/Helpers/Cdn.ts
|
|
694
|
+
var CDN_SIZE_LADDER = [
|
|
695
|
+
16,
|
|
696
|
+
20,
|
|
697
|
+
22,
|
|
698
|
+
24,
|
|
699
|
+
28,
|
|
700
|
+
32,
|
|
701
|
+
40,
|
|
702
|
+
44,
|
|
703
|
+
48,
|
|
704
|
+
56,
|
|
705
|
+
60,
|
|
706
|
+
64,
|
|
707
|
+
80,
|
|
708
|
+
96,
|
|
709
|
+
100,
|
|
710
|
+
128,
|
|
711
|
+
160,
|
|
712
|
+
240,
|
|
713
|
+
256,
|
|
714
|
+
300,
|
|
715
|
+
320,
|
|
716
|
+
480,
|
|
717
|
+
512,
|
|
718
|
+
600,
|
|
719
|
+
640,
|
|
720
|
+
1024,
|
|
721
|
+
1280,
|
|
722
|
+
1536,
|
|
723
|
+
2048,
|
|
724
|
+
3072,
|
|
725
|
+
4096,
|
|
726
|
+
8192,
|
|
727
|
+
16384
|
|
728
|
+
];
|
|
729
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
730
|
+
icon: { min: 128, max: 1024 },
|
|
731
|
+
banner: { min: 480, max: 2400 },
|
|
732
|
+
emoji: { min: 32, max: 512 },
|
|
733
|
+
sticker: { min: 128, max: 512 }
|
|
734
|
+
};
|
|
735
|
+
function nearestSize(requested, candidates) {
|
|
736
|
+
let best = candidates[0];
|
|
737
|
+
let bestDist = Math.abs(requested - best);
|
|
738
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
739
|
+
const step = candidates[i];
|
|
740
|
+
const dist = Math.abs(requested - step);
|
|
741
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
742
|
+
best = step;
|
|
743
|
+
bestDist = dist;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return best;
|
|
747
|
+
}
|
|
748
|
+
function snapCdnSize(requested, assetClass) {
|
|
749
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
750
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
751
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
752
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
753
|
+
return nearestSize(clamped, allowed);
|
|
754
|
+
}
|
|
755
|
+
function mediaBase(options) {
|
|
756
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
757
|
+
}
|
|
758
|
+
function appendSize(options, assetClass) {
|
|
759
|
+
const size = options?.size;
|
|
760
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
761
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
762
|
+
}
|
|
763
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
764
|
+
const ext = animated ? "gif" : "png";
|
|
765
|
+
const size = appendSize(options, "sticker");
|
|
766
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// src/Domain/Message/MessageSticker.ts
|
|
770
|
+
var MessageSticker = class extends Base {
|
|
771
|
+
client;
|
|
772
|
+
id;
|
|
773
|
+
name;
|
|
774
|
+
description;
|
|
775
|
+
tags;
|
|
776
|
+
animated;
|
|
777
|
+
constructor(client, data) {
|
|
778
|
+
super();
|
|
779
|
+
this.client = client;
|
|
780
|
+
this.id = data.id;
|
|
781
|
+
this.name = data.name;
|
|
782
|
+
this.description = data.description ?? "";
|
|
783
|
+
this.tags = data.tags ?? [];
|
|
784
|
+
this.animated = data.animated ?? false;
|
|
785
|
+
}
|
|
786
|
+
/** CDN URL for this sticker image. */
|
|
787
|
+
get url() {
|
|
788
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
789
|
+
mediaBase: this.client.instance.endpoints.media
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
793
|
+
get createdTimestamp() {
|
|
794
|
+
return import_util3.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
795
|
+
}
|
|
796
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
797
|
+
get createdAt() {
|
|
798
|
+
return import_util3.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
// src/Domain/Message/Reactions.ts
|
|
803
|
+
var import_types3 = require("@fluxerjs/types");
|
|
804
|
+
async function emojiPath(message, emoji) {
|
|
805
|
+
return message.client.resolveEmoji(emoji, message.guildId);
|
|
533
806
|
}
|
|
534
807
|
async function reactToMessage(message, emoji) {
|
|
535
808
|
const wire = await emojiPath(message, emoji);
|
|
536
809
|
await message.client.rest.put(
|
|
537
810
|
import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
538
811
|
);
|
|
539
|
-
emitOwnReactionAdd(message, wire);
|
|
540
812
|
}
|
|
541
813
|
async function removeMessageReaction(message, emoji, userId) {
|
|
542
814
|
const e = await emojiPath(message, emoji);
|
|
@@ -642,7 +914,33 @@ async function replyToMessage(message, options, replyOptions) {
|
|
|
642
914
|
}
|
|
643
915
|
|
|
644
916
|
// src/Domain/Message/Message.ts
|
|
917
|
+
function toMessageCall(data) {
|
|
918
|
+
return {
|
|
919
|
+
participants: data.participants,
|
|
920
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
function toMessageSnapshot(client, data) {
|
|
924
|
+
return {
|
|
925
|
+
content: data.content ?? null,
|
|
926
|
+
createdAt: new Date(data.timestamp),
|
|
927
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
928
|
+
mentionUserIds: data.mentions ?? [],
|
|
929
|
+
mentionRoles: data.mention_roles ?? [],
|
|
930
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
931
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
932
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
933
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
function resolveMessageFlags(flags) {
|
|
937
|
+
if (flags === void 0) return void 0;
|
|
938
|
+
if (typeof flags === "number") return flags;
|
|
939
|
+
return Number(import_util4.MessageFlagsBitField.resolve(flags));
|
|
940
|
+
}
|
|
645
941
|
var Message = class _Message extends Base {
|
|
942
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
943
|
+
partial = false;
|
|
646
944
|
/** The {@link Client} that instantiated this message. */
|
|
647
945
|
client;
|
|
648
946
|
/** Snowflake ID of this message. */
|
|
@@ -671,7 +969,7 @@ var Message = class _Message extends Base {
|
|
|
671
969
|
mentionEveryone;
|
|
672
970
|
/** Whether this is a text-to-speech message. */
|
|
673
971
|
tts;
|
|
674
|
-
/** Embedded content (
|
|
972
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
675
973
|
embeds;
|
|
676
974
|
/** Stickers sent with the message. */
|
|
677
975
|
stickers;
|
|
@@ -693,26 +991,43 @@ var Message = class _Message extends Base {
|
|
|
693
991
|
mentionRoles;
|
|
694
992
|
/** Client-side nonce for deduplication. */
|
|
695
993
|
nonce;
|
|
696
|
-
/**
|
|
994
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
995
|
+
nsfwEmojis;
|
|
996
|
+
/**
|
|
997
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
998
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
999
|
+
*/
|
|
697
1000
|
get channel() {
|
|
698
|
-
|
|
1001
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1002
|
+
return channel?.isTextBased() ? channel : null;
|
|
699
1003
|
}
|
|
700
1004
|
/** Cached guild, or null for DMs / uncached. */
|
|
701
1005
|
get guild() {
|
|
702
1006
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
703
1007
|
}
|
|
704
|
-
/**
|
|
1008
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
1009
|
+
get member() {
|
|
1010
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1014
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1015
|
+
* @example
|
|
1016
|
+
* const channel = await message.resolveChannel();
|
|
1017
|
+
* await channel.delete();
|
|
1018
|
+
*/
|
|
705
1019
|
async resolveChannel() {
|
|
706
1020
|
return this.client.channels.resolve(this.channelId);
|
|
707
1021
|
}
|
|
708
|
-
/**
|
|
1022
|
+
/**
|
|
1023
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
1024
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
1025
|
+
* @example
|
|
1026
|
+
* const guild = await message.resolveGuild();
|
|
1027
|
+
*/
|
|
709
1028
|
async resolveGuild() {
|
|
710
1029
|
if (!this.guildId) return null;
|
|
711
|
-
|
|
712
|
-
return await this.client.guilds.resolve(this.guildId);
|
|
713
|
-
} catch {
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
1030
|
+
return this.client.guilds.resolve(this.guildId);
|
|
716
1031
|
}
|
|
717
1032
|
/**
|
|
718
1033
|
* Construct a message from API data.
|
|
@@ -729,29 +1044,75 @@ var Message = class _Message extends Base {
|
|
|
729
1044
|
this.createdAt = new Date(data.timestamp);
|
|
730
1045
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
731
1046
|
this.pinned = data.pinned;
|
|
732
|
-
this.attachments = new
|
|
733
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
1047
|
+
this.attachments = new import_collection3.Collection();
|
|
1048
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
734
1049
|
this.type = data.type ?? import_types5.MessageType.Default;
|
|
735
|
-
this.flags = data.flags ?? 0;
|
|
1050
|
+
this.flags = new import_util4.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
736
1051
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
737
1052
|
this.tts = data.tts ?? false;
|
|
738
|
-
this.embeds = data.embeds ?? [];
|
|
739
|
-
this.stickers = data.stickers ?? [];
|
|
740
|
-
this.reactions =
|
|
741
|
-
this.
|
|
742
|
-
this.
|
|
743
|
-
|
|
1053
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1054
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
1055
|
+
this.reactions = new MessageReactionManager(this);
|
|
1056
|
+
this.reactions._patch(data.reactions);
|
|
1057
|
+
this.messageReference = data.message_reference ? {
|
|
1058
|
+
channelId: data.message_reference.channel_id,
|
|
1059
|
+
messageId: data.message_reference.message_id,
|
|
1060
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1061
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1062
|
+
} : null;
|
|
1063
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
1064
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
744
1065
|
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
745
1066
|
this.webhookId = data.webhook_id ?? null;
|
|
746
1067
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
747
1068
|
this.mentionRoles = data.mention_roles ?? [];
|
|
748
1069
|
this.nonce = data.nonce ?? null;
|
|
1070
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
749
1071
|
}
|
|
750
|
-
/**
|
|
1072
|
+
/**
|
|
1073
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
1074
|
+
* @internal
|
|
1075
|
+
*/
|
|
1076
|
+
_patch(data) {
|
|
1077
|
+
this.content = data.content;
|
|
1078
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1079
|
+
this.pinned = data.pinned;
|
|
1080
|
+
this.attachments.clear();
|
|
1081
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1082
|
+
this.flags = new import_util4.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1083
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1084
|
+
this.tts = data.tts ?? false;
|
|
1085
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1086
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1087
|
+
this.reactions._patch(data.reactions);
|
|
1088
|
+
this.messageReference = data.message_reference ? {
|
|
1089
|
+
channelId: data.message_reference.channel_id,
|
|
1090
|
+
messageId: data.message_reference.message_id,
|
|
1091
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1092
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1093
|
+
} : null;
|
|
1094
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1095
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1096
|
+
);
|
|
1097
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1098
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1099
|
+
this.webhookId = data.webhook_id ?? null;
|
|
1100
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1101
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
1102
|
+
this.nonce = data.nonce ?? null;
|
|
1103
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Send a standalone message in this channel (not a reply).
|
|
1107
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
1108
|
+
*/
|
|
751
1109
|
async send(options) {
|
|
752
1110
|
return sendMessage(this, options);
|
|
753
1111
|
}
|
|
754
|
-
/**
|
|
1112
|
+
/**
|
|
1113
|
+
* Send a message to another channel by ID.
|
|
1114
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
1115
|
+
*/
|
|
755
1116
|
async sendTo(channelId, options) {
|
|
756
1117
|
return sendMessageTo(this, channelId, options);
|
|
757
1118
|
}
|
|
@@ -765,6 +1126,16 @@ var Message = class _Message extends Base {
|
|
|
765
1126
|
async reply(options, replyOptions) {
|
|
766
1127
|
return replyToMessage(this, options, replyOptions);
|
|
767
1128
|
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Hydrate a partial message, or return the message as-is.
|
|
1131
|
+
* @example
|
|
1132
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
1133
|
+
* const message = await Message.resolve(msg);
|
|
1134
|
+
* });
|
|
1135
|
+
*/
|
|
1136
|
+
static async resolve(message) {
|
|
1137
|
+
return message.partial ? message.fetch() : message;
|
|
1138
|
+
}
|
|
768
1139
|
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
769
1140
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
770
1141
|
return createMessageBody(content, referenced_message, ping);
|
|
@@ -777,7 +1148,7 @@ var Message = class _Message extends Base {
|
|
|
777
1148
|
async edit(options) {
|
|
778
1149
|
const body = {};
|
|
779
1150
|
if (options.content !== void 0) body.content = options.content;
|
|
780
|
-
if (options.embeds
|
|
1151
|
+
if (options.embeds !== void 0) {
|
|
781
1152
|
body.embeds = options.embeds.map(
|
|
782
1153
|
(e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e
|
|
783
1154
|
);
|
|
@@ -785,7 +1156,8 @@ var Message = class _Message extends Base {
|
|
|
785
1156
|
if (options.allowedMentions) {
|
|
786
1157
|
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
787
1158
|
}
|
|
788
|
-
|
|
1159
|
+
const flags = resolveMessageFlags(options.flags);
|
|
1160
|
+
if (flags !== void 0) body.flags = flags;
|
|
789
1161
|
if (options.attachments !== void 0) {
|
|
790
1162
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
791
1163
|
}
|
|
@@ -800,13 +1172,22 @@ var Message = class _Message extends Base {
|
|
|
800
1172
|
createReactionCollector(options) {
|
|
801
1173
|
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
802
1174
|
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
1177
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1178
|
+
*/
|
|
1179
|
+
awaitReactions(options) {
|
|
1180
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1181
|
+
}
|
|
803
1182
|
/** Fetch the latest version of this message from the API. */
|
|
804
1183
|
async fetch() {
|
|
805
1184
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
806
1185
|
}
|
|
807
1186
|
/** Delete this message. */
|
|
808
|
-
async delete() {
|
|
809
|
-
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id)
|
|
1187
|
+
async delete(reason) {
|
|
1188
|
+
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id), {
|
|
1189
|
+
...auditReasonHeaders(reason)
|
|
1190
|
+
});
|
|
810
1191
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
811
1192
|
}
|
|
812
1193
|
/** Delete a specific attachment from this message. */
|
|
@@ -852,7 +1233,59 @@ var Message = class _Message extends Base {
|
|
|
852
1233
|
return fetchMessageReactionUsersPage(this, emoji, options);
|
|
853
1234
|
}
|
|
854
1235
|
};
|
|
1236
|
+
|
|
1237
|
+
// src/Domain/Message/PartialMessage.ts
|
|
1238
|
+
var import_util5 = require("@fluxerjs/util");
|
|
1239
|
+
var PartialMessage = class {
|
|
1240
|
+
partial = true;
|
|
1241
|
+
client;
|
|
1242
|
+
id;
|
|
1243
|
+
channelId;
|
|
1244
|
+
guildId;
|
|
1245
|
+
content;
|
|
1246
|
+
authorId;
|
|
1247
|
+
author;
|
|
1248
|
+
createdAt;
|
|
1249
|
+
constructor(client, data) {
|
|
1250
|
+
this.client = client;
|
|
1251
|
+
this.id = data.id;
|
|
1252
|
+
this.channelId = data.channelId;
|
|
1253
|
+
this.guildId = data.guildId ?? null;
|
|
1254
|
+
this.content = data.content ?? null;
|
|
1255
|
+
this.authorId = data.authorId ?? null;
|
|
1256
|
+
this.author = data.author ?? null;
|
|
1257
|
+
this.createdAt = data.createdAt ?? (import_util5.SnowflakeUtil.isValid(data.id) ? import_util5.SnowflakeUtil.dateFromSnowflake(data.id) : null);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
1261
|
+
* Same contract as {@link Message.channel}.
|
|
1262
|
+
*/
|
|
1263
|
+
get channel() {
|
|
1264
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1265
|
+
return channel?.isTextBased() ? channel : null;
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1269
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1270
|
+
* @example
|
|
1271
|
+
* const channel = await message.resolveChannel();
|
|
1272
|
+
* await channel.delete();
|
|
1273
|
+
*/
|
|
1274
|
+
async resolveChannel() {
|
|
1275
|
+
return this.client.channels.resolve(this.channelId);
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Fetch the full message from the API.
|
|
1279
|
+
* @example
|
|
1280
|
+
* const message = await partial.fetch();
|
|
1281
|
+
* await message.reply('Pong!');
|
|
1282
|
+
*/
|
|
1283
|
+
async fetch() {
|
|
1284
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
855
1287
|
// Annotate the CommonJS export names for ESM import in node:
|
|
856
1288
|
0 && (module.exports = {
|
|
857
|
-
Message
|
|
1289
|
+
Message,
|
|
1290
|
+
PartialMessage
|
|
858
1291
|
});
|