@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.
- package/dist/{SubpathMessage-CNJlnR6y.d.mts → SubpathMessage-3ykAJr_F.d.mts} +250 -12
- package/dist/{SubpathMessage-DjLo6il5.d.ts → SubpathMessage-nY2WQ8V1.d.ts} +250 -12
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1039 -358
- package/dist/client.mjs +959 -278
- package/dist/cluster.d.mts +1 -1
- package/dist/cluster.d.ts +1 -1
- package/dist/cluster.js +1039 -358
- package/dist/cluster.mjs +959 -278
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1078 -395
- package/dist/index.mjs +961 -280
- package/dist/message.d.mts +1 -1
- package/dist/message.d.ts +1 -1
- package/dist/message.js +159 -44
- package/dist/message.mjs +159 -44
- package/package.json +7 -7
package/dist/message.mjs
CHANGED
|
@@ -474,6 +474,7 @@ var Events = {
|
|
|
474
474
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
475
475
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
476
476
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
477
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
477
478
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
478
479
|
GuildMemberAdd: "guildMemberAdd",
|
|
479
480
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -508,7 +509,16 @@ var Events = {
|
|
|
508
509
|
VoiceStateAck: "voiceStateAck",
|
|
509
510
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
510
511
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
512
|
+
VoiceSignal: "voiceSignal",
|
|
513
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
511
514
|
VoiceStatesSync: "voiceStatesSync",
|
|
515
|
+
VoiceJoinQueued: "voiceJoinQueued",
|
|
516
|
+
StageInstanceCreate: "stageInstanceCreate",
|
|
517
|
+
StageInstanceUpdate: "stageInstanceUpdate",
|
|
518
|
+
StageInstanceDelete: "stageInstanceDelete",
|
|
519
|
+
StageCountsUpdate: "stageCountsUpdate",
|
|
520
|
+
StageVoiceStatesSync: "stageVoiceStatesSync",
|
|
521
|
+
StageAudienceListUpdate: "stageAudienceListUpdate",
|
|
512
522
|
WebhooksUpdate: "webhooksUpdate",
|
|
513
523
|
Resumed: "resumed",
|
|
514
524
|
Error: "error",
|
|
@@ -637,6 +647,45 @@ import { SnowflakeUtil } from "@fluxerjs/util";
|
|
|
637
647
|
// src/ClientCore/MessageManager.ts
|
|
638
648
|
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
639
649
|
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
650
|
+
|
|
651
|
+
// src/ClientCore/Resolve.ts
|
|
652
|
+
function normalizeSnowflakeId(value, label) {
|
|
653
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
654
|
+
throw new TypeError(
|
|
655
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
659
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
660
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
661
|
+
}
|
|
662
|
+
return id;
|
|
663
|
+
}
|
|
664
|
+
function assertApiObjectWithId(data, label) {
|
|
665
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
666
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
667
|
+
}
|
|
668
|
+
return data;
|
|
669
|
+
}
|
|
670
|
+
function assertApiArray(data, label) {
|
|
671
|
+
if (!Array.isArray(data)) {
|
|
672
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
673
|
+
}
|
|
674
|
+
return data;
|
|
675
|
+
}
|
|
676
|
+
async function dedupeFetch(pending, key, fn) {
|
|
677
|
+
const existing = pending.get(key);
|
|
678
|
+
if (existing) return existing;
|
|
679
|
+
const request = fn();
|
|
680
|
+
pending.set(key, request);
|
|
681
|
+
try {
|
|
682
|
+
return await request;
|
|
683
|
+
} finally {
|
|
684
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// src/ClientCore/MessageManager.ts
|
|
640
689
|
var MessageManager = class {
|
|
641
690
|
constructor(client, channelId) {
|
|
642
691
|
this.client = client;
|
|
@@ -644,25 +693,32 @@ var MessageManager = class {
|
|
|
644
693
|
}
|
|
645
694
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
646
695
|
_structures = new Collection2();
|
|
696
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
647
697
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
648
698
|
get(messageId) {
|
|
649
|
-
const
|
|
699
|
+
const id = String(messageId ?? "").trim();
|
|
700
|
+
if (!id) return void 0;
|
|
701
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
650
702
|
if (!data) {
|
|
651
|
-
this._structures.delete(
|
|
703
|
+
this._structures.delete(id);
|
|
652
704
|
return void 0;
|
|
653
705
|
}
|
|
654
|
-
const existing = this._structures.get(
|
|
655
|
-
if (existing)
|
|
706
|
+
const existing = this._structures.get(id);
|
|
707
|
+
if (existing) {
|
|
708
|
+
existing._patch(data);
|
|
709
|
+
return existing;
|
|
710
|
+
}
|
|
656
711
|
const message = new Message(this.client, data);
|
|
657
|
-
this._structures.set(
|
|
712
|
+
this._structures.set(id, message);
|
|
658
713
|
return message;
|
|
659
714
|
}
|
|
660
715
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
661
716
|
async resolve(messageId) {
|
|
662
|
-
|
|
717
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
718
|
+
return this.get(id) ?? this.fetch(id);
|
|
663
719
|
}
|
|
664
720
|
async fetch(idOrOptions) {
|
|
665
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
721
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
666
722
|
}
|
|
667
723
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
668
724
|
wrap(data) {
|
|
@@ -679,9 +735,13 @@ var MessageManager = class {
|
|
|
679
735
|
}
|
|
680
736
|
/** Fetch a single message from the API. */
|
|
681
737
|
async fetchOne(messageId) {
|
|
738
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
739
|
+
}
|
|
740
|
+
async fetchOneFresh(messageId) {
|
|
682
741
|
try {
|
|
683
|
-
const data =
|
|
684
|
-
Routes2.channelMessage(this.channelId, messageId)
|
|
742
|
+
const data = assertApiObjectWithId(
|
|
743
|
+
await this.client.rest.get(Routes2.channelMessage(this.channelId, messageId)),
|
|
744
|
+
"messages.fetch()"
|
|
685
745
|
);
|
|
686
746
|
return this.wrap(data);
|
|
687
747
|
} catch (err) {
|
|
@@ -707,9 +767,15 @@ var MessageManager = class {
|
|
|
707
767
|
if (value != null && value !== "") qs.set(key, String(value));
|
|
708
768
|
}
|
|
709
769
|
const base = Routes2.channelMessages(this.channelId);
|
|
710
|
-
const data =
|
|
770
|
+
const data = assertApiArray(
|
|
771
|
+
await this.client.rest.get(qs.size > 0 ? `${base}?${qs}` : base),
|
|
772
|
+
"messages.fetch()"
|
|
773
|
+
);
|
|
711
774
|
const collection = new Collection2();
|
|
712
|
-
for (const msg of data)
|
|
775
|
+
for (const msg of data) {
|
|
776
|
+
if (!msg?.id) continue;
|
|
777
|
+
collection.set(msg.id, this.wrap(msg));
|
|
778
|
+
}
|
|
713
779
|
return collection;
|
|
714
780
|
}
|
|
715
781
|
};
|
|
@@ -913,6 +979,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
913
979
|
}
|
|
914
980
|
|
|
915
981
|
// src/Domain/Channel/Base.ts
|
|
982
|
+
function isFullChannelData(data) {
|
|
983
|
+
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;
|
|
984
|
+
}
|
|
916
985
|
var Channel = class extends Base {
|
|
917
986
|
#messages;
|
|
918
987
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -927,6 +996,11 @@ var Channel = class extends Base {
|
|
|
927
996
|
icon;
|
|
928
997
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
929
998
|
lastPinTimestamp;
|
|
999
|
+
/**
|
|
1000
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
1001
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
1002
|
+
*/
|
|
1003
|
+
partial;
|
|
930
1004
|
constructor(client, data) {
|
|
931
1005
|
super();
|
|
932
1006
|
this.client = client;
|
|
@@ -935,6 +1009,7 @@ var Channel = class extends Base {
|
|
|
935
1009
|
this.name = data.name ?? null;
|
|
936
1010
|
this.icon = data.icon ?? null;
|
|
937
1011
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1012
|
+
this.partial = !isFullChannelData(data);
|
|
938
1013
|
}
|
|
939
1014
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
940
1015
|
get createdTimestamp() {
|
|
@@ -955,6 +1030,7 @@ var Channel = class extends Base {
|
|
|
955
1030
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
956
1031
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
957
1032
|
}
|
|
1033
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
958
1034
|
}
|
|
959
1035
|
/** @internal Factory wired after subclasses load. */
|
|
960
1036
|
static from(_c, _d) {
|
|
@@ -974,11 +1050,11 @@ var Channel = class extends Base {
|
|
|
974
1050
|
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
975
1051
|
*/
|
|
976
1052
|
isTextBased() {
|
|
977
|
-
return this.type === ChannelType2.GuildText || this.type === ChannelType2.GuildAnnouncement || this.type === ChannelType2.GuildVoice || this.type === ChannelType2.DM || this.type === ChannelType2.GroupDM || this.type === ChannelType2.DMPersonalNotes || this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread;
|
|
1053
|
+
return this.type === ChannelType2.GuildText || this.type === ChannelType2.GuildAnnouncement || this.type === ChannelType2.GuildVoice || this.type === ChannelType2.GuildStageVoice || this.type === ChannelType2.DM || this.type === ChannelType2.GroupDM || this.type === ChannelType2.DMPersonalNotes || this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread;
|
|
978
1054
|
}
|
|
979
1055
|
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
980
1056
|
isGuild() {
|
|
981
|
-
return this.type === ChannelType2.GuildText || this.type === ChannelType2.GuildAnnouncement || this.type === ChannelType2.GuildVoice || this.type === ChannelType2.GuildCategory || this.type === ChannelType2.GuildLink || this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread || this.type === ChannelType2.GuildForum || this.type === ChannelType2.GuildMedia;
|
|
1057
|
+
return this.type === ChannelType2.GuildText || this.type === ChannelType2.GuildAnnouncement || this.type === ChannelType2.GuildVoice || this.type === ChannelType2.GuildStageVoice || this.type === ChannelType2.GuildCategory || this.type === ChannelType2.GuildLink || this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread || this.type === ChannelType2.GuildForum || this.type === ChannelType2.GuildMedia;
|
|
982
1058
|
}
|
|
983
1059
|
/** Check if this is a thread (public, private, or announcement). */
|
|
984
1060
|
isThread() {
|
|
@@ -1012,10 +1088,18 @@ var Channel = class extends Base {
|
|
|
1012
1088
|
isPersonalNotes() {
|
|
1013
1089
|
return this.type === ChannelType2.DMPersonalNotes;
|
|
1014
1090
|
}
|
|
1015
|
-
/** Check if this is a voice channel. */
|
|
1091
|
+
/** Check if this is a voice channel (type 2 only; see {@link isVoiceBased} to include stages). */
|
|
1016
1092
|
isVoice() {
|
|
1017
1093
|
return this.type === ChannelType2.GuildVoice;
|
|
1018
1094
|
}
|
|
1095
|
+
/** Check if this is a stage channel (type 13). */
|
|
1096
|
+
isStage() {
|
|
1097
|
+
return this.type === ChannelType2.GuildStageVoice;
|
|
1098
|
+
}
|
|
1099
|
+
/** Check if this is a voice or stage channel, i.e. one `@fluxerjs/voice` can join. */
|
|
1100
|
+
isVoiceBased() {
|
|
1101
|
+
return this.type === ChannelType2.GuildVoice || this.type === ChannelType2.GuildStageVoice;
|
|
1102
|
+
}
|
|
1019
1103
|
/** Check if this is a link channel. */
|
|
1020
1104
|
isLink() {
|
|
1021
1105
|
return this.type === ChannelType2.GuildLink;
|
|
@@ -1682,10 +1766,10 @@ var Message = class _Message extends Base {
|
|
|
1682
1766
|
this.channelId = data.channel_id;
|
|
1683
1767
|
this.guildId = data.guild_id ?? null;
|
|
1684
1768
|
this.author = client.getOrCreateUser(data.author);
|
|
1685
|
-
this.content = data.content;
|
|
1686
|
-
this.createdAt = new Date(data.timestamp);
|
|
1769
|
+
this.content = data.content ?? "";
|
|
1770
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
1687
1771
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1688
|
-
this.pinned = data.pinned;
|
|
1772
|
+
this.pinned = data.pinned ?? false;
|
|
1689
1773
|
this.attachments = new Collection5();
|
|
1690
1774
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1691
1775
|
this.type = data.type ?? MessageType.Default;
|
|
@@ -1717,33 +1801,47 @@ var Message = class _Message extends Base {
|
|
|
1717
1801
|
* @internal
|
|
1718
1802
|
*/
|
|
1719
1803
|
_patch(data) {
|
|
1720
|
-
this.content = data.content;
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
this.
|
|
1731
|
-
this.
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1804
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
1805
|
+
if (data.edited_timestamp !== void 0) {
|
|
1806
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1807
|
+
}
|
|
1808
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
1809
|
+
if (data.attachments !== void 0) {
|
|
1810
|
+
this.attachments.clear();
|
|
1811
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1812
|
+
}
|
|
1813
|
+
if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1814
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
1815
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
1816
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1817
|
+
if (data.stickers !== void 0) {
|
|
1818
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1819
|
+
}
|
|
1820
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
1821
|
+
if (data.message_reference !== void 0) {
|
|
1822
|
+
this.messageReference = data.message_reference ? {
|
|
1823
|
+
channelId: data.message_reference.channel_id,
|
|
1824
|
+
messageId: data.message_reference.message_id,
|
|
1825
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1826
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1827
|
+
} : null;
|
|
1828
|
+
}
|
|
1829
|
+
if (data.message_snapshots !== void 0) {
|
|
1830
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1831
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
1835
|
+
if (data.referenced_message !== void 0) {
|
|
1836
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1837
|
+
}
|
|
1838
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
1839
|
+
if (data.mentions !== void 0) {
|
|
1840
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1841
|
+
}
|
|
1842
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
1843
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
1844
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1747
1845
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1748
1846
|
}
|
|
1749
1847
|
/**
|
|
@@ -1844,6 +1942,23 @@ var Message = class _Message extends Base {
|
|
|
1844
1942
|
async fetch() {
|
|
1845
1943
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1846
1944
|
}
|
|
1945
|
+
/** Publish this announcement message to channels following its channel. */
|
|
1946
|
+
async crosspost() {
|
|
1947
|
+
const data = await this.client.rest.post(
|
|
1948
|
+
Routes7.channelMessageCrosspost(this.channelId, this.id),
|
|
1949
|
+
{ auth: true }
|
|
1950
|
+
);
|
|
1951
|
+
const published = new _Message(this.client, data);
|
|
1952
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
1953
|
+
return published;
|
|
1954
|
+
}
|
|
1955
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
1956
|
+
async fetchCrosspostSource() {
|
|
1957
|
+
return this.client.rest.get(
|
|
1958
|
+
Routes7.channelMessageCrosspostSource(this.channelId, this.id),
|
|
1959
|
+
{ auth: true }
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1847
1962
|
/** Delete this message. */
|
|
1848
1963
|
async delete(reason) {
|
|
1849
1964
|
await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.5.0",
|
|
7
7
|
"description": "A fully-featured SDK for Fluxer bots",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"dist"
|
|
60
60
|
],
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@fluxerjs/
|
|
63
|
-
"@fluxerjs/
|
|
64
|
-
"@fluxerjs/
|
|
65
|
-
"@fluxerjs/collection": "3.
|
|
66
|
-
"@fluxerjs/
|
|
67
|
-
"@fluxerjs/
|
|
62
|
+
"@fluxerjs/rest": "3.5.0",
|
|
63
|
+
"@fluxerjs/ws": "3.5.0",
|
|
64
|
+
"@fluxerjs/builders": "3.5.0",
|
|
65
|
+
"@fluxerjs/collection": "3.5.0",
|
|
66
|
+
"@fluxerjs/types": "3.5.0",
|
|
67
|
+
"@fluxerjs/util": "3.5.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/node": "^20.0.0",
|