@fluxerjs/core 2.2.0 → 3.0.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-CjQBbVmb.d.mts} +1390 -1104
- package/dist/{SubpathMessage-D70lAT7N.d.ts → SubpathMessage-DNlKq2Nj.d.ts} +1390 -1104
- package/dist/Sudo-CFfbmis3.d.mts +453 -0
- package/dist/Sudo-CFfbmis3.d.ts +453 -0
- package/dist/client.d.mts +4 -3
- package/dist/client.d.ts +4 -3
- package/dist/client.js +1976 -1001
- package/dist/client.mjs +1768 -796
- package/dist/cluster.d.mts +4 -3
- package/dist/cluster.d.ts +4 -3
- package/dist/cluster.js +1898 -923
- package/dist/cluster.mjs +1770 -798
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1957 -1008
- package/dist/index.mjs +1797 -834
- 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 +446 -93
- package/dist/message.mjs +446 -94
- 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) {
|
|
@@ -115,6 +117,37 @@ function applyReplyPingSuppression(body) {
|
|
|
115
117
|
function assignIfDefined(target, key, value) {
|
|
116
118
|
if (value !== void 0) target[key] = value;
|
|
117
119
|
}
|
|
120
|
+
function normalizeSendFiles(files) {
|
|
121
|
+
if (!files?.length) return void 0;
|
|
122
|
+
const normalized = [];
|
|
123
|
+
const metaFromBuilders = [];
|
|
124
|
+
let anyBuilderMeta = false;
|
|
125
|
+
for (let i = 0; i < files.length; i++) {
|
|
126
|
+
const file = files[i];
|
|
127
|
+
if (!file) continue;
|
|
128
|
+
if (file instanceof import_builders.AttachmentBuilder) {
|
|
129
|
+
normalized.push(file.toFileData());
|
|
130
|
+
const meta = {
|
|
131
|
+
id: i,
|
|
132
|
+
filename: file.filename,
|
|
133
|
+
...file.description != null ? { description: file.description } : {},
|
|
134
|
+
...file.spoiler ? { flags: import_types.MessageAttachmentFlags.IS_SPOILER } : {}
|
|
135
|
+
};
|
|
136
|
+
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
137
|
+
metaFromBuilders.push(meta);
|
|
138
|
+
} else {
|
|
139
|
+
normalized.push(file);
|
|
140
|
+
metaFromBuilders.push({
|
|
141
|
+
id: i,
|
|
142
|
+
filename: file.filename ?? file.name
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
files: normalized,
|
|
148
|
+
metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
|
|
149
|
+
};
|
|
150
|
+
}
|
|
118
151
|
function buildSendBody(options) {
|
|
119
152
|
const body = typeof options === "string" ? { content: options } : options;
|
|
120
153
|
const result = {};
|
|
@@ -122,16 +155,17 @@ function buildSendBody(options) {
|
|
|
122
155
|
if (body.embeds?.length) {
|
|
123
156
|
result.embeds = body.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
|
|
124
157
|
}
|
|
158
|
+
const normalizedFiles = normalizeSendFiles(body.files);
|
|
125
159
|
if (body.uploadedAttachments?.length) {
|
|
126
160
|
result.attachments = body.uploadedAttachments;
|
|
127
|
-
} else if (
|
|
161
|
+
} else if (normalizedFiles?.files.length) {
|
|
128
162
|
result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
|
|
129
163
|
id: a.id,
|
|
130
164
|
filename: a.filename,
|
|
131
165
|
...a.title != null && { title: a.title },
|
|
132
166
|
...a.description != null && { description: a.description },
|
|
133
167
|
...a.flags != null && { flags: a.flags }
|
|
134
|
-
})) :
|
|
168
|
+
})) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
|
|
135
169
|
}
|
|
136
170
|
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
137
171
|
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
@@ -225,9 +259,10 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
225
259
|
} else if (allowedMentions?.repliedUser === false) {
|
|
226
260
|
applyReplyPingSuppression(body);
|
|
227
261
|
}
|
|
262
|
+
const resolvedFiles = normalizeSendFiles(files);
|
|
228
263
|
return {
|
|
229
264
|
body,
|
|
230
|
-
files: !uploadedAttachments?.length && files
|
|
265
|
+
files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
|
|
231
266
|
};
|
|
232
267
|
}
|
|
233
268
|
|
|
@@ -273,13 +308,17 @@ var Base = class {
|
|
|
273
308
|
};
|
|
274
309
|
|
|
275
310
|
// src/Domain/Message/MessageReaction.ts
|
|
276
|
-
var MessageReaction = class extends Base {
|
|
311
|
+
var MessageReaction = class _MessageReaction extends Base {
|
|
277
312
|
client;
|
|
278
313
|
messageId;
|
|
279
314
|
channelId;
|
|
280
315
|
guildId;
|
|
281
316
|
emoji;
|
|
282
|
-
/**
|
|
317
|
+
/** Total count when hydrated from a message payload; `1` for gateway add events. */
|
|
318
|
+
count;
|
|
319
|
+
/** Whether the current user reacted (message payload); false for gateway remove. */
|
|
320
|
+
me;
|
|
321
|
+
/** Raw gateway payload for low-level access (null when built from a message aggregate). */
|
|
283
322
|
_data;
|
|
284
323
|
constructor(client, data) {
|
|
285
324
|
super();
|
|
@@ -293,6 +332,26 @@ var MessageReaction = class extends Base {
|
|
|
293
332
|
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
294
333
|
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
295
334
|
};
|
|
335
|
+
this.count = 1;
|
|
336
|
+
this.me = false;
|
|
337
|
+
}
|
|
338
|
+
/** Build a reaction aggregate from a message's `reactions` array entry. */
|
|
339
|
+
static fromMessage(message, data) {
|
|
340
|
+
const reaction = new _MessageReaction(message.client, {
|
|
341
|
+
user_id: message.client.user?.id ?? "0",
|
|
342
|
+
message_id: message.id,
|
|
343
|
+
channel_id: message.channelId,
|
|
344
|
+
guild_id: message.guildId ?? void 0,
|
|
345
|
+
emoji: {
|
|
346
|
+
name: data.emoji.name,
|
|
347
|
+
id: data.emoji.id ?? void 0,
|
|
348
|
+
animated: data.emoji.animated ?? void 0
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
Object.defineProperty(reaction, "_data", { value: null });
|
|
352
|
+
reaction.count = data.count;
|
|
353
|
+
reaction.me = data.me ?? false;
|
|
354
|
+
return reaction;
|
|
296
355
|
}
|
|
297
356
|
/** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
|
|
298
357
|
get emojiIdentifier() {
|
|
@@ -302,12 +361,23 @@ var MessageReaction = class extends Base {
|
|
|
302
361
|
get guild() {
|
|
303
362
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
304
363
|
}
|
|
364
|
+
/** Cached message this reaction belongs to, or null if the message was not cached. */
|
|
365
|
+
get message() {
|
|
366
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
|
|
367
|
+
return cached ? new Message(this.client, cached) : null;
|
|
368
|
+
}
|
|
369
|
+
/** Cached text-capable channel, or null if uncached / not text-based. */
|
|
370
|
+
get channel() {
|
|
371
|
+
const channel = this.client.channels.get(this.channelId);
|
|
372
|
+
return channel?.isTextBased() ? channel : null;
|
|
373
|
+
}
|
|
305
374
|
/**
|
|
306
|
-
* Fetch the message this reaction belongs to.
|
|
307
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
375
|
+
* Fetch the message this reaction belongs to (cache first, then REST).
|
|
308
376
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
309
377
|
*/
|
|
310
378
|
async fetchMessage() {
|
|
379
|
+
const cached = this.message;
|
|
380
|
+
if (cached) return cached;
|
|
311
381
|
try {
|
|
312
382
|
const data = await this.client.rest.get(
|
|
313
383
|
import_types2.Routes.channelMessage(this.channelId, this.messageId)
|
|
@@ -378,11 +448,17 @@ var Events = {
|
|
|
378
448
|
WebhooksUpdate: "webhooksUpdate",
|
|
379
449
|
Resumed: "resumed",
|
|
380
450
|
Error: "error",
|
|
381
|
-
Debug: "debug"
|
|
451
|
+
Debug: "debug",
|
|
452
|
+
ShardReady: "shardReady",
|
|
453
|
+
ShardResumed: "shardResumed",
|
|
454
|
+
ShardDisconnect: "shardDisconnect",
|
|
455
|
+
ShardReconnecting: "shardReconnecting",
|
|
456
|
+
ShardError: "shardError",
|
|
457
|
+
ShardingRequired: "shardingRequired"
|
|
382
458
|
};
|
|
383
459
|
|
|
384
460
|
// src/Helpers/ReactionCollector.ts
|
|
385
|
-
var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
461
|
+
var ReactionCollector = class _ReactionCollector extends import_node_events.EventEmitter {
|
|
386
462
|
client;
|
|
387
463
|
messageId;
|
|
388
464
|
channelId;
|
|
@@ -425,15 +501,17 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
425
501
|
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
426
502
|
}
|
|
427
503
|
});
|
|
428
|
-
const
|
|
504
|
+
const cached = this.client.users.get(entry.userId);
|
|
505
|
+
const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
|
|
506
|
+
{
|
|
429
507
|
id: entry.userId,
|
|
430
508
|
username: "Unknown",
|
|
431
509
|
discriminator: "0",
|
|
432
|
-
|
|
510
|
+
globalName: null,
|
|
433
511
|
avatar: null,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
512
|
+
bot: false,
|
|
513
|
+
system: false
|
|
514
|
+
};
|
|
437
515
|
this._collect(reaction, user, entry.userId);
|
|
438
516
|
}
|
|
439
517
|
};
|
|
@@ -465,6 +543,21 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
465
543
|
}
|
|
466
544
|
this.emit("end", this.collected, reason);
|
|
467
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* One-shot helper used by {@link Message.awaitReactions}.
|
|
548
|
+
* Resolves with the collected reactions when the collector ends.
|
|
549
|
+
* Rejects if `options.errors` includes the end reason.
|
|
550
|
+
*/
|
|
551
|
+
static awaitReactions(client, messageId, channelId, options) {
|
|
552
|
+
const errors = options?.errors ?? [];
|
|
553
|
+
return new Promise((resolve, reject) => {
|
|
554
|
+
const collector = new _ReactionCollector(client, messageId, channelId, options);
|
|
555
|
+
collector.on("end", (collected, reason) => {
|
|
556
|
+
if (errors.includes(reason)) reject(collected);
|
|
557
|
+
else resolve(collected);
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
}
|
|
468
561
|
on(event, listener) {
|
|
469
562
|
return super.on(event, listener);
|
|
470
563
|
}
|
|
@@ -473,70 +566,175 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
473
566
|
}
|
|
474
567
|
};
|
|
475
568
|
|
|
476
|
-
// src/Domain/Message/
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
569
|
+
// src/Domain/Message/Attachment.ts
|
|
570
|
+
function toMessageAttachment(data) {
|
|
571
|
+
return {
|
|
572
|
+
id: data.id,
|
|
573
|
+
filename: data.filename,
|
|
574
|
+
title: data.title ?? null,
|
|
575
|
+
description: data.description ?? null,
|
|
576
|
+
contentType: data.content_type ?? null,
|
|
577
|
+
contentHash: data.content_hash ?? null,
|
|
578
|
+
size: data.size,
|
|
579
|
+
url: data.url ?? null,
|
|
580
|
+
proxyUrl: data.proxy_url ?? null,
|
|
581
|
+
width: data.width ?? null,
|
|
582
|
+
height: data.height ?? null,
|
|
583
|
+
placeholder: data.placeholder ?? null,
|
|
584
|
+
flags: data.flags ?? 0,
|
|
585
|
+
nsfw: data.nsfw ?? false,
|
|
586
|
+
duration: data.duration ?? null,
|
|
587
|
+
waveform: data.waveform ?? null,
|
|
588
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
589
|
+
expired: data.expired ?? false
|
|
590
|
+
};
|
|
481
591
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
592
|
+
|
|
593
|
+
// src/Domain/Message/Embed.ts
|
|
594
|
+
function toMessageEmbedAuthor(data) {
|
|
595
|
+
return {
|
|
596
|
+
name: data.name ?? null,
|
|
597
|
+
url: data.url ?? null,
|
|
598
|
+
iconUrl: data.icon_url ?? null,
|
|
599
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
function toMessageEmbedFooter(data) {
|
|
603
|
+
return {
|
|
604
|
+
text: data.text,
|
|
605
|
+
iconUrl: data.icon_url ?? null,
|
|
606
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
function toMessageEmbedMedia(data) {
|
|
610
|
+
return {
|
|
611
|
+
url: data.url,
|
|
612
|
+
proxyUrl: data.proxy_url ?? null,
|
|
613
|
+
contentType: data.content_type ?? null,
|
|
614
|
+
contentHash: data.content_hash ?? null,
|
|
615
|
+
width: data.width ?? null,
|
|
616
|
+
height: data.height ?? null,
|
|
617
|
+
description: data.description ?? null,
|
|
618
|
+
placeholder: data.placeholder ?? null,
|
|
619
|
+
duration: data.duration ?? null,
|
|
620
|
+
flags: data.flags ?? null
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function toMessageEmbed(data) {
|
|
624
|
+
const full = data;
|
|
625
|
+
return {
|
|
626
|
+
type: data.type ?? "rich",
|
|
627
|
+
url: data.url ?? null,
|
|
628
|
+
title: data.title ?? null,
|
|
629
|
+
color: data.color ?? null,
|
|
630
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
631
|
+
description: data.description ?? null,
|
|
632
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
633
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
634
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
635
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
636
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
637
|
+
name: f.name,
|
|
638
|
+
value: f.value,
|
|
639
|
+
inline: f.inline ?? false
|
|
640
|
+
})),
|
|
641
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
642
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
643
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
644
|
+
nsfw: data.nsfw ?? false,
|
|
645
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
646
|
+
html: full.html ?? null,
|
|
647
|
+
htmlWidth: full.html_width ?? null,
|
|
648
|
+
htmlHeight: full.html_height ?? null
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
653
|
+
var import_collection2 = require("@fluxerjs/collection");
|
|
654
|
+
var MessageReactionManager = class {
|
|
655
|
+
constructor(message) {
|
|
656
|
+
this.message = message;
|
|
489
657
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
658
|
+
_cache = new import_collection2.Collection();
|
|
659
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
660
|
+
get cache() {
|
|
661
|
+
return this._cache;
|
|
493
662
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
return {
|
|
497
|
-
name: parsed.name,
|
|
498
|
-
id: parsed.id,
|
|
499
|
-
...parsed.animated ? { animated: true } : {}
|
|
500
|
-
};
|
|
663
|
+
get size() {
|
|
664
|
+
return this._cache.size;
|
|
501
665
|
}
|
|
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 } : {}
|
|
666
|
+
[Symbol.iterator]() {
|
|
667
|
+
return this._cache.values();
|
|
668
|
+
}
|
|
669
|
+
/** @internal Sync from an API message payload. */
|
|
670
|
+
_patch(reactions) {
|
|
671
|
+
this._cache.clear();
|
|
672
|
+
for (const data of reactions ?? []) {
|
|
673
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
674
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
522
675
|
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
// src/Domain/Message/MessageSticker.ts
|
|
680
|
+
var import_util3 = require("@fluxerjs/util");
|
|
681
|
+
|
|
682
|
+
// src/Helpers/Constants.ts
|
|
683
|
+
var import_rest2 = require("@fluxerjs/rest");
|
|
684
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
685
|
+
|
|
686
|
+
// src/Helpers/Cdn.ts
|
|
687
|
+
function mediaBase(options) {
|
|
688
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
689
|
+
}
|
|
690
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
691
|
+
const ext = animated ? "gif" : "png";
|
|
692
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// src/Domain/Message/MessageSticker.ts
|
|
696
|
+
var MessageSticker = class extends Base {
|
|
697
|
+
client;
|
|
698
|
+
id;
|
|
699
|
+
name;
|
|
700
|
+
description;
|
|
701
|
+
tags;
|
|
702
|
+
animated;
|
|
703
|
+
constructor(client, data) {
|
|
704
|
+
super();
|
|
705
|
+
this.client = client;
|
|
706
|
+
this.id = data.id;
|
|
707
|
+
this.name = data.name;
|
|
708
|
+
this.description = data.description ?? "";
|
|
709
|
+
this.tags = data.tags ?? [];
|
|
710
|
+
this.animated = data.animated ?? false;
|
|
711
|
+
}
|
|
712
|
+
/** CDN URL for this sticker image. */
|
|
713
|
+
get url() {
|
|
714
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
715
|
+
mediaBase: this.client.instance.endpoints.media
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
719
|
+
get createdTimestamp() {
|
|
720
|
+
return import_util3.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
721
|
+
}
|
|
722
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
723
|
+
get createdAt() {
|
|
724
|
+
return import_util3.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
// src/Domain/Message/Reactions.ts
|
|
729
|
+
var import_types3 = require("@fluxerjs/types");
|
|
730
|
+
async function emojiPath(message, emoji) {
|
|
731
|
+
return message.client.resolveEmoji(emoji, message.guildId);
|
|
533
732
|
}
|
|
534
733
|
async function reactToMessage(message, emoji) {
|
|
535
734
|
const wire = await emojiPath(message, emoji);
|
|
536
735
|
await message.client.rest.put(
|
|
537
736
|
import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
538
737
|
);
|
|
539
|
-
emitOwnReactionAdd(message, wire);
|
|
540
738
|
}
|
|
541
739
|
async function removeMessageReaction(message, emoji, userId) {
|
|
542
740
|
const e = await emojiPath(message, emoji);
|
|
@@ -642,7 +840,33 @@ async function replyToMessage(message, options, replyOptions) {
|
|
|
642
840
|
}
|
|
643
841
|
|
|
644
842
|
// src/Domain/Message/Message.ts
|
|
843
|
+
function toMessageCall(data) {
|
|
844
|
+
return {
|
|
845
|
+
participants: data.participants,
|
|
846
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function toMessageSnapshot(client, data) {
|
|
850
|
+
return {
|
|
851
|
+
content: data.content ?? null,
|
|
852
|
+
createdAt: new Date(data.timestamp),
|
|
853
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
854
|
+
mentionUserIds: data.mentions ?? [],
|
|
855
|
+
mentionRoles: data.mention_roles ?? [],
|
|
856
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
857
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
858
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
859
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
function resolveMessageFlags(flags) {
|
|
863
|
+
if (flags === void 0) return void 0;
|
|
864
|
+
if (typeof flags === "number") return flags;
|
|
865
|
+
return Number(import_util4.MessageFlagsBitField.resolve(flags));
|
|
866
|
+
}
|
|
645
867
|
var Message = class _Message extends Base {
|
|
868
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
869
|
+
partial = false;
|
|
646
870
|
/** The {@link Client} that instantiated this message. */
|
|
647
871
|
client;
|
|
648
872
|
/** Snowflake ID of this message. */
|
|
@@ -671,7 +895,7 @@ var Message = class _Message extends Base {
|
|
|
671
895
|
mentionEveryone;
|
|
672
896
|
/** Whether this is a text-to-speech message. */
|
|
673
897
|
tts;
|
|
674
|
-
/** Embedded content (
|
|
898
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
675
899
|
embeds;
|
|
676
900
|
/** Stickers sent with the message. */
|
|
677
901
|
stickers;
|
|
@@ -693,26 +917,41 @@ var Message = class _Message extends Base {
|
|
|
693
917
|
mentionRoles;
|
|
694
918
|
/** Client-side nonce for deduplication. */
|
|
695
919
|
nonce;
|
|
696
|
-
/**
|
|
920
|
+
/**
|
|
921
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
922
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
923
|
+
*/
|
|
697
924
|
get channel() {
|
|
698
|
-
|
|
925
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
926
|
+
return channel?.isTextBased() ? channel : null;
|
|
699
927
|
}
|
|
700
928
|
/** Cached guild, or null for DMs / uncached. */
|
|
701
929
|
get guild() {
|
|
702
930
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
703
931
|
}
|
|
704
|
-
/**
|
|
932
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
933
|
+
get member() {
|
|
934
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
938
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
939
|
+
* @example
|
|
940
|
+
* const channel = await message.resolveChannel();
|
|
941
|
+
* await channel.delete();
|
|
942
|
+
*/
|
|
705
943
|
async resolveChannel() {
|
|
706
944
|
return this.client.channels.resolve(this.channelId);
|
|
707
945
|
}
|
|
708
|
-
/**
|
|
946
|
+
/**
|
|
947
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
948
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
949
|
+
* @example
|
|
950
|
+
* const guild = await message.resolveGuild();
|
|
951
|
+
*/
|
|
709
952
|
async resolveGuild() {
|
|
710
953
|
if (!this.guildId) return null;
|
|
711
|
-
|
|
712
|
-
return await this.client.guilds.resolve(this.guildId);
|
|
713
|
-
} catch {
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
954
|
+
return this.client.guilds.resolve(this.guildId);
|
|
716
955
|
}
|
|
717
956
|
/**
|
|
718
957
|
* Construct a message from API data.
|
|
@@ -729,29 +968,73 @@ var Message = class _Message extends Base {
|
|
|
729
968
|
this.createdAt = new Date(data.timestamp);
|
|
730
969
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
731
970
|
this.pinned = data.pinned;
|
|
732
|
-
this.attachments = new
|
|
733
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
971
|
+
this.attachments = new import_collection3.Collection();
|
|
972
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
734
973
|
this.type = data.type ?? import_types5.MessageType.Default;
|
|
735
|
-
this.flags = data.flags ?? 0;
|
|
974
|
+
this.flags = new import_util4.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
736
975
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
737
976
|
this.tts = data.tts ?? false;
|
|
738
|
-
this.embeds = data.embeds ?? [];
|
|
739
|
-
this.stickers = data.stickers ?? [];
|
|
740
|
-
this.reactions =
|
|
741
|
-
this.
|
|
742
|
-
this.
|
|
743
|
-
|
|
977
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
978
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
979
|
+
this.reactions = new MessageReactionManager(this);
|
|
980
|
+
this.reactions._patch(data.reactions);
|
|
981
|
+
this.messageReference = data.message_reference ? {
|
|
982
|
+
channelId: data.message_reference.channel_id,
|
|
983
|
+
messageId: data.message_reference.message_id,
|
|
984
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
985
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
986
|
+
} : null;
|
|
987
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
988
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
744
989
|
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
745
990
|
this.webhookId = data.webhook_id ?? null;
|
|
746
991
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
747
992
|
this.mentionRoles = data.mention_roles ?? [];
|
|
748
993
|
this.nonce = data.nonce ?? null;
|
|
749
994
|
}
|
|
750
|
-
/**
|
|
995
|
+
/**
|
|
996
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
997
|
+
* @internal
|
|
998
|
+
*/
|
|
999
|
+
_patch(data) {
|
|
1000
|
+
this.content = data.content;
|
|
1001
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1002
|
+
this.pinned = data.pinned;
|
|
1003
|
+
this.attachments.clear();
|
|
1004
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1005
|
+
this.flags = new import_util4.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1006
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1007
|
+
this.tts = data.tts ?? false;
|
|
1008
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1009
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1010
|
+
this.reactions._patch(data.reactions);
|
|
1011
|
+
this.messageReference = data.message_reference ? {
|
|
1012
|
+
channelId: data.message_reference.channel_id,
|
|
1013
|
+
messageId: data.message_reference.message_id,
|
|
1014
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1015
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1016
|
+
} : null;
|
|
1017
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1018
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1019
|
+
);
|
|
1020
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1021
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1022
|
+
this.webhookId = data.webhook_id ?? null;
|
|
1023
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1024
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
1025
|
+
this.nonce = data.nonce ?? null;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Send a standalone message in this channel (not a reply).
|
|
1029
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
1030
|
+
*/
|
|
751
1031
|
async send(options) {
|
|
752
1032
|
return sendMessage(this, options);
|
|
753
1033
|
}
|
|
754
|
-
/**
|
|
1034
|
+
/**
|
|
1035
|
+
* Send a message to another channel by ID.
|
|
1036
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
1037
|
+
*/
|
|
755
1038
|
async sendTo(channelId, options) {
|
|
756
1039
|
return sendMessageTo(this, channelId, options);
|
|
757
1040
|
}
|
|
@@ -765,6 +1048,16 @@ var Message = class _Message extends Base {
|
|
|
765
1048
|
async reply(options, replyOptions) {
|
|
766
1049
|
return replyToMessage(this, options, replyOptions);
|
|
767
1050
|
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Hydrate a partial message, or return the message as-is.
|
|
1053
|
+
* @example
|
|
1054
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
1055
|
+
* const message = await Message.resolve(msg);
|
|
1056
|
+
* });
|
|
1057
|
+
*/
|
|
1058
|
+
static async resolve(message) {
|
|
1059
|
+
return message.partial ? message.fetch() : message;
|
|
1060
|
+
}
|
|
768
1061
|
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
769
1062
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
770
1063
|
return createMessageBody(content, referenced_message, ping);
|
|
@@ -777,7 +1070,7 @@ var Message = class _Message extends Base {
|
|
|
777
1070
|
async edit(options) {
|
|
778
1071
|
const body = {};
|
|
779
1072
|
if (options.content !== void 0) body.content = options.content;
|
|
780
|
-
if (options.embeds
|
|
1073
|
+
if (options.embeds !== void 0) {
|
|
781
1074
|
body.embeds = options.embeds.map(
|
|
782
1075
|
(e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e
|
|
783
1076
|
);
|
|
@@ -785,7 +1078,8 @@ var Message = class _Message extends Base {
|
|
|
785
1078
|
if (options.allowedMentions) {
|
|
786
1079
|
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
787
1080
|
}
|
|
788
|
-
|
|
1081
|
+
const flags = resolveMessageFlags(options.flags);
|
|
1082
|
+
if (flags !== void 0) body.flags = flags;
|
|
789
1083
|
if (options.attachments !== void 0) {
|
|
790
1084
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
791
1085
|
}
|
|
@@ -800,6 +1094,13 @@ var Message = class _Message extends Base {
|
|
|
800
1094
|
createReactionCollector(options) {
|
|
801
1095
|
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
802
1096
|
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
1099
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1100
|
+
*/
|
|
1101
|
+
awaitReactions(options) {
|
|
1102
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1103
|
+
}
|
|
803
1104
|
/** Fetch the latest version of this message from the API. */
|
|
804
1105
|
async fetch() {
|
|
805
1106
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
@@ -852,7 +1153,59 @@ var Message = class _Message extends Base {
|
|
|
852
1153
|
return fetchMessageReactionUsersPage(this, emoji, options);
|
|
853
1154
|
}
|
|
854
1155
|
};
|
|
1156
|
+
|
|
1157
|
+
// src/Domain/Message/PartialMessage.ts
|
|
1158
|
+
var import_util5 = require("@fluxerjs/util");
|
|
1159
|
+
var PartialMessage = class {
|
|
1160
|
+
partial = true;
|
|
1161
|
+
client;
|
|
1162
|
+
id;
|
|
1163
|
+
channelId;
|
|
1164
|
+
guildId;
|
|
1165
|
+
content;
|
|
1166
|
+
authorId;
|
|
1167
|
+
author;
|
|
1168
|
+
createdAt;
|
|
1169
|
+
constructor(client, data) {
|
|
1170
|
+
this.client = client;
|
|
1171
|
+
this.id = data.id;
|
|
1172
|
+
this.channelId = data.channelId;
|
|
1173
|
+
this.guildId = data.guildId ?? null;
|
|
1174
|
+
this.content = data.content ?? null;
|
|
1175
|
+
this.authorId = data.authorId ?? null;
|
|
1176
|
+
this.author = data.author ?? null;
|
|
1177
|
+
this.createdAt = data.createdAt ?? (import_util5.SnowflakeUtil.isValid(data.id) ? import_util5.SnowflakeUtil.dateFromSnowflake(data.id) : null);
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
1181
|
+
* Same contract as {@link Message.channel}.
|
|
1182
|
+
*/
|
|
1183
|
+
get channel() {
|
|
1184
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1185
|
+
return channel?.isTextBased() ? channel : null;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1189
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1190
|
+
* @example
|
|
1191
|
+
* const channel = await message.resolveChannel();
|
|
1192
|
+
* await channel.delete();
|
|
1193
|
+
*/
|
|
1194
|
+
async resolveChannel() {
|
|
1195
|
+
return this.client.channels.resolve(this.channelId);
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Fetch the full message from the API.
|
|
1199
|
+
* @example
|
|
1200
|
+
* const message = await partial.fetch();
|
|
1201
|
+
* await message.reply('Pong!');
|
|
1202
|
+
*/
|
|
1203
|
+
async fetch() {
|
|
1204
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
855
1207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
856
1208
|
0 && (module.exports = {
|
|
857
|
-
Message
|
|
1209
|
+
Message,
|
|
1210
|
+
PartialMessage
|
|
858
1211
|
});
|