@fluxerjs/core 3.3.0 → 3.4.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-BAwFSagN.d.mts} +86 -10
- package/dist/{SubpathMessage-DjLo6il5.d.ts → SubpathMessage-Dq-1tI7E.d.ts} +86 -10
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +533 -133
- package/dist/client.mjs +533 -133
- package/dist/cluster.d.mts +1 -1
- package/dist/cluster.d.ts +1 -1
- package/dist/cluster.js +533 -133
- package/dist/cluster.mjs +533 -133
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +531 -133
- package/dist/index.mjs +531 -133
- package/dist/message.d.mts +1 -1
- package/dist/message.d.ts +1 -1
- package/dist/message.js +141 -41
- package/dist/message.mjs +141 -41
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1146,6 +1146,7 @@ var Events = {
|
|
|
1146
1146
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
1147
1147
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
1148
1148
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
1149
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
1149
1150
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
1150
1151
|
GuildMemberAdd: "guildMemberAdd",
|
|
1151
1152
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -1180,6 +1181,8 @@ var Events = {
|
|
|
1180
1181
|
VoiceStateAck: "voiceStateAck",
|
|
1181
1182
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
1182
1183
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
1184
|
+
VoiceSignal: "voiceSignal",
|
|
1185
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
1183
1186
|
VoiceStatesSync: "voiceStatesSync",
|
|
1184
1187
|
WebhooksUpdate: "webhooksUpdate",
|
|
1185
1188
|
Resumed: "resumed",
|
|
@@ -1846,10 +1849,10 @@ var Message = class _Message extends Base {
|
|
|
1846
1849
|
this.channelId = data.channel_id;
|
|
1847
1850
|
this.guildId = data.guild_id ?? null;
|
|
1848
1851
|
this.author = client.getOrCreateUser(data.author);
|
|
1849
|
-
this.content = data.content;
|
|
1850
|
-
this.createdAt = new Date(data.timestamp);
|
|
1852
|
+
this.content = data.content ?? "";
|
|
1853
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
1851
1854
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1852
|
-
this.pinned = data.pinned;
|
|
1855
|
+
this.pinned = data.pinned ?? false;
|
|
1853
1856
|
this.attachments = new Collection3();
|
|
1854
1857
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1855
1858
|
this.type = data.type ?? MessageType.Default;
|
|
@@ -1881,33 +1884,47 @@ var Message = class _Message extends Base {
|
|
|
1881
1884
|
* @internal
|
|
1882
1885
|
*/
|
|
1883
1886
|
_patch(data) {
|
|
1884
|
-
this.content = data.content;
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
this.
|
|
1895
|
-
this.
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1887
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
1888
|
+
if (data.edited_timestamp !== void 0) {
|
|
1889
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1890
|
+
}
|
|
1891
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
1892
|
+
if (data.attachments !== void 0) {
|
|
1893
|
+
this.attachments.clear();
|
|
1894
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1895
|
+
}
|
|
1896
|
+
if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1897
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
1898
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
1899
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1900
|
+
if (data.stickers !== void 0) {
|
|
1901
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1902
|
+
}
|
|
1903
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
1904
|
+
if (data.message_reference !== void 0) {
|
|
1905
|
+
this.messageReference = data.message_reference ? {
|
|
1906
|
+
channelId: data.message_reference.channel_id,
|
|
1907
|
+
messageId: data.message_reference.message_id,
|
|
1908
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1909
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1910
|
+
} : null;
|
|
1911
|
+
}
|
|
1912
|
+
if (data.message_snapshots !== void 0) {
|
|
1913
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1914
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1915
|
+
);
|
|
1916
|
+
}
|
|
1917
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
1918
|
+
if (data.referenced_message !== void 0) {
|
|
1919
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1920
|
+
}
|
|
1921
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
1922
|
+
if (data.mentions !== void 0) {
|
|
1923
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1924
|
+
}
|
|
1925
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
1926
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
1927
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1911
1928
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1912
1929
|
}
|
|
1913
1930
|
/**
|
|
@@ -2008,6 +2025,23 @@ var Message = class _Message extends Base {
|
|
|
2008
2025
|
async fetch() {
|
|
2009
2026
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2010
2027
|
}
|
|
2028
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2029
|
+
async crosspost() {
|
|
2030
|
+
const data = await this.client.rest.post(
|
|
2031
|
+
Routes4.channelMessageCrosspost(this.channelId, this.id),
|
|
2032
|
+
{ auth: true }
|
|
2033
|
+
);
|
|
2034
|
+
const published = new _Message(this.client, data);
|
|
2035
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2036
|
+
return published;
|
|
2037
|
+
}
|
|
2038
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2039
|
+
async fetchCrosspostSource() {
|
|
2040
|
+
return this.client.rest.get(
|
|
2041
|
+
Routes4.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2042
|
+
{ auth: true }
|
|
2043
|
+
);
|
|
2044
|
+
}
|
|
2011
2045
|
/** Delete this message. */
|
|
2012
2046
|
async delete(reason) {
|
|
2013
2047
|
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
|
|
@@ -2110,6 +2144,43 @@ var PartialMessage = class {
|
|
|
2110
2144
|
}
|
|
2111
2145
|
};
|
|
2112
2146
|
|
|
2147
|
+
// src/ClientCore/Resolve.ts
|
|
2148
|
+
function normalizeSnowflakeId(value, label) {
|
|
2149
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
2150
|
+
throw new TypeError(
|
|
2151
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
2152
|
+
);
|
|
2153
|
+
}
|
|
2154
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
2155
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
2156
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
2157
|
+
}
|
|
2158
|
+
return id;
|
|
2159
|
+
}
|
|
2160
|
+
function assertApiObjectWithId(data, label) {
|
|
2161
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
2162
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
2163
|
+
}
|
|
2164
|
+
return data;
|
|
2165
|
+
}
|
|
2166
|
+
function assertApiArray(data, label) {
|
|
2167
|
+
if (!Array.isArray(data)) {
|
|
2168
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
2169
|
+
}
|
|
2170
|
+
return data;
|
|
2171
|
+
}
|
|
2172
|
+
async function dedupeFetch(pending, key, fn) {
|
|
2173
|
+
const existing = pending.get(key);
|
|
2174
|
+
if (existing) return existing;
|
|
2175
|
+
const request = fn();
|
|
2176
|
+
pending.set(key, request);
|
|
2177
|
+
try {
|
|
2178
|
+
return await request;
|
|
2179
|
+
} finally {
|
|
2180
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2113
2184
|
// src/ClientCore/MessageManager.ts
|
|
2114
2185
|
var BULK = {
|
|
2115
2186
|
requests: { min: 1, max: 25 },
|
|
@@ -2146,25 +2217,32 @@ var MessageManager = class {
|
|
|
2146
2217
|
}
|
|
2147
2218
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
2148
2219
|
_structures = new Collection4();
|
|
2220
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
2149
2221
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
2150
2222
|
get(messageId) {
|
|
2151
|
-
const
|
|
2223
|
+
const id = String(messageId ?? "").trim();
|
|
2224
|
+
if (!id) return void 0;
|
|
2225
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
2152
2226
|
if (!data) {
|
|
2153
|
-
this._structures.delete(
|
|
2227
|
+
this._structures.delete(id);
|
|
2154
2228
|
return void 0;
|
|
2155
2229
|
}
|
|
2156
|
-
const existing = this._structures.get(
|
|
2157
|
-
if (existing)
|
|
2230
|
+
const existing = this._structures.get(id);
|
|
2231
|
+
if (existing) {
|
|
2232
|
+
existing._patch(data);
|
|
2233
|
+
return existing;
|
|
2234
|
+
}
|
|
2158
2235
|
const message = new Message(this.client, data);
|
|
2159
|
-
this._structures.set(
|
|
2236
|
+
this._structures.set(id, message);
|
|
2160
2237
|
return message;
|
|
2161
2238
|
}
|
|
2162
2239
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
2163
2240
|
async resolve(messageId) {
|
|
2164
|
-
|
|
2241
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
2242
|
+
return this.get(id) ?? this.fetch(id);
|
|
2165
2243
|
}
|
|
2166
2244
|
async fetch(idOrOptions) {
|
|
2167
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
2245
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
2168
2246
|
}
|
|
2169
2247
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
2170
2248
|
wrap(data) {
|
|
@@ -2181,9 +2259,13 @@ var MessageManager = class {
|
|
|
2181
2259
|
}
|
|
2182
2260
|
/** Fetch a single message from the API. */
|
|
2183
2261
|
async fetchOne(messageId) {
|
|
2262
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
2263
|
+
}
|
|
2264
|
+
async fetchOneFresh(messageId) {
|
|
2184
2265
|
try {
|
|
2185
|
-
const data =
|
|
2186
|
-
Routes5.channelMessage(this.channelId, messageId)
|
|
2266
|
+
const data = assertApiObjectWithId(
|
|
2267
|
+
await this.client.rest.get(Routes5.channelMessage(this.channelId, messageId)),
|
|
2268
|
+
"messages.fetch()"
|
|
2187
2269
|
);
|
|
2188
2270
|
return this.wrap(data);
|
|
2189
2271
|
} catch (err) {
|
|
@@ -2209,9 +2291,15 @@ var MessageManager = class {
|
|
|
2209
2291
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
2210
2292
|
}
|
|
2211
2293
|
const base = Routes5.channelMessages(this.channelId);
|
|
2212
|
-
const data =
|
|
2294
|
+
const data = assertApiArray(
|
|
2295
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
2296
|
+
"messages.fetch()"
|
|
2297
|
+
);
|
|
2213
2298
|
const collection = new Collection4();
|
|
2214
|
-
for (const msg of data)
|
|
2299
|
+
for (const msg of data) {
|
|
2300
|
+
if (!msg?.id) continue;
|
|
2301
|
+
collection.set(msg.id, this.wrap(msg));
|
|
2302
|
+
}
|
|
2215
2303
|
return collection;
|
|
2216
2304
|
}
|
|
2217
2305
|
};
|
|
@@ -2415,6 +2503,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
2415
2503
|
}
|
|
2416
2504
|
|
|
2417
2505
|
// src/Domain/Channel/Base.ts
|
|
2506
|
+
function isFullChannelData(data) {
|
|
2507
|
+
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;
|
|
2508
|
+
}
|
|
2418
2509
|
var Channel = class extends Base {
|
|
2419
2510
|
#messages;
|
|
2420
2511
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -2429,6 +2520,11 @@ var Channel = class extends Base {
|
|
|
2429
2520
|
icon;
|
|
2430
2521
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
2431
2522
|
lastPinTimestamp;
|
|
2523
|
+
/**
|
|
2524
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
2525
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
2526
|
+
*/
|
|
2527
|
+
partial;
|
|
2432
2528
|
constructor(client, data) {
|
|
2433
2529
|
super();
|
|
2434
2530
|
this.client = client;
|
|
@@ -2437,6 +2533,7 @@ var Channel = class extends Base {
|
|
|
2437
2533
|
this.name = data.name ?? null;
|
|
2438
2534
|
this.icon = data.icon ?? null;
|
|
2439
2535
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
2536
|
+
this.partial = !isFullChannelData(data);
|
|
2440
2537
|
}
|
|
2441
2538
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
2442
2539
|
get createdTimestamp() {
|
|
@@ -2457,6 +2554,7 @@ var Channel = class extends Base {
|
|
|
2457
2554
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
2458
2555
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
2459
2556
|
}
|
|
2557
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
2460
2558
|
}
|
|
2461
2559
|
/** @internal Factory wired after subclasses load. */
|
|
2462
2560
|
static from(_c, _d) {
|
|
@@ -2748,7 +2846,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2748
2846
|
const full = data;
|
|
2749
2847
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2750
2848
|
this.ownerId = full.owner_id ?? null;
|
|
2751
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2849
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2752
2850
|
this.nicks = full.nicks ?? {};
|
|
2753
2851
|
}
|
|
2754
2852
|
/**
|
|
@@ -2763,7 +2861,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2763
2861
|
}
|
|
2764
2862
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2765
2863
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2766
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2864
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2767
2865
|
}
|
|
2768
2866
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2769
2867
|
}
|
|
@@ -2848,17 +2946,19 @@ import {
|
|
|
2848
2946
|
// src/Helpers/Instance.ts
|
|
2849
2947
|
import { isRecord } from "@fluxerjs/util";
|
|
2850
2948
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2851
|
-
api: "https://
|
|
2852
|
-
api_client: "https://
|
|
2853
|
-
api_public: "https://
|
|
2854
|
-
gateway: "wss://gateway.fluxer.
|
|
2949
|
+
api: "https://fluxer.com/api",
|
|
2950
|
+
api_client: "https://fluxer.com/api",
|
|
2951
|
+
api_public: "https://fluxer.com/api",
|
|
2952
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2855
2953
|
media: CDN_URL,
|
|
2954
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2856
2955
|
static_cdn: STATIC_CDN_URL,
|
|
2857
|
-
marketing: "https://fluxer.
|
|
2956
|
+
marketing: "https://fluxer.com",
|
|
2957
|
+
docs: "https://docs.fluxer.com",
|
|
2858
2958
|
admin: "https://admin.fluxer.app",
|
|
2859
2959
|
invite: "https://fluxer.gg",
|
|
2860
2960
|
gift: "https://fluxer.gift",
|
|
2861
|
-
webapp: "https://
|
|
2961
|
+
webapp: "https://fluxer.com"
|
|
2862
2962
|
});
|
|
2863
2963
|
var ENDPOINT_KEYS = [
|
|
2864
2964
|
"api",
|
|
@@ -2873,6 +2973,11 @@ var ENDPOINT_KEYS = [
|
|
|
2873
2973
|
"gift",
|
|
2874
2974
|
"webapp"
|
|
2875
2975
|
];
|
|
2976
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
2977
|
+
"api_transport",
|
|
2978
|
+
"upload_relay",
|
|
2979
|
+
"docs"
|
|
2980
|
+
];
|
|
2876
2981
|
function requireString(obj, key, path) {
|
|
2877
2982
|
const value = obj[key];
|
|
2878
2983
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2913,6 +3018,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2913
3018
|
for (const key of ENDPOINT_KEYS) {
|
|
2914
3019
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2915
3020
|
}
|
|
3021
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
3022
|
+
const value = raw.endpoints[key];
|
|
3023
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
3024
|
+
}
|
|
2916
3025
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2917
3026
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2918
3027
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -2966,7 +3075,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
2966
3075
|
defaultsHash: ""
|
|
2967
3076
|
},
|
|
2968
3077
|
push: raw.push ?? { public_vapid_key: null },
|
|
2969
|
-
app_public: raw.app_public ?? {}
|
|
3078
|
+
app_public: raw.app_public ?? {},
|
|
3079
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
3080
|
+
age_policy: isRecord(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
3081
|
+
...raw.notice === null || isRecord(raw.notice) ? { notice: raw.notice } : {},
|
|
3082
|
+
...isRecord(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
3083
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
3084
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
3085
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
3086
|
+
...isRecord(raw.built_in_guild_badge_images) ? {
|
|
3087
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
3088
|
+
} : {},
|
|
3089
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
3090
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
3091
|
+
} : {},
|
|
3092
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
2970
3093
|
};
|
|
2971
3094
|
}
|
|
2972
3095
|
function resolveInstanceEndpoints(input) {
|
|
@@ -2986,7 +3109,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
2986
3109
|
}
|
|
2987
3110
|
const partial = input;
|
|
2988
3111
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
2989
|
-
for (const key of ENDPOINT_KEYS) {
|
|
3112
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
2990
3113
|
const value = partial[key];
|
|
2991
3114
|
if (typeof value === "string" && value.length > 0) {
|
|
2992
3115
|
merged[key] = value;
|
|
@@ -3606,6 +3729,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3606
3729
|
}
|
|
3607
3730
|
};
|
|
3608
3731
|
var AnnouncementChannel = class extends TextChannel {
|
|
3732
|
+
/**
|
|
3733
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3734
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3735
|
+
*/
|
|
3736
|
+
async follow(webhookChannelId) {
|
|
3737
|
+
return this.client.rest.post(
|
|
3738
|
+
Routes13.channelFollowers(this.id),
|
|
3739
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3740
|
+
);
|
|
3741
|
+
}
|
|
3742
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3743
|
+
async fetchFollowerStats() {
|
|
3744
|
+
return this.client.rest.get(
|
|
3745
|
+
Routes13.channelFollowerStats(this.id),
|
|
3746
|
+
{ auth: true }
|
|
3747
|
+
);
|
|
3748
|
+
}
|
|
3609
3749
|
};
|
|
3610
3750
|
var CategoryChannel = class extends GuildChannel {
|
|
3611
3751
|
};
|
|
@@ -3632,6 +3772,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3632
3772
|
voiceConnectionLimit;
|
|
3633
3773
|
/** RTC region override for this channel. */
|
|
3634
3774
|
rtcRegion;
|
|
3775
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3776
|
+
rtcP2p;
|
|
3635
3777
|
constructor(client, data) {
|
|
3636
3778
|
super(client, data);
|
|
3637
3779
|
this.topic = data.topic ?? null;
|
|
@@ -3645,6 +3787,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3645
3787
|
this.userLimit = data.user_limit ?? null;
|
|
3646
3788
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3647
3789
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3790
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3648
3791
|
}
|
|
3649
3792
|
/**
|
|
3650
3793
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3671,6 +3814,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3671
3814
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3672
3815
|
}
|
|
3673
3816
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3817
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3674
3818
|
}
|
|
3675
3819
|
};
|
|
3676
3820
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -4729,6 +4873,8 @@ var Role = class _Role extends Base {
|
|
|
4729
4873
|
mentionable;
|
|
4730
4874
|
/** Unicode emoji for this role (null = none). */
|
|
4731
4875
|
unicodeEmoji;
|
|
4876
|
+
/** Role icon image hash (null = none). */
|
|
4877
|
+
icon;
|
|
4732
4878
|
/** Hoist position (null = not hoisted). */
|
|
4733
4879
|
hoistPosition;
|
|
4734
4880
|
constructor(client, data, guildId) {
|
|
@@ -4736,20 +4882,26 @@ var Role = class _Role extends Base {
|
|
|
4736
4882
|
this.client = client;
|
|
4737
4883
|
this.id = data.id;
|
|
4738
4884
|
this.guildId = guildId;
|
|
4739
|
-
this.name = data.name;
|
|
4740
|
-
this.color = data.color;
|
|
4741
|
-
this.position = data.position;
|
|
4742
|
-
this._permissions = data.permissions;
|
|
4885
|
+
this.name = data.name ?? "";
|
|
4886
|
+
this.color = data.color ?? 0;
|
|
4887
|
+
this.position = data.position ?? 0;
|
|
4888
|
+
this._permissions = data.permissions ?? "0";
|
|
4743
4889
|
this.hoist = !!data.hoist;
|
|
4744
4890
|
this.mentionable = !!data.mentionable;
|
|
4745
4891
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4892
|
+
this.icon = data.icon ?? null;
|
|
4746
4893
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4747
4894
|
}
|
|
4748
4895
|
/**
|
|
4749
4896
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4750
4897
|
*/
|
|
4751
4898
|
get permissions() {
|
|
4752
|
-
|
|
4899
|
+
let bits;
|
|
4900
|
+
try {
|
|
4901
|
+
bits = BigInt(this._permissions ?? "0");
|
|
4902
|
+
} catch {
|
|
4903
|
+
bits = 0n;
|
|
4904
|
+
}
|
|
4753
4905
|
return new PermissionsBitField3(
|
|
4754
4906
|
(bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
|
|
4755
4907
|
);
|
|
@@ -4779,14 +4931,15 @@ var Role = class _Role extends Base {
|
|
|
4779
4931
|
}
|
|
4780
4932
|
/** @internal */
|
|
4781
4933
|
_patch(data) {
|
|
4782
|
-
this.name = data.name;
|
|
4783
|
-
this.color = data.color;
|
|
4784
|
-
this.position = data.position;
|
|
4785
|
-
this._permissions = data.permissions;
|
|
4786
|
-
this.hoist = !!data.hoist;
|
|
4787
|
-
this.mentionable = !!data.mentionable;
|
|
4788
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4789
|
-
this.
|
|
4934
|
+
if (data.name !== void 0) this.name = data.name;
|
|
4935
|
+
if (data.color !== void 0) this.color = data.color;
|
|
4936
|
+
if (data.position !== void 0) this.position = data.position;
|
|
4937
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
4938
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
4939
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
4940
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4941
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
4942
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4790
4943
|
}
|
|
4791
4944
|
/**
|
|
4792
4945
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4804,6 +4957,7 @@ var Role = class _Role extends Base {
|
|
|
4804
4957
|
hoist: this.hoist,
|
|
4805
4958
|
mentionable: this.mentionable,
|
|
4806
4959
|
unicode_emoji: this.unicodeEmoji,
|
|
4960
|
+
icon: this.icon,
|
|
4807
4961
|
hoist_position: this.hoistPosition
|
|
4808
4962
|
},
|
|
4809
4963
|
this.guildId
|
|
@@ -4981,6 +5135,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4981
5135
|
});
|
|
4982
5136
|
this.client = client;
|
|
4983
5137
|
}
|
|
5138
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
4984
5139
|
/**
|
|
4985
5140
|
* Remove a channel from cache. Does not delete it on the API.
|
|
4986
5141
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -4993,9 +5148,11 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4993
5148
|
}
|
|
4994
5149
|
return deleted;
|
|
4995
5150
|
}
|
|
4996
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5151
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
4997
5152
|
async resolve(channelId) {
|
|
4998
|
-
|
|
5153
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5154
|
+
const cached = this.get(id);
|
|
5155
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
4999
5156
|
}
|
|
5000
5157
|
/**
|
|
5001
5158
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5008,10 +5165,23 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5008
5165
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5009
5166
|
*/
|
|
5010
5167
|
async fetch(channelId, options) {
|
|
5011
|
-
const
|
|
5012
|
-
|
|
5168
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5169
|
+
const cached = this.get(id);
|
|
5170
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5171
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5172
|
+
}
|
|
5173
|
+
async fetchFresh(channelId) {
|
|
5013
5174
|
try {
|
|
5014
|
-
const data =
|
|
5175
|
+
const data = assertApiObjectWithId(
|
|
5176
|
+
await this.client.rest.get(Routes22.channel(channelId)),
|
|
5177
|
+
"channels.fetch()"
|
|
5178
|
+
);
|
|
5179
|
+
const existing = this.get(channelId);
|
|
5180
|
+
if (existing && existing.type === data.type) {
|
|
5181
|
+
existing._patch(data);
|
|
5182
|
+
putChannel(this.client, existing);
|
|
5183
|
+
return existing;
|
|
5184
|
+
}
|
|
5015
5185
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5016
5186
|
if (guildId) {
|
|
5017
5187
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5096,12 +5266,15 @@ var User = class extends Base {
|
|
|
5096
5266
|
system;
|
|
5097
5267
|
/** Banner hash for profile. */
|
|
5098
5268
|
banner;
|
|
5269
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
5270
|
+
partial;
|
|
5099
5271
|
constructor(client, data) {
|
|
5100
5272
|
super();
|
|
5101
5273
|
this.client = client;
|
|
5102
5274
|
this.id = data.id;
|
|
5103
|
-
this.
|
|
5104
|
-
this.
|
|
5275
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
5276
|
+
this.username = data.username ?? "Unknown";
|
|
5277
|
+
this.discriminator = data.discriminator ?? "0";
|
|
5105
5278
|
this.globalName = data.global_name ?? null;
|
|
5106
5279
|
this.avatar = data.avatar ?? null;
|
|
5107
5280
|
this.bot = !!data.bot;
|
|
@@ -5112,13 +5285,18 @@ var User = class extends Base {
|
|
|
5112
5285
|
}
|
|
5113
5286
|
/** @internal */
|
|
5114
5287
|
_patch(data) {
|
|
5115
|
-
this.username = data.username;
|
|
5116
|
-
this.discriminator = data.discriminator;
|
|
5117
|
-
this.globalName = data.global_name ?? null;
|
|
5118
|
-
this.avatar = data.avatar ?? null;
|
|
5288
|
+
if (data.username !== void 0) this.username = data.username;
|
|
5289
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
5290
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
5291
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
5119
5292
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
5120
5293
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
5121
5294
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
5295
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
5296
|
+
}
|
|
5297
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
5298
|
+
async fetch() {
|
|
5299
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
5122
5300
|
}
|
|
5123
5301
|
cdnOpts() {
|
|
5124
5302
|
return {
|
|
@@ -5360,6 +5538,68 @@ async function searchMessages(client, options = {}) {
|
|
|
5360
5538
|
});
|
|
5361
5539
|
return toMessageSearchResponse(data);
|
|
5362
5540
|
}
|
|
5541
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5542
|
+
return client.rest.get(
|
|
5543
|
+
Routes24.emojiSource(emojiId),
|
|
5544
|
+
{ auth: true }
|
|
5545
|
+
);
|
|
5546
|
+
}
|
|
5547
|
+
function fetchStickerSource(client, stickerId) {
|
|
5548
|
+
return client.rest.get(
|
|
5549
|
+
Routes24.stickerSource(stickerId),
|
|
5550
|
+
{ auth: true }
|
|
5551
|
+
);
|
|
5552
|
+
}
|
|
5553
|
+
function fetchDiscoveryCategories(client) {
|
|
5554
|
+
return client.rest.get(
|
|
5555
|
+
Routes24.discoveryCategories(),
|
|
5556
|
+
{ auth: true }
|
|
5557
|
+
);
|
|
5558
|
+
}
|
|
5559
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5560
|
+
const params = new URLSearchParams();
|
|
5561
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5562
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5563
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5564
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5565
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5566
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5567
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5568
|
+
const qs2 = params.toString();
|
|
5569
|
+
return client.rest.get(
|
|
5570
|
+
qs2 ? `${Routes24.discoveryGuilds()}?${qs2}` : Routes24.discoveryGuilds(),
|
|
5571
|
+
{ auth: true }
|
|
5572
|
+
);
|
|
5573
|
+
}
|
|
5574
|
+
function fetchExperiments(client) {
|
|
5575
|
+
return client.rest.get(Routes24.experiments(), {
|
|
5576
|
+
auth: true
|
|
5577
|
+
});
|
|
5578
|
+
}
|
|
5579
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5580
|
+
return client.rest.post(
|
|
5581
|
+
Routes24.attachmentsRefreshUrls(),
|
|
5582
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5583
|
+
);
|
|
5584
|
+
}
|
|
5585
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5586
|
+
const params = new URLSearchParams();
|
|
5587
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5588
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5589
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5590
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5591
|
+
const qs2 = params.toString();
|
|
5592
|
+
return client.rest.get(
|
|
5593
|
+
qs2 ? `${Routes24.instanceBadges()}?${qs2}` : Routes24.instanceBadges(),
|
|
5594
|
+
{ auth: false }
|
|
5595
|
+
);
|
|
5596
|
+
}
|
|
5597
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5598
|
+
return client.rest.post(
|
|
5599
|
+
Routes24.channelPostData(channelId),
|
|
5600
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5601
|
+
);
|
|
5602
|
+
}
|
|
5363
5603
|
|
|
5364
5604
|
// src/ClientCore/ClientEvents.ts
|
|
5365
5605
|
function createEventMethods(client) {
|
|
@@ -5390,6 +5630,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5390
5630
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5391
5631
|
this.guild = guild;
|
|
5392
5632
|
}
|
|
5633
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5393
5634
|
/**
|
|
5394
5635
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5395
5636
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5401,7 +5642,9 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5401
5642
|
* console.log(member.displayName);
|
|
5402
5643
|
*/
|
|
5403
5644
|
async resolve(userId) {
|
|
5404
|
-
|
|
5645
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5646
|
+
const cached = this.get(id);
|
|
5647
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5405
5648
|
}
|
|
5406
5649
|
/**
|
|
5407
5650
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5429,10 +5672,11 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5429
5672
|
return this.guild.fetchMe();
|
|
5430
5673
|
}
|
|
5431
5674
|
async fetch(userIdOrOptions, options) {
|
|
5432
|
-
if (typeof userIdOrOptions === "string") {
|
|
5433
|
-
const
|
|
5434
|
-
|
|
5435
|
-
|
|
5675
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5676
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5677
|
+
const cached = this.get(id);
|
|
5678
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5679
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5436
5680
|
}
|
|
5437
5681
|
return this.fetchMany(userIdOrOptions);
|
|
5438
5682
|
}
|
|
@@ -5442,9 +5686,13 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5442
5686
|
if (options?.after) params.set("after", options.after);
|
|
5443
5687
|
const qs2 = params.toString();
|
|
5444
5688
|
const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5445
|
-
const data =
|
|
5689
|
+
const data = assertApiArray(
|
|
5690
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5691
|
+
"members.fetch()"
|
|
5692
|
+
);
|
|
5446
5693
|
const members = [];
|
|
5447
5694
|
for (const m of data) {
|
|
5695
|
+
if (!m?.user?.id) continue;
|
|
5448
5696
|
const member = new GuildMember(
|
|
5449
5697
|
this.guild.client,
|
|
5450
5698
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5610,7 +5858,12 @@ async function createChannel(guild, options) {
|
|
|
5610
5858
|
return cacheChannel(guild, created);
|
|
5611
5859
|
}
|
|
5612
5860
|
async function fetchChannels(guild) {
|
|
5613
|
-
const
|
|
5861
|
+
const raw = await guild.client.rest.get(Routes27.guildChannels(guild.id));
|
|
5862
|
+
if (!Array.isArray(raw))
|
|
5863
|
+
throw new TypeError(
|
|
5864
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
5865
|
+
);
|
|
5866
|
+
const data = raw;
|
|
5614
5867
|
const channels = [];
|
|
5615
5868
|
for (const ch of data) {
|
|
5616
5869
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5705,16 +5958,20 @@ var GuildRoleManager = class extends LimitedCollection3 {
|
|
|
5705
5958
|
// src/Domain/Guild/MemberHttp.ts
|
|
5706
5959
|
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
5707
5960
|
async function fetchMember(guild, userId) {
|
|
5961
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5708
5962
|
try {
|
|
5709
5963
|
const data = await guild.client.rest.get(
|
|
5710
|
-
Routes29.guildMember(guild.id,
|
|
5964
|
+
Routes29.guildMember(guild.id, id)
|
|
5711
5965
|
);
|
|
5966
|
+
if (!data?.user?.id) {
|
|
5967
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
5968
|
+
}
|
|
5712
5969
|
return cacheMember(guild, data);
|
|
5713
5970
|
} catch (err) {
|
|
5714
5971
|
rethrowMapped(err, {
|
|
5715
5972
|
notFound: {
|
|
5716
5973
|
code: ErrorCodes.MemberNotFound,
|
|
5717
|
-
message: `Member ${
|
|
5974
|
+
message: `Member ${id} not found in guild`
|
|
5718
5975
|
},
|
|
5719
5976
|
fallback: "Failed to fetch guild member"
|
|
5720
5977
|
});
|
|
@@ -5725,6 +5982,9 @@ async function fetchMe(guild) {
|
|
|
5725
5982
|
Routes29.guildMemberMe(guild.id),
|
|
5726
5983
|
{ auth: true }
|
|
5727
5984
|
);
|
|
5985
|
+
if (!data?.user?.id) {
|
|
5986
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
5987
|
+
}
|
|
5728
5988
|
return cacheMember(guild, data);
|
|
5729
5989
|
}
|
|
5730
5990
|
|
|
@@ -5775,6 +6035,10 @@ async function ban(guild, userId, options) {
|
|
|
5775
6035
|
...auditReasonHeaders(options?.reason)
|
|
5776
6036
|
});
|
|
5777
6037
|
}
|
|
6038
|
+
async function fetchBan(guild, userId) {
|
|
6039
|
+
const data = await guild.client.rest.get(Routes31.guildBan(guild.id, userId));
|
|
6040
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
6041
|
+
}
|
|
5778
6042
|
async function fetchBans(guild) {
|
|
5779
6043
|
const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
|
|
5780
6044
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
@@ -5806,6 +6070,8 @@ async function createRole(guild, options = {}) {
|
|
|
5806
6070
|
}
|
|
5807
6071
|
async function fetchRoles(guild) {
|
|
5808
6072
|
const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
|
|
6073
|
+
if (!Array.isArray(data))
|
|
6074
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5809
6075
|
return data.map((r) => cacheRole(guild, r));
|
|
5810
6076
|
}
|
|
5811
6077
|
async function fetchRole(guild, roleId2) {
|
|
@@ -5905,6 +6171,11 @@ var Guild = class extends Base {
|
|
|
5905
6171
|
id;
|
|
5906
6172
|
/** Whether the guild is currently available through the gateway. */
|
|
5907
6173
|
available = true;
|
|
6174
|
+
/**
|
|
6175
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6176
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6177
|
+
*/
|
|
6178
|
+
partial = true;
|
|
5908
6179
|
/** Guild name. */
|
|
5909
6180
|
name;
|
|
5910
6181
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -6199,6 +6470,10 @@ var Guild = class extends Base {
|
|
|
6199
6470
|
ban(userId, options) {
|
|
6200
6471
|
return ban(this, userId, options);
|
|
6201
6472
|
}
|
|
6473
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6474
|
+
fetchBan(userId) {
|
|
6475
|
+
return fetchBan(this, userId);
|
|
6476
|
+
}
|
|
6202
6477
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6203
6478
|
fetchBans() {
|
|
6204
6479
|
return fetchBans(this);
|
|
@@ -6379,6 +6654,7 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6379
6654
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6380
6655
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6381
6656
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6657
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6382
6658
|
return { guild, created, recovered };
|
|
6383
6659
|
}
|
|
6384
6660
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6462,15 +6738,7 @@ var ClientUser = class extends User {
|
|
|
6462
6738
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6463
6739
|
import { asRecord, num, str } from "@fluxerjs/util";
|
|
6464
6740
|
function unknownUser(id) {
|
|
6465
|
-
return {
|
|
6466
|
-
id,
|
|
6467
|
-
username: "Unknown",
|
|
6468
|
-
discriminator: "0",
|
|
6469
|
-
global_name: null,
|
|
6470
|
-
avatar: null,
|
|
6471
|
-
avatar_color: null,
|
|
6472
|
-
flags: 0
|
|
6473
|
-
};
|
|
6741
|
+
return { id };
|
|
6474
6742
|
}
|
|
6475
6743
|
function indexMember(_client, guild, data) {
|
|
6476
6744
|
if (!data.user?.id) return null;
|
|
@@ -7154,6 +7422,9 @@ var passthroughHandlers = {
|
|
|
7154
7422
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7155
7423
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7156
7424
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7425
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7426
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7427
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7157
7428
|
TYPING_START(client, d) {
|
|
7158
7429
|
const data = d;
|
|
7159
7430
|
const payload = {
|
|
@@ -7344,29 +7615,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7344
7615
|
}
|
|
7345
7616
|
return dispatchGatewayPayload(client, payload);
|
|
7346
7617
|
}
|
|
7347
|
-
|
|
7618
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7619
|
+
function queueFor(client) {
|
|
7620
|
+
let queue = dispatchQueues.get(client);
|
|
7621
|
+
if (!queue) {
|
|
7622
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7623
|
+
dispatchQueues.set(client, queue);
|
|
7624
|
+
}
|
|
7625
|
+
return queue;
|
|
7626
|
+
}
|
|
7627
|
+
async function runGatewayHandler(client, payload) {
|
|
7348
7628
|
const event = payload.t;
|
|
7349
|
-
if (!event) return
|
|
7629
|
+
if (!event) return;
|
|
7350
7630
|
const handler = eventHandlers.get(event);
|
|
7351
7631
|
if (!handler) {
|
|
7352
7632
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7353
|
-
return
|
|
7633
|
+
return;
|
|
7354
7634
|
}
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
}
|
|
7362
|
-
if (client.options.gatewayDeferHandlers
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
};
|
|
7367
|
-
|
|
7368
|
-
|
|
7635
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7636
|
+
client.emit(
|
|
7637
|
+
Events.Debug,
|
|
7638
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7639
|
+
);
|
|
7640
|
+
return;
|
|
7641
|
+
}
|
|
7642
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7643
|
+
await new Promise((resolve) => {
|
|
7644
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7645
|
+
else setTimeout(resolve, 0);
|
|
7646
|
+
});
|
|
7647
|
+
}
|
|
7648
|
+
try {
|
|
7649
|
+
await handler(client, payload.d);
|
|
7650
|
+
} catch (err) {
|
|
7651
|
+
emitClientError(client, err);
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7655
|
+
const queue = queueFor(client);
|
|
7656
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7657
|
+
queue.pending++;
|
|
7658
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7659
|
+
queue.pending--;
|
|
7660
|
+
});
|
|
7661
|
+
queue.tail = run.catch(() => {
|
|
7662
|
+
});
|
|
7663
|
+
return run;
|
|
7664
|
+
}
|
|
7665
|
+
queue.pending++;
|
|
7666
|
+
const next = queue.tail.then(
|
|
7667
|
+
() => runGatewayHandler(client, payload),
|
|
7668
|
+
() => runGatewayHandler(client, payload)
|
|
7669
|
+
).finally(() => {
|
|
7670
|
+
queue.pending--;
|
|
7369
7671
|
});
|
|
7672
|
+
queue.tail = next.catch(() => {
|
|
7673
|
+
});
|
|
7674
|
+
return next;
|
|
7370
7675
|
}
|
|
7371
7676
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7372
7677
|
while (deferred.length > 0) {
|
|
@@ -7554,6 +7859,7 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7554
7859
|
});
|
|
7555
7860
|
this.client = client;
|
|
7556
7861
|
}
|
|
7862
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7557
7863
|
/**
|
|
7558
7864
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7559
7865
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7568,35 +7874,73 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7568
7874
|
}
|
|
7569
7875
|
/**
|
|
7570
7876
|
* Get a guild from cache or fetch from the API if not present.
|
|
7877
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7571
7878
|
* @param guildId - Snowflake of the guild
|
|
7572
7879
|
* @returns The guild
|
|
7573
7880
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7574
7881
|
*/
|
|
7575
7882
|
async resolve(guildId) {
|
|
7576
|
-
|
|
7883
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
7884
|
+
const cached = this.get(id);
|
|
7885
|
+
if (cached && !cached.partial) return cached;
|
|
7886
|
+
if (cached) {
|
|
7887
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7888
|
+
await this.hydrate(cached);
|
|
7889
|
+
return cached;
|
|
7890
|
+
});
|
|
7891
|
+
return cached;
|
|
7892
|
+
}
|
|
7893
|
+
const guild = await this.fetch(id);
|
|
7894
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7895
|
+
await this.hydrate(guild);
|
|
7896
|
+
return guild;
|
|
7897
|
+
});
|
|
7898
|
+
return guild;
|
|
7577
7899
|
}
|
|
7578
7900
|
/**
|
|
7579
7901
|
* Fetch a guild by ID.
|
|
7580
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7902
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7903
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7581
7904
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7582
7905
|
*/
|
|
7583
7906
|
async fetch(guildId, options) {
|
|
7584
|
-
const
|
|
7907
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
7908
|
+
const cached = this.get(id);
|
|
7585
7909
|
if (cached && !options?.force) return cached;
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7910
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
7911
|
+
try {
|
|
7912
|
+
const data = assertApiObjectWithId(
|
|
7913
|
+
await this.client.rest.get(Routes35.guild(id)),
|
|
7914
|
+
"guilds.fetch()"
|
|
7915
|
+
);
|
|
7916
|
+
let guild;
|
|
7917
|
+
const existing = this.get(id);
|
|
7918
|
+
if (existing) {
|
|
7919
|
+
existing._patch(data);
|
|
7920
|
+
guild = existing;
|
|
7921
|
+
} else {
|
|
7922
|
+
guild = new Guild(this.client, data);
|
|
7923
|
+
this.set(guild.id, guild);
|
|
7924
|
+
}
|
|
7925
|
+
return guild;
|
|
7926
|
+
} catch (err) {
|
|
7927
|
+
rethrowMapped(err, {
|
|
7928
|
+
notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
7929
|
+
fallback: `Failed to fetch guild ${id}`
|
|
7930
|
+
});
|
|
7591
7931
|
}
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7932
|
+
});
|
|
7933
|
+
}
|
|
7934
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
7935
|
+
async hydrate(guild) {
|
|
7936
|
+
try {
|
|
7937
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
7938
|
+
guild.partial = false;
|
|
7595
7939
|
} catch (err) {
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7940
|
+
this.client.emit(
|
|
7941
|
+
Events.Debug,
|
|
7942
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
7943
|
+
);
|
|
7600
7944
|
}
|
|
7601
7945
|
}
|
|
7602
7946
|
};
|
|
@@ -7621,6 +7965,10 @@ var MessageCache = class {
|
|
|
7621
7965
|
if (limit === false) return;
|
|
7622
7966
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7623
7967
|
let cache = this.caches.get(channelId);
|
|
7968
|
+
if (cache) {
|
|
7969
|
+
this.caches.delete(channelId);
|
|
7970
|
+
this.caches.set(channelId, cache);
|
|
7971
|
+
}
|
|
7624
7972
|
if (!cache) {
|
|
7625
7973
|
const channelLimit = this.getChannelLimit();
|
|
7626
7974
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7680,6 +8028,7 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7680
8028
|
super({ maxSize: client.cache.limits.users });
|
|
7681
8029
|
this.client = client;
|
|
7682
8030
|
}
|
|
8031
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7683
8032
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7684
8033
|
sweep(filter) {
|
|
7685
8034
|
let removed = 0;
|
|
@@ -7693,16 +8042,30 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7693
8042
|
}
|
|
7694
8043
|
return removed;
|
|
7695
8044
|
}
|
|
7696
|
-
/**
|
|
8045
|
+
/**
|
|
8046
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
8047
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
8048
|
+
*/
|
|
7697
8049
|
async fetch(userId, options) {
|
|
7698
|
-
const
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
return
|
|
8050
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
8051
|
+
const cached = this.get(id);
|
|
8052
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
8053
|
+
return dedupeFetch(
|
|
8054
|
+
this.pendingFetches,
|
|
8055
|
+
id,
|
|
8056
|
+
async () => this.client.getOrCreateUser(
|
|
8057
|
+
assertApiObjectWithId(
|
|
8058
|
+
await this.client.rest.get(Routes36.user(id)),
|
|
8059
|
+
"users.fetch()"
|
|
8060
|
+
)
|
|
8061
|
+
)
|
|
8062
|
+
);
|
|
7702
8063
|
}
|
|
7703
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8064
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7704
8065
|
async resolve(userId) {
|
|
7705
|
-
|
|
8066
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8067
|
+
const cached = this.get(id);
|
|
8068
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7706
8069
|
}
|
|
7707
8070
|
/**
|
|
7708
8071
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7843,7 +8206,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7843
8206
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7844
8207
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7845
8208
|
*
|
|
7846
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8209
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7847
8210
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7848
8211
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7849
8212
|
*/
|
|
@@ -7920,6 +8283,38 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7920
8283
|
fetchStickerMetadata(stickerId) {
|
|
7921
8284
|
return fetchStickerMetadata(this, stickerId);
|
|
7922
8285
|
}
|
|
8286
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8287
|
+
fetchEmojiSource(emojiId) {
|
|
8288
|
+
return fetchEmojiSource(this, emojiId);
|
|
8289
|
+
}
|
|
8290
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8291
|
+
fetchStickerSource(stickerId) {
|
|
8292
|
+
return fetchStickerSource(this, stickerId);
|
|
8293
|
+
}
|
|
8294
|
+
/** List discovery categories. */
|
|
8295
|
+
fetchDiscoveryCategories() {
|
|
8296
|
+
return fetchDiscoveryCategories(this);
|
|
8297
|
+
}
|
|
8298
|
+
/** Search discoverable guilds. */
|
|
8299
|
+
searchDiscoveryGuilds(options) {
|
|
8300
|
+
return searchDiscoveryGuilds(this, options);
|
|
8301
|
+
}
|
|
8302
|
+
/** Fetch experiment assignments for this account. */
|
|
8303
|
+
fetchExperiments() {
|
|
8304
|
+
return fetchExperiments(this);
|
|
8305
|
+
}
|
|
8306
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8307
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8308
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8309
|
+
}
|
|
8310
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8311
|
+
fetchInstanceBadges(options) {
|
|
8312
|
+
return fetchInstanceBadges(this, options);
|
|
8313
|
+
}
|
|
8314
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8315
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8316
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8317
|
+
}
|
|
7923
8318
|
/**
|
|
7924
8319
|
* Fetch the current application (`/applications/@me`).
|
|
7925
8320
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -8014,6 +8409,9 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
8014
8409
|
* @internal
|
|
8015
8410
|
*/
|
|
8016
8411
|
getOrCreateUser(data) {
|
|
8412
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8413
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8414
|
+
}
|
|
8017
8415
|
const existing = this.users.get(data.id);
|
|
8018
8416
|
if (existing) {
|
|
8019
8417
|
existing._patch(data);
|