@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.js
CHANGED
|
@@ -1234,6 +1234,7 @@ var Events = {
|
|
|
1234
1234
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
1235
1235
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
1236
1236
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
1237
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
1237
1238
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
1238
1239
|
GuildMemberAdd: "guildMemberAdd",
|
|
1239
1240
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -1268,6 +1269,8 @@ var Events = {
|
|
|
1268
1269
|
VoiceStateAck: "voiceStateAck",
|
|
1269
1270
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
1270
1271
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
1272
|
+
VoiceSignal: "voiceSignal",
|
|
1273
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
1271
1274
|
VoiceStatesSync: "voiceStatesSync",
|
|
1272
1275
|
WebhooksUpdate: "webhooksUpdate",
|
|
1273
1276
|
Resumed: "resumed",
|
|
@@ -1934,10 +1937,10 @@ var Message = class _Message extends Base {
|
|
|
1934
1937
|
this.channelId = data.channel_id;
|
|
1935
1938
|
this.guildId = data.guild_id ?? null;
|
|
1936
1939
|
this.author = client.getOrCreateUser(data.author);
|
|
1937
|
-
this.content = data.content;
|
|
1938
|
-
this.createdAt = new Date(data.timestamp);
|
|
1940
|
+
this.content = data.content ?? "";
|
|
1941
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
1939
1942
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1940
|
-
this.pinned = data.pinned;
|
|
1943
|
+
this.pinned = data.pinned ?? false;
|
|
1941
1944
|
this.attachments = new import_collection3.Collection();
|
|
1942
1945
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1943
1946
|
this.type = data.type ?? import_types7.MessageType.Default;
|
|
@@ -1969,33 +1972,47 @@ var Message = class _Message extends Base {
|
|
|
1969
1972
|
* @internal
|
|
1970
1973
|
*/
|
|
1971
1974
|
_patch(data) {
|
|
1972
|
-
this.content = data.content;
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
this.
|
|
1983
|
-
this.
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1975
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
1976
|
+
if (data.edited_timestamp !== void 0) {
|
|
1977
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1978
|
+
}
|
|
1979
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
1980
|
+
if (data.attachments !== void 0) {
|
|
1981
|
+
this.attachments.clear();
|
|
1982
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1983
|
+
}
|
|
1984
|
+
if (data.flags !== void 0) this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1985
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
1986
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
1987
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1988
|
+
if (data.stickers !== void 0) {
|
|
1989
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1990
|
+
}
|
|
1991
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
1992
|
+
if (data.message_reference !== void 0) {
|
|
1993
|
+
this.messageReference = data.message_reference ? {
|
|
1994
|
+
channelId: data.message_reference.channel_id,
|
|
1995
|
+
messageId: data.message_reference.message_id,
|
|
1996
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1997
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1998
|
+
} : null;
|
|
1999
|
+
}
|
|
2000
|
+
if (data.message_snapshots !== void 0) {
|
|
2001
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
2002
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
2006
|
+
if (data.referenced_message !== void 0) {
|
|
2007
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
2008
|
+
}
|
|
2009
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
2010
|
+
if (data.mentions !== void 0) {
|
|
2011
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2012
|
+
}
|
|
2013
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
2014
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
2015
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1999
2016
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
2000
2017
|
}
|
|
2001
2018
|
/**
|
|
@@ -2096,6 +2113,23 @@ var Message = class _Message extends Base {
|
|
|
2096
2113
|
async fetch() {
|
|
2097
2114
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2098
2115
|
}
|
|
2116
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2117
|
+
async crosspost() {
|
|
2118
|
+
const data = await this.client.rest.post(
|
|
2119
|
+
import_types7.Routes.channelMessageCrosspost(this.channelId, this.id),
|
|
2120
|
+
{ auth: true }
|
|
2121
|
+
);
|
|
2122
|
+
const published = new _Message(this.client, data);
|
|
2123
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2124
|
+
return published;
|
|
2125
|
+
}
|
|
2126
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2127
|
+
async fetchCrosspostSource() {
|
|
2128
|
+
return this.client.rest.get(
|
|
2129
|
+
import_types7.Routes.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2130
|
+
{ auth: true }
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2099
2133
|
/** Delete this message. */
|
|
2100
2134
|
async delete(reason) {
|
|
2101
2135
|
await this.client.rest.delete(import_types7.Routes.channelMessage(this.channelId, this.id), {
|
|
@@ -2198,6 +2232,43 @@ var PartialMessage = class {
|
|
|
2198
2232
|
}
|
|
2199
2233
|
};
|
|
2200
2234
|
|
|
2235
|
+
// src/ClientCore/Resolve.ts
|
|
2236
|
+
function normalizeSnowflakeId(value, label) {
|
|
2237
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
2238
|
+
throw new TypeError(
|
|
2239
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
2243
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
2244
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
2245
|
+
}
|
|
2246
|
+
return id;
|
|
2247
|
+
}
|
|
2248
|
+
function assertApiObjectWithId(data, label) {
|
|
2249
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
2250
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
2251
|
+
}
|
|
2252
|
+
return data;
|
|
2253
|
+
}
|
|
2254
|
+
function assertApiArray(data, label) {
|
|
2255
|
+
if (!Array.isArray(data)) {
|
|
2256
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
2257
|
+
}
|
|
2258
|
+
return data;
|
|
2259
|
+
}
|
|
2260
|
+
async function dedupeFetch(pending, key, fn) {
|
|
2261
|
+
const existing = pending.get(key);
|
|
2262
|
+
if (existing) return existing;
|
|
2263
|
+
const request = fn();
|
|
2264
|
+
pending.set(key, request);
|
|
2265
|
+
try {
|
|
2266
|
+
return await request;
|
|
2267
|
+
} finally {
|
|
2268
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2201
2272
|
// src/ClientCore/MessageManager.ts
|
|
2202
2273
|
var BULK = {
|
|
2203
2274
|
requests: { min: 1, max: 25 },
|
|
@@ -2234,25 +2305,32 @@ var MessageManager = class {
|
|
|
2234
2305
|
}
|
|
2235
2306
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
2236
2307
|
_structures = new import_collection4.Collection();
|
|
2308
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
2237
2309
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
2238
2310
|
get(messageId) {
|
|
2239
|
-
const
|
|
2311
|
+
const id = String(messageId ?? "").trim();
|
|
2312
|
+
if (!id) return void 0;
|
|
2313
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
2240
2314
|
if (!data) {
|
|
2241
|
-
this._structures.delete(
|
|
2315
|
+
this._structures.delete(id);
|
|
2242
2316
|
return void 0;
|
|
2243
2317
|
}
|
|
2244
|
-
const existing = this._structures.get(
|
|
2245
|
-
if (existing)
|
|
2318
|
+
const existing = this._structures.get(id);
|
|
2319
|
+
if (existing) {
|
|
2320
|
+
existing._patch(data);
|
|
2321
|
+
return existing;
|
|
2322
|
+
}
|
|
2246
2323
|
const message = new Message(this.client, data);
|
|
2247
|
-
this._structures.set(
|
|
2324
|
+
this._structures.set(id, message);
|
|
2248
2325
|
return message;
|
|
2249
2326
|
}
|
|
2250
2327
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
2251
2328
|
async resolve(messageId) {
|
|
2252
|
-
|
|
2329
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
2330
|
+
return this.get(id) ?? this.fetch(id);
|
|
2253
2331
|
}
|
|
2254
2332
|
async fetch(idOrOptions) {
|
|
2255
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
2333
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
2256
2334
|
}
|
|
2257
2335
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
2258
2336
|
wrap(data) {
|
|
@@ -2269,9 +2347,13 @@ var MessageManager = class {
|
|
|
2269
2347
|
}
|
|
2270
2348
|
/** Fetch a single message from the API. */
|
|
2271
2349
|
async fetchOne(messageId) {
|
|
2350
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
2351
|
+
}
|
|
2352
|
+
async fetchOneFresh(messageId) {
|
|
2272
2353
|
try {
|
|
2273
|
-
const data =
|
|
2274
|
-
import_types8.Routes.channelMessage(this.channelId, messageId)
|
|
2354
|
+
const data = assertApiObjectWithId(
|
|
2355
|
+
await this.client.rest.get(import_types8.Routes.channelMessage(this.channelId, messageId)),
|
|
2356
|
+
"messages.fetch()"
|
|
2275
2357
|
);
|
|
2276
2358
|
return this.wrap(data);
|
|
2277
2359
|
} catch (err) {
|
|
@@ -2297,9 +2379,15 @@ var MessageManager = class {
|
|
|
2297
2379
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
2298
2380
|
}
|
|
2299
2381
|
const base = import_types8.Routes.channelMessages(this.channelId);
|
|
2300
|
-
const data =
|
|
2382
|
+
const data = assertApiArray(
|
|
2383
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
2384
|
+
"messages.fetch()"
|
|
2385
|
+
);
|
|
2301
2386
|
const collection = new import_collection4.Collection();
|
|
2302
|
-
for (const msg of data)
|
|
2387
|
+
for (const msg of data) {
|
|
2388
|
+
if (!msg?.id) continue;
|
|
2389
|
+
collection.set(msg.id, this.wrap(msg));
|
|
2390
|
+
}
|
|
2303
2391
|
return collection;
|
|
2304
2392
|
}
|
|
2305
2393
|
};
|
|
@@ -2503,6 +2591,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
2503
2591
|
}
|
|
2504
2592
|
|
|
2505
2593
|
// src/Domain/Channel/Base.ts
|
|
2594
|
+
function isFullChannelData(data) {
|
|
2595
|
+
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;
|
|
2596
|
+
}
|
|
2506
2597
|
var Channel = class extends Base {
|
|
2507
2598
|
#messages;
|
|
2508
2599
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -2517,6 +2608,11 @@ var Channel = class extends Base {
|
|
|
2517
2608
|
icon;
|
|
2518
2609
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
2519
2610
|
lastPinTimestamp;
|
|
2611
|
+
/**
|
|
2612
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
2613
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
2614
|
+
*/
|
|
2615
|
+
partial;
|
|
2520
2616
|
constructor(client, data) {
|
|
2521
2617
|
super();
|
|
2522
2618
|
this.client = client;
|
|
@@ -2525,6 +2621,7 @@ var Channel = class extends Base {
|
|
|
2525
2621
|
this.name = data.name ?? null;
|
|
2526
2622
|
this.icon = data.icon ?? null;
|
|
2527
2623
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
2624
|
+
this.partial = !isFullChannelData(data);
|
|
2528
2625
|
}
|
|
2529
2626
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
2530
2627
|
get createdTimestamp() {
|
|
@@ -2545,6 +2642,7 @@ var Channel = class extends Base {
|
|
|
2545
2642
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
2546
2643
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
2547
2644
|
}
|
|
2645
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
2548
2646
|
}
|
|
2549
2647
|
/** @internal Factory wired after subclasses load. */
|
|
2550
2648
|
static from(_c, _d) {
|
|
@@ -2836,7 +2934,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2836
2934
|
const full = data;
|
|
2837
2935
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2838
2936
|
this.ownerId = full.owner_id ?? null;
|
|
2839
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2937
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2840
2938
|
this.nicks = full.nicks ?? {};
|
|
2841
2939
|
}
|
|
2842
2940
|
/**
|
|
@@ -2851,7 +2949,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2851
2949
|
}
|
|
2852
2950
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2853
2951
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2854
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2952
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2855
2953
|
}
|
|
2856
2954
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2857
2955
|
}
|
|
@@ -2928,17 +3026,19 @@ var import_types13 = require("@fluxerjs/types");
|
|
|
2928
3026
|
// src/Helpers/Instance.ts
|
|
2929
3027
|
var import_util9 = require("@fluxerjs/util");
|
|
2930
3028
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2931
|
-
api: "https://
|
|
2932
|
-
api_client: "https://
|
|
2933
|
-
api_public: "https://
|
|
2934
|
-
gateway: "wss://gateway.fluxer.
|
|
3029
|
+
api: "https://fluxer.com/api",
|
|
3030
|
+
api_client: "https://fluxer.com/api",
|
|
3031
|
+
api_public: "https://fluxer.com/api",
|
|
3032
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2935
3033
|
media: CDN_URL,
|
|
3034
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2936
3035
|
static_cdn: STATIC_CDN_URL,
|
|
2937
|
-
marketing: "https://fluxer.
|
|
3036
|
+
marketing: "https://fluxer.com",
|
|
3037
|
+
docs: "https://docs.fluxer.com",
|
|
2938
3038
|
admin: "https://admin.fluxer.app",
|
|
2939
3039
|
invite: "https://fluxer.gg",
|
|
2940
3040
|
gift: "https://fluxer.gift",
|
|
2941
|
-
webapp: "https://
|
|
3041
|
+
webapp: "https://fluxer.com"
|
|
2942
3042
|
});
|
|
2943
3043
|
var ENDPOINT_KEYS = [
|
|
2944
3044
|
"api",
|
|
@@ -2953,6 +3053,11 @@ var ENDPOINT_KEYS = [
|
|
|
2953
3053
|
"gift",
|
|
2954
3054
|
"webapp"
|
|
2955
3055
|
];
|
|
3056
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
3057
|
+
"api_transport",
|
|
3058
|
+
"upload_relay",
|
|
3059
|
+
"docs"
|
|
3060
|
+
];
|
|
2956
3061
|
function requireString(obj, key, path) {
|
|
2957
3062
|
const value = obj[key];
|
|
2958
3063
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2993,6 +3098,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2993
3098
|
for (const key of ENDPOINT_KEYS) {
|
|
2994
3099
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2995
3100
|
}
|
|
3101
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
3102
|
+
const value = raw.endpoints[key];
|
|
3103
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
3104
|
+
}
|
|
2996
3105
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2997
3106
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2998
3107
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -3046,7 +3155,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
3046
3155
|
defaultsHash: ""
|
|
3047
3156
|
},
|
|
3048
3157
|
push: raw.push ?? { public_vapid_key: null },
|
|
3049
|
-
app_public: raw.app_public ?? {}
|
|
3158
|
+
app_public: raw.app_public ?? {},
|
|
3159
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
3160
|
+
age_policy: (0, import_util9.isRecord)(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
3161
|
+
...raw.notice === null || (0, import_util9.isRecord)(raw.notice) ? { notice: raw.notice } : {},
|
|
3162
|
+
...(0, import_util9.isRecord)(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
3163
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
3164
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
3165
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
3166
|
+
...(0, import_util9.isRecord)(raw.built_in_guild_badge_images) ? {
|
|
3167
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
3168
|
+
} : {},
|
|
3169
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
3170
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
3171
|
+
} : {},
|
|
3172
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
3050
3173
|
};
|
|
3051
3174
|
}
|
|
3052
3175
|
function resolveInstanceEndpoints(input) {
|
|
@@ -3066,7 +3189,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
3066
3189
|
}
|
|
3067
3190
|
const partial = input;
|
|
3068
3191
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
3069
|
-
for (const key of ENDPOINT_KEYS) {
|
|
3192
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
3070
3193
|
const value = partial[key];
|
|
3071
3194
|
if (typeof value === "string" && value.length > 0) {
|
|
3072
3195
|
merged[key] = value;
|
|
@@ -3683,6 +3806,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3683
3806
|
}
|
|
3684
3807
|
};
|
|
3685
3808
|
var AnnouncementChannel = class extends TextChannel {
|
|
3809
|
+
/**
|
|
3810
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3811
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3812
|
+
*/
|
|
3813
|
+
async follow(webhookChannelId) {
|
|
3814
|
+
return this.client.rest.post(
|
|
3815
|
+
import_types16.Routes.channelFollowers(this.id),
|
|
3816
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3817
|
+
);
|
|
3818
|
+
}
|
|
3819
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3820
|
+
async fetchFollowerStats() {
|
|
3821
|
+
return this.client.rest.get(
|
|
3822
|
+
import_types16.Routes.channelFollowerStats(this.id),
|
|
3823
|
+
{ auth: true }
|
|
3824
|
+
);
|
|
3825
|
+
}
|
|
3686
3826
|
};
|
|
3687
3827
|
var CategoryChannel = class extends GuildChannel {
|
|
3688
3828
|
};
|
|
@@ -3709,6 +3849,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3709
3849
|
voiceConnectionLimit;
|
|
3710
3850
|
/** RTC region override for this channel. */
|
|
3711
3851
|
rtcRegion;
|
|
3852
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3853
|
+
rtcP2p;
|
|
3712
3854
|
constructor(client, data) {
|
|
3713
3855
|
super(client, data);
|
|
3714
3856
|
this.topic = data.topic ?? null;
|
|
@@ -3722,6 +3864,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3722
3864
|
this.userLimit = data.user_limit ?? null;
|
|
3723
3865
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3724
3866
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3867
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3725
3868
|
}
|
|
3726
3869
|
/**
|
|
3727
3870
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3748,6 +3891,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3748
3891
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3749
3892
|
}
|
|
3750
3893
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3894
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3751
3895
|
}
|
|
3752
3896
|
};
|
|
3753
3897
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -4801,6 +4945,8 @@ var Role = class _Role extends Base {
|
|
|
4801
4945
|
mentionable;
|
|
4802
4946
|
/** Unicode emoji for this role (null = none). */
|
|
4803
4947
|
unicodeEmoji;
|
|
4948
|
+
/** Role icon image hash (null = none). */
|
|
4949
|
+
icon;
|
|
4804
4950
|
/** Hoist position (null = not hoisted). */
|
|
4805
4951
|
hoistPosition;
|
|
4806
4952
|
constructor(client, data, guildId) {
|
|
@@ -4808,20 +4954,26 @@ var Role = class _Role extends Base {
|
|
|
4808
4954
|
this.client = client;
|
|
4809
4955
|
this.id = data.id;
|
|
4810
4956
|
this.guildId = guildId;
|
|
4811
|
-
this.name = data.name;
|
|
4812
|
-
this.color = data.color;
|
|
4813
|
-
this.position = data.position;
|
|
4814
|
-
this._permissions = data.permissions;
|
|
4957
|
+
this.name = data.name ?? "";
|
|
4958
|
+
this.color = data.color ?? 0;
|
|
4959
|
+
this.position = data.position ?? 0;
|
|
4960
|
+
this._permissions = data.permissions ?? "0";
|
|
4815
4961
|
this.hoist = !!data.hoist;
|
|
4816
4962
|
this.mentionable = !!data.mentionable;
|
|
4817
4963
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4964
|
+
this.icon = data.icon ?? null;
|
|
4818
4965
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4819
4966
|
}
|
|
4820
4967
|
/**
|
|
4821
4968
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4822
4969
|
*/
|
|
4823
4970
|
get permissions() {
|
|
4824
|
-
|
|
4971
|
+
let bits;
|
|
4972
|
+
try {
|
|
4973
|
+
bits = BigInt(this._permissions ?? "0");
|
|
4974
|
+
} catch {
|
|
4975
|
+
bits = 0n;
|
|
4976
|
+
}
|
|
4825
4977
|
return new import_util18.PermissionsBitField(
|
|
4826
4978
|
(bits & import_util18.PermissionFlags.Administrator) !== 0n ? import_util18.ALL_PERMISSIONS_BIGINT : bits
|
|
4827
4979
|
);
|
|
@@ -4851,14 +5003,15 @@ var Role = class _Role extends Base {
|
|
|
4851
5003
|
}
|
|
4852
5004
|
/** @internal */
|
|
4853
5005
|
_patch(data) {
|
|
4854
|
-
this.name = data.name;
|
|
4855
|
-
this.color = data.color;
|
|
4856
|
-
this.position = data.position;
|
|
4857
|
-
this._permissions = data.permissions;
|
|
4858
|
-
this.hoist = !!data.hoist;
|
|
4859
|
-
this.mentionable = !!data.mentionable;
|
|
4860
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4861
|
-
this.
|
|
5006
|
+
if (data.name !== void 0) this.name = data.name;
|
|
5007
|
+
if (data.color !== void 0) this.color = data.color;
|
|
5008
|
+
if (data.position !== void 0) this.position = data.position;
|
|
5009
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
5010
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
5011
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
5012
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5013
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
5014
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4862
5015
|
}
|
|
4863
5016
|
/**
|
|
4864
5017
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4876,6 +5029,7 @@ var Role = class _Role extends Base {
|
|
|
4876
5029
|
hoist: this.hoist,
|
|
4877
5030
|
mentionable: this.mentionable,
|
|
4878
5031
|
unicode_emoji: this.unicodeEmoji,
|
|
5032
|
+
icon: this.icon,
|
|
4879
5033
|
hoist_position: this.hoistPosition
|
|
4880
5034
|
},
|
|
4881
5035
|
this.guildId
|
|
@@ -5053,6 +5207,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5053
5207
|
});
|
|
5054
5208
|
this.client = client;
|
|
5055
5209
|
}
|
|
5210
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5056
5211
|
/**
|
|
5057
5212
|
* Remove a channel from cache. Does not delete it on the API.
|
|
5058
5213
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -5065,9 +5220,11 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5065
5220
|
}
|
|
5066
5221
|
return deleted;
|
|
5067
5222
|
}
|
|
5068
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5223
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
5069
5224
|
async resolve(channelId) {
|
|
5070
|
-
|
|
5225
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5226
|
+
const cached = this.get(id);
|
|
5227
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
5071
5228
|
}
|
|
5072
5229
|
/**
|
|
5073
5230
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5080,10 +5237,23 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5080
5237
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5081
5238
|
*/
|
|
5082
5239
|
async fetch(channelId, options) {
|
|
5083
|
-
const
|
|
5084
|
-
|
|
5240
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5241
|
+
const cached = this.get(id);
|
|
5242
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5243
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5244
|
+
}
|
|
5245
|
+
async fetchFresh(channelId) {
|
|
5085
5246
|
try {
|
|
5086
|
-
const data =
|
|
5247
|
+
const data = assertApiObjectWithId(
|
|
5248
|
+
await this.client.rest.get(import_types28.Routes.channel(channelId)),
|
|
5249
|
+
"channels.fetch()"
|
|
5250
|
+
);
|
|
5251
|
+
const existing = this.get(channelId);
|
|
5252
|
+
if (existing && existing.type === data.type) {
|
|
5253
|
+
existing._patch(data);
|
|
5254
|
+
putChannel(this.client, existing);
|
|
5255
|
+
return existing;
|
|
5256
|
+
}
|
|
5087
5257
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5088
5258
|
if (guildId) {
|
|
5089
5259
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5168,12 +5338,15 @@ var User = class extends Base {
|
|
|
5168
5338
|
system;
|
|
5169
5339
|
/** Banner hash for profile. */
|
|
5170
5340
|
banner;
|
|
5341
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
5342
|
+
partial;
|
|
5171
5343
|
constructor(client, data) {
|
|
5172
5344
|
super();
|
|
5173
5345
|
this.client = client;
|
|
5174
5346
|
this.id = data.id;
|
|
5175
|
-
this.
|
|
5176
|
-
this.
|
|
5347
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
5348
|
+
this.username = data.username ?? "Unknown";
|
|
5349
|
+
this.discriminator = data.discriminator ?? "0";
|
|
5177
5350
|
this.globalName = data.global_name ?? null;
|
|
5178
5351
|
this.avatar = data.avatar ?? null;
|
|
5179
5352
|
this.bot = !!data.bot;
|
|
@@ -5184,13 +5357,18 @@ var User = class extends Base {
|
|
|
5184
5357
|
}
|
|
5185
5358
|
/** @internal */
|
|
5186
5359
|
_patch(data) {
|
|
5187
|
-
this.username = data.username;
|
|
5188
|
-
this.discriminator = data.discriminator;
|
|
5189
|
-
this.globalName = data.global_name ?? null;
|
|
5190
|
-
this.avatar = data.avatar ?? null;
|
|
5360
|
+
if (data.username !== void 0) this.username = data.username;
|
|
5361
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
5362
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
5363
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
5191
5364
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
5192
5365
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
5193
5366
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
5367
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
5368
|
+
}
|
|
5369
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
5370
|
+
async fetch() {
|
|
5371
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
5194
5372
|
}
|
|
5195
5373
|
cdnOpts() {
|
|
5196
5374
|
return {
|
|
@@ -5432,6 +5610,68 @@ async function searchMessages(client, options = {}) {
|
|
|
5432
5610
|
});
|
|
5433
5611
|
return toMessageSearchResponse(data);
|
|
5434
5612
|
}
|
|
5613
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5614
|
+
return client.rest.get(
|
|
5615
|
+
import_types30.Routes.emojiSource(emojiId),
|
|
5616
|
+
{ auth: true }
|
|
5617
|
+
);
|
|
5618
|
+
}
|
|
5619
|
+
function fetchStickerSource(client, stickerId) {
|
|
5620
|
+
return client.rest.get(
|
|
5621
|
+
import_types30.Routes.stickerSource(stickerId),
|
|
5622
|
+
{ auth: true }
|
|
5623
|
+
);
|
|
5624
|
+
}
|
|
5625
|
+
function fetchDiscoveryCategories(client) {
|
|
5626
|
+
return client.rest.get(
|
|
5627
|
+
import_types30.Routes.discoveryCategories(),
|
|
5628
|
+
{ auth: true }
|
|
5629
|
+
);
|
|
5630
|
+
}
|
|
5631
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5632
|
+
const params = new URLSearchParams();
|
|
5633
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5634
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5635
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5636
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5637
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5638
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5639
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5640
|
+
const qs2 = params.toString();
|
|
5641
|
+
return client.rest.get(
|
|
5642
|
+
qs2 ? `${import_types30.Routes.discoveryGuilds()}?${qs2}` : import_types30.Routes.discoveryGuilds(),
|
|
5643
|
+
{ auth: true }
|
|
5644
|
+
);
|
|
5645
|
+
}
|
|
5646
|
+
function fetchExperiments(client) {
|
|
5647
|
+
return client.rest.get(import_types30.Routes.experiments(), {
|
|
5648
|
+
auth: true
|
|
5649
|
+
});
|
|
5650
|
+
}
|
|
5651
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5652
|
+
return client.rest.post(
|
|
5653
|
+
import_types30.Routes.attachmentsRefreshUrls(),
|
|
5654
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5655
|
+
);
|
|
5656
|
+
}
|
|
5657
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5658
|
+
const params = new URLSearchParams();
|
|
5659
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5660
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5661
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5662
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5663
|
+
const qs2 = params.toString();
|
|
5664
|
+
return client.rest.get(
|
|
5665
|
+
qs2 ? `${import_types30.Routes.instanceBadges()}?${qs2}` : import_types30.Routes.instanceBadges(),
|
|
5666
|
+
{ auth: false }
|
|
5667
|
+
);
|
|
5668
|
+
}
|
|
5669
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5670
|
+
return client.rest.post(
|
|
5671
|
+
import_types30.Routes.channelPostData(channelId),
|
|
5672
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5673
|
+
);
|
|
5674
|
+
}
|
|
5435
5675
|
|
|
5436
5676
|
// src/ClientCore/ClientEvents.ts
|
|
5437
5677
|
function createEventMethods(client) {
|
|
@@ -5462,6 +5702,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5462
5702
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5463
5703
|
this.guild = guild;
|
|
5464
5704
|
}
|
|
5705
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5465
5706
|
/**
|
|
5466
5707
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5467
5708
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5473,7 +5714,9 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5473
5714
|
* console.log(member.displayName);
|
|
5474
5715
|
*/
|
|
5475
5716
|
async resolve(userId) {
|
|
5476
|
-
|
|
5717
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5718
|
+
const cached = this.get(id);
|
|
5719
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5477
5720
|
}
|
|
5478
5721
|
/**
|
|
5479
5722
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5501,10 +5744,11 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5501
5744
|
return this.guild.fetchMe();
|
|
5502
5745
|
}
|
|
5503
5746
|
async fetch(userIdOrOptions, options) {
|
|
5504
|
-
if (typeof userIdOrOptions === "string") {
|
|
5505
|
-
const
|
|
5506
|
-
|
|
5507
|
-
|
|
5747
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5748
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5749
|
+
const cached = this.get(id);
|
|
5750
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5751
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5508
5752
|
}
|
|
5509
5753
|
return this.fetchMany(userIdOrOptions);
|
|
5510
5754
|
}
|
|
@@ -5514,9 +5758,13 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5514
5758
|
if (options?.after) params.set("after", options.after);
|
|
5515
5759
|
const qs2 = params.toString();
|
|
5516
5760
|
const url = import_types31.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5517
|
-
const data =
|
|
5761
|
+
const data = assertApiArray(
|
|
5762
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5763
|
+
"members.fetch()"
|
|
5764
|
+
);
|
|
5518
5765
|
const members = [];
|
|
5519
5766
|
for (const m of data) {
|
|
5767
|
+
if (!m?.user?.id) continue;
|
|
5520
5768
|
const member = new GuildMember(
|
|
5521
5769
|
this.guild.client,
|
|
5522
5770
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5682,7 +5930,12 @@ async function createChannel(guild, options) {
|
|
|
5682
5930
|
return cacheChannel(guild, created);
|
|
5683
5931
|
}
|
|
5684
5932
|
async function fetchChannels(guild) {
|
|
5685
|
-
const
|
|
5933
|
+
const raw = await guild.client.rest.get(import_types33.Routes.guildChannels(guild.id));
|
|
5934
|
+
if (!Array.isArray(raw))
|
|
5935
|
+
throw new TypeError(
|
|
5936
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
5937
|
+
);
|
|
5938
|
+
const data = raw;
|
|
5686
5939
|
const channels = [];
|
|
5687
5940
|
for (const ch of data) {
|
|
5688
5941
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5777,16 +6030,20 @@ var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
|
5777
6030
|
// src/Domain/Guild/MemberHttp.ts
|
|
5778
6031
|
var import_types35 = require("@fluxerjs/types");
|
|
5779
6032
|
async function fetchMember(guild, userId) {
|
|
6033
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5780
6034
|
try {
|
|
5781
6035
|
const data = await guild.client.rest.get(
|
|
5782
|
-
import_types35.Routes.guildMember(guild.id,
|
|
6036
|
+
import_types35.Routes.guildMember(guild.id, id)
|
|
5783
6037
|
);
|
|
6038
|
+
if (!data?.user?.id) {
|
|
6039
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
6040
|
+
}
|
|
5784
6041
|
return cacheMember(guild, data);
|
|
5785
6042
|
} catch (err) {
|
|
5786
6043
|
rethrowMapped(err, {
|
|
5787
6044
|
notFound: {
|
|
5788
6045
|
code: import_util3.ErrorCodes.MemberNotFound,
|
|
5789
|
-
message: `Member ${
|
|
6046
|
+
message: `Member ${id} not found in guild`
|
|
5790
6047
|
},
|
|
5791
6048
|
fallback: "Failed to fetch guild member"
|
|
5792
6049
|
});
|
|
@@ -5797,6 +6054,9 @@ async function fetchMe(guild) {
|
|
|
5797
6054
|
import_types35.Routes.guildMemberMe(guild.id),
|
|
5798
6055
|
{ auth: true }
|
|
5799
6056
|
);
|
|
6057
|
+
if (!data?.user?.id) {
|
|
6058
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
6059
|
+
}
|
|
5800
6060
|
return cacheMember(guild, data);
|
|
5801
6061
|
}
|
|
5802
6062
|
|
|
@@ -5847,6 +6107,10 @@ async function ban(guild, userId, options) {
|
|
|
5847
6107
|
...auditReasonHeaders(options?.reason)
|
|
5848
6108
|
});
|
|
5849
6109
|
}
|
|
6110
|
+
async function fetchBan(guild, userId) {
|
|
6111
|
+
const data = await guild.client.rest.get(import_types37.Routes.guildBan(guild.id, userId));
|
|
6112
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
6113
|
+
}
|
|
5850
6114
|
async function fetchBans(guild) {
|
|
5851
6115
|
const data = await guild.client.rest.get(import_types37.Routes.guildBans(guild.id));
|
|
5852
6116
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
@@ -5878,6 +6142,8 @@ async function createRole(guild, options = {}) {
|
|
|
5878
6142
|
}
|
|
5879
6143
|
async function fetchRoles(guild) {
|
|
5880
6144
|
const data = await guild.client.rest.get(import_types38.Routes.guildRoles(guild.id));
|
|
6145
|
+
if (!Array.isArray(data))
|
|
6146
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5881
6147
|
return data.map((r) => cacheRole(guild, r));
|
|
5882
6148
|
}
|
|
5883
6149
|
async function fetchRole(guild, roleId2) {
|
|
@@ -5977,6 +6243,11 @@ var Guild = class extends Base {
|
|
|
5977
6243
|
id;
|
|
5978
6244
|
/** Whether the guild is currently available through the gateway. */
|
|
5979
6245
|
available = true;
|
|
6246
|
+
/**
|
|
6247
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6248
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6249
|
+
*/
|
|
6250
|
+
partial = true;
|
|
5980
6251
|
/** Guild name. */
|
|
5981
6252
|
name;
|
|
5982
6253
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -6271,6 +6542,10 @@ var Guild = class extends Base {
|
|
|
6271
6542
|
ban(userId, options) {
|
|
6272
6543
|
return ban(this, userId, options);
|
|
6273
6544
|
}
|
|
6545
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6546
|
+
fetchBan(userId) {
|
|
6547
|
+
return fetchBan(this, userId);
|
|
6548
|
+
}
|
|
6274
6549
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6275
6550
|
fetchBans() {
|
|
6276
6551
|
return fetchBans(this);
|
|
@@ -6451,6 +6726,7 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6451
6726
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6452
6727
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6453
6728
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6729
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6454
6730
|
return { guild, created, recovered };
|
|
6455
6731
|
}
|
|
6456
6732
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6534,15 +6810,7 @@ var ClientUser = class extends User {
|
|
|
6534
6810
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6535
6811
|
var import_util24 = require("@fluxerjs/util");
|
|
6536
6812
|
function unknownUser(id) {
|
|
6537
|
-
return {
|
|
6538
|
-
id,
|
|
6539
|
-
username: "Unknown",
|
|
6540
|
-
discriminator: "0",
|
|
6541
|
-
global_name: null,
|
|
6542
|
-
avatar: null,
|
|
6543
|
-
avatar_color: null,
|
|
6544
|
-
flags: 0
|
|
6545
|
-
};
|
|
6813
|
+
return { id };
|
|
6546
6814
|
}
|
|
6547
6815
|
function indexMember(_client, guild, data) {
|
|
6548
6816
|
if (!data.user?.id) return null;
|
|
@@ -7223,6 +7491,9 @@ var passthroughHandlers = {
|
|
|
7223
7491
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7224
7492
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7225
7493
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7494
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7495
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7496
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7226
7497
|
TYPING_START(client, d) {
|
|
7227
7498
|
const data = d;
|
|
7228
7499
|
const payload = {
|
|
@@ -7413,29 +7684,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7413
7684
|
}
|
|
7414
7685
|
return dispatchGatewayPayload(client, payload);
|
|
7415
7686
|
}
|
|
7416
|
-
|
|
7687
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7688
|
+
function queueFor(client) {
|
|
7689
|
+
let queue = dispatchQueues.get(client);
|
|
7690
|
+
if (!queue) {
|
|
7691
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7692
|
+
dispatchQueues.set(client, queue);
|
|
7693
|
+
}
|
|
7694
|
+
return queue;
|
|
7695
|
+
}
|
|
7696
|
+
async function runGatewayHandler(client, payload) {
|
|
7417
7697
|
const event = payload.t;
|
|
7418
|
-
if (!event) return
|
|
7698
|
+
if (!event) return;
|
|
7419
7699
|
const handler = eventHandlers.get(event);
|
|
7420
7700
|
if (!handler) {
|
|
7421
7701
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7422
|
-
return
|
|
7702
|
+
return;
|
|
7423
7703
|
}
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
}
|
|
7431
|
-
if (client.options.gatewayDeferHandlers
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
};
|
|
7436
|
-
|
|
7437
|
-
|
|
7704
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7705
|
+
client.emit(
|
|
7706
|
+
Events.Debug,
|
|
7707
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7708
|
+
);
|
|
7709
|
+
return;
|
|
7710
|
+
}
|
|
7711
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7712
|
+
await new Promise((resolve) => {
|
|
7713
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7714
|
+
else setTimeout(resolve, 0);
|
|
7715
|
+
});
|
|
7716
|
+
}
|
|
7717
|
+
try {
|
|
7718
|
+
await handler(client, payload.d);
|
|
7719
|
+
} catch (err) {
|
|
7720
|
+
emitClientError(client, err);
|
|
7721
|
+
}
|
|
7722
|
+
}
|
|
7723
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7724
|
+
const queue = queueFor(client);
|
|
7725
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7726
|
+
queue.pending++;
|
|
7727
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7728
|
+
queue.pending--;
|
|
7729
|
+
});
|
|
7730
|
+
queue.tail = run.catch(() => {
|
|
7731
|
+
});
|
|
7732
|
+
return run;
|
|
7733
|
+
}
|
|
7734
|
+
queue.pending++;
|
|
7735
|
+
const next = queue.tail.then(
|
|
7736
|
+
() => runGatewayHandler(client, payload),
|
|
7737
|
+
() => runGatewayHandler(client, payload)
|
|
7738
|
+
).finally(() => {
|
|
7739
|
+
queue.pending--;
|
|
7438
7740
|
});
|
|
7741
|
+
queue.tail = next.catch(() => {
|
|
7742
|
+
});
|
|
7743
|
+
return next;
|
|
7439
7744
|
}
|
|
7440
7745
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7441
7746
|
while (deferred.length > 0) {
|
|
@@ -7623,6 +7928,7 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7623
7928
|
});
|
|
7624
7929
|
this.client = client;
|
|
7625
7930
|
}
|
|
7931
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7626
7932
|
/**
|
|
7627
7933
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7628
7934
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7637,35 +7943,73 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7637
7943
|
}
|
|
7638
7944
|
/**
|
|
7639
7945
|
* Get a guild from cache or fetch from the API if not present.
|
|
7946
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7640
7947
|
* @param guildId - Snowflake of the guild
|
|
7641
7948
|
* @returns The guild
|
|
7642
7949
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7643
7950
|
*/
|
|
7644
7951
|
async resolve(guildId) {
|
|
7645
|
-
|
|
7952
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
7953
|
+
const cached = this.get(id);
|
|
7954
|
+
if (cached && !cached.partial) return cached;
|
|
7955
|
+
if (cached) {
|
|
7956
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7957
|
+
await this.hydrate(cached);
|
|
7958
|
+
return cached;
|
|
7959
|
+
});
|
|
7960
|
+
return cached;
|
|
7961
|
+
}
|
|
7962
|
+
const guild = await this.fetch(id);
|
|
7963
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7964
|
+
await this.hydrate(guild);
|
|
7965
|
+
return guild;
|
|
7966
|
+
});
|
|
7967
|
+
return guild;
|
|
7646
7968
|
}
|
|
7647
7969
|
/**
|
|
7648
7970
|
* Fetch a guild by ID.
|
|
7649
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7971
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7972
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7650
7973
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7651
7974
|
*/
|
|
7652
7975
|
async fetch(guildId, options) {
|
|
7653
|
-
const
|
|
7976
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
7977
|
+
const cached = this.get(id);
|
|
7654
7978
|
if (cached && !options?.force) return cached;
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7979
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
7980
|
+
try {
|
|
7981
|
+
const data = assertApiObjectWithId(
|
|
7982
|
+
await this.client.rest.get(import_types43.Routes.guild(id)),
|
|
7983
|
+
"guilds.fetch()"
|
|
7984
|
+
);
|
|
7985
|
+
let guild;
|
|
7986
|
+
const existing = this.get(id);
|
|
7987
|
+
if (existing) {
|
|
7988
|
+
existing._patch(data);
|
|
7989
|
+
guild = existing;
|
|
7990
|
+
} else {
|
|
7991
|
+
guild = new Guild(this.client, data);
|
|
7992
|
+
this.set(guild.id, guild);
|
|
7993
|
+
}
|
|
7994
|
+
return guild;
|
|
7995
|
+
} catch (err) {
|
|
7996
|
+
rethrowMapped(err, {
|
|
7997
|
+
notFound: { code: import_util3.ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
7998
|
+
fallback: `Failed to fetch guild ${id}`
|
|
7999
|
+
});
|
|
7660
8000
|
}
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
8001
|
+
});
|
|
8002
|
+
}
|
|
8003
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
8004
|
+
async hydrate(guild) {
|
|
8005
|
+
try {
|
|
8006
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
8007
|
+
guild.partial = false;
|
|
7664
8008
|
} catch (err) {
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
8009
|
+
this.client.emit(
|
|
8010
|
+
Events.Debug,
|
|
8011
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
8012
|
+
);
|
|
7669
8013
|
}
|
|
7670
8014
|
}
|
|
7671
8015
|
};
|
|
@@ -7690,6 +8034,10 @@ var MessageCache = class {
|
|
|
7690
8034
|
if (limit === false) return;
|
|
7691
8035
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7692
8036
|
let cache = this.caches.get(channelId);
|
|
8037
|
+
if (cache) {
|
|
8038
|
+
this.caches.delete(channelId);
|
|
8039
|
+
this.caches.set(channelId, cache);
|
|
8040
|
+
}
|
|
7693
8041
|
if (!cache) {
|
|
7694
8042
|
const channelLimit = this.getChannelLimit();
|
|
7695
8043
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7747,6 +8095,7 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7747
8095
|
super({ maxSize: client.cache.limits.users });
|
|
7748
8096
|
this.client = client;
|
|
7749
8097
|
}
|
|
8098
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7750
8099
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7751
8100
|
sweep(filter) {
|
|
7752
8101
|
let removed = 0;
|
|
@@ -7760,16 +8109,30 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7760
8109
|
}
|
|
7761
8110
|
return removed;
|
|
7762
8111
|
}
|
|
7763
|
-
/**
|
|
8112
|
+
/**
|
|
8113
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
8114
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
8115
|
+
*/
|
|
7764
8116
|
async fetch(userId, options) {
|
|
7765
|
-
const
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
return
|
|
8117
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
8118
|
+
const cached = this.get(id);
|
|
8119
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
8120
|
+
return dedupeFetch(
|
|
8121
|
+
this.pendingFetches,
|
|
8122
|
+
id,
|
|
8123
|
+
async () => this.client.getOrCreateUser(
|
|
8124
|
+
assertApiObjectWithId(
|
|
8125
|
+
await this.client.rest.get(import_types44.Routes.user(id)),
|
|
8126
|
+
"users.fetch()"
|
|
8127
|
+
)
|
|
8128
|
+
)
|
|
8129
|
+
);
|
|
7769
8130
|
}
|
|
7770
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8131
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7771
8132
|
async resolve(userId) {
|
|
7772
|
-
|
|
8133
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8134
|
+
const cached = this.get(id);
|
|
8135
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7773
8136
|
}
|
|
7774
8137
|
/**
|
|
7775
8138
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7910,7 +8273,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7910
8273
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7911
8274
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7912
8275
|
*
|
|
7913
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8276
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7914
8277
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7915
8278
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7916
8279
|
*/
|
|
@@ -7987,6 +8350,38 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7987
8350
|
fetchStickerMetadata(stickerId) {
|
|
7988
8351
|
return fetchStickerMetadata(this, stickerId);
|
|
7989
8352
|
}
|
|
8353
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8354
|
+
fetchEmojiSource(emojiId) {
|
|
8355
|
+
return fetchEmojiSource(this, emojiId);
|
|
8356
|
+
}
|
|
8357
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8358
|
+
fetchStickerSource(stickerId) {
|
|
8359
|
+
return fetchStickerSource(this, stickerId);
|
|
8360
|
+
}
|
|
8361
|
+
/** List discovery categories. */
|
|
8362
|
+
fetchDiscoveryCategories() {
|
|
8363
|
+
return fetchDiscoveryCategories(this);
|
|
8364
|
+
}
|
|
8365
|
+
/** Search discoverable guilds. */
|
|
8366
|
+
searchDiscoveryGuilds(options) {
|
|
8367
|
+
return searchDiscoveryGuilds(this, options);
|
|
8368
|
+
}
|
|
8369
|
+
/** Fetch experiment assignments for this account. */
|
|
8370
|
+
fetchExperiments() {
|
|
8371
|
+
return fetchExperiments(this);
|
|
8372
|
+
}
|
|
8373
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8374
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8375
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8376
|
+
}
|
|
8377
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8378
|
+
fetchInstanceBadges(options) {
|
|
8379
|
+
return fetchInstanceBadges(this, options);
|
|
8380
|
+
}
|
|
8381
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8382
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8383
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8384
|
+
}
|
|
7990
8385
|
/**
|
|
7991
8386
|
* Fetch the current application (`/applications/@me`).
|
|
7992
8387
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -8081,6 +8476,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
8081
8476
|
* @internal
|
|
8082
8477
|
*/
|
|
8083
8478
|
getOrCreateUser(data) {
|
|
8479
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8480
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8481
|
+
}
|
|
8084
8482
|
const existing = this.users.get(data.id);
|
|
8085
8483
|
if (existing) {
|
|
8086
8484
|
existing._patch(data);
|