@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/client.js
CHANGED
|
@@ -969,6 +969,7 @@ var Events = {
|
|
|
969
969
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
970
970
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
971
971
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
972
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
972
973
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
973
974
|
GuildMemberAdd: "guildMemberAdd",
|
|
974
975
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -1003,6 +1004,8 @@ var Events = {
|
|
|
1003
1004
|
VoiceStateAck: "voiceStateAck",
|
|
1004
1005
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
1005
1006
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
1007
|
+
VoiceSignal: "voiceSignal",
|
|
1008
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
1006
1009
|
VoiceStatesSync: "voiceStatesSync",
|
|
1007
1010
|
WebhooksUpdate: "webhooksUpdate",
|
|
1008
1011
|
Resumed: "resumed",
|
|
@@ -1132,6 +1135,45 @@ var import_util5 = require("@fluxerjs/util");
|
|
|
1132
1135
|
// src/ClientCore/MessageManager.ts
|
|
1133
1136
|
var import_collection2 = require("@fluxerjs/collection");
|
|
1134
1137
|
var import_types5 = require("@fluxerjs/types");
|
|
1138
|
+
|
|
1139
|
+
// src/ClientCore/Resolve.ts
|
|
1140
|
+
function normalizeSnowflakeId(value, label) {
|
|
1141
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1142
|
+
throw new TypeError(
|
|
1143
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
1147
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
1148
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
1149
|
+
}
|
|
1150
|
+
return id;
|
|
1151
|
+
}
|
|
1152
|
+
function assertApiObjectWithId(data, label) {
|
|
1153
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
1154
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
1155
|
+
}
|
|
1156
|
+
return data;
|
|
1157
|
+
}
|
|
1158
|
+
function assertApiArray(data, label) {
|
|
1159
|
+
if (!Array.isArray(data)) {
|
|
1160
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
1161
|
+
}
|
|
1162
|
+
return data;
|
|
1163
|
+
}
|
|
1164
|
+
async function dedupeFetch(pending, key, fn) {
|
|
1165
|
+
const existing = pending.get(key);
|
|
1166
|
+
if (existing) return existing;
|
|
1167
|
+
const request = fn();
|
|
1168
|
+
pending.set(key, request);
|
|
1169
|
+
try {
|
|
1170
|
+
return await request;
|
|
1171
|
+
} finally {
|
|
1172
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// src/ClientCore/MessageManager.ts
|
|
1135
1177
|
var BULK = {
|
|
1136
1178
|
requests: { min: 1, max: 25 },
|
|
1137
1179
|
limit: { min: 1, max: 25 },
|
|
@@ -1167,25 +1209,32 @@ var MessageManager = class {
|
|
|
1167
1209
|
}
|
|
1168
1210
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1169
1211
|
_structures = new import_collection2.Collection();
|
|
1212
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
1170
1213
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1171
1214
|
get(messageId) {
|
|
1172
|
-
const
|
|
1215
|
+
const id = String(messageId ?? "").trim();
|
|
1216
|
+
if (!id) return void 0;
|
|
1217
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
1173
1218
|
if (!data) {
|
|
1174
|
-
this._structures.delete(
|
|
1219
|
+
this._structures.delete(id);
|
|
1175
1220
|
return void 0;
|
|
1176
1221
|
}
|
|
1177
|
-
const existing = this._structures.get(
|
|
1178
|
-
if (existing)
|
|
1222
|
+
const existing = this._structures.get(id);
|
|
1223
|
+
if (existing) {
|
|
1224
|
+
existing._patch(data);
|
|
1225
|
+
return existing;
|
|
1226
|
+
}
|
|
1179
1227
|
const message = new Message(this.client, data);
|
|
1180
|
-
this._structures.set(
|
|
1228
|
+
this._structures.set(id, message);
|
|
1181
1229
|
return message;
|
|
1182
1230
|
}
|
|
1183
1231
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1184
1232
|
async resolve(messageId) {
|
|
1185
|
-
|
|
1233
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
1234
|
+
return this.get(id) ?? this.fetch(id);
|
|
1186
1235
|
}
|
|
1187
1236
|
async fetch(idOrOptions) {
|
|
1188
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1237
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
1189
1238
|
}
|
|
1190
1239
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1191
1240
|
wrap(data) {
|
|
@@ -1202,9 +1251,13 @@ var MessageManager = class {
|
|
|
1202
1251
|
}
|
|
1203
1252
|
/** Fetch a single message from the API. */
|
|
1204
1253
|
async fetchOne(messageId) {
|
|
1254
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
1255
|
+
}
|
|
1256
|
+
async fetchOneFresh(messageId) {
|
|
1205
1257
|
try {
|
|
1206
|
-
const data =
|
|
1207
|
-
import_types5.Routes.channelMessage(this.channelId, messageId)
|
|
1258
|
+
const data = assertApiObjectWithId(
|
|
1259
|
+
await this.client.rest.get(import_types5.Routes.channelMessage(this.channelId, messageId)),
|
|
1260
|
+
"messages.fetch()"
|
|
1208
1261
|
);
|
|
1209
1262
|
return this.wrap(data);
|
|
1210
1263
|
} catch (err) {
|
|
@@ -1230,9 +1283,15 @@ var MessageManager = class {
|
|
|
1230
1283
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1231
1284
|
}
|
|
1232
1285
|
const base = import_types5.Routes.channelMessages(this.channelId);
|
|
1233
|
-
const data =
|
|
1286
|
+
const data = assertApiArray(
|
|
1287
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
1288
|
+
"messages.fetch()"
|
|
1289
|
+
);
|
|
1234
1290
|
const collection = new import_collection2.Collection();
|
|
1235
|
-
for (const msg of data)
|
|
1291
|
+
for (const msg of data) {
|
|
1292
|
+
if (!msg?.id) continue;
|
|
1293
|
+
collection.set(msg.id, this.wrap(msg));
|
|
1294
|
+
}
|
|
1236
1295
|
return collection;
|
|
1237
1296
|
}
|
|
1238
1297
|
};
|
|
@@ -1436,6 +1495,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1436
1495
|
}
|
|
1437
1496
|
|
|
1438
1497
|
// src/Domain/Channel/Base.ts
|
|
1498
|
+
function isFullChannelData(data) {
|
|
1499
|
+
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;
|
|
1500
|
+
}
|
|
1439
1501
|
var Channel = class extends Base {
|
|
1440
1502
|
#messages;
|
|
1441
1503
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -1450,6 +1512,11 @@ var Channel = class extends Base {
|
|
|
1450
1512
|
icon;
|
|
1451
1513
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
1452
1514
|
lastPinTimestamp;
|
|
1515
|
+
/**
|
|
1516
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
1517
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
1518
|
+
*/
|
|
1519
|
+
partial;
|
|
1453
1520
|
constructor(client, data) {
|
|
1454
1521
|
super();
|
|
1455
1522
|
this.client = client;
|
|
@@ -1458,6 +1525,7 @@ var Channel = class extends Base {
|
|
|
1458
1525
|
this.name = data.name ?? null;
|
|
1459
1526
|
this.icon = data.icon ?? null;
|
|
1460
1527
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1528
|
+
this.partial = !isFullChannelData(data);
|
|
1461
1529
|
}
|
|
1462
1530
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1463
1531
|
get createdTimestamp() {
|
|
@@ -1478,6 +1546,7 @@ var Channel = class extends Base {
|
|
|
1478
1546
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1479
1547
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1480
1548
|
}
|
|
1549
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
1481
1550
|
}
|
|
1482
1551
|
/** @internal Factory wired after subclasses load. */
|
|
1483
1552
|
static from(_c, _d) {
|
|
@@ -2253,10 +2322,10 @@ var Message = class _Message extends Base {
|
|
|
2253
2322
|
this.channelId = data.channel_id;
|
|
2254
2323
|
this.guildId = data.guild_id ?? null;
|
|
2255
2324
|
this.author = client.getOrCreateUser(data.author);
|
|
2256
|
-
this.content = data.content;
|
|
2257
|
-
this.createdAt = new Date(data.timestamp);
|
|
2325
|
+
this.content = data.content ?? "";
|
|
2326
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
2258
2327
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2259
|
-
this.pinned = data.pinned;
|
|
2328
|
+
this.pinned = data.pinned ?? false;
|
|
2260
2329
|
this.attachments = new import_collection5.Collection();
|
|
2261
2330
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2262
2331
|
this.type = data.type ?? import_types10.MessageType.Default;
|
|
@@ -2288,33 +2357,47 @@ var Message = class _Message extends Base {
|
|
|
2288
2357
|
* @internal
|
|
2289
2358
|
*/
|
|
2290
2359
|
_patch(data) {
|
|
2291
|
-
this.content = data.content;
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
this.
|
|
2302
|
-
this.
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2360
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
2361
|
+
if (data.edited_timestamp !== void 0) {
|
|
2362
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2363
|
+
}
|
|
2364
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
2365
|
+
if (data.attachments !== void 0) {
|
|
2366
|
+
this.attachments.clear();
|
|
2367
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2368
|
+
}
|
|
2369
|
+
if (data.flags !== void 0) this.flags = new import_util7.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
2370
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
2371
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
2372
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
2373
|
+
if (data.stickers !== void 0) {
|
|
2374
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
2375
|
+
}
|
|
2376
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
2377
|
+
if (data.message_reference !== void 0) {
|
|
2378
|
+
this.messageReference = data.message_reference ? {
|
|
2379
|
+
channelId: data.message_reference.channel_id,
|
|
2380
|
+
messageId: data.message_reference.message_id,
|
|
2381
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
2382
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
2383
|
+
} : null;
|
|
2384
|
+
}
|
|
2385
|
+
if (data.message_snapshots !== void 0) {
|
|
2386
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
2387
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
2388
|
+
);
|
|
2389
|
+
}
|
|
2390
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
2391
|
+
if (data.referenced_message !== void 0) {
|
|
2392
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
2393
|
+
}
|
|
2394
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
2395
|
+
if (data.mentions !== void 0) {
|
|
2396
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2397
|
+
}
|
|
2398
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
2399
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
2400
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
2318
2401
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
2319
2402
|
}
|
|
2320
2403
|
/**
|
|
@@ -2415,6 +2498,23 @@ var Message = class _Message extends Base {
|
|
|
2415
2498
|
async fetch() {
|
|
2416
2499
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2417
2500
|
}
|
|
2501
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2502
|
+
async crosspost() {
|
|
2503
|
+
const data = await this.client.rest.post(
|
|
2504
|
+
import_types10.Routes.channelMessageCrosspost(this.channelId, this.id),
|
|
2505
|
+
{ auth: true }
|
|
2506
|
+
);
|
|
2507
|
+
const published = new _Message(this.client, data);
|
|
2508
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2509
|
+
return published;
|
|
2510
|
+
}
|
|
2511
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2512
|
+
async fetchCrosspostSource() {
|
|
2513
|
+
return this.client.rest.get(
|
|
2514
|
+
import_types10.Routes.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2515
|
+
{ auth: true }
|
|
2516
|
+
);
|
|
2517
|
+
}
|
|
2418
2518
|
/** Delete this message. */
|
|
2419
2519
|
async delete(reason) {
|
|
2420
2520
|
await this.client.rest.delete(import_types10.Routes.channelMessage(this.channelId, this.id), {
|
|
@@ -2578,7 +2678,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2578
2678
|
const full = data;
|
|
2579
2679
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2580
2680
|
this.ownerId = full.owner_id ?? null;
|
|
2581
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2681
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2582
2682
|
this.nicks = full.nicks ?? {};
|
|
2583
2683
|
}
|
|
2584
2684
|
/**
|
|
@@ -2593,7 +2693,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2593
2693
|
}
|
|
2594
2694
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2595
2695
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2596
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2696
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2597
2697
|
}
|
|
2598
2698
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2599
2699
|
}
|
|
@@ -2670,17 +2770,19 @@ var import_types13 = require("@fluxerjs/types");
|
|
|
2670
2770
|
// src/Helpers/Instance.ts
|
|
2671
2771
|
var import_util9 = require("@fluxerjs/util");
|
|
2672
2772
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2673
|
-
api: "https://
|
|
2674
|
-
api_client: "https://
|
|
2675
|
-
api_public: "https://
|
|
2676
|
-
gateway: "wss://gateway.fluxer.
|
|
2773
|
+
api: "https://fluxer.com/api",
|
|
2774
|
+
api_client: "https://fluxer.com/api",
|
|
2775
|
+
api_public: "https://fluxer.com/api",
|
|
2776
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2677
2777
|
media: CDN_URL,
|
|
2778
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2678
2779
|
static_cdn: STATIC_CDN_URL,
|
|
2679
|
-
marketing: "https://fluxer.
|
|
2780
|
+
marketing: "https://fluxer.com",
|
|
2781
|
+
docs: "https://docs.fluxer.com",
|
|
2680
2782
|
admin: "https://admin.fluxer.app",
|
|
2681
2783
|
invite: "https://fluxer.gg",
|
|
2682
2784
|
gift: "https://fluxer.gift",
|
|
2683
|
-
webapp: "https://
|
|
2785
|
+
webapp: "https://fluxer.com"
|
|
2684
2786
|
});
|
|
2685
2787
|
var ENDPOINT_KEYS = [
|
|
2686
2788
|
"api",
|
|
@@ -2695,6 +2797,11 @@ var ENDPOINT_KEYS = [
|
|
|
2695
2797
|
"gift",
|
|
2696
2798
|
"webapp"
|
|
2697
2799
|
];
|
|
2800
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
2801
|
+
"api_transport",
|
|
2802
|
+
"upload_relay",
|
|
2803
|
+
"docs"
|
|
2804
|
+
];
|
|
2698
2805
|
function requireString(obj, key, path) {
|
|
2699
2806
|
const value = obj[key];
|
|
2700
2807
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2735,6 +2842,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2735
2842
|
for (const key of ENDPOINT_KEYS) {
|
|
2736
2843
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2737
2844
|
}
|
|
2845
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
2846
|
+
const value = raw.endpoints[key];
|
|
2847
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
2848
|
+
}
|
|
2738
2849
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2739
2850
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2740
2851
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -2788,7 +2899,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
2788
2899
|
defaultsHash: ""
|
|
2789
2900
|
},
|
|
2790
2901
|
push: raw.push ?? { public_vapid_key: null },
|
|
2791
|
-
app_public: raw.app_public ?? {}
|
|
2902
|
+
app_public: raw.app_public ?? {},
|
|
2903
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
2904
|
+
age_policy: (0, import_util9.isRecord)(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
2905
|
+
...raw.notice === null || (0, import_util9.isRecord)(raw.notice) ? { notice: raw.notice } : {},
|
|
2906
|
+
...(0, import_util9.isRecord)(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
2907
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
2908
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
2909
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
2910
|
+
...(0, import_util9.isRecord)(raw.built_in_guild_badge_images) ? {
|
|
2911
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
2912
|
+
} : {},
|
|
2913
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
2914
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
2915
|
+
} : {},
|
|
2916
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
2792
2917
|
};
|
|
2793
2918
|
}
|
|
2794
2919
|
function resolveInstanceEndpoints(input) {
|
|
@@ -2808,7 +2933,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
2808
2933
|
}
|
|
2809
2934
|
const partial = input;
|
|
2810
2935
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
2811
|
-
for (const key of ENDPOINT_KEYS) {
|
|
2936
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
2812
2937
|
const value = partial[key];
|
|
2813
2938
|
if (typeof value === "string" && value.length > 0) {
|
|
2814
2939
|
merged[key] = value;
|
|
@@ -3425,6 +3550,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3425
3550
|
}
|
|
3426
3551
|
};
|
|
3427
3552
|
var AnnouncementChannel = class extends TextChannel {
|
|
3553
|
+
/**
|
|
3554
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3555
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3556
|
+
*/
|
|
3557
|
+
async follow(webhookChannelId) {
|
|
3558
|
+
return this.client.rest.post(
|
|
3559
|
+
import_types16.Routes.channelFollowers(this.id),
|
|
3560
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3561
|
+
);
|
|
3562
|
+
}
|
|
3563
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3564
|
+
async fetchFollowerStats() {
|
|
3565
|
+
return this.client.rest.get(
|
|
3566
|
+
import_types16.Routes.channelFollowerStats(this.id),
|
|
3567
|
+
{ auth: true }
|
|
3568
|
+
);
|
|
3569
|
+
}
|
|
3428
3570
|
};
|
|
3429
3571
|
var CategoryChannel = class extends GuildChannel {
|
|
3430
3572
|
};
|
|
@@ -3451,6 +3593,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3451
3593
|
voiceConnectionLimit;
|
|
3452
3594
|
/** RTC region override for this channel. */
|
|
3453
3595
|
rtcRegion;
|
|
3596
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3597
|
+
rtcP2p;
|
|
3454
3598
|
constructor(client, data) {
|
|
3455
3599
|
super(client, data);
|
|
3456
3600
|
this.topic = data.topic ?? null;
|
|
@@ -3464,6 +3608,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3464
3608
|
this.userLimit = data.user_limit ?? null;
|
|
3465
3609
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3466
3610
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3611
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3467
3612
|
}
|
|
3468
3613
|
/**
|
|
3469
3614
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3490,6 +3635,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3490
3635
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3491
3636
|
}
|
|
3492
3637
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3638
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3493
3639
|
}
|
|
3494
3640
|
};
|
|
3495
3641
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -4055,12 +4201,15 @@ var User = class extends Base {
|
|
|
4055
4201
|
system;
|
|
4056
4202
|
/** Banner hash for profile. */
|
|
4057
4203
|
banner;
|
|
4204
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
4205
|
+
partial;
|
|
4058
4206
|
constructor(client, data) {
|
|
4059
4207
|
super();
|
|
4060
4208
|
this.client = client;
|
|
4061
4209
|
this.id = data.id;
|
|
4062
|
-
this.
|
|
4063
|
-
this.
|
|
4210
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
4211
|
+
this.username = data.username ?? "Unknown";
|
|
4212
|
+
this.discriminator = data.discriminator ?? "0";
|
|
4064
4213
|
this.globalName = data.global_name ?? null;
|
|
4065
4214
|
this.avatar = data.avatar ?? null;
|
|
4066
4215
|
this.bot = !!data.bot;
|
|
@@ -4071,13 +4220,18 @@ var User = class extends Base {
|
|
|
4071
4220
|
}
|
|
4072
4221
|
/** @internal */
|
|
4073
4222
|
_patch(data) {
|
|
4074
|
-
this.username = data.username;
|
|
4075
|
-
this.discriminator = data.discriminator;
|
|
4076
|
-
this.globalName = data.global_name ?? null;
|
|
4077
|
-
this.avatar = data.avatar ?? null;
|
|
4223
|
+
if (data.username !== void 0) this.username = data.username;
|
|
4224
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
4225
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
4226
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
4078
4227
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
4079
4228
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
4080
4229
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
4230
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
4231
|
+
}
|
|
4232
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
4233
|
+
async fetch() {
|
|
4234
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
4081
4235
|
}
|
|
4082
4236
|
cdnOpts() {
|
|
4083
4237
|
return {
|
|
@@ -4860,6 +5014,8 @@ var Role = class _Role extends Base {
|
|
|
4860
5014
|
mentionable;
|
|
4861
5015
|
/** Unicode emoji for this role (null = none). */
|
|
4862
5016
|
unicodeEmoji;
|
|
5017
|
+
/** Role icon image hash (null = none). */
|
|
5018
|
+
icon;
|
|
4863
5019
|
/** Hoist position (null = not hoisted). */
|
|
4864
5020
|
hoistPosition;
|
|
4865
5021
|
constructor(client, data, guildId) {
|
|
@@ -4867,20 +5023,26 @@ var Role = class _Role extends Base {
|
|
|
4867
5023
|
this.client = client;
|
|
4868
5024
|
this.id = data.id;
|
|
4869
5025
|
this.guildId = guildId;
|
|
4870
|
-
this.name = data.name;
|
|
4871
|
-
this.color = data.color;
|
|
4872
|
-
this.position = data.position;
|
|
4873
|
-
this._permissions = data.permissions;
|
|
5026
|
+
this.name = data.name ?? "";
|
|
5027
|
+
this.color = data.color ?? 0;
|
|
5028
|
+
this.position = data.position ?? 0;
|
|
5029
|
+
this._permissions = data.permissions ?? "0";
|
|
4874
5030
|
this.hoist = !!data.hoist;
|
|
4875
5031
|
this.mentionable = !!data.mentionable;
|
|
4876
5032
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5033
|
+
this.icon = data.icon ?? null;
|
|
4877
5034
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4878
5035
|
}
|
|
4879
5036
|
/**
|
|
4880
5037
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4881
5038
|
*/
|
|
4882
5039
|
get permissions() {
|
|
4883
|
-
|
|
5040
|
+
let bits;
|
|
5041
|
+
try {
|
|
5042
|
+
bits = BigInt(this._permissions ?? "0");
|
|
5043
|
+
} catch {
|
|
5044
|
+
bits = 0n;
|
|
5045
|
+
}
|
|
4884
5046
|
return new import_util19.PermissionsBitField(
|
|
4885
5047
|
(bits & import_util19.PermissionFlags.Administrator) !== 0n ? import_util19.ALL_PERMISSIONS_BIGINT : bits
|
|
4886
5048
|
);
|
|
@@ -4910,14 +5072,15 @@ var Role = class _Role extends Base {
|
|
|
4910
5072
|
}
|
|
4911
5073
|
/** @internal */
|
|
4912
5074
|
_patch(data) {
|
|
4913
|
-
this.name = data.name;
|
|
4914
|
-
this.color = data.color;
|
|
4915
|
-
this.position = data.position;
|
|
4916
|
-
this._permissions = data.permissions;
|
|
4917
|
-
this.hoist = !!data.hoist;
|
|
4918
|
-
this.mentionable = !!data.mentionable;
|
|
4919
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4920
|
-
this.
|
|
5075
|
+
if (data.name !== void 0) this.name = data.name;
|
|
5076
|
+
if (data.color !== void 0) this.color = data.color;
|
|
5077
|
+
if (data.position !== void 0) this.position = data.position;
|
|
5078
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
5079
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
5080
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
5081
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5082
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
5083
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4921
5084
|
}
|
|
4922
5085
|
/**
|
|
4923
5086
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4935,6 +5098,7 @@ var Role = class _Role extends Base {
|
|
|
4935
5098
|
hoist: this.hoist,
|
|
4936
5099
|
mentionable: this.mentionable,
|
|
4937
5100
|
unicode_emoji: this.unicodeEmoji,
|
|
5101
|
+
icon: this.icon,
|
|
4938
5102
|
hoist_position: this.hoistPosition
|
|
4939
5103
|
},
|
|
4940
5104
|
this.guildId
|
|
@@ -5112,6 +5276,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5112
5276
|
});
|
|
5113
5277
|
this.client = client;
|
|
5114
5278
|
}
|
|
5279
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5115
5280
|
/**
|
|
5116
5281
|
* Remove a channel from cache. Does not delete it on the API.
|
|
5117
5282
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -5124,9 +5289,11 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5124
5289
|
}
|
|
5125
5290
|
return deleted;
|
|
5126
5291
|
}
|
|
5127
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5292
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
5128
5293
|
async resolve(channelId) {
|
|
5129
|
-
|
|
5294
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5295
|
+
const cached = this.get(id);
|
|
5296
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
5130
5297
|
}
|
|
5131
5298
|
/**
|
|
5132
5299
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5139,10 +5306,23 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5139
5306
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5140
5307
|
*/
|
|
5141
5308
|
async fetch(channelId, options) {
|
|
5142
|
-
const
|
|
5143
|
-
|
|
5309
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5310
|
+
const cached = this.get(id);
|
|
5311
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5312
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5313
|
+
}
|
|
5314
|
+
async fetchFresh(channelId) {
|
|
5144
5315
|
try {
|
|
5145
|
-
const data =
|
|
5316
|
+
const data = assertApiObjectWithId(
|
|
5317
|
+
await this.client.rest.get(import_types29.Routes.channel(channelId)),
|
|
5318
|
+
"channels.fetch()"
|
|
5319
|
+
);
|
|
5320
|
+
const existing = this.get(channelId);
|
|
5321
|
+
if (existing && existing.type === data.type) {
|
|
5322
|
+
existing._patch(data);
|
|
5323
|
+
putChannel(this.client, existing);
|
|
5324
|
+
return existing;
|
|
5325
|
+
}
|
|
5146
5326
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5147
5327
|
if (guildId) {
|
|
5148
5328
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5309,6 +5489,68 @@ async function searchMessages(client, options = {}) {
|
|
|
5309
5489
|
});
|
|
5310
5490
|
return toMessageSearchResponse(data);
|
|
5311
5491
|
}
|
|
5492
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5493
|
+
return client.rest.get(
|
|
5494
|
+
import_types30.Routes.emojiSource(emojiId),
|
|
5495
|
+
{ auth: true }
|
|
5496
|
+
);
|
|
5497
|
+
}
|
|
5498
|
+
function fetchStickerSource(client, stickerId) {
|
|
5499
|
+
return client.rest.get(
|
|
5500
|
+
import_types30.Routes.stickerSource(stickerId),
|
|
5501
|
+
{ auth: true }
|
|
5502
|
+
);
|
|
5503
|
+
}
|
|
5504
|
+
function fetchDiscoveryCategories(client) {
|
|
5505
|
+
return client.rest.get(
|
|
5506
|
+
import_types30.Routes.discoveryCategories(),
|
|
5507
|
+
{ auth: true }
|
|
5508
|
+
);
|
|
5509
|
+
}
|
|
5510
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5511
|
+
const params = new URLSearchParams();
|
|
5512
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5513
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5514
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5515
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5516
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5517
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5518
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5519
|
+
const qs2 = params.toString();
|
|
5520
|
+
return client.rest.get(
|
|
5521
|
+
qs2 ? `${import_types30.Routes.discoveryGuilds()}?${qs2}` : import_types30.Routes.discoveryGuilds(),
|
|
5522
|
+
{ auth: true }
|
|
5523
|
+
);
|
|
5524
|
+
}
|
|
5525
|
+
function fetchExperiments(client) {
|
|
5526
|
+
return client.rest.get(import_types30.Routes.experiments(), {
|
|
5527
|
+
auth: true
|
|
5528
|
+
});
|
|
5529
|
+
}
|
|
5530
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5531
|
+
return client.rest.post(
|
|
5532
|
+
import_types30.Routes.attachmentsRefreshUrls(),
|
|
5533
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5534
|
+
);
|
|
5535
|
+
}
|
|
5536
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5537
|
+
const params = new URLSearchParams();
|
|
5538
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5539
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5540
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5541
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5542
|
+
const qs2 = params.toString();
|
|
5543
|
+
return client.rest.get(
|
|
5544
|
+
qs2 ? `${import_types30.Routes.instanceBadges()}?${qs2}` : import_types30.Routes.instanceBadges(),
|
|
5545
|
+
{ auth: false }
|
|
5546
|
+
);
|
|
5547
|
+
}
|
|
5548
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5549
|
+
return client.rest.post(
|
|
5550
|
+
import_types30.Routes.channelPostData(channelId),
|
|
5551
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5552
|
+
);
|
|
5553
|
+
}
|
|
5312
5554
|
|
|
5313
5555
|
// src/ClientCore/ClientEvents.ts
|
|
5314
5556
|
function createEventMethods(client) {
|
|
@@ -5339,6 +5581,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5339
5581
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5340
5582
|
this.guild = guild;
|
|
5341
5583
|
}
|
|
5584
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5342
5585
|
/**
|
|
5343
5586
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5344
5587
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5350,7 +5593,9 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5350
5593
|
* console.log(member.displayName);
|
|
5351
5594
|
*/
|
|
5352
5595
|
async resolve(userId) {
|
|
5353
|
-
|
|
5596
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5597
|
+
const cached = this.get(id);
|
|
5598
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5354
5599
|
}
|
|
5355
5600
|
/**
|
|
5356
5601
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5378,10 +5623,11 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5378
5623
|
return this.guild.fetchMe();
|
|
5379
5624
|
}
|
|
5380
5625
|
async fetch(userIdOrOptions, options) {
|
|
5381
|
-
if (typeof userIdOrOptions === "string") {
|
|
5382
|
-
const
|
|
5383
|
-
|
|
5384
|
-
|
|
5626
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5627
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5628
|
+
const cached = this.get(id);
|
|
5629
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5630
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5385
5631
|
}
|
|
5386
5632
|
return this.fetchMany(userIdOrOptions);
|
|
5387
5633
|
}
|
|
@@ -5391,9 +5637,13 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5391
5637
|
if (options?.after) params.set("after", options.after);
|
|
5392
5638
|
const qs2 = params.toString();
|
|
5393
5639
|
const url = import_types31.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5394
|
-
const data =
|
|
5640
|
+
const data = assertApiArray(
|
|
5641
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5642
|
+
"members.fetch()"
|
|
5643
|
+
);
|
|
5395
5644
|
const members = [];
|
|
5396
5645
|
for (const m of data) {
|
|
5646
|
+
if (!m?.user?.id) continue;
|
|
5397
5647
|
const member = new GuildMember(
|
|
5398
5648
|
this.guild.client,
|
|
5399
5649
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5559,7 +5809,12 @@ async function createChannel(guild, options) {
|
|
|
5559
5809
|
return cacheChannel(guild, created);
|
|
5560
5810
|
}
|
|
5561
5811
|
async function fetchChannels(guild) {
|
|
5562
|
-
const
|
|
5812
|
+
const raw = await guild.client.rest.get(import_types33.Routes.guildChannels(guild.id));
|
|
5813
|
+
if (!Array.isArray(raw))
|
|
5814
|
+
throw new TypeError(
|
|
5815
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
5816
|
+
);
|
|
5817
|
+
const data = raw;
|
|
5563
5818
|
const channels = [];
|
|
5564
5819
|
for (const ch of data) {
|
|
5565
5820
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5654,16 +5909,20 @@ var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
|
5654
5909
|
// src/Domain/Guild/MemberHttp.ts
|
|
5655
5910
|
var import_types35 = require("@fluxerjs/types");
|
|
5656
5911
|
async function fetchMember(guild, userId) {
|
|
5912
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5657
5913
|
try {
|
|
5658
5914
|
const data = await guild.client.rest.get(
|
|
5659
|
-
import_types35.Routes.guildMember(guild.id,
|
|
5915
|
+
import_types35.Routes.guildMember(guild.id, id)
|
|
5660
5916
|
);
|
|
5917
|
+
if (!data?.user?.id) {
|
|
5918
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
5919
|
+
}
|
|
5661
5920
|
return cacheMember(guild, data);
|
|
5662
5921
|
} catch (err) {
|
|
5663
5922
|
rethrowMapped(err, {
|
|
5664
5923
|
notFound: {
|
|
5665
5924
|
code: import_util3.ErrorCodes.MemberNotFound,
|
|
5666
|
-
message: `Member ${
|
|
5925
|
+
message: `Member ${id} not found in guild`
|
|
5667
5926
|
},
|
|
5668
5927
|
fallback: "Failed to fetch guild member"
|
|
5669
5928
|
});
|
|
@@ -5674,6 +5933,9 @@ async function fetchMe(guild) {
|
|
|
5674
5933
|
import_types35.Routes.guildMemberMe(guild.id),
|
|
5675
5934
|
{ auth: true }
|
|
5676
5935
|
);
|
|
5936
|
+
if (!data?.user?.id) {
|
|
5937
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
5938
|
+
}
|
|
5677
5939
|
return cacheMember(guild, data);
|
|
5678
5940
|
}
|
|
5679
5941
|
|
|
@@ -5724,6 +5986,10 @@ async function ban(guild, userId, options) {
|
|
|
5724
5986
|
...auditReasonHeaders(options?.reason)
|
|
5725
5987
|
});
|
|
5726
5988
|
}
|
|
5989
|
+
async function fetchBan(guild, userId) {
|
|
5990
|
+
const data = await guild.client.rest.get(import_types37.Routes.guildBan(guild.id, userId));
|
|
5991
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
5992
|
+
}
|
|
5727
5993
|
async function fetchBans(guild) {
|
|
5728
5994
|
const data = await guild.client.rest.get(import_types37.Routes.guildBans(guild.id));
|
|
5729
5995
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
@@ -5755,6 +6021,8 @@ async function createRole(guild, options = {}) {
|
|
|
5755
6021
|
}
|
|
5756
6022
|
async function fetchRoles(guild) {
|
|
5757
6023
|
const data = await guild.client.rest.get(import_types38.Routes.guildRoles(guild.id));
|
|
6024
|
+
if (!Array.isArray(data))
|
|
6025
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5758
6026
|
return data.map((r) => cacheRole(guild, r));
|
|
5759
6027
|
}
|
|
5760
6028
|
async function fetchRole(guild, roleId2) {
|
|
@@ -5854,6 +6122,11 @@ var Guild = class extends Base {
|
|
|
5854
6122
|
id;
|
|
5855
6123
|
/** Whether the guild is currently available through the gateway. */
|
|
5856
6124
|
available = true;
|
|
6125
|
+
/**
|
|
6126
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6127
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6128
|
+
*/
|
|
6129
|
+
partial = true;
|
|
5857
6130
|
/** Guild name. */
|
|
5858
6131
|
name;
|
|
5859
6132
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -6148,6 +6421,10 @@ var Guild = class extends Base {
|
|
|
6148
6421
|
ban(userId, options) {
|
|
6149
6422
|
return ban(this, userId, options);
|
|
6150
6423
|
}
|
|
6424
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6425
|
+
fetchBan(userId) {
|
|
6426
|
+
return fetchBan(this, userId);
|
|
6427
|
+
}
|
|
6151
6428
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6152
6429
|
fetchBans() {
|
|
6153
6430
|
return fetchBans(this);
|
|
@@ -6328,6 +6605,7 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6328
6605
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6329
6606
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6330
6607
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6608
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6331
6609
|
return { guild, created, recovered };
|
|
6332
6610
|
}
|
|
6333
6611
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6411,15 +6689,7 @@ var ClientUser = class extends User {
|
|
|
6411
6689
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6412
6690
|
var import_util24 = require("@fluxerjs/util");
|
|
6413
6691
|
function unknownUser(id) {
|
|
6414
|
-
return {
|
|
6415
|
-
id,
|
|
6416
|
-
username: "Unknown",
|
|
6417
|
-
discriminator: "0",
|
|
6418
|
-
global_name: null,
|
|
6419
|
-
avatar: null,
|
|
6420
|
-
avatar_color: null,
|
|
6421
|
-
flags: 0
|
|
6422
|
-
};
|
|
6692
|
+
return { id };
|
|
6423
6693
|
}
|
|
6424
6694
|
function indexMember(_client, guild, data) {
|
|
6425
6695
|
if (!data.user?.id) return null;
|
|
@@ -7100,6 +7370,9 @@ var passthroughHandlers = {
|
|
|
7100
7370
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7101
7371
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7102
7372
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7373
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7374
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7375
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7103
7376
|
TYPING_START(client, d) {
|
|
7104
7377
|
const data = d;
|
|
7105
7378
|
const payload = {
|
|
@@ -7290,29 +7563,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7290
7563
|
}
|
|
7291
7564
|
return dispatchGatewayPayload(client, payload);
|
|
7292
7565
|
}
|
|
7293
|
-
|
|
7566
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7567
|
+
function queueFor(client) {
|
|
7568
|
+
let queue = dispatchQueues.get(client);
|
|
7569
|
+
if (!queue) {
|
|
7570
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7571
|
+
dispatchQueues.set(client, queue);
|
|
7572
|
+
}
|
|
7573
|
+
return queue;
|
|
7574
|
+
}
|
|
7575
|
+
async function runGatewayHandler(client, payload) {
|
|
7294
7576
|
const event = payload.t;
|
|
7295
|
-
if (!event) return
|
|
7577
|
+
if (!event) return;
|
|
7296
7578
|
const handler = eventHandlers.get(event);
|
|
7297
7579
|
if (!handler) {
|
|
7298
7580
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7299
|
-
return
|
|
7581
|
+
return;
|
|
7300
7582
|
}
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
}
|
|
7308
|
-
if (client.options.gatewayDeferHandlers
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
};
|
|
7313
|
-
|
|
7314
|
-
|
|
7583
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7584
|
+
client.emit(
|
|
7585
|
+
Events.Debug,
|
|
7586
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7587
|
+
);
|
|
7588
|
+
return;
|
|
7589
|
+
}
|
|
7590
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7591
|
+
await new Promise((resolve) => {
|
|
7592
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7593
|
+
else setTimeout(resolve, 0);
|
|
7594
|
+
});
|
|
7595
|
+
}
|
|
7596
|
+
try {
|
|
7597
|
+
await handler(client, payload.d);
|
|
7598
|
+
} catch (err) {
|
|
7599
|
+
emitClientError(client, err);
|
|
7600
|
+
}
|
|
7601
|
+
}
|
|
7602
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7603
|
+
const queue = queueFor(client);
|
|
7604
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7605
|
+
queue.pending++;
|
|
7606
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7607
|
+
queue.pending--;
|
|
7608
|
+
});
|
|
7609
|
+
queue.tail = run.catch(() => {
|
|
7610
|
+
});
|
|
7611
|
+
return run;
|
|
7612
|
+
}
|
|
7613
|
+
queue.pending++;
|
|
7614
|
+
const next = queue.tail.then(
|
|
7615
|
+
() => runGatewayHandler(client, payload),
|
|
7616
|
+
() => runGatewayHandler(client, payload)
|
|
7617
|
+
).finally(() => {
|
|
7618
|
+
queue.pending--;
|
|
7619
|
+
});
|
|
7620
|
+
queue.tail = next.catch(() => {
|
|
7315
7621
|
});
|
|
7622
|
+
return next;
|
|
7316
7623
|
}
|
|
7317
7624
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7318
7625
|
while (deferred.length > 0) {
|
|
@@ -7500,6 +7807,7 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7500
7807
|
});
|
|
7501
7808
|
this.client = client;
|
|
7502
7809
|
}
|
|
7810
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7503
7811
|
/**
|
|
7504
7812
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7505
7813
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7514,35 +7822,73 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7514
7822
|
}
|
|
7515
7823
|
/**
|
|
7516
7824
|
* Get a guild from cache or fetch from the API if not present.
|
|
7825
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7517
7826
|
* @param guildId - Snowflake of the guild
|
|
7518
7827
|
* @returns The guild
|
|
7519
7828
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7520
7829
|
*/
|
|
7521
7830
|
async resolve(guildId) {
|
|
7522
|
-
|
|
7831
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
7832
|
+
const cached = this.get(id);
|
|
7833
|
+
if (cached && !cached.partial) return cached;
|
|
7834
|
+
if (cached) {
|
|
7835
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7836
|
+
await this.hydrate(cached);
|
|
7837
|
+
return cached;
|
|
7838
|
+
});
|
|
7839
|
+
return cached;
|
|
7840
|
+
}
|
|
7841
|
+
const guild = await this.fetch(id);
|
|
7842
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7843
|
+
await this.hydrate(guild);
|
|
7844
|
+
return guild;
|
|
7845
|
+
});
|
|
7846
|
+
return guild;
|
|
7523
7847
|
}
|
|
7524
7848
|
/**
|
|
7525
7849
|
* Fetch a guild by ID.
|
|
7526
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7850
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7851
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7527
7852
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7528
7853
|
*/
|
|
7529
7854
|
async fetch(guildId, options) {
|
|
7530
|
-
const
|
|
7855
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
7856
|
+
const cached = this.get(id);
|
|
7531
7857
|
if (cached && !options?.force) return cached;
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7858
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
7859
|
+
try {
|
|
7860
|
+
const data = assertApiObjectWithId(
|
|
7861
|
+
await this.client.rest.get(import_types43.Routes.guild(id)),
|
|
7862
|
+
"guilds.fetch()"
|
|
7863
|
+
);
|
|
7864
|
+
let guild;
|
|
7865
|
+
const existing = this.get(id);
|
|
7866
|
+
if (existing) {
|
|
7867
|
+
existing._patch(data);
|
|
7868
|
+
guild = existing;
|
|
7869
|
+
} else {
|
|
7870
|
+
guild = new Guild(this.client, data);
|
|
7871
|
+
this.set(guild.id, guild);
|
|
7872
|
+
}
|
|
7873
|
+
return guild;
|
|
7874
|
+
} catch (err) {
|
|
7875
|
+
rethrowMapped(err, {
|
|
7876
|
+
notFound: { code: import_util3.ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
7877
|
+
fallback: `Failed to fetch guild ${id}`
|
|
7878
|
+
});
|
|
7537
7879
|
}
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7880
|
+
});
|
|
7881
|
+
}
|
|
7882
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
7883
|
+
async hydrate(guild) {
|
|
7884
|
+
try {
|
|
7885
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
7886
|
+
guild.partial = false;
|
|
7541
7887
|
} catch (err) {
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7888
|
+
this.client.emit(
|
|
7889
|
+
Events.Debug,
|
|
7890
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
7891
|
+
);
|
|
7546
7892
|
}
|
|
7547
7893
|
}
|
|
7548
7894
|
};
|
|
@@ -7567,6 +7913,10 @@ var MessageCache = class {
|
|
|
7567
7913
|
if (limit === false) return;
|
|
7568
7914
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7569
7915
|
let cache = this.caches.get(channelId);
|
|
7916
|
+
if (cache) {
|
|
7917
|
+
this.caches.delete(channelId);
|
|
7918
|
+
this.caches.set(channelId, cache);
|
|
7919
|
+
}
|
|
7570
7920
|
if (!cache) {
|
|
7571
7921
|
const channelLimit = this.getChannelLimit();
|
|
7572
7922
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7624,6 +7974,7 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7624
7974
|
super({ maxSize: client.cache.limits.users });
|
|
7625
7975
|
this.client = client;
|
|
7626
7976
|
}
|
|
7977
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7627
7978
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7628
7979
|
sweep(filter) {
|
|
7629
7980
|
let removed = 0;
|
|
@@ -7637,16 +7988,30 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7637
7988
|
}
|
|
7638
7989
|
return removed;
|
|
7639
7990
|
}
|
|
7640
|
-
/**
|
|
7991
|
+
/**
|
|
7992
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
7993
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
7994
|
+
*/
|
|
7641
7995
|
async fetch(userId, options) {
|
|
7642
|
-
const
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
return
|
|
7996
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
7997
|
+
const cached = this.get(id);
|
|
7998
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
7999
|
+
return dedupeFetch(
|
|
8000
|
+
this.pendingFetches,
|
|
8001
|
+
id,
|
|
8002
|
+
async () => this.client.getOrCreateUser(
|
|
8003
|
+
assertApiObjectWithId(
|
|
8004
|
+
await this.client.rest.get(import_types44.Routes.user(id)),
|
|
8005
|
+
"users.fetch()"
|
|
8006
|
+
)
|
|
8007
|
+
)
|
|
8008
|
+
);
|
|
7646
8009
|
}
|
|
7647
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8010
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7648
8011
|
async resolve(userId) {
|
|
7649
|
-
|
|
8012
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8013
|
+
const cached = this.get(id);
|
|
8014
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7650
8015
|
}
|
|
7651
8016
|
/**
|
|
7652
8017
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7787,7 +8152,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7787
8152
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7788
8153
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7789
8154
|
*
|
|
7790
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8155
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7791
8156
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7792
8157
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7793
8158
|
*/
|
|
@@ -7864,6 +8229,38 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7864
8229
|
fetchStickerMetadata(stickerId) {
|
|
7865
8230
|
return fetchStickerMetadata(this, stickerId);
|
|
7866
8231
|
}
|
|
8232
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8233
|
+
fetchEmojiSource(emojiId) {
|
|
8234
|
+
return fetchEmojiSource(this, emojiId);
|
|
8235
|
+
}
|
|
8236
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8237
|
+
fetchStickerSource(stickerId) {
|
|
8238
|
+
return fetchStickerSource(this, stickerId);
|
|
8239
|
+
}
|
|
8240
|
+
/** List discovery categories. */
|
|
8241
|
+
fetchDiscoveryCategories() {
|
|
8242
|
+
return fetchDiscoveryCategories(this);
|
|
8243
|
+
}
|
|
8244
|
+
/** Search discoverable guilds. */
|
|
8245
|
+
searchDiscoveryGuilds(options) {
|
|
8246
|
+
return searchDiscoveryGuilds(this, options);
|
|
8247
|
+
}
|
|
8248
|
+
/** Fetch experiment assignments for this account. */
|
|
8249
|
+
fetchExperiments() {
|
|
8250
|
+
return fetchExperiments(this);
|
|
8251
|
+
}
|
|
8252
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8253
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8254
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8255
|
+
}
|
|
8256
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8257
|
+
fetchInstanceBadges(options) {
|
|
8258
|
+
return fetchInstanceBadges(this, options);
|
|
8259
|
+
}
|
|
8260
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8261
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8262
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8263
|
+
}
|
|
7867
8264
|
/**
|
|
7868
8265
|
* Fetch the current application (`/applications/@me`).
|
|
7869
8266
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -7958,6 +8355,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7958
8355
|
* @internal
|
|
7959
8356
|
*/
|
|
7960
8357
|
getOrCreateUser(data) {
|
|
8358
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8359
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8360
|
+
}
|
|
7961
8361
|
const existing = this.users.get(data.id);
|
|
7962
8362
|
if (existing) {
|
|
7963
8363
|
existing._patch(data);
|