@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/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 Collection2 } from "@fluxerjs/collection";
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) {
@@ -22,8 +23,8 @@ function toMessageAttachmentEditWire(attachments) {
22
23
  }
23
24
 
24
25
  // src/Helpers/MessageUtils/Body.ts
25
- import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
26
- import { MessageReferenceType } from "@fluxerjs/types";
26
+ import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
27
+ import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
27
28
 
28
29
  // src/LibErrors/ErrorCodes.ts
29
30
  import { ErrorCodes } from "@fluxerjs/util";
@@ -92,6 +93,37 @@ function applyReplyPingSuppression(body) {
92
93
  function assignIfDefined(target, key, value) {
93
94
  if (value !== void 0) target[key] = value;
94
95
  }
96
+ function normalizeSendFiles(files) {
97
+ if (!files?.length) return void 0;
98
+ const normalized = [];
99
+ const metaFromBuilders = [];
100
+ let anyBuilderMeta = false;
101
+ for (let i = 0; i < files.length; i++) {
102
+ const file = files[i];
103
+ if (!file) continue;
104
+ if (file instanceof AttachmentBuilder) {
105
+ normalized.push(file.toFileData());
106
+ const meta = {
107
+ id: i,
108
+ filename: file.filename,
109
+ ...file.description != null ? { description: file.description } : {},
110
+ ...file.spoiler ? { flags: MessageAttachmentFlags.IS_SPOILER } : {}
111
+ };
112
+ if (file.description != null || file.spoiler) anyBuilderMeta = true;
113
+ metaFromBuilders.push(meta);
114
+ } else {
115
+ normalized.push(file);
116
+ metaFromBuilders.push({
117
+ id: i,
118
+ filename: file.filename ?? file.name
119
+ });
120
+ }
121
+ }
122
+ return {
123
+ files: normalized,
124
+ metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
125
+ };
126
+ }
95
127
  function buildSendBody(options) {
96
128
  const body = typeof options === "string" ? { content: options } : options;
97
129
  const result = {};
@@ -99,16 +131,17 @@ function buildSendBody(options) {
99
131
  if (body.embeds?.length) {
100
132
  result.embeds = body.embeds.map((e) => e instanceof EmbedBuilder ? e.toJSON() : e);
101
133
  }
134
+ const normalizedFiles = normalizeSendFiles(body.files);
102
135
  if (body.uploadedAttachments?.length) {
103
136
  result.attachments = body.uploadedAttachments;
104
- } else if (body.files?.length) {
137
+ } else if (normalizedFiles?.files.length) {
105
138
  result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
106
139
  id: a.id,
107
140
  filename: a.filename,
108
141
  ...a.title != null && { title: a.title },
109
142
  ...a.description != null && { description: a.description },
110
143
  ...a.flags != null && { flags: a.flags }
111
- })) : body.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
144
+ })) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
112
145
  }
113
146
  if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
114
147
  if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
@@ -202,9 +235,10 @@ async function prepareMessagePostPayload(options, defaults) {
202
235
  } else if (allowedMentions?.repliedUser === false) {
203
236
  applyReplyPingSuppression(body);
204
237
  }
238
+ const resolvedFiles = normalizeSendFiles(files);
205
239
  return {
206
240
  body,
207
- files: !uploadedAttachments?.length && files?.length ? await resolveMessageFiles(files) : void 0
241
+ files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
208
242
  };
209
243
  }
210
244
 
@@ -250,13 +284,17 @@ var Base = class {
250
284
  };
251
285
 
252
286
  // src/Domain/Message/MessageReaction.ts
253
- var MessageReaction = class extends Base {
287
+ var MessageReaction = class _MessageReaction extends Base {
254
288
  client;
255
289
  messageId;
256
290
  channelId;
257
291
  guildId;
258
292
  emoji;
259
- /** Raw gateway payload for low-level access. */
293
+ /** Total count when hydrated from a message payload; `1` for gateway add events. */
294
+ count;
295
+ /** Whether the current user reacted (message payload); false for gateway remove. */
296
+ me;
297
+ /** Raw gateway payload for low-level access (null when built from a message aggregate). */
260
298
  _data;
261
299
  constructor(client, data) {
262
300
  super();
@@ -270,6 +308,26 @@ var MessageReaction = class extends Base {
270
308
  ...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
271
309
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
272
310
  };
311
+ this.count = 1;
312
+ this.me = false;
313
+ }
314
+ /** Build a reaction aggregate from a message's `reactions` array entry. */
315
+ static fromMessage(message, data) {
316
+ const reaction = new _MessageReaction(message.client, {
317
+ user_id: message.client.user?.id ?? "0",
318
+ message_id: message.id,
319
+ channel_id: message.channelId,
320
+ guild_id: message.guildId ?? void 0,
321
+ emoji: {
322
+ name: data.emoji.name,
323
+ id: data.emoji.id ?? void 0,
324
+ animated: data.emoji.animated ?? void 0
325
+ }
326
+ });
327
+ Object.defineProperty(reaction, "_data", { value: null });
328
+ reaction.count = data.count;
329
+ reaction.me = data.me ?? false;
330
+ return reaction;
273
331
  }
274
332
  /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
275
333
  get emojiIdentifier() {
@@ -279,12 +337,23 @@ var MessageReaction = class extends Base {
279
337
  get guild() {
280
338
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
281
339
  }
340
+ /** Cached message this reaction belongs to, or null if the message was not cached. */
341
+ get message() {
342
+ const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
343
+ return cached ? new Message(this.client, cached) : null;
344
+ }
345
+ /** Cached text-capable channel, or null if uncached / not text-based. */
346
+ get channel() {
347
+ const channel = this.client.channels.get(this.channelId);
348
+ return channel?.isTextBased() ? channel : null;
349
+ }
282
350
  /**
283
- * Fetch the message this reaction belongs to.
284
- * Use when you need to edit, delete, or otherwise interact with the message.
351
+ * Fetch the message this reaction belongs to (cache first, then REST).
285
352
  * @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
286
353
  */
287
354
  async fetchMessage() {
355
+ const cached = this.message;
356
+ if (cached) return cached;
288
357
  try {
289
358
  const data = await this.client.rest.get(
290
359
  Routes.channelMessage(this.channelId, this.messageId)
@@ -355,11 +424,17 @@ var Events = {
355
424
  WebhooksUpdate: "webhooksUpdate",
356
425
  Resumed: "resumed",
357
426
  Error: "error",
358
- Debug: "debug"
427
+ Debug: "debug",
428
+ ShardReady: "shardReady",
429
+ ShardResumed: "shardResumed",
430
+ ShardDisconnect: "shardDisconnect",
431
+ ShardReconnecting: "shardReconnecting",
432
+ ShardError: "shardError",
433
+ ShardingRequired: "shardingRequired"
359
434
  };
360
435
 
361
436
  // src/Helpers/ReactionCollector.ts
362
- var ReactionCollector = class extends EventEmitter {
437
+ var ReactionCollector = class _ReactionCollector extends EventEmitter {
363
438
  client;
364
439
  messageId;
365
440
  channelId;
@@ -402,15 +477,17 @@ var ReactionCollector = class extends EventEmitter {
402
477
  ...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
403
478
  }
404
479
  });
405
- const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
480
+ const cached = this.client.users.get(entry.userId);
481
+ const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
482
+ {
406
483
  id: entry.userId,
407
484
  username: "Unknown",
408
485
  discriminator: "0",
409
- global_name: null,
486
+ globalName: null,
410
487
  avatar: null,
411
- avatar_color: null,
412
- flags: 0
413
- });
488
+ bot: false,
489
+ system: false
490
+ };
414
491
  this._collect(reaction, user, entry.userId);
415
492
  }
416
493
  };
@@ -442,6 +519,21 @@ var ReactionCollector = class extends EventEmitter {
442
519
  }
443
520
  this.emit("end", this.collected, reason);
444
521
  }
522
+ /**
523
+ * One-shot helper used by {@link Message.awaitReactions}.
524
+ * Resolves with the collected reactions when the collector ends.
525
+ * Rejects if `options.errors` includes the end reason.
526
+ */
527
+ static awaitReactions(client, messageId, channelId, options) {
528
+ const errors = options?.errors ?? [];
529
+ return new Promise((resolve, reject) => {
530
+ const collector = new _ReactionCollector(client, messageId, channelId, options);
531
+ collector.on("end", (collected, reason) => {
532
+ if (errors.includes(reason)) reject(collected);
533
+ else resolve(collected);
534
+ });
535
+ });
536
+ }
445
537
  on(event, listener) {
446
538
  return super.on(event, listener);
447
539
  }
@@ -450,70 +542,175 @@ var ReactionCollector = class extends EventEmitter {
450
542
  }
451
543
  };
452
544
 
453
- // src/Domain/Message/Reactions.ts
454
- import { Routes as Routes2 } from "@fluxerjs/types";
455
- import { parseEmoji } from "@fluxerjs/util";
456
- async function emojiPath(message, emoji) {
457
- return message.client.resolveEmoji(emoji, message.guildId);
545
+ // src/Domain/Message/Attachment.ts
546
+ function toMessageAttachment(data) {
547
+ return {
548
+ id: data.id,
549
+ filename: data.filename,
550
+ title: data.title ?? null,
551
+ description: data.description ?? null,
552
+ contentType: data.content_type ?? null,
553
+ contentHash: data.content_hash ?? null,
554
+ size: data.size,
555
+ url: data.url ?? null,
556
+ proxyUrl: data.proxy_url ?? null,
557
+ width: data.width ?? null,
558
+ height: data.height ?? null,
559
+ placeholder: data.placeholder ?? null,
560
+ flags: data.flags ?? 0,
561
+ nsfw: data.nsfw ?? false,
562
+ duration: data.duration ?? null,
563
+ waveform: data.waveform ?? null,
564
+ expiresAt: data.expires_at ? new Date(data.expires_at) : null,
565
+ expired: data.expired ?? false
566
+ };
458
567
  }
459
- function toReactionEmoji(emoji) {
460
- if (typeof emoji !== "string") {
461
- return {
462
- name: emoji.name,
463
- ...emoji.id !== void 0 ? { id: emoji.id } : {},
464
- ...emoji.animated !== void 0 ? { animated: emoji.animated } : {}
465
- };
568
+
569
+ // src/Domain/Message/Embed.ts
570
+ function toMessageEmbedAuthor(data) {
571
+ return {
572
+ name: data.name ?? null,
573
+ url: data.url ?? null,
574
+ iconUrl: data.icon_url ?? null,
575
+ proxyIconUrl: data.proxy_icon_url ?? null
576
+ };
577
+ }
578
+ function toMessageEmbedFooter(data) {
579
+ return {
580
+ text: data.text,
581
+ iconUrl: data.icon_url ?? null,
582
+ proxyIconUrl: data.proxy_icon_url ?? null
583
+ };
584
+ }
585
+ function toMessageEmbedMedia(data) {
586
+ return {
587
+ url: data.url,
588
+ proxyUrl: data.proxy_url ?? null,
589
+ contentType: data.content_type ?? null,
590
+ contentHash: data.content_hash ?? null,
591
+ width: data.width ?? null,
592
+ height: data.height ?? null,
593
+ description: data.description ?? null,
594
+ placeholder: data.placeholder ?? null,
595
+ duration: data.duration ?? null,
596
+ flags: data.flags ?? null
597
+ };
598
+ }
599
+ function toMessageEmbed(data) {
600
+ const full = data;
601
+ return {
602
+ type: data.type ?? "rich",
603
+ url: data.url ?? null,
604
+ title: data.title ?? null,
605
+ color: data.color ?? null,
606
+ timestamp: data.timestamp ? new Date(data.timestamp) : null,
607
+ description: data.description ?? null,
608
+ author: data.author ? toMessageEmbedAuthor(data.author) : null,
609
+ image: data.image ? toMessageEmbedMedia(data.image) : null,
610
+ thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
611
+ footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
612
+ fields: (data.fields ?? []).map((f) => ({
613
+ name: f.name,
614
+ value: f.value,
615
+ inline: f.inline ?? false
616
+ })),
617
+ provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
618
+ video: data.video ? toMessageEmbedMedia(data.video) : null,
619
+ audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
620
+ nsfw: data.nsfw ?? false,
621
+ children: (full.children ?? []).map(toMessageEmbed),
622
+ html: full.html ?? null,
623
+ htmlWidth: full.html_width ?? null,
624
+ htmlHeight: full.html_height ?? null
625
+ };
626
+ }
627
+
628
+ // src/Domain/Message/MessageReactionManager.ts
629
+ import { Collection as Collection2 } from "@fluxerjs/collection";
630
+ var MessageReactionManager = class {
631
+ constructor(message) {
632
+ this.message = message;
466
633
  }
467
- const animatedWire = /^a:(\w+):(\d+)$/.exec(emoji);
468
- if (animatedWire) {
469
- return { name: animatedWire[1], id: animatedWire[2], animated: true };
634
+ _cache = new Collection2();
635
+ /** Reactions keyed by unicode name or `name:id`. */
636
+ get cache() {
637
+ return this._cache;
470
638
  }
471
- const parsed = parseEmoji(emoji);
472
- if (parsed?.id) {
473
- return {
474
- name: parsed.name,
475
- id: parsed.id,
476
- ...parsed.animated ? { animated: true } : {}
477
- };
639
+ get size() {
640
+ return this._cache.size;
478
641
  }
479
- let name = emoji;
480
- try {
481
- name = decodeURIComponent(emoji);
482
- } catch {
483
- }
484
- return { name: parsed?.name ?? name };
485
- }
486
- function emitOwnReactionAdd(message, wireOrInput) {
487
- const user = message.client.user;
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 } : {}
642
+ [Symbol.iterator]() {
643
+ return this._cache.values();
644
+ }
645
+ /** @internal Sync from an API message payload. */
646
+ _patch(reactions) {
647
+ this._cache.clear();
648
+ for (const data of reactions ?? []) {
649
+ const reaction = MessageReaction.fromMessage(this.message, data);
650
+ this._cache.set(reaction.emojiIdentifier, reaction);
499
651
  }
500
- });
501
- const payload = {
502
- reaction,
503
- user,
504
- messageId: message.id,
505
- channelId: message.channelId,
506
- emoji: emojiPayload,
507
- userId: user.id
508
- };
509
- message.client.emit(Events.MessageReactionAdd, payload);
652
+ }
653
+ };
654
+
655
+ // src/Domain/Message/MessageSticker.ts
656
+ import { SnowflakeUtil } from "@fluxerjs/util";
657
+
658
+ // src/Helpers/Constants.ts
659
+ import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
660
+ var CDN_URL = "https://fluxerusercontent.com";
661
+
662
+ // src/Helpers/Cdn.ts
663
+ function mediaBase(options) {
664
+ return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
665
+ }
666
+ function cdnStickerURL(stickerId, animated, options) {
667
+ const ext = animated ? "gif" : "png";
668
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
669
+ }
670
+
671
+ // src/Domain/Message/MessageSticker.ts
672
+ var MessageSticker = class extends Base {
673
+ client;
674
+ id;
675
+ name;
676
+ description;
677
+ tags;
678
+ animated;
679
+ constructor(client, data) {
680
+ super();
681
+ this.client = client;
682
+ this.id = data.id;
683
+ this.name = data.name;
684
+ this.description = data.description ?? "";
685
+ this.tags = data.tags ?? [];
686
+ this.animated = data.animated ?? false;
687
+ }
688
+ /** CDN URL for this sticker image. */
689
+ get url() {
690
+ return cdnStickerURL(this.id, this.animated, {
691
+ mediaBase: this.client.instance.endpoints.media
692
+ });
693
+ }
694
+ /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
695
+ get createdTimestamp() {
696
+ return SnowflakeUtil.timestampFromSnowflake(this.id);
697
+ }
698
+ /** Date when this sticker was created, derived from its snowflake ID. */
699
+ get createdAt() {
700
+ return SnowflakeUtil.dateFromSnowflake(this.id);
701
+ }
702
+ };
703
+
704
+ // src/Domain/Message/Reactions.ts
705
+ import { Routes as Routes2 } from "@fluxerjs/types";
706
+ async function emojiPath(message, emoji) {
707
+ return message.client.resolveEmoji(emoji, message.guildId);
510
708
  }
511
709
  async function reactToMessage(message, emoji) {
512
710
  const wire = await emojiPath(message, emoji);
513
711
  await message.client.rest.put(
514
712
  Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
515
713
  );
516
- emitOwnReactionAdd(message, wire);
517
714
  }
518
715
  async function removeMessageReaction(message, emoji, userId) {
519
716
  const e = await emojiPath(message, emoji);
@@ -619,7 +816,33 @@ async function replyToMessage(message, options, replyOptions) {
619
816
  }
620
817
 
621
818
  // src/Domain/Message/Message.ts
819
+ function toMessageCall(data) {
820
+ return {
821
+ participants: data.participants,
822
+ endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
823
+ };
824
+ }
825
+ function toMessageSnapshot(client, data) {
826
+ return {
827
+ content: data.content ?? null,
828
+ createdAt: new Date(data.timestamp),
829
+ editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
830
+ mentionUserIds: data.mentions ?? [],
831
+ mentionRoles: data.mention_roles ?? [],
832
+ embeds: (data.embeds ?? []).map(toMessageEmbed),
833
+ attachments: (data.attachments ?? []).map(toMessageAttachment),
834
+ stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
835
+ ...data.type !== void 0 ? { type: data.type } : {}
836
+ };
837
+ }
838
+ function resolveMessageFlags(flags) {
839
+ if (flags === void 0) return void 0;
840
+ if (typeof flags === "number") return flags;
841
+ return Number(MessageFlagsBitField.resolve(flags));
842
+ }
622
843
  var Message = class _Message extends Base {
844
+ /** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
845
+ partial = false;
623
846
  /** The {@link Client} that instantiated this message. */
624
847
  client;
625
848
  /** Snowflake ID of this message. */
@@ -648,7 +871,7 @@ var Message = class _Message extends Base {
648
871
  mentionEveryone;
649
872
  /** Whether this is a text-to-speech message. */
650
873
  tts;
651
- /** Embedded content (rich previews, etc.). */
874
+ /** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
652
875
  embeds;
653
876
  /** Stickers sent with the message. */
654
877
  stickers;
@@ -670,26 +893,41 @@ var Message = class _Message extends Base {
670
893
  mentionRoles;
671
894
  /** Client-side nonce for deduplication. */
672
895
  nonce;
673
- /** Cached text/DM/guild channel, or null if uncached. */
896
+ /**
897
+ * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
898
+ * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
899
+ */
674
900
  get channel() {
675
- return this.client.channels.get(this.channelId) ?? null;
901
+ const channel = this.client.channels.get(this.channelId) ?? null;
902
+ return channel?.isTextBased() ? channel : null;
676
903
  }
677
904
  /** Cached guild, or null for DMs / uncached. */
678
905
  get guild() {
679
906
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
680
907
  }
681
- /** Fetch and resolve the channel this message is in. */
908
+ /** Cached guild member for the author, or null in DMs / if uncached. */
909
+ get member() {
910
+ return this.guild?.members.get(this.author.id) ?? null;
911
+ }
912
+ /**
913
+ * Fetch this message's channel (cache first). The returned {@link Channel}
914
+ * has {@link Channel.delete} and {@link Channel.send}.
915
+ * @example
916
+ * const channel = await message.resolveChannel();
917
+ * await channel.delete();
918
+ */
682
919
  async resolveChannel() {
683
920
  return this.client.channels.resolve(this.channelId);
684
921
  }
685
- /** Fetch and resolve the guild, or null if a DM. */
922
+ /**
923
+ * Fetch and resolve the guild, or null if a DM.
924
+ * Propagates network/auth errors; only returns null when there is no guildId.
925
+ * @example
926
+ * const guild = await message.resolveGuild();
927
+ */
686
928
  async resolveGuild() {
687
929
  if (!this.guildId) return null;
688
- try {
689
- return await this.client.guilds.resolve(this.guildId);
690
- } catch {
691
- return null;
692
- }
930
+ return this.client.guilds.resolve(this.guildId);
693
931
  }
694
932
  /**
695
933
  * Construct a message from API data.
@@ -706,29 +944,73 @@ var Message = class _Message extends Base {
706
944
  this.createdAt = new Date(data.timestamp);
707
945
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
708
946
  this.pinned = data.pinned;
709
- this.attachments = new Collection2();
710
- for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
947
+ this.attachments = new Collection3();
948
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
711
949
  this.type = data.type ?? MessageType.Default;
712
- this.flags = data.flags ?? 0;
950
+ this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
713
951
  this.mentionEveryone = data.mention_everyone ?? false;
714
952
  this.tts = data.tts ?? false;
715
- this.embeds = data.embeds ?? [];
716
- this.stickers = data.stickers ?? [];
717
- this.reactions = data.reactions ?? [];
718
- this.messageReference = data.message_reference ?? null;
719
- this.messageSnapshots = data.message_snapshots ?? [];
720
- this.call = data.call ?? null;
953
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
954
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
955
+ this.reactions = new MessageReactionManager(this);
956
+ this.reactions._patch(data.reactions);
957
+ this.messageReference = data.message_reference ? {
958
+ channelId: data.message_reference.channel_id,
959
+ messageId: data.message_reference.message_id,
960
+ guildId: data.message_reference.guild_id ?? null,
961
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
962
+ } : null;
963
+ this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
964
+ this.call = data.call ? toMessageCall(data.call) : null;
721
965
  this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
722
966
  this.webhookId = data.webhook_id ?? null;
723
967
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
724
968
  this.mentionRoles = data.mention_roles ?? [];
725
969
  this.nonce = data.nonce ?? null;
726
970
  }
727
- /** Send a message in this channel without replying. */
971
+ /**
972
+ * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
973
+ * @internal
974
+ */
975
+ _patch(data) {
976
+ this.content = data.content;
977
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
978
+ this.pinned = data.pinned;
979
+ this.attachments.clear();
980
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
981
+ this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
982
+ this.mentionEveryone = data.mention_everyone ?? false;
983
+ this.tts = data.tts ?? false;
984
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
985
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
986
+ this.reactions._patch(data.reactions);
987
+ this.messageReference = data.message_reference ? {
988
+ channelId: data.message_reference.channel_id,
989
+ messageId: data.message_reference.message_id,
990
+ guildId: data.message_reference.guild_id ?? null,
991
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
992
+ } : null;
993
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
994
+ (s) => toMessageSnapshot(this.client, s)
995
+ );
996
+ this.call = data.call ? toMessageCall(data.call) : null;
997
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
998
+ this.webhookId = data.webhook_id ?? null;
999
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1000
+ this.mentionRoles = data.mention_roles ?? [];
1001
+ this.nonce = data.nonce ?? null;
1002
+ }
1003
+ /**
1004
+ * Send a standalone message in this channel (not a reply).
1005
+ * Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
1006
+ */
728
1007
  async send(options) {
729
1008
  return sendMessage(this, options);
730
1009
  }
731
- /** Send a message to another channel by ID. */
1010
+ /**
1011
+ * Send a message to another channel by ID.
1012
+ * Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
1013
+ */
732
1014
  async sendTo(channelId, options) {
733
1015
  return sendMessageTo(this, channelId, options);
734
1016
  }
@@ -742,6 +1024,16 @@ var Message = class _Message extends Base {
742
1024
  async reply(options, replyOptions) {
743
1025
  return replyToMessage(this, options, replyOptions);
744
1026
  }
1027
+ /**
1028
+ * Hydrate a partial message, or return the message as-is.
1029
+ * @example
1030
+ * client.on(Events.MessageUpdate, async (_old, msg) => {
1031
+ * const message = await Message.resolve(msg);
1032
+ * });
1033
+ */
1034
+ static async resolve(message) {
1035
+ return message.partial ? message.fetch() : message;
1036
+ }
745
1037
  /** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
746
1038
  static async _createMessageBody(content, referenced_message, ping) {
747
1039
  return createMessageBody(content, referenced_message, ping);
@@ -754,7 +1046,7 @@ var Message = class _Message extends Base {
754
1046
  async edit(options) {
755
1047
  const body = {};
756
1048
  if (options.content !== void 0) body.content = options.content;
757
- if (options.embeds?.length) {
1049
+ if (options.embeds !== void 0) {
758
1050
  body.embeds = options.embeds.map(
759
1051
  (e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
760
1052
  );
@@ -762,7 +1054,8 @@ var Message = class _Message extends Base {
762
1054
  if (options.allowedMentions) {
763
1055
  body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
764
1056
  }
765
- if (options.flags !== void 0) body.flags = options.flags;
1057
+ const flags = resolveMessageFlags(options.flags);
1058
+ if (flags !== void 0) body.flags = flags;
766
1059
  if (options.attachments !== void 0) {
767
1060
  body.attachments = toMessageAttachmentEditWire(options.attachments);
768
1061
  }
@@ -777,6 +1070,13 @@ var Message = class _Message extends Base {
777
1070
  createReactionCollector(options) {
778
1071
  return new ReactionCollector(this.client, this.id, this.channelId, options);
779
1072
  }
1073
+ /**
1074
+ * Wait for reactions matching the filter, then resolve the collected set.
1075
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
1076
+ */
1077
+ awaitReactions(options) {
1078
+ return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
1079
+ }
780
1080
  /** Fetch the latest version of this message from the API. */
781
1081
  async fetch() {
782
1082
  return this.client.channels.fetchMessage(this.channelId, this.id);
@@ -829,6 +1129,58 @@ var Message = class _Message extends Base {
829
1129
  return fetchMessageReactionUsersPage(this, emoji, options);
830
1130
  }
831
1131
  };
1132
+
1133
+ // src/Domain/Message/PartialMessage.ts
1134
+ import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
1135
+ var PartialMessage = class {
1136
+ partial = true;
1137
+ client;
1138
+ id;
1139
+ channelId;
1140
+ guildId;
1141
+ content;
1142
+ authorId;
1143
+ author;
1144
+ createdAt;
1145
+ constructor(client, data) {
1146
+ this.client = client;
1147
+ this.id = data.id;
1148
+ this.channelId = data.channelId;
1149
+ this.guildId = data.guildId ?? null;
1150
+ this.content = data.content ?? null;
1151
+ this.authorId = data.authorId ?? null;
1152
+ this.author = data.author ?? null;
1153
+ this.createdAt = data.createdAt ?? (SnowflakeUtil2.isValid(data.id) ? SnowflakeUtil2.dateFromSnowflake(data.id) : null);
1154
+ }
1155
+ /**
1156
+ * Live text-capable channel from cache, or null if uncached / not text-based.
1157
+ * Same contract as {@link Message.channel}.
1158
+ */
1159
+ get channel() {
1160
+ const channel = this.client.channels.get(this.channelId) ?? null;
1161
+ return channel?.isTextBased() ? channel : null;
1162
+ }
1163
+ /**
1164
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1165
+ * has {@link Channel.delete} and {@link Channel.send}.
1166
+ * @example
1167
+ * const channel = await message.resolveChannel();
1168
+ * await channel.delete();
1169
+ */
1170
+ async resolveChannel() {
1171
+ return this.client.channels.resolve(this.channelId);
1172
+ }
1173
+ /**
1174
+ * Fetch the full message from the API.
1175
+ * @example
1176
+ * const message = await partial.fetch();
1177
+ * await message.reply('Pong!');
1178
+ */
1179
+ async fetch() {
1180
+ return this.client.channels.fetchMessage(this.channelId, this.id);
1181
+ }
1182
+ };
832
1183
  export {
833
- Message
1184
+ Message,
1185
+ PartialMessage
834
1186
  };