@fluxerjs/core 2.1.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,12 +1,13 @@
1
- // src/structures/message/Message.ts
2
- import { Collection as Collection2 } from "@fluxerjs/collection";
1
+ // src/Domain/Message/Message.ts
3
2
  import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
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
- // src/client/sdkOptions.ts
10
+ // src/ClientCore/SdkOptions/Attachments.ts
10
11
  function toMessageAttachmentEditWire(attachments) {
11
12
  return attachments.map((a) => {
12
13
  const out = { id: a.id };
@@ -21,13 +22,17 @@ function toMessageAttachmentEditWire(attachments) {
21
22
  });
22
23
  }
23
24
 
24
- // src/errors/ErrorCodes.ts
25
+ // src/Helpers/MessageUtils/Body.ts
26
+ import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
27
+ import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
28
+
29
+ // src/LibErrors/ErrorCodes.ts
25
30
  import { ErrorCodes } from "@fluxerjs/util";
26
31
 
27
- // src/errors/FluxerError.ts
32
+ // src/LibErrors/FluxerError.ts
28
33
  import { FluxerError } from "@fluxerjs/util";
29
34
 
30
- // src/util/messageUtils/files.ts
35
+ // src/Helpers/MessageUtils/Files.ts
31
36
  var FILE_FETCH_TIMEOUT_MS = 3e4;
32
37
  async function fetchFileBuffer(url, index) {
33
38
  if (!URL.canParse(url)) {
@@ -70,9 +75,7 @@ async function resolveMessageFiles(files) {
70
75
  return result;
71
76
  }
72
77
 
73
- // src/util/messageUtils/body.ts
74
- import { MessageReferenceType } from "@fluxerjs/types";
75
- import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
78
+ // src/Helpers/MessageUtils/Body.ts
76
79
  function toAPIAllowedMentions(options) {
77
80
  const result = {};
78
81
  if (options.parse !== void 0) result.parse = options.parse;
@@ -90,6 +93,37 @@ function applyReplyPingSuppression(body) {
90
93
  function assignIfDefined(target, key, value) {
91
94
  if (value !== void 0) target[key] = value;
92
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
+ }
93
127
  function buildSendBody(options) {
94
128
  const body = typeof options === "string" ? { content: options } : options;
95
129
  const result = {};
@@ -97,16 +131,17 @@ function buildSendBody(options) {
97
131
  if (body.embeds?.length) {
98
132
  result.embeds = body.embeds.map((e) => e instanceof EmbedBuilder ? e.toJSON() : e);
99
133
  }
134
+ const normalizedFiles = normalizeSendFiles(body.files);
100
135
  if (body.uploadedAttachments?.length) {
101
136
  result.attachments = body.uploadedAttachments;
102
- } else if (body.files?.length) {
137
+ } else if (normalizedFiles?.files.length) {
103
138
  result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
104
139
  id: a.id,
105
140
  filename: a.filename,
106
141
  ...a.title != null && { title: a.title },
107
142
  ...a.description != null && { description: a.description },
108
143
  ...a.flags != null && { flags: a.flags }
109
- })) : 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 }));
110
145
  }
111
146
  if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
112
147
  if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
@@ -200,32 +235,66 @@ async function prepareMessagePostPayload(options, defaults) {
200
235
  } else if (allowedMentions?.repliedUser === false) {
201
236
  applyReplyPingSuppression(body);
202
237
  }
238
+ const resolvedFiles = normalizeSendFiles(files);
203
239
  return {
204
240
  body,
205
- files: !uploadedAttachments?.length && files?.length ? await resolveMessageFiles(files) : void 0
241
+ files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
206
242
  };
207
243
  }
208
244
 
209
- // src/util/ReactionCollector.ts
245
+ // src/Helpers/ReactionCollector.ts
210
246
  import { EventEmitter } from "events";
211
247
  import { Collection } from "@fluxerjs/collection";
212
248
 
213
- // src/structures/MessageReaction.ts
249
+ // src/Domain/Message/MessageReaction.ts
214
250
  import { Routes } from "@fluxerjs/types";
251
+
252
+ // src/Helpers/HttpErrors.ts
215
253
  import { FluxerAPIError, RateLimitError } from "@fluxerjs/rest";
254
+ function httpStatus(err) {
255
+ if (err instanceof FluxerAPIError) return err.statusCode;
256
+ if (typeof err === "object" && err !== null && "statusCode" in err) {
257
+ const code = err.statusCode;
258
+ return typeof code === "number" ? code : void 0;
259
+ }
260
+ return void 0;
261
+ }
262
+ function errorMessage(err, fallback) {
263
+ if (err instanceof Error && err.message) return err.message;
264
+ if (typeof err === "string" && err.length > 0) return err;
265
+ return fallback;
266
+ }
267
+ function rethrowMapped(err, options) {
268
+ if (err instanceof RateLimitError) throw err;
269
+ if (err instanceof FluxerError) throw err;
270
+ if (options.notFound && httpStatus(err) === 404) {
271
+ throw new FluxerError(options.notFound.message, {
272
+ code: options.notFound.code,
273
+ cause: err
274
+ });
275
+ }
276
+ throw new FluxerError(errorMessage(err, options.fallback), {
277
+ code: options.code,
278
+ cause: err
279
+ });
280
+ }
216
281
 
217
- // src/structures/Base.ts
282
+ // src/Domain/Base.ts
218
283
  var Base = class {
219
284
  };
220
285
 
221
- // src/structures/MessageReaction.ts
222
- var MessageReaction = class extends Base {
286
+ // src/Domain/Message/MessageReaction.ts
287
+ var MessageReaction = class _MessageReaction extends Base {
223
288
  client;
224
289
  messageId;
225
290
  channelId;
226
291
  guildId;
227
292
  emoji;
228
- /** 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). */
229
298
  _data;
230
299
  constructor(client, data) {
231
300
  super();
@@ -239,40 +308,70 @@ var MessageReaction = class extends Base {
239
308
  ...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
240
309
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
241
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;
242
331
  }
243
- /** Emoji as a string: unicode or "name:id" for custom. */
332
+ /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
244
333
  get emojiIdentifier() {
245
- return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
334
+ return this.emoji.id ? this.emoji.animated ? `a:${this.emoji.name}:${this.emoji.id}` : `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
246
335
  }
247
336
  /** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
248
337
  get guild() {
249
338
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
250
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
+ }
251
350
  /**
252
- * Fetch the message this reaction belongs to.
253
- * 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).
254
352
  * @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
255
353
  */
256
354
  async fetchMessage() {
355
+ const cached = this.message;
356
+ if (cached) return cached;
257
357
  try {
258
358
  const data = await this.client.rest.get(
259
359
  Routes.channelMessage(this.channelId, this.messageId)
260
360
  );
261
361
  return new Message(this.client, data);
262
362
  } catch (err) {
263
- if (err instanceof RateLimitError) throw err;
264
- if (err instanceof FluxerAPIError && err.statusCode === 404) {
265
- throw new FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
363
+ rethrowMapped(err, {
364
+ notFound: {
266
365
  code: ErrorCodes.MessageNotFound,
267
- cause: err
268
- });
269
- }
270
- throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
366
+ message: `Message ${this.messageId} not found in channel ${this.channelId}`
367
+ },
368
+ fallback: `Failed to fetch message ${this.messageId}`
369
+ });
271
370
  }
272
371
  }
273
372
  };
274
373
 
275
- // src/util/Events.ts
374
+ // src/Helpers/Events.ts
276
375
  var Events = {
277
376
  Ready: "ready",
278
377
  MessageCreate: "messageCreate",
@@ -307,6 +406,8 @@ var Events = {
307
406
  ChannelUpdate: "channelUpdate",
308
407
  ChannelDelete: "channelDelete",
309
408
  ChannelPinsUpdate: "channelPinsUpdate",
409
+ ChannelRecipientAdd: "channelRecipientAdd",
410
+ ChannelRecipientRemove: "channelRecipientRemove",
310
411
  InviteCreate: "inviteCreate",
311
412
  InviteDelete: "inviteDelete",
312
413
  TypingStart: "typingStart",
@@ -323,11 +424,17 @@ var Events = {
323
424
  WebhooksUpdate: "webhooksUpdate",
324
425
  Resumed: "resumed",
325
426
  Error: "error",
326
- Debug: "debug"
427
+ Debug: "debug",
428
+ ShardReady: "shardReady",
429
+ ShardResumed: "shardResumed",
430
+ ShardDisconnect: "shardDisconnect",
431
+ ShardReconnecting: "shardReconnecting",
432
+ ShardError: "shardError",
433
+ ShardingRequired: "shardingRequired"
327
434
  };
328
435
 
329
- // src/util/ReactionCollector.ts
330
- var ReactionCollector = class extends EventEmitter {
436
+ // src/Helpers/ReactionCollector.ts
437
+ var ReactionCollector = class _ReactionCollector extends EventEmitter {
331
438
  client;
332
439
  messageId;
333
440
  channelId;
@@ -370,11 +477,17 @@ var ReactionCollector = class extends EventEmitter {
370
477
  ...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
371
478
  }
372
479
  });
373
- 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
+ {
374
483
  id: entry.userId,
375
484
  username: "Unknown",
376
- discriminator: "0"
377
- });
485
+ discriminator: "0",
486
+ globalName: null,
487
+ avatar: null,
488
+ bot: false,
489
+ system: false
490
+ };
378
491
  this._collect(reaction, user, entry.userId);
379
492
  }
380
493
  };
@@ -388,6 +501,7 @@ var ReactionCollector = class extends EventEmitter {
388
501
  if (this._ended) return;
389
502
  if (!this.options.filter(reaction, user)) return;
390
503
  const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
504
+ if (this.collected.has(key)) return;
391
505
  this.collected.set(key, { reaction, user });
392
506
  this.emit("collect", reaction, user);
393
507
  if (this.options.max > 0 && this.collected.size >= this.options.max) {
@@ -405,6 +519,21 @@ var ReactionCollector = class extends EventEmitter {
405
519
  }
406
520
  this.emit("end", this.collected, reason);
407
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
+ }
408
537
  on(event, listener) {
409
538
  return super.on(event, listener);
410
539
  }
@@ -413,14 +542,175 @@ var ReactionCollector = class extends EventEmitter {
413
542
  }
414
543
  };
415
544
 
416
- // src/structures/message/reactions.ts
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
+ };
567
+ }
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;
633
+ }
634
+ _cache = new Collection2();
635
+ /** Reactions keyed by unicode name or `name:id`. */
636
+ get cache() {
637
+ return this._cache;
638
+ }
639
+ get size() {
640
+ return this._cache.size;
641
+ }
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);
651
+ }
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
417
705
  import { Routes as Routes2 } from "@fluxerjs/types";
418
706
  async function emojiPath(message, emoji) {
419
707
  return message.client.resolveEmoji(emoji, message.guildId);
420
708
  }
421
709
  async function reactToMessage(message, emoji) {
422
- const e = await emojiPath(message, emoji);
423
- await message.client.rest.put(Routes2.channelMessageReactionMe(message.channelId, message.id, e));
710
+ const wire = await emojiPath(message, emoji);
711
+ await message.client.rest.put(
712
+ Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
713
+ );
424
714
  }
425
715
  async function removeMessageReaction(message, emoji, userId) {
426
716
  const e = await emojiPath(message, emoji);
@@ -460,7 +750,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
460
750
  };
461
751
  }
462
752
 
463
- // src/structures/message/send.ts
753
+ // src/Domain/Message/Send.ts
464
754
  import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
465
755
  import { Routes as Routes3 } from "@fluxerjs/types";
466
756
  function toReplyTarget(ref) {
@@ -525,8 +815,34 @@ async function replyToMessage(message, options, replyOptions) {
525
815
  );
526
816
  }
527
817
 
528
- // src/structures/message/Message.ts
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
+ }
529
843
  var Message = class _Message extends Base {
844
+ /** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
845
+ partial = false;
530
846
  /** The {@link Client} that instantiated this message. */
531
847
  client;
532
848
  /** Snowflake ID of this message. */
@@ -555,7 +871,7 @@ var Message = class _Message extends Base {
555
871
  mentionEveryone;
556
872
  /** Whether this is a text-to-speech message. */
557
873
  tts;
558
- /** Embedded content (rich previews, etc.). */
874
+ /** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
559
875
  embeds;
560
876
  /** Stickers sent with the message. */
561
877
  stickers;
@@ -577,26 +893,41 @@ var Message = class _Message extends Base {
577
893
  mentionRoles;
578
894
  /** Client-side nonce for deduplication. */
579
895
  nonce;
580
- /** 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
+ */
581
900
  get channel() {
582
- return this.client.channels.get(this.channelId) ?? null;
901
+ const channel = this.client.channels.get(this.channelId) ?? null;
902
+ return channel?.isTextBased() ? channel : null;
583
903
  }
584
904
  /** Cached guild, or null for DMs / uncached. */
585
905
  get guild() {
586
906
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
587
907
  }
588
- /** 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
+ */
589
919
  async resolveChannel() {
590
920
  return this.client.channels.resolve(this.channelId);
591
921
  }
592
- /** 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
+ */
593
928
  async resolveGuild() {
594
929
  if (!this.guildId) return null;
595
- try {
596
- return await this.client.guilds.resolve(this.guildId);
597
- } catch {
598
- return null;
599
- }
930
+ return this.client.guilds.resolve(this.guildId);
600
931
  }
601
932
  /**
602
933
  * Construct a message from API data.
@@ -613,29 +944,73 @@ var Message = class _Message extends Base {
613
944
  this.createdAt = new Date(data.timestamp);
614
945
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
615
946
  this.pinned = data.pinned;
616
- this.attachments = new Collection2();
617
- 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));
618
949
  this.type = data.type ?? MessageType.Default;
619
- this.flags = data.flags ?? 0;
950
+ this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
620
951
  this.mentionEveryone = data.mention_everyone ?? false;
621
952
  this.tts = data.tts ?? false;
622
- this.embeds = data.embeds ?? [];
623
- this.stickers = data.stickers ?? [];
624
- this.reactions = data.reactions ?? [];
625
- this.messageReference = data.message_reference ?? null;
626
- this.messageSnapshots = data.message_snapshots ?? [];
627
- 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;
628
965
  this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
629
966
  this.webhookId = data.webhook_id ?? null;
630
967
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
631
968
  this.mentionRoles = data.mention_roles ?? [];
632
969
  this.nonce = data.nonce ?? null;
633
970
  }
634
- /** 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
+ */
635
1007
  async send(options) {
636
1008
  return sendMessage(this, options);
637
1009
  }
638
- /** 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
+ */
639
1014
  async sendTo(channelId, options) {
640
1015
  return sendMessageTo(this, channelId, options);
641
1016
  }
@@ -649,6 +1024,16 @@ var Message = class _Message extends Base {
649
1024
  async reply(options, replyOptions) {
650
1025
  return replyToMessage(this, options, replyOptions);
651
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
+ }
652
1037
  /** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
653
1038
  static async _createMessageBody(content, referenced_message, ping) {
654
1039
  return createMessageBody(content, referenced_message, ping);
@@ -661,7 +1046,7 @@ var Message = class _Message extends Base {
661
1046
  async edit(options) {
662
1047
  const body = {};
663
1048
  if (options.content !== void 0) body.content = options.content;
664
- if (options.embeds?.length) {
1049
+ if (options.embeds !== void 0) {
665
1050
  body.embeds = options.embeds.map(
666
1051
  (e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
667
1052
  );
@@ -669,7 +1054,8 @@ var Message = class _Message extends Base {
669
1054
  if (options.allowedMentions) {
670
1055
  body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
671
1056
  }
672
- if (options.flags !== void 0) body.flags = options.flags;
1057
+ const flags = resolveMessageFlags(options.flags);
1058
+ if (flags !== void 0) body.flags = flags;
673
1059
  if (options.attachments !== void 0) {
674
1060
  body.attachments = toMessageAttachmentEditWire(options.attachments);
675
1061
  }
@@ -684,6 +1070,13 @@ var Message = class _Message extends Base {
684
1070
  createReactionCollector(options) {
685
1071
  return new ReactionCollector(this.client, this.id, this.channelId, options);
686
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
+ }
687
1080
  /** Fetch the latest version of this message from the API. */
688
1081
  async fetch() {
689
1082
  return this.client.channels.fetchMessage(this.channelId, this.id);
@@ -736,6 +1129,58 @@ var Message = class _Message extends Base {
736
1129
  return fetchMessageReactionUsersPage(this, emoji, options);
737
1130
  }
738
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
+ };
739
1183
  export {
740
- Message
1184
+ Message,
1185
+ PartialMessage
741
1186
  };