@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/cluster.js
CHANGED
|
@@ -53,6 +53,7 @@ var Events = {
|
|
|
53
53
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
54
54
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
55
55
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
56
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
56
57
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
57
58
|
GuildMemberAdd: "guildMemberAdd",
|
|
58
59
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -87,6 +88,8 @@ var Events = {
|
|
|
87
88
|
VoiceStateAck: "voiceStateAck",
|
|
88
89
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
89
90
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
91
|
+
VoiceSignal: "voiceSignal",
|
|
92
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
90
93
|
VoiceStatesSync: "voiceStatesSync",
|
|
91
94
|
WebhooksUpdate: "webhooksUpdate",
|
|
92
95
|
Resumed: "resumed",
|
|
@@ -1137,6 +1140,45 @@ var import_util5 = require("@fluxerjs/util");
|
|
|
1137
1140
|
// src/ClientCore/MessageManager.ts
|
|
1138
1141
|
var import_collection2 = require("@fluxerjs/collection");
|
|
1139
1142
|
var import_types5 = require("@fluxerjs/types");
|
|
1143
|
+
|
|
1144
|
+
// src/ClientCore/Resolve.ts
|
|
1145
|
+
function normalizeSnowflakeId(value, label) {
|
|
1146
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1147
|
+
throw new TypeError(
|
|
1148
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
1152
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
1153
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
1154
|
+
}
|
|
1155
|
+
return id;
|
|
1156
|
+
}
|
|
1157
|
+
function assertApiObjectWithId(data, label) {
|
|
1158
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
1159
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
1160
|
+
}
|
|
1161
|
+
return data;
|
|
1162
|
+
}
|
|
1163
|
+
function assertApiArray(data, label) {
|
|
1164
|
+
if (!Array.isArray(data)) {
|
|
1165
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
1166
|
+
}
|
|
1167
|
+
return data;
|
|
1168
|
+
}
|
|
1169
|
+
async function dedupeFetch(pending, key, fn) {
|
|
1170
|
+
const existing = pending.get(key);
|
|
1171
|
+
if (existing) return existing;
|
|
1172
|
+
const request = fn();
|
|
1173
|
+
pending.set(key, request);
|
|
1174
|
+
try {
|
|
1175
|
+
return await request;
|
|
1176
|
+
} finally {
|
|
1177
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// src/ClientCore/MessageManager.ts
|
|
1140
1182
|
var BULK = {
|
|
1141
1183
|
requests: { min: 1, max: 25 },
|
|
1142
1184
|
limit: { min: 1, max: 25 },
|
|
@@ -1172,25 +1214,32 @@ var MessageManager = class {
|
|
|
1172
1214
|
}
|
|
1173
1215
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1174
1216
|
_structures = new import_collection2.Collection();
|
|
1217
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
1175
1218
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1176
1219
|
get(messageId) {
|
|
1177
|
-
const
|
|
1220
|
+
const id = String(messageId ?? "").trim();
|
|
1221
|
+
if (!id) return void 0;
|
|
1222
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
1178
1223
|
if (!data) {
|
|
1179
|
-
this._structures.delete(
|
|
1224
|
+
this._structures.delete(id);
|
|
1180
1225
|
return void 0;
|
|
1181
1226
|
}
|
|
1182
|
-
const existing = this._structures.get(
|
|
1183
|
-
if (existing)
|
|
1227
|
+
const existing = this._structures.get(id);
|
|
1228
|
+
if (existing) {
|
|
1229
|
+
existing._patch(data);
|
|
1230
|
+
return existing;
|
|
1231
|
+
}
|
|
1184
1232
|
const message = new Message(this.client, data);
|
|
1185
|
-
this._structures.set(
|
|
1233
|
+
this._structures.set(id, message);
|
|
1186
1234
|
return message;
|
|
1187
1235
|
}
|
|
1188
1236
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1189
1237
|
async resolve(messageId) {
|
|
1190
|
-
|
|
1238
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
1239
|
+
return this.get(id) ?? this.fetch(id);
|
|
1191
1240
|
}
|
|
1192
1241
|
async fetch(idOrOptions) {
|
|
1193
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1242
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
1194
1243
|
}
|
|
1195
1244
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1196
1245
|
wrap(data) {
|
|
@@ -1207,9 +1256,13 @@ var MessageManager = class {
|
|
|
1207
1256
|
}
|
|
1208
1257
|
/** Fetch a single message from the API. */
|
|
1209
1258
|
async fetchOne(messageId) {
|
|
1259
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
1260
|
+
}
|
|
1261
|
+
async fetchOneFresh(messageId) {
|
|
1210
1262
|
try {
|
|
1211
|
-
const data =
|
|
1212
|
-
import_types5.Routes.channelMessage(this.channelId, messageId)
|
|
1263
|
+
const data = assertApiObjectWithId(
|
|
1264
|
+
await this.client.rest.get(import_types5.Routes.channelMessage(this.channelId, messageId)),
|
|
1265
|
+
"messages.fetch()"
|
|
1213
1266
|
);
|
|
1214
1267
|
return this.wrap(data);
|
|
1215
1268
|
} catch (err) {
|
|
@@ -1235,9 +1288,15 @@ var MessageManager = class {
|
|
|
1235
1288
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1236
1289
|
}
|
|
1237
1290
|
const base = import_types5.Routes.channelMessages(this.channelId);
|
|
1238
|
-
const data =
|
|
1291
|
+
const data = assertApiArray(
|
|
1292
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
1293
|
+
"messages.fetch()"
|
|
1294
|
+
);
|
|
1239
1295
|
const collection = new import_collection2.Collection();
|
|
1240
|
-
for (const msg of data)
|
|
1296
|
+
for (const msg of data) {
|
|
1297
|
+
if (!msg?.id) continue;
|
|
1298
|
+
collection.set(msg.id, this.wrap(msg));
|
|
1299
|
+
}
|
|
1241
1300
|
return collection;
|
|
1242
1301
|
}
|
|
1243
1302
|
};
|
|
@@ -1441,6 +1500,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1441
1500
|
}
|
|
1442
1501
|
|
|
1443
1502
|
// src/Domain/Channel/Base.ts
|
|
1503
|
+
function isFullChannelData(data) {
|
|
1504
|
+
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;
|
|
1505
|
+
}
|
|
1444
1506
|
var Channel = class extends Base {
|
|
1445
1507
|
#messages;
|
|
1446
1508
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -1455,6 +1517,11 @@ var Channel = class extends Base {
|
|
|
1455
1517
|
icon;
|
|
1456
1518
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
1457
1519
|
lastPinTimestamp;
|
|
1520
|
+
/**
|
|
1521
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
1522
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
1523
|
+
*/
|
|
1524
|
+
partial;
|
|
1458
1525
|
constructor(client, data) {
|
|
1459
1526
|
super();
|
|
1460
1527
|
this.client = client;
|
|
@@ -1463,6 +1530,7 @@ var Channel = class extends Base {
|
|
|
1463
1530
|
this.name = data.name ?? null;
|
|
1464
1531
|
this.icon = data.icon ?? null;
|
|
1465
1532
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1533
|
+
this.partial = !isFullChannelData(data);
|
|
1466
1534
|
}
|
|
1467
1535
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1468
1536
|
get createdTimestamp() {
|
|
@@ -1483,6 +1551,7 @@ var Channel = class extends Base {
|
|
|
1483
1551
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1484
1552
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1485
1553
|
}
|
|
1554
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
1486
1555
|
}
|
|
1487
1556
|
/** @internal Factory wired after subclasses load. */
|
|
1488
1557
|
static from(_c, _d) {
|
|
@@ -2258,10 +2327,10 @@ var Message = class _Message extends Base {
|
|
|
2258
2327
|
this.channelId = data.channel_id;
|
|
2259
2328
|
this.guildId = data.guild_id ?? null;
|
|
2260
2329
|
this.author = client.getOrCreateUser(data.author);
|
|
2261
|
-
this.content = data.content;
|
|
2262
|
-
this.createdAt = new Date(data.timestamp);
|
|
2330
|
+
this.content = data.content ?? "";
|
|
2331
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
2263
2332
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2264
|
-
this.pinned = data.pinned;
|
|
2333
|
+
this.pinned = data.pinned ?? false;
|
|
2265
2334
|
this.attachments = new import_collection5.Collection();
|
|
2266
2335
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2267
2336
|
this.type = data.type ?? import_types10.MessageType.Default;
|
|
@@ -2293,33 +2362,47 @@ var Message = class _Message extends Base {
|
|
|
2293
2362
|
* @internal
|
|
2294
2363
|
*/
|
|
2295
2364
|
_patch(data) {
|
|
2296
|
-
this.content = data.content;
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
this.
|
|
2307
|
-
this.
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2365
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
2366
|
+
if (data.edited_timestamp !== void 0) {
|
|
2367
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2368
|
+
}
|
|
2369
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
2370
|
+
if (data.attachments !== void 0) {
|
|
2371
|
+
this.attachments.clear();
|
|
2372
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2373
|
+
}
|
|
2374
|
+
if (data.flags !== void 0) this.flags = new import_util7.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
2375
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
2376
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
2377
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
2378
|
+
if (data.stickers !== void 0) {
|
|
2379
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
2380
|
+
}
|
|
2381
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
2382
|
+
if (data.message_reference !== void 0) {
|
|
2383
|
+
this.messageReference = data.message_reference ? {
|
|
2384
|
+
channelId: data.message_reference.channel_id,
|
|
2385
|
+
messageId: data.message_reference.message_id,
|
|
2386
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
2387
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
2388
|
+
} : null;
|
|
2389
|
+
}
|
|
2390
|
+
if (data.message_snapshots !== void 0) {
|
|
2391
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
2392
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2395
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
2396
|
+
if (data.referenced_message !== void 0) {
|
|
2397
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
2398
|
+
}
|
|
2399
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
2400
|
+
if (data.mentions !== void 0) {
|
|
2401
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2402
|
+
}
|
|
2403
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
2404
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
2405
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
2323
2406
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
2324
2407
|
}
|
|
2325
2408
|
/**
|
|
@@ -2420,6 +2503,23 @@ var Message = class _Message extends Base {
|
|
|
2420
2503
|
async fetch() {
|
|
2421
2504
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2422
2505
|
}
|
|
2506
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2507
|
+
async crosspost() {
|
|
2508
|
+
const data = await this.client.rest.post(
|
|
2509
|
+
import_types10.Routes.channelMessageCrosspost(this.channelId, this.id),
|
|
2510
|
+
{ auth: true }
|
|
2511
|
+
);
|
|
2512
|
+
const published = new _Message(this.client, data);
|
|
2513
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2514
|
+
return published;
|
|
2515
|
+
}
|
|
2516
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2517
|
+
async fetchCrosspostSource() {
|
|
2518
|
+
return this.client.rest.get(
|
|
2519
|
+
import_types10.Routes.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2520
|
+
{ auth: true }
|
|
2521
|
+
);
|
|
2522
|
+
}
|
|
2423
2523
|
/** Delete this message. */
|
|
2424
2524
|
async delete(reason) {
|
|
2425
2525
|
await this.client.rest.delete(import_types10.Routes.channelMessage(this.channelId, this.id), {
|
|
@@ -2583,7 +2683,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2583
2683
|
const full = data;
|
|
2584
2684
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2585
2685
|
this.ownerId = full.owner_id ?? null;
|
|
2586
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2686
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2587
2687
|
this.nicks = full.nicks ?? {};
|
|
2588
2688
|
}
|
|
2589
2689
|
/**
|
|
@@ -2598,7 +2698,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2598
2698
|
}
|
|
2599
2699
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2600
2700
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2601
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2701
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2602
2702
|
}
|
|
2603
2703
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2604
2704
|
}
|
|
@@ -2675,17 +2775,19 @@ var import_types13 = require("@fluxerjs/types");
|
|
|
2675
2775
|
// src/Helpers/Instance.ts
|
|
2676
2776
|
var import_util9 = require("@fluxerjs/util");
|
|
2677
2777
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2678
|
-
api: "https://
|
|
2679
|
-
api_client: "https://
|
|
2680
|
-
api_public: "https://
|
|
2681
|
-
gateway: "wss://gateway.fluxer.
|
|
2778
|
+
api: "https://fluxer.com/api",
|
|
2779
|
+
api_client: "https://fluxer.com/api",
|
|
2780
|
+
api_public: "https://fluxer.com/api",
|
|
2781
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2682
2782
|
media: CDN_URL,
|
|
2783
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2683
2784
|
static_cdn: STATIC_CDN_URL,
|
|
2684
|
-
marketing: "https://fluxer.
|
|
2785
|
+
marketing: "https://fluxer.com",
|
|
2786
|
+
docs: "https://docs.fluxer.com",
|
|
2685
2787
|
admin: "https://admin.fluxer.app",
|
|
2686
2788
|
invite: "https://fluxer.gg",
|
|
2687
2789
|
gift: "https://fluxer.gift",
|
|
2688
|
-
webapp: "https://
|
|
2790
|
+
webapp: "https://fluxer.com"
|
|
2689
2791
|
});
|
|
2690
2792
|
var ENDPOINT_KEYS = [
|
|
2691
2793
|
"api",
|
|
@@ -2700,6 +2802,11 @@ var ENDPOINT_KEYS = [
|
|
|
2700
2802
|
"gift",
|
|
2701
2803
|
"webapp"
|
|
2702
2804
|
];
|
|
2805
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
2806
|
+
"api_transport",
|
|
2807
|
+
"upload_relay",
|
|
2808
|
+
"docs"
|
|
2809
|
+
];
|
|
2703
2810
|
function requireString(obj, key, path) {
|
|
2704
2811
|
const value = obj[key];
|
|
2705
2812
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2740,6 +2847,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2740
2847
|
for (const key of ENDPOINT_KEYS) {
|
|
2741
2848
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2742
2849
|
}
|
|
2850
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
2851
|
+
const value = raw.endpoints[key];
|
|
2852
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
2853
|
+
}
|
|
2743
2854
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2744
2855
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2745
2856
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -2793,7 +2904,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
2793
2904
|
defaultsHash: ""
|
|
2794
2905
|
},
|
|
2795
2906
|
push: raw.push ?? { public_vapid_key: null },
|
|
2796
|
-
app_public: raw.app_public ?? {}
|
|
2907
|
+
app_public: raw.app_public ?? {},
|
|
2908
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
2909
|
+
age_policy: (0, import_util9.isRecord)(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
2910
|
+
...raw.notice === null || (0, import_util9.isRecord)(raw.notice) ? { notice: raw.notice } : {},
|
|
2911
|
+
...(0, import_util9.isRecord)(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
2912
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
2913
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
2914
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
2915
|
+
...(0, import_util9.isRecord)(raw.built_in_guild_badge_images) ? {
|
|
2916
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
2917
|
+
} : {},
|
|
2918
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
2919
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
2920
|
+
} : {},
|
|
2921
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
2797
2922
|
};
|
|
2798
2923
|
}
|
|
2799
2924
|
function resolveInstanceEndpoints(input) {
|
|
@@ -2813,7 +2938,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
2813
2938
|
}
|
|
2814
2939
|
const partial = input;
|
|
2815
2940
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
2816
|
-
for (const key of ENDPOINT_KEYS) {
|
|
2941
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
2817
2942
|
const value = partial[key];
|
|
2818
2943
|
if (typeof value === "string" && value.length > 0) {
|
|
2819
2944
|
merged[key] = value;
|
|
@@ -3430,6 +3555,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3430
3555
|
}
|
|
3431
3556
|
};
|
|
3432
3557
|
var AnnouncementChannel = class extends TextChannel {
|
|
3558
|
+
/**
|
|
3559
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3560
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3561
|
+
*/
|
|
3562
|
+
async follow(webhookChannelId) {
|
|
3563
|
+
return this.client.rest.post(
|
|
3564
|
+
import_types16.Routes.channelFollowers(this.id),
|
|
3565
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3566
|
+
);
|
|
3567
|
+
}
|
|
3568
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3569
|
+
async fetchFollowerStats() {
|
|
3570
|
+
return this.client.rest.get(
|
|
3571
|
+
import_types16.Routes.channelFollowerStats(this.id),
|
|
3572
|
+
{ auth: true }
|
|
3573
|
+
);
|
|
3574
|
+
}
|
|
3433
3575
|
};
|
|
3434
3576
|
var CategoryChannel = class extends GuildChannel {
|
|
3435
3577
|
};
|
|
@@ -3456,6 +3598,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3456
3598
|
voiceConnectionLimit;
|
|
3457
3599
|
/** RTC region override for this channel. */
|
|
3458
3600
|
rtcRegion;
|
|
3601
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3602
|
+
rtcP2p;
|
|
3459
3603
|
constructor(client, data) {
|
|
3460
3604
|
super(client, data);
|
|
3461
3605
|
this.topic = data.topic ?? null;
|
|
@@ -3469,6 +3613,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3469
3613
|
this.userLimit = data.user_limit ?? null;
|
|
3470
3614
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3471
3615
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3616
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3472
3617
|
}
|
|
3473
3618
|
/**
|
|
3474
3619
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3495,6 +3640,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3495
3640
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3496
3641
|
}
|
|
3497
3642
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3643
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3498
3644
|
}
|
|
3499
3645
|
};
|
|
3500
3646
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -4060,12 +4206,15 @@ var User = class extends Base {
|
|
|
4060
4206
|
system;
|
|
4061
4207
|
/** Banner hash for profile. */
|
|
4062
4208
|
banner;
|
|
4209
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
4210
|
+
partial;
|
|
4063
4211
|
constructor(client, data) {
|
|
4064
4212
|
super();
|
|
4065
4213
|
this.client = client;
|
|
4066
4214
|
this.id = data.id;
|
|
4067
|
-
this.
|
|
4068
|
-
this.
|
|
4215
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
4216
|
+
this.username = data.username ?? "Unknown";
|
|
4217
|
+
this.discriminator = data.discriminator ?? "0";
|
|
4069
4218
|
this.globalName = data.global_name ?? null;
|
|
4070
4219
|
this.avatar = data.avatar ?? null;
|
|
4071
4220
|
this.bot = !!data.bot;
|
|
@@ -4076,13 +4225,18 @@ var User = class extends Base {
|
|
|
4076
4225
|
}
|
|
4077
4226
|
/** @internal */
|
|
4078
4227
|
_patch(data) {
|
|
4079
|
-
this.username = data.username;
|
|
4080
|
-
this.discriminator = data.discriminator;
|
|
4081
|
-
this.globalName = data.global_name ?? null;
|
|
4082
|
-
this.avatar = data.avatar ?? null;
|
|
4228
|
+
if (data.username !== void 0) this.username = data.username;
|
|
4229
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
4230
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
4231
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
4083
4232
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
4084
4233
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
4085
4234
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
4235
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
4236
|
+
}
|
|
4237
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
4238
|
+
async fetch() {
|
|
4239
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
4086
4240
|
}
|
|
4087
4241
|
cdnOpts() {
|
|
4088
4242
|
return {
|
|
@@ -4865,6 +5019,8 @@ var Role = class _Role extends Base {
|
|
|
4865
5019
|
mentionable;
|
|
4866
5020
|
/** Unicode emoji for this role (null = none). */
|
|
4867
5021
|
unicodeEmoji;
|
|
5022
|
+
/** Role icon image hash (null = none). */
|
|
5023
|
+
icon;
|
|
4868
5024
|
/** Hoist position (null = not hoisted). */
|
|
4869
5025
|
hoistPosition;
|
|
4870
5026
|
constructor(client, data, guildId) {
|
|
@@ -4872,20 +5028,26 @@ var Role = class _Role extends Base {
|
|
|
4872
5028
|
this.client = client;
|
|
4873
5029
|
this.id = data.id;
|
|
4874
5030
|
this.guildId = guildId;
|
|
4875
|
-
this.name = data.name;
|
|
4876
|
-
this.color = data.color;
|
|
4877
|
-
this.position = data.position;
|
|
4878
|
-
this._permissions = data.permissions;
|
|
5031
|
+
this.name = data.name ?? "";
|
|
5032
|
+
this.color = data.color ?? 0;
|
|
5033
|
+
this.position = data.position ?? 0;
|
|
5034
|
+
this._permissions = data.permissions ?? "0";
|
|
4879
5035
|
this.hoist = !!data.hoist;
|
|
4880
5036
|
this.mentionable = !!data.mentionable;
|
|
4881
5037
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5038
|
+
this.icon = data.icon ?? null;
|
|
4882
5039
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4883
5040
|
}
|
|
4884
5041
|
/**
|
|
4885
5042
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4886
5043
|
*/
|
|
4887
5044
|
get permissions() {
|
|
4888
|
-
|
|
5045
|
+
let bits;
|
|
5046
|
+
try {
|
|
5047
|
+
bits = BigInt(this._permissions ?? "0");
|
|
5048
|
+
} catch {
|
|
5049
|
+
bits = 0n;
|
|
5050
|
+
}
|
|
4889
5051
|
return new import_util19.PermissionsBitField(
|
|
4890
5052
|
(bits & import_util19.PermissionFlags.Administrator) !== 0n ? import_util19.ALL_PERMISSIONS_BIGINT : bits
|
|
4891
5053
|
);
|
|
@@ -4915,14 +5077,15 @@ var Role = class _Role extends Base {
|
|
|
4915
5077
|
}
|
|
4916
5078
|
/** @internal */
|
|
4917
5079
|
_patch(data) {
|
|
4918
|
-
this.name = data.name;
|
|
4919
|
-
this.color = data.color;
|
|
4920
|
-
this.position = data.position;
|
|
4921
|
-
this._permissions = data.permissions;
|
|
4922
|
-
this.hoist = !!data.hoist;
|
|
4923
|
-
this.mentionable = !!data.mentionable;
|
|
4924
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4925
|
-
this.
|
|
5080
|
+
if (data.name !== void 0) this.name = data.name;
|
|
5081
|
+
if (data.color !== void 0) this.color = data.color;
|
|
5082
|
+
if (data.position !== void 0) this.position = data.position;
|
|
5083
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
5084
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
5085
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
5086
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5087
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
5088
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4926
5089
|
}
|
|
4927
5090
|
/**
|
|
4928
5091
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4940,6 +5103,7 @@ var Role = class _Role extends Base {
|
|
|
4940
5103
|
hoist: this.hoist,
|
|
4941
5104
|
mentionable: this.mentionable,
|
|
4942
5105
|
unicode_emoji: this.unicodeEmoji,
|
|
5106
|
+
icon: this.icon,
|
|
4943
5107
|
hoist_position: this.hoistPosition
|
|
4944
5108
|
},
|
|
4945
5109
|
this.guildId
|
|
@@ -5117,6 +5281,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5117
5281
|
});
|
|
5118
5282
|
this.client = client;
|
|
5119
5283
|
}
|
|
5284
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5120
5285
|
/**
|
|
5121
5286
|
* Remove a channel from cache. Does not delete it on the API.
|
|
5122
5287
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -5129,9 +5294,11 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5129
5294
|
}
|
|
5130
5295
|
return deleted;
|
|
5131
5296
|
}
|
|
5132
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5297
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
5133
5298
|
async resolve(channelId) {
|
|
5134
|
-
|
|
5299
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5300
|
+
const cached = this.get(id);
|
|
5301
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
5135
5302
|
}
|
|
5136
5303
|
/**
|
|
5137
5304
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5144,10 +5311,23 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5144
5311
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5145
5312
|
*/
|
|
5146
5313
|
async fetch(channelId, options) {
|
|
5147
|
-
const
|
|
5148
|
-
|
|
5314
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5315
|
+
const cached = this.get(id);
|
|
5316
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5317
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5318
|
+
}
|
|
5319
|
+
async fetchFresh(channelId) {
|
|
5149
5320
|
try {
|
|
5150
|
-
const data =
|
|
5321
|
+
const data = assertApiObjectWithId(
|
|
5322
|
+
await this.client.rest.get(import_types29.Routes.channel(channelId)),
|
|
5323
|
+
"channels.fetch()"
|
|
5324
|
+
);
|
|
5325
|
+
const existing = this.get(channelId);
|
|
5326
|
+
if (existing && existing.type === data.type) {
|
|
5327
|
+
existing._patch(data);
|
|
5328
|
+
putChannel(this.client, existing);
|
|
5329
|
+
return existing;
|
|
5330
|
+
}
|
|
5151
5331
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5152
5332
|
if (guildId) {
|
|
5153
5333
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5314,6 +5494,68 @@ async function searchMessages(client, options = {}) {
|
|
|
5314
5494
|
});
|
|
5315
5495
|
return toMessageSearchResponse(data);
|
|
5316
5496
|
}
|
|
5497
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5498
|
+
return client.rest.get(
|
|
5499
|
+
import_types30.Routes.emojiSource(emojiId),
|
|
5500
|
+
{ auth: true }
|
|
5501
|
+
);
|
|
5502
|
+
}
|
|
5503
|
+
function fetchStickerSource(client, stickerId) {
|
|
5504
|
+
return client.rest.get(
|
|
5505
|
+
import_types30.Routes.stickerSource(stickerId),
|
|
5506
|
+
{ auth: true }
|
|
5507
|
+
);
|
|
5508
|
+
}
|
|
5509
|
+
function fetchDiscoveryCategories(client) {
|
|
5510
|
+
return client.rest.get(
|
|
5511
|
+
import_types30.Routes.discoveryCategories(),
|
|
5512
|
+
{ auth: true }
|
|
5513
|
+
);
|
|
5514
|
+
}
|
|
5515
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5516
|
+
const params = new URLSearchParams();
|
|
5517
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5518
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5519
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5520
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5521
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5522
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5523
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5524
|
+
const qs2 = params.toString();
|
|
5525
|
+
return client.rest.get(
|
|
5526
|
+
qs2 ? `${import_types30.Routes.discoveryGuilds()}?${qs2}` : import_types30.Routes.discoveryGuilds(),
|
|
5527
|
+
{ auth: true }
|
|
5528
|
+
);
|
|
5529
|
+
}
|
|
5530
|
+
function fetchExperiments(client) {
|
|
5531
|
+
return client.rest.get(import_types30.Routes.experiments(), {
|
|
5532
|
+
auth: true
|
|
5533
|
+
});
|
|
5534
|
+
}
|
|
5535
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5536
|
+
return client.rest.post(
|
|
5537
|
+
import_types30.Routes.attachmentsRefreshUrls(),
|
|
5538
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5539
|
+
);
|
|
5540
|
+
}
|
|
5541
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5542
|
+
const params = new URLSearchParams();
|
|
5543
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5544
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5545
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5546
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5547
|
+
const qs2 = params.toString();
|
|
5548
|
+
return client.rest.get(
|
|
5549
|
+
qs2 ? `${import_types30.Routes.instanceBadges()}?${qs2}` : import_types30.Routes.instanceBadges(),
|
|
5550
|
+
{ auth: false }
|
|
5551
|
+
);
|
|
5552
|
+
}
|
|
5553
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5554
|
+
return client.rest.post(
|
|
5555
|
+
import_types30.Routes.channelPostData(channelId),
|
|
5556
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5557
|
+
);
|
|
5558
|
+
}
|
|
5317
5559
|
|
|
5318
5560
|
// src/ClientCore/ClientEvents.ts
|
|
5319
5561
|
function createEventMethods(client) {
|
|
@@ -5344,6 +5586,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5344
5586
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5345
5587
|
this.guild = guild;
|
|
5346
5588
|
}
|
|
5589
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5347
5590
|
/**
|
|
5348
5591
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5349
5592
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5355,7 +5598,9 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5355
5598
|
* console.log(member.displayName);
|
|
5356
5599
|
*/
|
|
5357
5600
|
async resolve(userId) {
|
|
5358
|
-
|
|
5601
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5602
|
+
const cached = this.get(id);
|
|
5603
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5359
5604
|
}
|
|
5360
5605
|
/**
|
|
5361
5606
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5383,10 +5628,11 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5383
5628
|
return this.guild.fetchMe();
|
|
5384
5629
|
}
|
|
5385
5630
|
async fetch(userIdOrOptions, options) {
|
|
5386
|
-
if (typeof userIdOrOptions === "string") {
|
|
5387
|
-
const
|
|
5388
|
-
|
|
5389
|
-
|
|
5631
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5632
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5633
|
+
const cached = this.get(id);
|
|
5634
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5635
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5390
5636
|
}
|
|
5391
5637
|
return this.fetchMany(userIdOrOptions);
|
|
5392
5638
|
}
|
|
@@ -5396,9 +5642,13 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5396
5642
|
if (options?.after) params.set("after", options.after);
|
|
5397
5643
|
const qs2 = params.toString();
|
|
5398
5644
|
const url = import_types31.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5399
|
-
const data =
|
|
5645
|
+
const data = assertApiArray(
|
|
5646
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5647
|
+
"members.fetch()"
|
|
5648
|
+
);
|
|
5400
5649
|
const members = [];
|
|
5401
5650
|
for (const m of data) {
|
|
5651
|
+
if (!m?.user?.id) continue;
|
|
5402
5652
|
const member = new GuildMember(
|
|
5403
5653
|
this.guild.client,
|
|
5404
5654
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5564,7 +5814,12 @@ async function createChannel(guild, options) {
|
|
|
5564
5814
|
return cacheChannel(guild, created);
|
|
5565
5815
|
}
|
|
5566
5816
|
async function fetchChannels(guild) {
|
|
5567
|
-
const
|
|
5817
|
+
const raw = await guild.client.rest.get(import_types33.Routes.guildChannels(guild.id));
|
|
5818
|
+
if (!Array.isArray(raw))
|
|
5819
|
+
throw new TypeError(
|
|
5820
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
5821
|
+
);
|
|
5822
|
+
const data = raw;
|
|
5568
5823
|
const channels = [];
|
|
5569
5824
|
for (const ch of data) {
|
|
5570
5825
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5659,16 +5914,20 @@ var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
|
5659
5914
|
// src/Domain/Guild/MemberHttp.ts
|
|
5660
5915
|
var import_types35 = require("@fluxerjs/types");
|
|
5661
5916
|
async function fetchMember(guild, userId) {
|
|
5917
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5662
5918
|
try {
|
|
5663
5919
|
const data = await guild.client.rest.get(
|
|
5664
|
-
import_types35.Routes.guildMember(guild.id,
|
|
5920
|
+
import_types35.Routes.guildMember(guild.id, id)
|
|
5665
5921
|
);
|
|
5922
|
+
if (!data?.user?.id) {
|
|
5923
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
5924
|
+
}
|
|
5666
5925
|
return cacheMember(guild, data);
|
|
5667
5926
|
} catch (err) {
|
|
5668
5927
|
rethrowMapped(err, {
|
|
5669
5928
|
notFound: {
|
|
5670
5929
|
code: import_util.ErrorCodes.MemberNotFound,
|
|
5671
|
-
message: `Member ${
|
|
5930
|
+
message: `Member ${id} not found in guild`
|
|
5672
5931
|
},
|
|
5673
5932
|
fallback: "Failed to fetch guild member"
|
|
5674
5933
|
});
|
|
@@ -5679,6 +5938,9 @@ async function fetchMe(guild) {
|
|
|
5679
5938
|
import_types35.Routes.guildMemberMe(guild.id),
|
|
5680
5939
|
{ auth: true }
|
|
5681
5940
|
);
|
|
5941
|
+
if (!data?.user?.id) {
|
|
5942
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
5943
|
+
}
|
|
5682
5944
|
return cacheMember(guild, data);
|
|
5683
5945
|
}
|
|
5684
5946
|
|
|
@@ -5729,6 +5991,10 @@ async function ban(guild, userId, options) {
|
|
|
5729
5991
|
...auditReasonHeaders(options?.reason)
|
|
5730
5992
|
});
|
|
5731
5993
|
}
|
|
5994
|
+
async function fetchBan(guild, userId) {
|
|
5995
|
+
const data = await guild.client.rest.get(import_types37.Routes.guildBan(guild.id, userId));
|
|
5996
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
5997
|
+
}
|
|
5732
5998
|
async function fetchBans(guild) {
|
|
5733
5999
|
const data = await guild.client.rest.get(import_types37.Routes.guildBans(guild.id));
|
|
5734
6000
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
@@ -5760,6 +6026,8 @@ async function createRole(guild, options = {}) {
|
|
|
5760
6026
|
}
|
|
5761
6027
|
async function fetchRoles(guild) {
|
|
5762
6028
|
const data = await guild.client.rest.get(import_types38.Routes.guildRoles(guild.id));
|
|
6029
|
+
if (!Array.isArray(data))
|
|
6030
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5763
6031
|
return data.map((r) => cacheRole(guild, r));
|
|
5764
6032
|
}
|
|
5765
6033
|
async function fetchRole(guild, roleId2) {
|
|
@@ -5859,6 +6127,11 @@ var Guild = class extends Base {
|
|
|
5859
6127
|
id;
|
|
5860
6128
|
/** Whether the guild is currently available through the gateway. */
|
|
5861
6129
|
available = true;
|
|
6130
|
+
/**
|
|
6131
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6132
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6133
|
+
*/
|
|
6134
|
+
partial = true;
|
|
5862
6135
|
/** Guild name. */
|
|
5863
6136
|
name;
|
|
5864
6137
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -6153,6 +6426,10 @@ var Guild = class extends Base {
|
|
|
6153
6426
|
ban(userId, options) {
|
|
6154
6427
|
return ban(this, userId, options);
|
|
6155
6428
|
}
|
|
6429
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6430
|
+
fetchBan(userId) {
|
|
6431
|
+
return fetchBan(this, userId);
|
|
6432
|
+
}
|
|
6156
6433
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6157
6434
|
fetchBans() {
|
|
6158
6435
|
return fetchBans(this);
|
|
@@ -6333,6 +6610,7 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6333
6610
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6334
6611
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6335
6612
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6613
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6336
6614
|
return { guild, created, recovered };
|
|
6337
6615
|
}
|
|
6338
6616
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6416,15 +6694,7 @@ var ClientUser = class extends User {
|
|
|
6416
6694
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6417
6695
|
var import_util24 = require("@fluxerjs/util");
|
|
6418
6696
|
function unknownUser(id) {
|
|
6419
|
-
return {
|
|
6420
|
-
id,
|
|
6421
|
-
username: "Unknown",
|
|
6422
|
-
discriminator: "0",
|
|
6423
|
-
global_name: null,
|
|
6424
|
-
avatar: null,
|
|
6425
|
-
avatar_color: null,
|
|
6426
|
-
flags: 0
|
|
6427
|
-
};
|
|
6697
|
+
return { id };
|
|
6428
6698
|
}
|
|
6429
6699
|
function indexMember(_client, guild, data) {
|
|
6430
6700
|
if (!data.user?.id) return null;
|
|
@@ -7105,6 +7375,9 @@ var passthroughHandlers = {
|
|
|
7105
7375
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7106
7376
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7107
7377
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7378
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7379
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7380
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7108
7381
|
TYPING_START(client, d) {
|
|
7109
7382
|
const data = d;
|
|
7110
7383
|
const payload = {
|
|
@@ -7295,29 +7568,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7295
7568
|
}
|
|
7296
7569
|
return dispatchGatewayPayload(client, payload);
|
|
7297
7570
|
}
|
|
7298
|
-
|
|
7571
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7572
|
+
function queueFor(client) {
|
|
7573
|
+
let queue = dispatchQueues.get(client);
|
|
7574
|
+
if (!queue) {
|
|
7575
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7576
|
+
dispatchQueues.set(client, queue);
|
|
7577
|
+
}
|
|
7578
|
+
return queue;
|
|
7579
|
+
}
|
|
7580
|
+
async function runGatewayHandler(client, payload) {
|
|
7299
7581
|
const event = payload.t;
|
|
7300
|
-
if (!event) return
|
|
7582
|
+
if (!event) return;
|
|
7301
7583
|
const handler = eventHandlers.get(event);
|
|
7302
7584
|
if (!handler) {
|
|
7303
7585
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7304
|
-
return
|
|
7586
|
+
return;
|
|
7305
7587
|
}
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
}
|
|
7313
|
-
if (client.options.gatewayDeferHandlers
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
};
|
|
7318
|
-
|
|
7319
|
-
|
|
7588
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7589
|
+
client.emit(
|
|
7590
|
+
Events.Debug,
|
|
7591
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7592
|
+
);
|
|
7593
|
+
return;
|
|
7594
|
+
}
|
|
7595
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7596
|
+
await new Promise((resolve) => {
|
|
7597
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7598
|
+
else setTimeout(resolve, 0);
|
|
7599
|
+
});
|
|
7600
|
+
}
|
|
7601
|
+
try {
|
|
7602
|
+
await handler(client, payload.d);
|
|
7603
|
+
} catch (err) {
|
|
7604
|
+
emitClientError(client, err);
|
|
7605
|
+
}
|
|
7606
|
+
}
|
|
7607
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7608
|
+
const queue = queueFor(client);
|
|
7609
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7610
|
+
queue.pending++;
|
|
7611
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7612
|
+
queue.pending--;
|
|
7613
|
+
});
|
|
7614
|
+
queue.tail = run.catch(() => {
|
|
7615
|
+
});
|
|
7616
|
+
return run;
|
|
7617
|
+
}
|
|
7618
|
+
queue.pending++;
|
|
7619
|
+
const next = queue.tail.then(
|
|
7620
|
+
() => runGatewayHandler(client, payload),
|
|
7621
|
+
() => runGatewayHandler(client, payload)
|
|
7622
|
+
).finally(() => {
|
|
7623
|
+
queue.pending--;
|
|
7624
|
+
});
|
|
7625
|
+
queue.tail = next.catch(() => {
|
|
7320
7626
|
});
|
|
7627
|
+
return next;
|
|
7321
7628
|
}
|
|
7322
7629
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7323
7630
|
while (deferred.length > 0) {
|
|
@@ -7505,6 +7812,7 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7505
7812
|
});
|
|
7506
7813
|
this.client = client;
|
|
7507
7814
|
}
|
|
7815
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7508
7816
|
/**
|
|
7509
7817
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7510
7818
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7519,35 +7827,73 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7519
7827
|
}
|
|
7520
7828
|
/**
|
|
7521
7829
|
* Get a guild from cache or fetch from the API if not present.
|
|
7830
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7522
7831
|
* @param guildId - Snowflake of the guild
|
|
7523
7832
|
* @returns The guild
|
|
7524
7833
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7525
7834
|
*/
|
|
7526
7835
|
async resolve(guildId) {
|
|
7527
|
-
|
|
7836
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
7837
|
+
const cached = this.get(id);
|
|
7838
|
+
if (cached && !cached.partial) return cached;
|
|
7839
|
+
if (cached) {
|
|
7840
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7841
|
+
await this.hydrate(cached);
|
|
7842
|
+
return cached;
|
|
7843
|
+
});
|
|
7844
|
+
return cached;
|
|
7845
|
+
}
|
|
7846
|
+
const guild = await this.fetch(id);
|
|
7847
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7848
|
+
await this.hydrate(guild);
|
|
7849
|
+
return guild;
|
|
7850
|
+
});
|
|
7851
|
+
return guild;
|
|
7528
7852
|
}
|
|
7529
7853
|
/**
|
|
7530
7854
|
* Fetch a guild by ID.
|
|
7531
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7855
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7856
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7532
7857
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7533
7858
|
*/
|
|
7534
7859
|
async fetch(guildId, options) {
|
|
7535
|
-
const
|
|
7860
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
7861
|
+
const cached = this.get(id);
|
|
7536
7862
|
if (cached && !options?.force) return cached;
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7863
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
7864
|
+
try {
|
|
7865
|
+
const data = assertApiObjectWithId(
|
|
7866
|
+
await this.client.rest.get(import_types43.Routes.guild(id)),
|
|
7867
|
+
"guilds.fetch()"
|
|
7868
|
+
);
|
|
7869
|
+
let guild;
|
|
7870
|
+
const existing = this.get(id);
|
|
7871
|
+
if (existing) {
|
|
7872
|
+
existing._patch(data);
|
|
7873
|
+
guild = existing;
|
|
7874
|
+
} else {
|
|
7875
|
+
guild = new Guild(this.client, data);
|
|
7876
|
+
this.set(guild.id, guild);
|
|
7877
|
+
}
|
|
7878
|
+
return guild;
|
|
7879
|
+
} catch (err) {
|
|
7880
|
+
rethrowMapped(err, {
|
|
7881
|
+
notFound: { code: import_util.ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
7882
|
+
fallback: `Failed to fetch guild ${id}`
|
|
7883
|
+
});
|
|
7542
7884
|
}
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7885
|
+
});
|
|
7886
|
+
}
|
|
7887
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
7888
|
+
async hydrate(guild) {
|
|
7889
|
+
try {
|
|
7890
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
7891
|
+
guild.partial = false;
|
|
7546
7892
|
} catch (err) {
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7893
|
+
this.client.emit(
|
|
7894
|
+
Events.Debug,
|
|
7895
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
7896
|
+
);
|
|
7551
7897
|
}
|
|
7552
7898
|
}
|
|
7553
7899
|
};
|
|
@@ -7572,6 +7918,10 @@ var MessageCache = class {
|
|
|
7572
7918
|
if (limit === false) return;
|
|
7573
7919
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7574
7920
|
let cache = this.caches.get(channelId);
|
|
7921
|
+
if (cache) {
|
|
7922
|
+
this.caches.delete(channelId);
|
|
7923
|
+
this.caches.set(channelId, cache);
|
|
7924
|
+
}
|
|
7575
7925
|
if (!cache) {
|
|
7576
7926
|
const channelLimit = this.getChannelLimit();
|
|
7577
7927
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7629,6 +7979,7 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7629
7979
|
super({ maxSize: client.cache.limits.users });
|
|
7630
7980
|
this.client = client;
|
|
7631
7981
|
}
|
|
7982
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7632
7983
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7633
7984
|
sweep(filter) {
|
|
7634
7985
|
let removed = 0;
|
|
@@ -7642,16 +7993,30 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7642
7993
|
}
|
|
7643
7994
|
return removed;
|
|
7644
7995
|
}
|
|
7645
|
-
/**
|
|
7996
|
+
/**
|
|
7997
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
7998
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
7999
|
+
*/
|
|
7646
8000
|
async fetch(userId, options) {
|
|
7647
|
-
const
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
return
|
|
8001
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
8002
|
+
const cached = this.get(id);
|
|
8003
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
8004
|
+
return dedupeFetch(
|
|
8005
|
+
this.pendingFetches,
|
|
8006
|
+
id,
|
|
8007
|
+
async () => this.client.getOrCreateUser(
|
|
8008
|
+
assertApiObjectWithId(
|
|
8009
|
+
await this.client.rest.get(import_types44.Routes.user(id)),
|
|
8010
|
+
"users.fetch()"
|
|
8011
|
+
)
|
|
8012
|
+
)
|
|
8013
|
+
);
|
|
7651
8014
|
}
|
|
7652
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8015
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7653
8016
|
async resolve(userId) {
|
|
7654
|
-
|
|
8017
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8018
|
+
const cached = this.get(id);
|
|
8019
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7655
8020
|
}
|
|
7656
8021
|
/**
|
|
7657
8022
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7792,7 +8157,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7792
8157
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7793
8158
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7794
8159
|
*
|
|
7795
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8160
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7796
8161
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7797
8162
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7798
8163
|
*/
|
|
@@ -7869,6 +8234,38 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7869
8234
|
fetchStickerMetadata(stickerId) {
|
|
7870
8235
|
return fetchStickerMetadata(this, stickerId);
|
|
7871
8236
|
}
|
|
8237
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8238
|
+
fetchEmojiSource(emojiId) {
|
|
8239
|
+
return fetchEmojiSource(this, emojiId);
|
|
8240
|
+
}
|
|
8241
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8242
|
+
fetchStickerSource(stickerId) {
|
|
8243
|
+
return fetchStickerSource(this, stickerId);
|
|
8244
|
+
}
|
|
8245
|
+
/** List discovery categories. */
|
|
8246
|
+
fetchDiscoveryCategories() {
|
|
8247
|
+
return fetchDiscoveryCategories(this);
|
|
8248
|
+
}
|
|
8249
|
+
/** Search discoverable guilds. */
|
|
8250
|
+
searchDiscoveryGuilds(options) {
|
|
8251
|
+
return searchDiscoveryGuilds(this, options);
|
|
8252
|
+
}
|
|
8253
|
+
/** Fetch experiment assignments for this account. */
|
|
8254
|
+
fetchExperiments() {
|
|
8255
|
+
return fetchExperiments(this);
|
|
8256
|
+
}
|
|
8257
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8258
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8259
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8260
|
+
}
|
|
8261
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8262
|
+
fetchInstanceBadges(options) {
|
|
8263
|
+
return fetchInstanceBadges(this, options);
|
|
8264
|
+
}
|
|
8265
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8266
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8267
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8268
|
+
}
|
|
7872
8269
|
/**
|
|
7873
8270
|
* Fetch the current application (`/applications/@me`).
|
|
7874
8271
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -7963,6 +8360,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7963
8360
|
* @internal
|
|
7964
8361
|
*/
|
|
7965
8362
|
getOrCreateUser(data) {
|
|
8363
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8364
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8365
|
+
}
|
|
7966
8366
|
const existing = this.users.get(data.id);
|
|
7967
8367
|
if (existing) {
|
|
7968
8368
|
existing._patch(data);
|