@fluxerjs/core 3.3.0 → 3.5.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.
@@ -1,4 +1,4 @@
1
- export { a8 as Message, a9 as MessageAttachment, af as MessageEditOptions, ag as MessageEmbed, ah as MessageEmbedAuthor, ai as MessageEmbedField, aj as MessageEmbedFooter, ak as MessageEmbedMedia, at as MessageReference, ax as PartialMessage, aK as ReplyOptions } from './SubpathMessage-CNJlnR6y.mjs';
1
+ export { a8 as Message, a9 as MessageAttachment, af as MessageEditOptions, ag as MessageEmbed, ah as MessageEmbedAuthor, ai as MessageEmbedField, aj as MessageEmbedFooter, ak as MessageEmbedMedia, at as MessageReference, ax as PartialMessage, aK as ReplyOptions } from './SubpathMessage-3ykAJr_F.mjs';
2
2
  export { $ as MessageSendOptions } from './Sudo-mzPLv6YU.mjs';
3
3
  import '@fluxerjs/types';
4
4
  import '@fluxerjs/collection';
package/dist/message.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a8 as Message, a9 as MessageAttachment, af as MessageEditOptions, ag as MessageEmbed, ah as MessageEmbedAuthor, ai as MessageEmbedField, aj as MessageEmbedFooter, ak as MessageEmbedMedia, at as MessageReference, ax as PartialMessage, aK as ReplyOptions } from './SubpathMessage-DjLo6il5.js';
1
+ export { a8 as Message, a9 as MessageAttachment, af as MessageEditOptions, ag as MessageEmbed, ah as MessageEmbedAuthor, ai as MessageEmbedField, aj as MessageEmbedFooter, ak as MessageEmbedMedia, at as MessageReference, ax as PartialMessage, aK as ReplyOptions } from './SubpathMessage-nY2WQ8V1.js';
2
2
  export { $ as MessageSendOptions } from './Sudo-mzPLv6YU.js';
3
3
  import '@fluxerjs/types';
4
4
  import '@fluxerjs/collection';
package/dist/message.js CHANGED
@@ -496,6 +496,7 @@ var Events = {
496
496
  GuildEmojisUpdate: "guildEmojisUpdate",
497
497
  GuildStickersUpdate: "guildStickersUpdate",
498
498
  GuildCountsUpdate: "guildCountsUpdate",
499
+ GuildHealthUpdate: "guildHealthUpdate",
499
500
  ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
500
501
  GuildMemberAdd: "guildMemberAdd",
501
502
  GuildMemberUpdate: "guildMemberUpdate",
@@ -530,7 +531,16 @@ var Events = {
530
531
  VoiceStateAck: "voiceStateAck",
531
532
  VoiceServerUpdate: "voiceServerUpdate",
532
533
  EntranceSoundPlay: "entranceSoundPlay",
534
+ VoiceSignal: "voiceSignal",
535
+ OperatorPassUpdate: "operatorPassUpdate",
533
536
  VoiceStatesSync: "voiceStatesSync",
537
+ VoiceJoinQueued: "voiceJoinQueued",
538
+ StageInstanceCreate: "stageInstanceCreate",
539
+ StageInstanceUpdate: "stageInstanceUpdate",
540
+ StageInstanceDelete: "stageInstanceDelete",
541
+ StageCountsUpdate: "stageCountsUpdate",
542
+ StageVoiceStatesSync: "stageVoiceStatesSync",
543
+ StageAudienceListUpdate: "stageAudienceListUpdate",
534
544
  WebhooksUpdate: "webhooksUpdate",
535
545
  Resumed: "resumed",
536
546
  Error: "error",
@@ -659,6 +669,45 @@ var import_util3 = require("@fluxerjs/util");
659
669
  // src/ClientCore/MessageManager.ts
660
670
  var import_collection2 = require("@fluxerjs/collection");
661
671
  var import_types4 = require("@fluxerjs/types");
672
+
673
+ // src/ClientCore/Resolve.ts
674
+ function normalizeSnowflakeId(value, label) {
675
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
676
+ throw new TypeError(
677
+ `${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
678
+ );
679
+ }
680
+ const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
681
+ if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
682
+ throw new TypeError(`${label} requires a non-empty ID`);
683
+ }
684
+ return id;
685
+ }
686
+ function assertApiObjectWithId(data, label) {
687
+ if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
688
+ throw new TypeError(`${label} received an invalid API payload (missing string id)`);
689
+ }
690
+ return data;
691
+ }
692
+ function assertApiArray(data, label) {
693
+ if (!Array.isArray(data)) {
694
+ throw new TypeError(`${label} received an invalid API payload (expected an array)`);
695
+ }
696
+ return data;
697
+ }
698
+ async function dedupeFetch(pending, key, fn) {
699
+ const existing = pending.get(key);
700
+ if (existing) return existing;
701
+ const request = fn();
702
+ pending.set(key, request);
703
+ try {
704
+ return await request;
705
+ } finally {
706
+ if (pending.get(key) === request) pending.delete(key);
707
+ }
708
+ }
709
+
710
+ // src/ClientCore/MessageManager.ts
662
711
  var MessageManager = class {
663
712
  constructor(client, channelId) {
664
713
  this.client = client;
@@ -666,25 +715,32 @@ var MessageManager = class {
666
715
  }
667
716
  /** Structure cache keyed by message id (identity for {@link get}). */
668
717
  _structures = new import_collection2.Collection();
718
+ pendingFetches = /* @__PURE__ */ new Map();
669
719
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
670
720
  get(messageId) {
671
- const data = this.client._getMessageCache(this.channelId)?.get(messageId);
721
+ const id = String(messageId ?? "").trim();
722
+ if (!id) return void 0;
723
+ const data = this.client._getMessageCache(this.channelId)?.get(id);
672
724
  if (!data) {
673
- this._structures.delete(messageId);
725
+ this._structures.delete(id);
674
726
  return void 0;
675
727
  }
676
- const existing = this._structures.get(messageId);
677
- if (existing) return existing;
728
+ const existing = this._structures.get(id);
729
+ if (existing) {
730
+ existing._patch(data);
731
+ return existing;
732
+ }
678
733
  const message = new Message(this.client, data);
679
- this._structures.set(messageId, message);
734
+ this._structures.set(id, message);
680
735
  return message;
681
736
  }
682
737
  /** Retrieve from cache, otherwise {@link fetch}. */
683
738
  async resolve(messageId) {
684
- return this.get(messageId) ?? this.fetch(messageId);
739
+ const id = normalizeSnowflakeId(messageId, "messages.resolve()");
740
+ return this.get(id) ?? this.fetch(id);
685
741
  }
686
742
  async fetch(idOrOptions) {
687
- return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
743
+ return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
688
744
  }
689
745
  /** Cache API data and return a {@link Message} (reusing identity when present). */
690
746
  wrap(data) {
@@ -701,9 +757,13 @@ var MessageManager = class {
701
757
  }
702
758
  /** Fetch a single message from the API. */
703
759
  async fetchOne(messageId) {
760
+ return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
761
+ }
762
+ async fetchOneFresh(messageId) {
704
763
  try {
705
- const data = await this.client.rest.get(
706
- import_types4.Routes.channelMessage(this.channelId, messageId)
764
+ const data = assertApiObjectWithId(
765
+ await this.client.rest.get(import_types4.Routes.channelMessage(this.channelId, messageId)),
766
+ "messages.fetch()"
707
767
  );
708
768
  return this.wrap(data);
709
769
  } catch (err) {
@@ -729,9 +789,15 @@ var MessageManager = class {
729
789
  if (value != null && value !== "") qs.set(key, String(value));
730
790
  }
731
791
  const base = import_types4.Routes.channelMessages(this.channelId);
732
- const data = await this.client.rest.get(qs.size > 0 ? `${base}?${qs}` : base);
792
+ const data = assertApiArray(
793
+ await this.client.rest.get(qs.size > 0 ? `${base}?${qs}` : base),
794
+ "messages.fetch()"
795
+ );
733
796
  const collection = new import_collection2.Collection();
734
- for (const msg of data) collection.set(msg.id, this.wrap(msg));
797
+ for (const msg of data) {
798
+ if (!msg?.id) continue;
799
+ collection.set(msg.id, this.wrap(msg));
800
+ }
735
801
  return collection;
736
802
  }
737
803
  };
@@ -935,6 +1001,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
935
1001
  }
936
1002
 
937
1003
  // src/Domain/Channel/Base.ts
1004
+ function isFullChannelData(data) {
1005
+ return "guild_id" in data || "permission_overwrites" in data || "position" in data || "last_message_id" in data || "topic" in data || "thread_metadata" in data || "available_tags" in data;
1006
+ }
938
1007
  var Channel = class extends Base {
939
1008
  #messages;
940
1009
  /** The {@link Client} that instantiated this channel. */
@@ -949,6 +1018,11 @@ var Channel = class extends Base {
949
1018
  icon;
950
1019
  /** ISO8601 timestamp of the last pinned message update. */
951
1020
  lastPinTimestamp;
1021
+ /**
1022
+ * True when built from a partial payload (e.g. a DM stub) and not yet hydrated
1023
+ * with a full channel object. `channels.resolve()` refetches partial channels.
1024
+ */
1025
+ partial;
952
1026
  constructor(client, data) {
953
1027
  super();
954
1028
  this.client = client;
@@ -957,6 +1031,7 @@ var Channel = class extends Base {
957
1031
  this.name = data.name ?? null;
958
1032
  this.icon = data.icon ?? null;
959
1033
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1034
+ this.partial = !isFullChannelData(data);
960
1035
  }
961
1036
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
962
1037
  get createdTimestamp() {
@@ -977,6 +1052,7 @@ var Channel = class extends Base {
977
1052
  if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
978
1053
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
979
1054
  }
1055
+ if (isFullChannelData(data)) this.partial = false;
980
1056
  }
981
1057
  /** @internal Factory wired after subclasses load. */
982
1058
  static from(_c, _d) {
@@ -996,11 +1072,11 @@ var Channel = class extends Base {
996
1072
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
997
1073
  */
998
1074
  isTextBased() {
999
- return this.type === import_types6.ChannelType.GuildText || this.type === import_types6.ChannelType.GuildAnnouncement || this.type === import_types6.ChannelType.GuildVoice || this.type === import_types6.ChannelType.DM || this.type === import_types6.ChannelType.GroupDM || this.type === import_types6.ChannelType.DMPersonalNotes || this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread;
1075
+ return this.type === import_types6.ChannelType.GuildText || this.type === import_types6.ChannelType.GuildAnnouncement || this.type === import_types6.ChannelType.GuildVoice || this.type === import_types6.ChannelType.GuildStageVoice || this.type === import_types6.ChannelType.DM || this.type === import_types6.ChannelType.GroupDM || this.type === import_types6.ChannelType.DMPersonalNotes || this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread;
1000
1076
  }
1001
1077
  /** Check if this is a guild channel, including threads, forums, and media channels. */
1002
1078
  isGuild() {
1003
- return this.type === import_types6.ChannelType.GuildText || this.type === import_types6.ChannelType.GuildAnnouncement || this.type === import_types6.ChannelType.GuildVoice || this.type === import_types6.ChannelType.GuildCategory || this.type === import_types6.ChannelType.GuildLink || this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread || this.type === import_types6.ChannelType.GuildForum || this.type === import_types6.ChannelType.GuildMedia;
1079
+ return this.type === import_types6.ChannelType.GuildText || this.type === import_types6.ChannelType.GuildAnnouncement || this.type === import_types6.ChannelType.GuildVoice || this.type === import_types6.ChannelType.GuildStageVoice || this.type === import_types6.ChannelType.GuildCategory || this.type === import_types6.ChannelType.GuildLink || this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread || this.type === import_types6.ChannelType.GuildForum || this.type === import_types6.ChannelType.GuildMedia;
1004
1080
  }
1005
1081
  /** Check if this is a thread (public, private, or announcement). */
1006
1082
  isThread() {
@@ -1034,10 +1110,18 @@ var Channel = class extends Base {
1034
1110
  isPersonalNotes() {
1035
1111
  return this.type === import_types6.ChannelType.DMPersonalNotes;
1036
1112
  }
1037
- /** Check if this is a voice channel. */
1113
+ /** Check if this is a voice channel (type 2 only; see {@link isVoiceBased} to include stages). */
1038
1114
  isVoice() {
1039
1115
  return this.type === import_types6.ChannelType.GuildVoice;
1040
1116
  }
1117
+ /** Check if this is a stage channel (type 13). */
1118
+ isStage() {
1119
+ return this.type === import_types6.ChannelType.GuildStageVoice;
1120
+ }
1121
+ /** Check if this is a voice or stage channel, i.e. one `@fluxerjs/voice` can join. */
1122
+ isVoiceBased() {
1123
+ return this.type === import_types6.ChannelType.GuildVoice || this.type === import_types6.ChannelType.GuildStageVoice;
1124
+ }
1041
1125
  /** Check if this is a link channel. */
1042
1126
  isLink() {
1043
1127
  return this.type === import_types6.ChannelType.GuildLink;
@@ -1704,10 +1788,10 @@ var Message = class _Message extends Base {
1704
1788
  this.channelId = data.channel_id;
1705
1789
  this.guildId = data.guild_id ?? null;
1706
1790
  this.author = client.getOrCreateUser(data.author);
1707
- this.content = data.content;
1708
- this.createdAt = new Date(data.timestamp);
1791
+ this.content = data.content ?? "";
1792
+ this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
1709
1793
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1710
- this.pinned = data.pinned;
1794
+ this.pinned = data.pinned ?? false;
1711
1795
  this.attachments = new import_collection5.Collection();
1712
1796
  for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1713
1797
  this.type = data.type ?? import_types9.MessageType.Default;
@@ -1739,33 +1823,47 @@ var Message = class _Message extends Base {
1739
1823
  * @internal
1740
1824
  */
1741
1825
  _patch(data) {
1742
- this.content = data.content;
1743
- this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1744
- this.pinned = data.pinned;
1745
- this.attachments.clear();
1746
- for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1747
- this.flags = new import_util5.MessageFlagsBitField(BigInt(data.flags ?? 0));
1748
- this.mentionEveryone = data.mention_everyone ?? false;
1749
- this.tts = data.tts ?? false;
1750
- this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1751
- this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1752
- this.reactions._patch(data.reactions);
1753
- this.messageReference = data.message_reference ? {
1754
- channelId: data.message_reference.channel_id,
1755
- messageId: data.message_reference.message_id,
1756
- guildId: data.message_reference.guild_id ?? null,
1757
- ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1758
- } : null;
1759
- this.messageSnapshots = (data.message_snapshots ?? []).map(
1760
- (s) => toMessageSnapshot(this.client, s)
1761
- );
1762
- this.call = data.call ? toMessageCall(data.call) : null;
1763
- this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
1764
- this.webhookId = data.webhook_id ?? null;
1765
- this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1766
- this.mentionRoles = data.mention_roles ?? [];
1767
- this.nonce = data.nonce ?? null;
1768
- this.nsfwEmojis = data.nsfw_emojis ?? [];
1826
+ if (data.content !== void 0) this.content = data.content ?? "";
1827
+ if (data.edited_timestamp !== void 0) {
1828
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1829
+ }
1830
+ if (data.pinned !== void 0) this.pinned = data.pinned;
1831
+ if (data.attachments !== void 0) {
1832
+ this.attachments.clear();
1833
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1834
+ }
1835
+ if (data.flags !== void 0) this.flags = new import_util5.MessageFlagsBitField(BigInt(data.flags ?? 0));
1836
+ if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
1837
+ if (data.tts !== void 0) this.tts = data.tts;
1838
+ if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1839
+ if (data.stickers !== void 0) {
1840
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1841
+ }
1842
+ if (data.reactions !== void 0) this.reactions._patch(data.reactions);
1843
+ if (data.message_reference !== void 0) {
1844
+ this.messageReference = data.message_reference ? {
1845
+ channelId: data.message_reference.channel_id,
1846
+ messageId: data.message_reference.message_id,
1847
+ guildId: data.message_reference.guild_id ?? null,
1848
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1849
+ } : null;
1850
+ }
1851
+ if (data.message_snapshots !== void 0) {
1852
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
1853
+ (s) => toMessageSnapshot(this.client, s)
1854
+ );
1855
+ }
1856
+ if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
1857
+ if (data.referenced_message !== void 0) {
1858
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
1859
+ }
1860
+ if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
1861
+ if (data.mentions !== void 0) {
1862
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1863
+ }
1864
+ if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
1865
+ if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
1866
+ if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
1769
1867
  if (data.thread) this.thread = cacheThread(this.client, data.thread);
1770
1868
  }
1771
1869
  /**
@@ -1866,6 +1964,23 @@ var Message = class _Message extends Base {
1866
1964
  async fetch() {
1867
1965
  return this.client.channels.fetchMessage(this.channelId, this.id);
1868
1966
  }
1967
+ /** Publish this announcement message to channels following its channel. */
1968
+ async crosspost() {
1969
+ const data = await this.client.rest.post(
1970
+ import_types9.Routes.channelMessageCrosspost(this.channelId, this.id),
1971
+ { auth: true }
1972
+ );
1973
+ const published = new _Message(this.client, data);
1974
+ this.client._addMessageToCache(this.channelId, data);
1975
+ return published;
1976
+ }
1977
+ /** Fetch the source guild of a crossposted (followed-channel) message. */
1978
+ async fetchCrosspostSource() {
1979
+ return this.client.rest.get(
1980
+ import_types9.Routes.channelMessageCrosspostSource(this.channelId, this.id),
1981
+ { auth: true }
1982
+ );
1983
+ }
1869
1984
  /** Delete this message. */
1870
1985
  async delete(reason) {
1871
1986
  await this.client.rest.delete(import_types9.Routes.channelMessage(this.channelId, this.id), {