@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.mjs
CHANGED
|
@@ -947,6 +947,7 @@ var Events = {
|
|
|
947
947
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
948
948
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
949
949
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
950
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
950
951
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
951
952
|
GuildMemberAdd: "guildMemberAdd",
|
|
952
953
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -981,6 +982,8 @@ var Events = {
|
|
|
981
982
|
VoiceStateAck: "voiceStateAck",
|
|
982
983
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
983
984
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
985
|
+
VoiceSignal: "voiceSignal",
|
|
986
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
984
987
|
VoiceStatesSync: "voiceStatesSync",
|
|
985
988
|
WebhooksUpdate: "webhooksUpdate",
|
|
986
989
|
Resumed: "resumed",
|
|
@@ -1110,6 +1113,45 @@ import { SnowflakeUtil } from "@fluxerjs/util";
|
|
|
1110
1113
|
// src/ClientCore/MessageManager.ts
|
|
1111
1114
|
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
1112
1115
|
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
1116
|
+
|
|
1117
|
+
// src/ClientCore/Resolve.ts
|
|
1118
|
+
function normalizeSnowflakeId(value, label) {
|
|
1119
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1120
|
+
throw new TypeError(
|
|
1121
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
1125
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
1126
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
1127
|
+
}
|
|
1128
|
+
return id;
|
|
1129
|
+
}
|
|
1130
|
+
function assertApiObjectWithId(data, label) {
|
|
1131
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
1132
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
1133
|
+
}
|
|
1134
|
+
return data;
|
|
1135
|
+
}
|
|
1136
|
+
function assertApiArray(data, label) {
|
|
1137
|
+
if (!Array.isArray(data)) {
|
|
1138
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
1139
|
+
}
|
|
1140
|
+
return data;
|
|
1141
|
+
}
|
|
1142
|
+
async function dedupeFetch(pending, key, fn) {
|
|
1143
|
+
const existing = pending.get(key);
|
|
1144
|
+
if (existing) return existing;
|
|
1145
|
+
const request = fn();
|
|
1146
|
+
pending.set(key, request);
|
|
1147
|
+
try {
|
|
1148
|
+
return await request;
|
|
1149
|
+
} finally {
|
|
1150
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// src/ClientCore/MessageManager.ts
|
|
1113
1155
|
var BULK = {
|
|
1114
1156
|
requests: { min: 1, max: 25 },
|
|
1115
1157
|
limit: { min: 1, max: 25 },
|
|
@@ -1145,25 +1187,32 @@ var MessageManager = class {
|
|
|
1145
1187
|
}
|
|
1146
1188
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1147
1189
|
_structures = new Collection2();
|
|
1190
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
1148
1191
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1149
1192
|
get(messageId) {
|
|
1150
|
-
const
|
|
1193
|
+
const id = String(messageId ?? "").trim();
|
|
1194
|
+
if (!id) return void 0;
|
|
1195
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
1151
1196
|
if (!data) {
|
|
1152
|
-
this._structures.delete(
|
|
1197
|
+
this._structures.delete(id);
|
|
1153
1198
|
return void 0;
|
|
1154
1199
|
}
|
|
1155
|
-
const existing = this._structures.get(
|
|
1156
|
-
if (existing)
|
|
1200
|
+
const existing = this._structures.get(id);
|
|
1201
|
+
if (existing) {
|
|
1202
|
+
existing._patch(data);
|
|
1203
|
+
return existing;
|
|
1204
|
+
}
|
|
1157
1205
|
const message = new Message(this.client, data);
|
|
1158
|
-
this._structures.set(
|
|
1206
|
+
this._structures.set(id, message);
|
|
1159
1207
|
return message;
|
|
1160
1208
|
}
|
|
1161
1209
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1162
1210
|
async resolve(messageId) {
|
|
1163
|
-
|
|
1211
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
1212
|
+
return this.get(id) ?? this.fetch(id);
|
|
1164
1213
|
}
|
|
1165
1214
|
async fetch(idOrOptions) {
|
|
1166
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1215
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
1167
1216
|
}
|
|
1168
1217
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1169
1218
|
wrap(data) {
|
|
@@ -1180,9 +1229,13 @@ var MessageManager = class {
|
|
|
1180
1229
|
}
|
|
1181
1230
|
/** Fetch a single message from the API. */
|
|
1182
1231
|
async fetchOne(messageId) {
|
|
1232
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
1233
|
+
}
|
|
1234
|
+
async fetchOneFresh(messageId) {
|
|
1183
1235
|
try {
|
|
1184
|
-
const data =
|
|
1185
|
-
Routes2.channelMessage(this.channelId, messageId)
|
|
1236
|
+
const data = assertApiObjectWithId(
|
|
1237
|
+
await this.client.rest.get(Routes2.channelMessage(this.channelId, messageId)),
|
|
1238
|
+
"messages.fetch()"
|
|
1186
1239
|
);
|
|
1187
1240
|
return this.wrap(data);
|
|
1188
1241
|
} catch (err) {
|
|
@@ -1208,9 +1261,15 @@ var MessageManager = class {
|
|
|
1208
1261
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1209
1262
|
}
|
|
1210
1263
|
const base = Routes2.channelMessages(this.channelId);
|
|
1211
|
-
const data =
|
|
1264
|
+
const data = assertApiArray(
|
|
1265
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
1266
|
+
"messages.fetch()"
|
|
1267
|
+
);
|
|
1212
1268
|
const collection = new Collection2();
|
|
1213
|
-
for (const msg of data)
|
|
1269
|
+
for (const msg of data) {
|
|
1270
|
+
if (!msg?.id) continue;
|
|
1271
|
+
collection.set(msg.id, this.wrap(msg));
|
|
1272
|
+
}
|
|
1214
1273
|
return collection;
|
|
1215
1274
|
}
|
|
1216
1275
|
};
|
|
@@ -1414,6 +1473,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1414
1473
|
}
|
|
1415
1474
|
|
|
1416
1475
|
// src/Domain/Channel/Base.ts
|
|
1476
|
+
function isFullChannelData(data) {
|
|
1477
|
+
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;
|
|
1478
|
+
}
|
|
1417
1479
|
var Channel = class extends Base {
|
|
1418
1480
|
#messages;
|
|
1419
1481
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -1428,6 +1490,11 @@ var Channel = class extends Base {
|
|
|
1428
1490
|
icon;
|
|
1429
1491
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
1430
1492
|
lastPinTimestamp;
|
|
1493
|
+
/**
|
|
1494
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
1495
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
1496
|
+
*/
|
|
1497
|
+
partial;
|
|
1431
1498
|
constructor(client, data) {
|
|
1432
1499
|
super();
|
|
1433
1500
|
this.client = client;
|
|
@@ -1436,6 +1503,7 @@ var Channel = class extends Base {
|
|
|
1436
1503
|
this.name = data.name ?? null;
|
|
1437
1504
|
this.icon = data.icon ?? null;
|
|
1438
1505
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1506
|
+
this.partial = !isFullChannelData(data);
|
|
1439
1507
|
}
|
|
1440
1508
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1441
1509
|
get createdTimestamp() {
|
|
@@ -1456,6 +1524,7 @@ var Channel = class extends Base {
|
|
|
1456
1524
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1457
1525
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1458
1526
|
}
|
|
1527
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
1459
1528
|
}
|
|
1460
1529
|
/** @internal Factory wired after subclasses load. */
|
|
1461
1530
|
static from(_c, _d) {
|
|
@@ -2231,10 +2300,10 @@ var Message = class _Message extends Base {
|
|
|
2231
2300
|
this.channelId = data.channel_id;
|
|
2232
2301
|
this.guildId = data.guild_id ?? null;
|
|
2233
2302
|
this.author = client.getOrCreateUser(data.author);
|
|
2234
|
-
this.content = data.content;
|
|
2235
|
-
this.createdAt = new Date(data.timestamp);
|
|
2303
|
+
this.content = data.content ?? "";
|
|
2304
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
2236
2305
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2237
|
-
this.pinned = data.pinned;
|
|
2306
|
+
this.pinned = data.pinned ?? false;
|
|
2238
2307
|
this.attachments = new Collection5();
|
|
2239
2308
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2240
2309
|
this.type = data.type ?? MessageType.Default;
|
|
@@ -2266,33 +2335,47 @@ var Message = class _Message extends Base {
|
|
|
2266
2335
|
* @internal
|
|
2267
2336
|
*/
|
|
2268
2337
|
_patch(data) {
|
|
2269
|
-
this.content = data.content;
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
this.
|
|
2280
|
-
this.
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2338
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
2339
|
+
if (data.edited_timestamp !== void 0) {
|
|
2340
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2341
|
+
}
|
|
2342
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
2343
|
+
if (data.attachments !== void 0) {
|
|
2344
|
+
this.attachments.clear();
|
|
2345
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2346
|
+
}
|
|
2347
|
+
if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
2348
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
2349
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
2350
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
2351
|
+
if (data.stickers !== void 0) {
|
|
2352
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
2353
|
+
}
|
|
2354
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
2355
|
+
if (data.message_reference !== void 0) {
|
|
2356
|
+
this.messageReference = data.message_reference ? {
|
|
2357
|
+
channelId: data.message_reference.channel_id,
|
|
2358
|
+
messageId: data.message_reference.message_id,
|
|
2359
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
2360
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
2361
|
+
} : null;
|
|
2362
|
+
}
|
|
2363
|
+
if (data.message_snapshots !== void 0) {
|
|
2364
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
2365
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
2366
|
+
);
|
|
2367
|
+
}
|
|
2368
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
2369
|
+
if (data.referenced_message !== void 0) {
|
|
2370
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
2371
|
+
}
|
|
2372
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
2373
|
+
if (data.mentions !== void 0) {
|
|
2374
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2375
|
+
}
|
|
2376
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
2377
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
2378
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
2296
2379
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
2297
2380
|
}
|
|
2298
2381
|
/**
|
|
@@ -2393,6 +2476,23 @@ var Message = class _Message extends Base {
|
|
|
2393
2476
|
async fetch() {
|
|
2394
2477
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2395
2478
|
}
|
|
2479
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2480
|
+
async crosspost() {
|
|
2481
|
+
const data = await this.client.rest.post(
|
|
2482
|
+
Routes7.channelMessageCrosspost(this.channelId, this.id),
|
|
2483
|
+
{ auth: true }
|
|
2484
|
+
);
|
|
2485
|
+
const published = new _Message(this.client, data);
|
|
2486
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2487
|
+
return published;
|
|
2488
|
+
}
|
|
2489
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2490
|
+
async fetchCrosspostSource() {
|
|
2491
|
+
return this.client.rest.get(
|
|
2492
|
+
Routes7.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2493
|
+
{ auth: true }
|
|
2494
|
+
);
|
|
2495
|
+
}
|
|
2396
2496
|
/** Delete this message. */
|
|
2397
2497
|
async delete(reason) {
|
|
2398
2498
|
await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
|
|
@@ -2556,7 +2656,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2556
2656
|
const full = data;
|
|
2557
2657
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2558
2658
|
this.ownerId = full.owner_id ?? null;
|
|
2559
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2659
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2560
2660
|
this.nicks = full.nicks ?? {};
|
|
2561
2661
|
}
|
|
2562
2662
|
/**
|
|
@@ -2571,7 +2671,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2571
2671
|
}
|
|
2572
2672
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2573
2673
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2574
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2674
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2575
2675
|
}
|
|
2576
2676
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2577
2677
|
}
|
|
@@ -2656,17 +2756,19 @@ import {
|
|
|
2656
2756
|
// src/Helpers/Instance.ts
|
|
2657
2757
|
import { isRecord } from "@fluxerjs/util";
|
|
2658
2758
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2659
|
-
api: "https://
|
|
2660
|
-
api_client: "https://
|
|
2661
|
-
api_public: "https://
|
|
2662
|
-
gateway: "wss://gateway.fluxer.
|
|
2759
|
+
api: "https://fluxer.com/api",
|
|
2760
|
+
api_client: "https://fluxer.com/api",
|
|
2761
|
+
api_public: "https://fluxer.com/api",
|
|
2762
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2663
2763
|
media: CDN_URL,
|
|
2764
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2664
2765
|
static_cdn: STATIC_CDN_URL,
|
|
2665
|
-
marketing: "https://fluxer.
|
|
2766
|
+
marketing: "https://fluxer.com",
|
|
2767
|
+
docs: "https://docs.fluxer.com",
|
|
2666
2768
|
admin: "https://admin.fluxer.app",
|
|
2667
2769
|
invite: "https://fluxer.gg",
|
|
2668
2770
|
gift: "https://fluxer.gift",
|
|
2669
|
-
webapp: "https://
|
|
2771
|
+
webapp: "https://fluxer.com"
|
|
2670
2772
|
});
|
|
2671
2773
|
var ENDPOINT_KEYS = [
|
|
2672
2774
|
"api",
|
|
@@ -2681,6 +2783,11 @@ var ENDPOINT_KEYS = [
|
|
|
2681
2783
|
"gift",
|
|
2682
2784
|
"webapp"
|
|
2683
2785
|
];
|
|
2786
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
2787
|
+
"api_transport",
|
|
2788
|
+
"upload_relay",
|
|
2789
|
+
"docs"
|
|
2790
|
+
];
|
|
2684
2791
|
function requireString(obj, key, path) {
|
|
2685
2792
|
const value = obj[key];
|
|
2686
2793
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2721,6 +2828,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2721
2828
|
for (const key of ENDPOINT_KEYS) {
|
|
2722
2829
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2723
2830
|
}
|
|
2831
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
2832
|
+
const value = raw.endpoints[key];
|
|
2833
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
2834
|
+
}
|
|
2724
2835
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2725
2836
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2726
2837
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -2774,7 +2885,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
2774
2885
|
defaultsHash: ""
|
|
2775
2886
|
},
|
|
2776
2887
|
push: raw.push ?? { public_vapid_key: null },
|
|
2777
|
-
app_public: raw.app_public ?? {}
|
|
2888
|
+
app_public: raw.app_public ?? {},
|
|
2889
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
2890
|
+
age_policy: isRecord(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
2891
|
+
...raw.notice === null || isRecord(raw.notice) ? { notice: raw.notice } : {},
|
|
2892
|
+
...isRecord(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
2893
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
2894
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
2895
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
2896
|
+
...isRecord(raw.built_in_guild_badge_images) ? {
|
|
2897
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
2898
|
+
} : {},
|
|
2899
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
2900
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
2901
|
+
} : {},
|
|
2902
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
2778
2903
|
};
|
|
2779
2904
|
}
|
|
2780
2905
|
function resolveInstanceEndpoints(input) {
|
|
@@ -2794,7 +2919,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
2794
2919
|
}
|
|
2795
2920
|
const partial = input;
|
|
2796
2921
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
2797
|
-
for (const key of ENDPOINT_KEYS) {
|
|
2922
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
2798
2923
|
const value = partial[key];
|
|
2799
2924
|
if (typeof value === "string" && value.length > 0) {
|
|
2800
2925
|
merged[key] = value;
|
|
@@ -3414,6 +3539,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3414
3539
|
}
|
|
3415
3540
|
};
|
|
3416
3541
|
var AnnouncementChannel = class extends TextChannel {
|
|
3542
|
+
/**
|
|
3543
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3544
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3545
|
+
*/
|
|
3546
|
+
async follow(webhookChannelId) {
|
|
3547
|
+
return this.client.rest.post(
|
|
3548
|
+
Routes13.channelFollowers(this.id),
|
|
3549
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3550
|
+
);
|
|
3551
|
+
}
|
|
3552
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3553
|
+
async fetchFollowerStats() {
|
|
3554
|
+
return this.client.rest.get(
|
|
3555
|
+
Routes13.channelFollowerStats(this.id),
|
|
3556
|
+
{ auth: true }
|
|
3557
|
+
);
|
|
3558
|
+
}
|
|
3417
3559
|
};
|
|
3418
3560
|
var CategoryChannel = class extends GuildChannel {
|
|
3419
3561
|
};
|
|
@@ -3440,6 +3582,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3440
3582
|
voiceConnectionLimit;
|
|
3441
3583
|
/** RTC region override for this channel. */
|
|
3442
3584
|
rtcRegion;
|
|
3585
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3586
|
+
rtcP2p;
|
|
3443
3587
|
constructor(client, data) {
|
|
3444
3588
|
super(client, data);
|
|
3445
3589
|
this.topic = data.topic ?? null;
|
|
@@ -3453,6 +3597,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3453
3597
|
this.userLimit = data.user_limit ?? null;
|
|
3454
3598
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3455
3599
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3600
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3456
3601
|
}
|
|
3457
3602
|
/**
|
|
3458
3603
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3479,6 +3624,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3479
3624
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3480
3625
|
}
|
|
3481
3626
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3627
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3482
3628
|
}
|
|
3483
3629
|
};
|
|
3484
3630
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -4044,12 +4190,15 @@ var User = class extends Base {
|
|
|
4044
4190
|
system;
|
|
4045
4191
|
/** Banner hash for profile. */
|
|
4046
4192
|
banner;
|
|
4193
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
4194
|
+
partial;
|
|
4047
4195
|
constructor(client, data) {
|
|
4048
4196
|
super();
|
|
4049
4197
|
this.client = client;
|
|
4050
4198
|
this.id = data.id;
|
|
4051
|
-
this.
|
|
4052
|
-
this.
|
|
4199
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
4200
|
+
this.username = data.username ?? "Unknown";
|
|
4201
|
+
this.discriminator = data.discriminator ?? "0";
|
|
4053
4202
|
this.globalName = data.global_name ?? null;
|
|
4054
4203
|
this.avatar = data.avatar ?? null;
|
|
4055
4204
|
this.bot = !!data.bot;
|
|
@@ -4060,13 +4209,18 @@ var User = class extends Base {
|
|
|
4060
4209
|
}
|
|
4061
4210
|
/** @internal */
|
|
4062
4211
|
_patch(data) {
|
|
4063
|
-
this.username = data.username;
|
|
4064
|
-
this.discriminator = data.discriminator;
|
|
4065
|
-
this.globalName = data.global_name ?? null;
|
|
4066
|
-
this.avatar = data.avatar ?? null;
|
|
4212
|
+
if (data.username !== void 0) this.username = data.username;
|
|
4213
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
4214
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
4215
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
4067
4216
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
4068
4217
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
4069
4218
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
4219
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
4220
|
+
}
|
|
4221
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
4222
|
+
async fetch() {
|
|
4223
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
4070
4224
|
}
|
|
4071
4225
|
cdnOpts() {
|
|
4072
4226
|
return {
|
|
@@ -4854,6 +5008,8 @@ var Role = class _Role extends Base {
|
|
|
4854
5008
|
mentionable;
|
|
4855
5009
|
/** Unicode emoji for this role (null = none). */
|
|
4856
5010
|
unicodeEmoji;
|
|
5011
|
+
/** Role icon image hash (null = none). */
|
|
5012
|
+
icon;
|
|
4857
5013
|
/** Hoist position (null = not hoisted). */
|
|
4858
5014
|
hoistPosition;
|
|
4859
5015
|
constructor(client, data, guildId) {
|
|
@@ -4861,20 +5017,26 @@ var Role = class _Role extends Base {
|
|
|
4861
5017
|
this.client = client;
|
|
4862
5018
|
this.id = data.id;
|
|
4863
5019
|
this.guildId = guildId;
|
|
4864
|
-
this.name = data.name;
|
|
4865
|
-
this.color = data.color;
|
|
4866
|
-
this.position = data.position;
|
|
4867
|
-
this._permissions = data.permissions;
|
|
5020
|
+
this.name = data.name ?? "";
|
|
5021
|
+
this.color = data.color ?? 0;
|
|
5022
|
+
this.position = data.position ?? 0;
|
|
5023
|
+
this._permissions = data.permissions ?? "0";
|
|
4868
5024
|
this.hoist = !!data.hoist;
|
|
4869
5025
|
this.mentionable = !!data.mentionable;
|
|
4870
5026
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5027
|
+
this.icon = data.icon ?? null;
|
|
4871
5028
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4872
5029
|
}
|
|
4873
5030
|
/**
|
|
4874
5031
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4875
5032
|
*/
|
|
4876
5033
|
get permissions() {
|
|
4877
|
-
|
|
5034
|
+
let bits;
|
|
5035
|
+
try {
|
|
5036
|
+
bits = BigInt(this._permissions ?? "0");
|
|
5037
|
+
} catch {
|
|
5038
|
+
bits = 0n;
|
|
5039
|
+
}
|
|
4878
5040
|
return new PermissionsBitField3(
|
|
4879
5041
|
(bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
|
|
4880
5042
|
);
|
|
@@ -4904,14 +5066,15 @@ var Role = class _Role extends Base {
|
|
|
4904
5066
|
}
|
|
4905
5067
|
/** @internal */
|
|
4906
5068
|
_patch(data) {
|
|
4907
|
-
this.name = data.name;
|
|
4908
|
-
this.color = data.color;
|
|
4909
|
-
this.position = data.position;
|
|
4910
|
-
this._permissions = data.permissions;
|
|
4911
|
-
this.hoist = !!data.hoist;
|
|
4912
|
-
this.mentionable = !!data.mentionable;
|
|
4913
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4914
|
-
this.
|
|
5069
|
+
if (data.name !== void 0) this.name = data.name;
|
|
5070
|
+
if (data.color !== void 0) this.color = data.color;
|
|
5071
|
+
if (data.position !== void 0) this.position = data.position;
|
|
5072
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
5073
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
5074
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
5075
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5076
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
5077
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4915
5078
|
}
|
|
4916
5079
|
/**
|
|
4917
5080
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4929,6 +5092,7 @@ var Role = class _Role extends Base {
|
|
|
4929
5092
|
hoist: this.hoist,
|
|
4930
5093
|
mentionable: this.mentionable,
|
|
4931
5094
|
unicode_emoji: this.unicodeEmoji,
|
|
5095
|
+
icon: this.icon,
|
|
4932
5096
|
hoist_position: this.hoistPosition
|
|
4933
5097
|
},
|
|
4934
5098
|
this.guildId
|
|
@@ -5106,6 +5270,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5106
5270
|
});
|
|
5107
5271
|
this.client = client;
|
|
5108
5272
|
}
|
|
5273
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5109
5274
|
/**
|
|
5110
5275
|
* Remove a channel from cache. Does not delete it on the API.
|
|
5111
5276
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -5118,9 +5283,11 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5118
5283
|
}
|
|
5119
5284
|
return deleted;
|
|
5120
5285
|
}
|
|
5121
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5286
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
5122
5287
|
async resolve(channelId) {
|
|
5123
|
-
|
|
5288
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5289
|
+
const cached = this.get(id);
|
|
5290
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
5124
5291
|
}
|
|
5125
5292
|
/**
|
|
5126
5293
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5133,10 +5300,23 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5133
5300
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5134
5301
|
*/
|
|
5135
5302
|
async fetch(channelId, options) {
|
|
5136
|
-
const
|
|
5137
|
-
|
|
5303
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5304
|
+
const cached = this.get(id);
|
|
5305
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5306
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5307
|
+
}
|
|
5308
|
+
async fetchFresh(channelId) {
|
|
5138
5309
|
try {
|
|
5139
|
-
const data =
|
|
5310
|
+
const data = assertApiObjectWithId(
|
|
5311
|
+
await this.client.rest.get(Routes23.channel(channelId)),
|
|
5312
|
+
"channels.fetch()"
|
|
5313
|
+
);
|
|
5314
|
+
const existing = this.get(channelId);
|
|
5315
|
+
if (existing && existing.type === data.type) {
|
|
5316
|
+
existing._patch(data);
|
|
5317
|
+
putChannel(this.client, existing);
|
|
5318
|
+
return existing;
|
|
5319
|
+
}
|
|
5140
5320
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5141
5321
|
if (guildId) {
|
|
5142
5322
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5303,6 +5483,68 @@ async function searchMessages(client, options = {}) {
|
|
|
5303
5483
|
});
|
|
5304
5484
|
return toMessageSearchResponse(data);
|
|
5305
5485
|
}
|
|
5486
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5487
|
+
return client.rest.get(
|
|
5488
|
+
Routes24.emojiSource(emojiId),
|
|
5489
|
+
{ auth: true }
|
|
5490
|
+
);
|
|
5491
|
+
}
|
|
5492
|
+
function fetchStickerSource(client, stickerId) {
|
|
5493
|
+
return client.rest.get(
|
|
5494
|
+
Routes24.stickerSource(stickerId),
|
|
5495
|
+
{ auth: true }
|
|
5496
|
+
);
|
|
5497
|
+
}
|
|
5498
|
+
function fetchDiscoveryCategories(client) {
|
|
5499
|
+
return client.rest.get(
|
|
5500
|
+
Routes24.discoveryCategories(),
|
|
5501
|
+
{ auth: true }
|
|
5502
|
+
);
|
|
5503
|
+
}
|
|
5504
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5505
|
+
const params = new URLSearchParams();
|
|
5506
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5507
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5508
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5509
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5510
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5511
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5512
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5513
|
+
const qs2 = params.toString();
|
|
5514
|
+
return client.rest.get(
|
|
5515
|
+
qs2 ? `${Routes24.discoveryGuilds()}?${qs2}` : Routes24.discoveryGuilds(),
|
|
5516
|
+
{ auth: true }
|
|
5517
|
+
);
|
|
5518
|
+
}
|
|
5519
|
+
function fetchExperiments(client) {
|
|
5520
|
+
return client.rest.get(Routes24.experiments(), {
|
|
5521
|
+
auth: true
|
|
5522
|
+
});
|
|
5523
|
+
}
|
|
5524
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5525
|
+
return client.rest.post(
|
|
5526
|
+
Routes24.attachmentsRefreshUrls(),
|
|
5527
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5528
|
+
);
|
|
5529
|
+
}
|
|
5530
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5531
|
+
const params = new URLSearchParams();
|
|
5532
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5533
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5534
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5535
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5536
|
+
const qs2 = params.toString();
|
|
5537
|
+
return client.rest.get(
|
|
5538
|
+
qs2 ? `${Routes24.instanceBadges()}?${qs2}` : Routes24.instanceBadges(),
|
|
5539
|
+
{ auth: false }
|
|
5540
|
+
);
|
|
5541
|
+
}
|
|
5542
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5543
|
+
return client.rest.post(
|
|
5544
|
+
Routes24.channelPostData(channelId),
|
|
5545
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5546
|
+
);
|
|
5547
|
+
}
|
|
5306
5548
|
|
|
5307
5549
|
// src/ClientCore/ClientEvents.ts
|
|
5308
5550
|
function createEventMethods(client) {
|
|
@@ -5333,6 +5575,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5333
5575
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5334
5576
|
this.guild = guild;
|
|
5335
5577
|
}
|
|
5578
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5336
5579
|
/**
|
|
5337
5580
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5338
5581
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5344,7 +5587,9 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5344
5587
|
* console.log(member.displayName);
|
|
5345
5588
|
*/
|
|
5346
5589
|
async resolve(userId) {
|
|
5347
|
-
|
|
5590
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5591
|
+
const cached = this.get(id);
|
|
5592
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5348
5593
|
}
|
|
5349
5594
|
/**
|
|
5350
5595
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5372,10 +5617,11 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5372
5617
|
return this.guild.fetchMe();
|
|
5373
5618
|
}
|
|
5374
5619
|
async fetch(userIdOrOptions, options) {
|
|
5375
|
-
if (typeof userIdOrOptions === "string") {
|
|
5376
|
-
const
|
|
5377
|
-
|
|
5378
|
-
|
|
5620
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5621
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5622
|
+
const cached = this.get(id);
|
|
5623
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5624
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5379
5625
|
}
|
|
5380
5626
|
return this.fetchMany(userIdOrOptions);
|
|
5381
5627
|
}
|
|
@@ -5385,9 +5631,13 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5385
5631
|
if (options?.after) params.set("after", options.after);
|
|
5386
5632
|
const qs2 = params.toString();
|
|
5387
5633
|
const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5388
|
-
const data =
|
|
5634
|
+
const data = assertApiArray(
|
|
5635
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5636
|
+
"members.fetch()"
|
|
5637
|
+
);
|
|
5389
5638
|
const members = [];
|
|
5390
5639
|
for (const m of data) {
|
|
5640
|
+
if (!m?.user?.id) continue;
|
|
5391
5641
|
const member = new GuildMember(
|
|
5392
5642
|
this.guild.client,
|
|
5393
5643
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5553,7 +5803,12 @@ async function createChannel(guild, options) {
|
|
|
5553
5803
|
return cacheChannel(guild, created);
|
|
5554
5804
|
}
|
|
5555
5805
|
async function fetchChannels(guild) {
|
|
5556
|
-
const
|
|
5806
|
+
const raw = await guild.client.rest.get(Routes27.guildChannels(guild.id));
|
|
5807
|
+
if (!Array.isArray(raw))
|
|
5808
|
+
throw new TypeError(
|
|
5809
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
5810
|
+
);
|
|
5811
|
+
const data = raw;
|
|
5557
5812
|
const channels = [];
|
|
5558
5813
|
for (const ch of data) {
|
|
5559
5814
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5648,16 +5903,20 @@ var GuildRoleManager = class extends LimitedCollection3 {
|
|
|
5648
5903
|
// src/Domain/Guild/MemberHttp.ts
|
|
5649
5904
|
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
5650
5905
|
async function fetchMember(guild, userId) {
|
|
5906
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5651
5907
|
try {
|
|
5652
5908
|
const data = await guild.client.rest.get(
|
|
5653
|
-
Routes29.guildMember(guild.id,
|
|
5909
|
+
Routes29.guildMember(guild.id, id)
|
|
5654
5910
|
);
|
|
5911
|
+
if (!data?.user?.id) {
|
|
5912
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
5913
|
+
}
|
|
5655
5914
|
return cacheMember(guild, data);
|
|
5656
5915
|
} catch (err) {
|
|
5657
5916
|
rethrowMapped(err, {
|
|
5658
5917
|
notFound: {
|
|
5659
5918
|
code: ErrorCodes.MemberNotFound,
|
|
5660
|
-
message: `Member ${
|
|
5919
|
+
message: `Member ${id} not found in guild`
|
|
5661
5920
|
},
|
|
5662
5921
|
fallback: "Failed to fetch guild member"
|
|
5663
5922
|
});
|
|
@@ -5668,6 +5927,9 @@ async function fetchMe(guild) {
|
|
|
5668
5927
|
Routes29.guildMemberMe(guild.id),
|
|
5669
5928
|
{ auth: true }
|
|
5670
5929
|
);
|
|
5930
|
+
if (!data?.user?.id) {
|
|
5931
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
5932
|
+
}
|
|
5671
5933
|
return cacheMember(guild, data);
|
|
5672
5934
|
}
|
|
5673
5935
|
|
|
@@ -5718,6 +5980,10 @@ async function ban(guild, userId, options) {
|
|
|
5718
5980
|
...auditReasonHeaders(options?.reason)
|
|
5719
5981
|
});
|
|
5720
5982
|
}
|
|
5983
|
+
async function fetchBan(guild, userId) {
|
|
5984
|
+
const data = await guild.client.rest.get(Routes31.guildBan(guild.id, userId));
|
|
5985
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
5986
|
+
}
|
|
5721
5987
|
async function fetchBans(guild) {
|
|
5722
5988
|
const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
|
|
5723
5989
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
@@ -5749,6 +6015,8 @@ async function createRole(guild, options = {}) {
|
|
|
5749
6015
|
}
|
|
5750
6016
|
async function fetchRoles(guild) {
|
|
5751
6017
|
const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
|
|
6018
|
+
if (!Array.isArray(data))
|
|
6019
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5752
6020
|
return data.map((r) => cacheRole(guild, r));
|
|
5753
6021
|
}
|
|
5754
6022
|
async function fetchRole(guild, roleId2) {
|
|
@@ -5848,6 +6116,11 @@ var Guild = class extends Base {
|
|
|
5848
6116
|
id;
|
|
5849
6117
|
/** Whether the guild is currently available through the gateway. */
|
|
5850
6118
|
available = true;
|
|
6119
|
+
/**
|
|
6120
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6121
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6122
|
+
*/
|
|
6123
|
+
partial = true;
|
|
5851
6124
|
/** Guild name. */
|
|
5852
6125
|
name;
|
|
5853
6126
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -6142,6 +6415,10 @@ var Guild = class extends Base {
|
|
|
6142
6415
|
ban(userId, options) {
|
|
6143
6416
|
return ban(this, userId, options);
|
|
6144
6417
|
}
|
|
6418
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6419
|
+
fetchBan(userId) {
|
|
6420
|
+
return fetchBan(this, userId);
|
|
6421
|
+
}
|
|
6145
6422
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6146
6423
|
fetchBans() {
|
|
6147
6424
|
return fetchBans(this);
|
|
@@ -6322,6 +6599,7 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6322
6599
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6323
6600
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6324
6601
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6602
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6325
6603
|
return { guild, created, recovered };
|
|
6326
6604
|
}
|
|
6327
6605
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6405,15 +6683,7 @@ var ClientUser = class extends User {
|
|
|
6405
6683
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6406
6684
|
import { asRecord, num, str } from "@fluxerjs/util";
|
|
6407
6685
|
function unknownUser(id) {
|
|
6408
|
-
return {
|
|
6409
|
-
id,
|
|
6410
|
-
username: "Unknown",
|
|
6411
|
-
discriminator: "0",
|
|
6412
|
-
global_name: null,
|
|
6413
|
-
avatar: null,
|
|
6414
|
-
avatar_color: null,
|
|
6415
|
-
flags: 0
|
|
6416
|
-
};
|
|
6686
|
+
return { id };
|
|
6417
6687
|
}
|
|
6418
6688
|
function indexMember(_client, guild, data) {
|
|
6419
6689
|
if (!data.user?.id) return null;
|
|
@@ -7097,6 +7367,9 @@ var passthroughHandlers = {
|
|
|
7097
7367
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7098
7368
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7099
7369
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7370
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7371
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7372
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7100
7373
|
TYPING_START(client, d) {
|
|
7101
7374
|
const data = d;
|
|
7102
7375
|
const payload = {
|
|
@@ -7287,29 +7560,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7287
7560
|
}
|
|
7288
7561
|
return dispatchGatewayPayload(client, payload);
|
|
7289
7562
|
}
|
|
7290
|
-
|
|
7563
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7564
|
+
function queueFor(client) {
|
|
7565
|
+
let queue = dispatchQueues.get(client);
|
|
7566
|
+
if (!queue) {
|
|
7567
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7568
|
+
dispatchQueues.set(client, queue);
|
|
7569
|
+
}
|
|
7570
|
+
return queue;
|
|
7571
|
+
}
|
|
7572
|
+
async function runGatewayHandler(client, payload) {
|
|
7291
7573
|
const event = payload.t;
|
|
7292
|
-
if (!event) return
|
|
7574
|
+
if (!event) return;
|
|
7293
7575
|
const handler = eventHandlers.get(event);
|
|
7294
7576
|
if (!handler) {
|
|
7295
7577
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7296
|
-
return
|
|
7578
|
+
return;
|
|
7297
7579
|
}
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
}
|
|
7305
|
-
if (client.options.gatewayDeferHandlers
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
};
|
|
7310
|
-
|
|
7311
|
-
|
|
7580
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7581
|
+
client.emit(
|
|
7582
|
+
Events.Debug,
|
|
7583
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7584
|
+
);
|
|
7585
|
+
return;
|
|
7586
|
+
}
|
|
7587
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7588
|
+
await new Promise((resolve) => {
|
|
7589
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7590
|
+
else setTimeout(resolve, 0);
|
|
7591
|
+
});
|
|
7592
|
+
}
|
|
7593
|
+
try {
|
|
7594
|
+
await handler(client, payload.d);
|
|
7595
|
+
} catch (err) {
|
|
7596
|
+
emitClientError(client, err);
|
|
7597
|
+
}
|
|
7598
|
+
}
|
|
7599
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7600
|
+
const queue = queueFor(client);
|
|
7601
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7602
|
+
queue.pending++;
|
|
7603
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7604
|
+
queue.pending--;
|
|
7605
|
+
});
|
|
7606
|
+
queue.tail = run.catch(() => {
|
|
7607
|
+
});
|
|
7608
|
+
return run;
|
|
7609
|
+
}
|
|
7610
|
+
queue.pending++;
|
|
7611
|
+
const next = queue.tail.then(
|
|
7612
|
+
() => runGatewayHandler(client, payload),
|
|
7613
|
+
() => runGatewayHandler(client, payload)
|
|
7614
|
+
).finally(() => {
|
|
7615
|
+
queue.pending--;
|
|
7616
|
+
});
|
|
7617
|
+
queue.tail = next.catch(() => {
|
|
7312
7618
|
});
|
|
7619
|
+
return next;
|
|
7313
7620
|
}
|
|
7314
7621
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7315
7622
|
while (deferred.length > 0) {
|
|
@@ -7497,6 +7804,7 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7497
7804
|
});
|
|
7498
7805
|
this.client = client;
|
|
7499
7806
|
}
|
|
7807
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7500
7808
|
/**
|
|
7501
7809
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7502
7810
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7511,35 +7819,73 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7511
7819
|
}
|
|
7512
7820
|
/**
|
|
7513
7821
|
* Get a guild from cache or fetch from the API if not present.
|
|
7822
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7514
7823
|
* @param guildId - Snowflake of the guild
|
|
7515
7824
|
* @returns The guild
|
|
7516
7825
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7517
7826
|
*/
|
|
7518
7827
|
async resolve(guildId) {
|
|
7519
|
-
|
|
7828
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
7829
|
+
const cached = this.get(id);
|
|
7830
|
+
if (cached && !cached.partial) return cached;
|
|
7831
|
+
if (cached) {
|
|
7832
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7833
|
+
await this.hydrate(cached);
|
|
7834
|
+
return cached;
|
|
7835
|
+
});
|
|
7836
|
+
return cached;
|
|
7837
|
+
}
|
|
7838
|
+
const guild = await this.fetch(id);
|
|
7839
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7840
|
+
await this.hydrate(guild);
|
|
7841
|
+
return guild;
|
|
7842
|
+
});
|
|
7843
|
+
return guild;
|
|
7520
7844
|
}
|
|
7521
7845
|
/**
|
|
7522
7846
|
* Fetch a guild by ID.
|
|
7523
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7847
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7848
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7524
7849
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7525
7850
|
*/
|
|
7526
7851
|
async fetch(guildId, options) {
|
|
7527
|
-
const
|
|
7852
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
7853
|
+
const cached = this.get(id);
|
|
7528
7854
|
if (cached && !options?.force) return cached;
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7855
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
7856
|
+
try {
|
|
7857
|
+
const data = assertApiObjectWithId(
|
|
7858
|
+
await this.client.rest.get(Routes35.guild(id)),
|
|
7859
|
+
"guilds.fetch()"
|
|
7860
|
+
);
|
|
7861
|
+
let guild;
|
|
7862
|
+
const existing = this.get(id);
|
|
7863
|
+
if (existing) {
|
|
7864
|
+
existing._patch(data);
|
|
7865
|
+
guild = existing;
|
|
7866
|
+
} else {
|
|
7867
|
+
guild = new Guild(this.client, data);
|
|
7868
|
+
this.set(guild.id, guild);
|
|
7869
|
+
}
|
|
7870
|
+
return guild;
|
|
7871
|
+
} catch (err) {
|
|
7872
|
+
rethrowMapped(err, {
|
|
7873
|
+
notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
7874
|
+
fallback: `Failed to fetch guild ${id}`
|
|
7875
|
+
});
|
|
7534
7876
|
}
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7877
|
+
});
|
|
7878
|
+
}
|
|
7879
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
7880
|
+
async hydrate(guild) {
|
|
7881
|
+
try {
|
|
7882
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
7883
|
+
guild.partial = false;
|
|
7538
7884
|
} catch (err) {
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7885
|
+
this.client.emit(
|
|
7886
|
+
Events.Debug,
|
|
7887
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
7888
|
+
);
|
|
7543
7889
|
}
|
|
7544
7890
|
}
|
|
7545
7891
|
};
|
|
@@ -7564,6 +7910,10 @@ var MessageCache = class {
|
|
|
7564
7910
|
if (limit === false) return;
|
|
7565
7911
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7566
7912
|
let cache = this.caches.get(channelId);
|
|
7913
|
+
if (cache) {
|
|
7914
|
+
this.caches.delete(channelId);
|
|
7915
|
+
this.caches.set(channelId, cache);
|
|
7916
|
+
}
|
|
7567
7917
|
if (!cache) {
|
|
7568
7918
|
const channelLimit = this.getChannelLimit();
|
|
7569
7919
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7623,6 +7973,7 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7623
7973
|
super({ maxSize: client.cache.limits.users });
|
|
7624
7974
|
this.client = client;
|
|
7625
7975
|
}
|
|
7976
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7626
7977
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7627
7978
|
sweep(filter) {
|
|
7628
7979
|
let removed = 0;
|
|
@@ -7636,16 +7987,30 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7636
7987
|
}
|
|
7637
7988
|
return removed;
|
|
7638
7989
|
}
|
|
7639
|
-
/**
|
|
7990
|
+
/**
|
|
7991
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
7992
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
7993
|
+
*/
|
|
7640
7994
|
async fetch(userId, options) {
|
|
7641
|
-
const
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
return
|
|
7995
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
7996
|
+
const cached = this.get(id);
|
|
7997
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
7998
|
+
return dedupeFetch(
|
|
7999
|
+
this.pendingFetches,
|
|
8000
|
+
id,
|
|
8001
|
+
async () => this.client.getOrCreateUser(
|
|
8002
|
+
assertApiObjectWithId(
|
|
8003
|
+
await this.client.rest.get(Routes36.user(id)),
|
|
8004
|
+
"users.fetch()"
|
|
8005
|
+
)
|
|
8006
|
+
)
|
|
8007
|
+
);
|
|
7645
8008
|
}
|
|
7646
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8009
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7647
8010
|
async resolve(userId) {
|
|
7648
|
-
|
|
8011
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8012
|
+
const cached = this.get(id);
|
|
8013
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7649
8014
|
}
|
|
7650
8015
|
/**
|
|
7651
8016
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7786,7 +8151,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7786
8151
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7787
8152
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7788
8153
|
*
|
|
7789
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8154
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7790
8155
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7791
8156
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7792
8157
|
*/
|
|
@@ -7863,6 +8228,38 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7863
8228
|
fetchStickerMetadata(stickerId) {
|
|
7864
8229
|
return fetchStickerMetadata(this, stickerId);
|
|
7865
8230
|
}
|
|
8231
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8232
|
+
fetchEmojiSource(emojiId) {
|
|
8233
|
+
return fetchEmojiSource(this, emojiId);
|
|
8234
|
+
}
|
|
8235
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8236
|
+
fetchStickerSource(stickerId) {
|
|
8237
|
+
return fetchStickerSource(this, stickerId);
|
|
8238
|
+
}
|
|
8239
|
+
/** List discovery categories. */
|
|
8240
|
+
fetchDiscoveryCategories() {
|
|
8241
|
+
return fetchDiscoveryCategories(this);
|
|
8242
|
+
}
|
|
8243
|
+
/** Search discoverable guilds. */
|
|
8244
|
+
searchDiscoveryGuilds(options) {
|
|
8245
|
+
return searchDiscoveryGuilds(this, options);
|
|
8246
|
+
}
|
|
8247
|
+
/** Fetch experiment assignments for this account. */
|
|
8248
|
+
fetchExperiments() {
|
|
8249
|
+
return fetchExperiments(this);
|
|
8250
|
+
}
|
|
8251
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8252
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8253
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8254
|
+
}
|
|
8255
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8256
|
+
fetchInstanceBadges(options) {
|
|
8257
|
+
return fetchInstanceBadges(this, options);
|
|
8258
|
+
}
|
|
8259
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8260
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8261
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8262
|
+
}
|
|
7866
8263
|
/**
|
|
7867
8264
|
* Fetch the current application (`/applications/@me`).
|
|
7868
8265
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -7957,6 +8354,9 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7957
8354
|
* @internal
|
|
7958
8355
|
*/
|
|
7959
8356
|
getOrCreateUser(data) {
|
|
8357
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8358
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8359
|
+
}
|
|
7960
8360
|
const existing = this.users.get(data.id);
|
|
7961
8361
|
if (existing) {
|
|
7962
8362
|
existing._patch(data);
|