@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.mjs
CHANGED
|
@@ -24,6 +24,7 @@ var Events = {
|
|
|
24
24
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
25
25
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
26
26
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
27
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
27
28
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
28
29
|
GuildMemberAdd: "guildMemberAdd",
|
|
29
30
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -58,6 +59,8 @@ var Events = {
|
|
|
58
59
|
VoiceStateAck: "voiceStateAck",
|
|
59
60
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
60
61
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
62
|
+
VoiceSignal: "voiceSignal",
|
|
63
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
61
64
|
VoiceStatesSync: "voiceStatesSync",
|
|
62
65
|
WebhooksUpdate: "webhooksUpdate",
|
|
63
66
|
Resumed: "resumed",
|
|
@@ -1113,6 +1116,45 @@ import { SnowflakeUtil } from "@fluxerjs/util";
|
|
|
1113
1116
|
// src/ClientCore/MessageManager.ts
|
|
1114
1117
|
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
1115
1118
|
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
1119
|
+
|
|
1120
|
+
// src/ClientCore/Resolve.ts
|
|
1121
|
+
function normalizeSnowflakeId(value, label) {
|
|
1122
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1123
|
+
throw new TypeError(
|
|
1124
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
1128
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
1129
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
1130
|
+
}
|
|
1131
|
+
return id;
|
|
1132
|
+
}
|
|
1133
|
+
function assertApiObjectWithId(data, label) {
|
|
1134
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
1135
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
1136
|
+
}
|
|
1137
|
+
return data;
|
|
1138
|
+
}
|
|
1139
|
+
function assertApiArray(data, label) {
|
|
1140
|
+
if (!Array.isArray(data)) {
|
|
1141
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
1142
|
+
}
|
|
1143
|
+
return data;
|
|
1144
|
+
}
|
|
1145
|
+
async function dedupeFetch(pending, key, fn) {
|
|
1146
|
+
const existing = pending.get(key);
|
|
1147
|
+
if (existing) return existing;
|
|
1148
|
+
const request = fn();
|
|
1149
|
+
pending.set(key, request);
|
|
1150
|
+
try {
|
|
1151
|
+
return await request;
|
|
1152
|
+
} finally {
|
|
1153
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// src/ClientCore/MessageManager.ts
|
|
1116
1158
|
var BULK = {
|
|
1117
1159
|
requests: { min: 1, max: 25 },
|
|
1118
1160
|
limit: { min: 1, max: 25 },
|
|
@@ -1148,25 +1190,32 @@ var MessageManager = class {
|
|
|
1148
1190
|
}
|
|
1149
1191
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1150
1192
|
_structures = new Collection2();
|
|
1193
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
1151
1194
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1152
1195
|
get(messageId) {
|
|
1153
|
-
const
|
|
1196
|
+
const id = String(messageId ?? "").trim();
|
|
1197
|
+
if (!id) return void 0;
|
|
1198
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
1154
1199
|
if (!data) {
|
|
1155
|
-
this._structures.delete(
|
|
1200
|
+
this._structures.delete(id);
|
|
1156
1201
|
return void 0;
|
|
1157
1202
|
}
|
|
1158
|
-
const existing = this._structures.get(
|
|
1159
|
-
if (existing)
|
|
1203
|
+
const existing = this._structures.get(id);
|
|
1204
|
+
if (existing) {
|
|
1205
|
+
existing._patch(data);
|
|
1206
|
+
return existing;
|
|
1207
|
+
}
|
|
1160
1208
|
const message = new Message(this.client, data);
|
|
1161
|
-
this._structures.set(
|
|
1209
|
+
this._structures.set(id, message);
|
|
1162
1210
|
return message;
|
|
1163
1211
|
}
|
|
1164
1212
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1165
1213
|
async resolve(messageId) {
|
|
1166
|
-
|
|
1214
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
1215
|
+
return this.get(id) ?? this.fetch(id);
|
|
1167
1216
|
}
|
|
1168
1217
|
async fetch(idOrOptions) {
|
|
1169
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1218
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
1170
1219
|
}
|
|
1171
1220
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1172
1221
|
wrap(data) {
|
|
@@ -1183,9 +1232,13 @@ var MessageManager = class {
|
|
|
1183
1232
|
}
|
|
1184
1233
|
/** Fetch a single message from the API. */
|
|
1185
1234
|
async fetchOne(messageId) {
|
|
1235
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
1236
|
+
}
|
|
1237
|
+
async fetchOneFresh(messageId) {
|
|
1186
1238
|
try {
|
|
1187
|
-
const data =
|
|
1188
|
-
Routes2.channelMessage(this.channelId, messageId)
|
|
1239
|
+
const data = assertApiObjectWithId(
|
|
1240
|
+
await this.client.rest.get(Routes2.channelMessage(this.channelId, messageId)),
|
|
1241
|
+
"messages.fetch()"
|
|
1189
1242
|
);
|
|
1190
1243
|
return this.wrap(data);
|
|
1191
1244
|
} catch (err) {
|
|
@@ -1211,9 +1264,15 @@ var MessageManager = class {
|
|
|
1211
1264
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1212
1265
|
}
|
|
1213
1266
|
const base = Routes2.channelMessages(this.channelId);
|
|
1214
|
-
const data =
|
|
1267
|
+
const data = assertApiArray(
|
|
1268
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
1269
|
+
"messages.fetch()"
|
|
1270
|
+
);
|
|
1215
1271
|
const collection = new Collection2();
|
|
1216
|
-
for (const msg of data)
|
|
1272
|
+
for (const msg of data) {
|
|
1273
|
+
if (!msg?.id) continue;
|
|
1274
|
+
collection.set(msg.id, this.wrap(msg));
|
|
1275
|
+
}
|
|
1217
1276
|
return collection;
|
|
1218
1277
|
}
|
|
1219
1278
|
};
|
|
@@ -1417,6 +1476,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1417
1476
|
}
|
|
1418
1477
|
|
|
1419
1478
|
// src/Domain/Channel/Base.ts
|
|
1479
|
+
function isFullChannelData(data) {
|
|
1480
|
+
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;
|
|
1481
|
+
}
|
|
1420
1482
|
var Channel = class extends Base {
|
|
1421
1483
|
#messages;
|
|
1422
1484
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -1431,6 +1493,11 @@ var Channel = class extends Base {
|
|
|
1431
1493
|
icon;
|
|
1432
1494
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
1433
1495
|
lastPinTimestamp;
|
|
1496
|
+
/**
|
|
1497
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
1498
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
1499
|
+
*/
|
|
1500
|
+
partial;
|
|
1434
1501
|
constructor(client, data) {
|
|
1435
1502
|
super();
|
|
1436
1503
|
this.client = client;
|
|
@@ -1439,6 +1506,7 @@ var Channel = class extends Base {
|
|
|
1439
1506
|
this.name = data.name ?? null;
|
|
1440
1507
|
this.icon = data.icon ?? null;
|
|
1441
1508
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1509
|
+
this.partial = !isFullChannelData(data);
|
|
1442
1510
|
}
|
|
1443
1511
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1444
1512
|
get createdTimestamp() {
|
|
@@ -1459,6 +1527,7 @@ var Channel = class extends Base {
|
|
|
1459
1527
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1460
1528
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1461
1529
|
}
|
|
1530
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
1462
1531
|
}
|
|
1463
1532
|
/** @internal Factory wired after subclasses load. */
|
|
1464
1533
|
static from(_c, _d) {
|
|
@@ -2234,10 +2303,10 @@ var Message = class _Message extends Base {
|
|
|
2234
2303
|
this.channelId = data.channel_id;
|
|
2235
2304
|
this.guildId = data.guild_id ?? null;
|
|
2236
2305
|
this.author = client.getOrCreateUser(data.author);
|
|
2237
|
-
this.content = data.content;
|
|
2238
|
-
this.createdAt = new Date(data.timestamp);
|
|
2306
|
+
this.content = data.content ?? "";
|
|
2307
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
2239
2308
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2240
|
-
this.pinned = data.pinned;
|
|
2309
|
+
this.pinned = data.pinned ?? false;
|
|
2241
2310
|
this.attachments = new Collection5();
|
|
2242
2311
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2243
2312
|
this.type = data.type ?? MessageType.Default;
|
|
@@ -2269,33 +2338,47 @@ var Message = class _Message extends Base {
|
|
|
2269
2338
|
* @internal
|
|
2270
2339
|
*/
|
|
2271
2340
|
_patch(data) {
|
|
2272
|
-
this.content = data.content;
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
this.
|
|
2283
|
-
this.
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2341
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
2342
|
+
if (data.edited_timestamp !== void 0) {
|
|
2343
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2344
|
+
}
|
|
2345
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
2346
|
+
if (data.attachments !== void 0) {
|
|
2347
|
+
this.attachments.clear();
|
|
2348
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2349
|
+
}
|
|
2350
|
+
if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
2351
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
2352
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
2353
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
2354
|
+
if (data.stickers !== void 0) {
|
|
2355
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
2356
|
+
}
|
|
2357
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
2358
|
+
if (data.message_reference !== void 0) {
|
|
2359
|
+
this.messageReference = data.message_reference ? {
|
|
2360
|
+
channelId: data.message_reference.channel_id,
|
|
2361
|
+
messageId: data.message_reference.message_id,
|
|
2362
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
2363
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
2364
|
+
} : null;
|
|
2365
|
+
}
|
|
2366
|
+
if (data.message_snapshots !== void 0) {
|
|
2367
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
2368
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
2372
|
+
if (data.referenced_message !== void 0) {
|
|
2373
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
2374
|
+
}
|
|
2375
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
2376
|
+
if (data.mentions !== void 0) {
|
|
2377
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2378
|
+
}
|
|
2379
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
2380
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
2381
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
2299
2382
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
2300
2383
|
}
|
|
2301
2384
|
/**
|
|
@@ -2396,6 +2479,23 @@ var Message = class _Message extends Base {
|
|
|
2396
2479
|
async fetch() {
|
|
2397
2480
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2398
2481
|
}
|
|
2482
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2483
|
+
async crosspost() {
|
|
2484
|
+
const data = await this.client.rest.post(
|
|
2485
|
+
Routes7.channelMessageCrosspost(this.channelId, this.id),
|
|
2486
|
+
{ auth: true }
|
|
2487
|
+
);
|
|
2488
|
+
const published = new _Message(this.client, data);
|
|
2489
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2490
|
+
return published;
|
|
2491
|
+
}
|
|
2492
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2493
|
+
async fetchCrosspostSource() {
|
|
2494
|
+
return this.client.rest.get(
|
|
2495
|
+
Routes7.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2496
|
+
{ auth: true }
|
|
2497
|
+
);
|
|
2498
|
+
}
|
|
2399
2499
|
/** Delete this message. */
|
|
2400
2500
|
async delete(reason) {
|
|
2401
2501
|
await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
|
|
@@ -2559,7 +2659,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2559
2659
|
const full = data;
|
|
2560
2660
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2561
2661
|
this.ownerId = full.owner_id ?? null;
|
|
2562
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2662
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2563
2663
|
this.nicks = full.nicks ?? {};
|
|
2564
2664
|
}
|
|
2565
2665
|
/**
|
|
@@ -2574,7 +2674,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2574
2674
|
}
|
|
2575
2675
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2576
2676
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2577
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2677
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2578
2678
|
}
|
|
2579
2679
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2580
2680
|
}
|
|
@@ -2659,17 +2759,19 @@ import {
|
|
|
2659
2759
|
// src/Helpers/Instance.ts
|
|
2660
2760
|
import { isRecord } from "@fluxerjs/util";
|
|
2661
2761
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2662
|
-
api: "https://
|
|
2663
|
-
api_client: "https://
|
|
2664
|
-
api_public: "https://
|
|
2665
|
-
gateway: "wss://gateway.fluxer.
|
|
2762
|
+
api: "https://fluxer.com/api",
|
|
2763
|
+
api_client: "https://fluxer.com/api",
|
|
2764
|
+
api_public: "https://fluxer.com/api",
|
|
2765
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2666
2766
|
media: CDN_URL,
|
|
2767
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2667
2768
|
static_cdn: STATIC_CDN_URL,
|
|
2668
|
-
marketing: "https://fluxer.
|
|
2769
|
+
marketing: "https://fluxer.com",
|
|
2770
|
+
docs: "https://docs.fluxer.com",
|
|
2669
2771
|
admin: "https://admin.fluxer.app",
|
|
2670
2772
|
invite: "https://fluxer.gg",
|
|
2671
2773
|
gift: "https://fluxer.gift",
|
|
2672
|
-
webapp: "https://
|
|
2774
|
+
webapp: "https://fluxer.com"
|
|
2673
2775
|
});
|
|
2674
2776
|
var ENDPOINT_KEYS = [
|
|
2675
2777
|
"api",
|
|
@@ -2684,6 +2786,11 @@ var ENDPOINT_KEYS = [
|
|
|
2684
2786
|
"gift",
|
|
2685
2787
|
"webapp"
|
|
2686
2788
|
];
|
|
2789
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
2790
|
+
"api_transport",
|
|
2791
|
+
"upload_relay",
|
|
2792
|
+
"docs"
|
|
2793
|
+
];
|
|
2687
2794
|
function requireString(obj, key, path) {
|
|
2688
2795
|
const value = obj[key];
|
|
2689
2796
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2724,6 +2831,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2724
2831
|
for (const key of ENDPOINT_KEYS) {
|
|
2725
2832
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2726
2833
|
}
|
|
2834
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
2835
|
+
const value = raw.endpoints[key];
|
|
2836
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
2837
|
+
}
|
|
2727
2838
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2728
2839
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2729
2840
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -2777,7 +2888,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
2777
2888
|
defaultsHash: ""
|
|
2778
2889
|
},
|
|
2779
2890
|
push: raw.push ?? { public_vapid_key: null },
|
|
2780
|
-
app_public: raw.app_public ?? {}
|
|
2891
|
+
app_public: raw.app_public ?? {},
|
|
2892
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
2893
|
+
age_policy: isRecord(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
2894
|
+
...raw.notice === null || isRecord(raw.notice) ? { notice: raw.notice } : {},
|
|
2895
|
+
...isRecord(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
2896
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
2897
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
2898
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
2899
|
+
...isRecord(raw.built_in_guild_badge_images) ? {
|
|
2900
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
2901
|
+
} : {},
|
|
2902
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
2903
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
2904
|
+
} : {},
|
|
2905
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
2781
2906
|
};
|
|
2782
2907
|
}
|
|
2783
2908
|
function resolveInstanceEndpoints(input) {
|
|
@@ -2797,7 +2922,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
2797
2922
|
}
|
|
2798
2923
|
const partial = input;
|
|
2799
2924
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
2800
|
-
for (const key of ENDPOINT_KEYS) {
|
|
2925
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
2801
2926
|
const value = partial[key];
|
|
2802
2927
|
if (typeof value === "string" && value.length > 0) {
|
|
2803
2928
|
merged[key] = value;
|
|
@@ -3417,6 +3542,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3417
3542
|
}
|
|
3418
3543
|
};
|
|
3419
3544
|
var AnnouncementChannel = class extends TextChannel {
|
|
3545
|
+
/**
|
|
3546
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3547
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3548
|
+
*/
|
|
3549
|
+
async follow(webhookChannelId) {
|
|
3550
|
+
return this.client.rest.post(
|
|
3551
|
+
Routes13.channelFollowers(this.id),
|
|
3552
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3553
|
+
);
|
|
3554
|
+
}
|
|
3555
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3556
|
+
async fetchFollowerStats() {
|
|
3557
|
+
return this.client.rest.get(
|
|
3558
|
+
Routes13.channelFollowerStats(this.id),
|
|
3559
|
+
{ auth: true }
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3420
3562
|
};
|
|
3421
3563
|
var CategoryChannel = class extends GuildChannel {
|
|
3422
3564
|
};
|
|
@@ -3443,6 +3585,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3443
3585
|
voiceConnectionLimit;
|
|
3444
3586
|
/** RTC region override for this channel. */
|
|
3445
3587
|
rtcRegion;
|
|
3588
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3589
|
+
rtcP2p;
|
|
3446
3590
|
constructor(client, data) {
|
|
3447
3591
|
super(client, data);
|
|
3448
3592
|
this.topic = data.topic ?? null;
|
|
@@ -3456,6 +3600,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3456
3600
|
this.userLimit = data.user_limit ?? null;
|
|
3457
3601
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3458
3602
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3603
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3459
3604
|
}
|
|
3460
3605
|
/**
|
|
3461
3606
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3482,6 +3627,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3482
3627
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3483
3628
|
}
|
|
3484
3629
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3630
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3485
3631
|
}
|
|
3486
3632
|
};
|
|
3487
3633
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -4047,12 +4193,15 @@ var User = class extends Base {
|
|
|
4047
4193
|
system;
|
|
4048
4194
|
/** Banner hash for profile. */
|
|
4049
4195
|
banner;
|
|
4196
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
4197
|
+
partial;
|
|
4050
4198
|
constructor(client, data) {
|
|
4051
4199
|
super();
|
|
4052
4200
|
this.client = client;
|
|
4053
4201
|
this.id = data.id;
|
|
4054
|
-
this.
|
|
4055
|
-
this.
|
|
4202
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
4203
|
+
this.username = data.username ?? "Unknown";
|
|
4204
|
+
this.discriminator = data.discriminator ?? "0";
|
|
4056
4205
|
this.globalName = data.global_name ?? null;
|
|
4057
4206
|
this.avatar = data.avatar ?? null;
|
|
4058
4207
|
this.bot = !!data.bot;
|
|
@@ -4063,13 +4212,18 @@ var User = class extends Base {
|
|
|
4063
4212
|
}
|
|
4064
4213
|
/** @internal */
|
|
4065
4214
|
_patch(data) {
|
|
4066
|
-
this.username = data.username;
|
|
4067
|
-
this.discriminator = data.discriminator;
|
|
4068
|
-
this.globalName = data.global_name ?? null;
|
|
4069
|
-
this.avatar = data.avatar ?? null;
|
|
4215
|
+
if (data.username !== void 0) this.username = data.username;
|
|
4216
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
4217
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
4218
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
4070
4219
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
4071
4220
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
4072
4221
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
4222
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
4223
|
+
}
|
|
4224
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
4225
|
+
async fetch() {
|
|
4226
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
4073
4227
|
}
|
|
4074
4228
|
cdnOpts() {
|
|
4075
4229
|
return {
|
|
@@ -4857,6 +5011,8 @@ var Role = class _Role extends Base {
|
|
|
4857
5011
|
mentionable;
|
|
4858
5012
|
/** Unicode emoji for this role (null = none). */
|
|
4859
5013
|
unicodeEmoji;
|
|
5014
|
+
/** Role icon image hash (null = none). */
|
|
5015
|
+
icon;
|
|
4860
5016
|
/** Hoist position (null = not hoisted). */
|
|
4861
5017
|
hoistPosition;
|
|
4862
5018
|
constructor(client, data, guildId) {
|
|
@@ -4864,20 +5020,26 @@ var Role = class _Role extends Base {
|
|
|
4864
5020
|
this.client = client;
|
|
4865
5021
|
this.id = data.id;
|
|
4866
5022
|
this.guildId = guildId;
|
|
4867
|
-
this.name = data.name;
|
|
4868
|
-
this.color = data.color;
|
|
4869
|
-
this.position = data.position;
|
|
4870
|
-
this._permissions = data.permissions;
|
|
5023
|
+
this.name = data.name ?? "";
|
|
5024
|
+
this.color = data.color ?? 0;
|
|
5025
|
+
this.position = data.position ?? 0;
|
|
5026
|
+
this._permissions = data.permissions ?? "0";
|
|
4871
5027
|
this.hoist = !!data.hoist;
|
|
4872
5028
|
this.mentionable = !!data.mentionable;
|
|
4873
5029
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5030
|
+
this.icon = data.icon ?? null;
|
|
4874
5031
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4875
5032
|
}
|
|
4876
5033
|
/**
|
|
4877
5034
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4878
5035
|
*/
|
|
4879
5036
|
get permissions() {
|
|
4880
|
-
|
|
5037
|
+
let bits;
|
|
5038
|
+
try {
|
|
5039
|
+
bits = BigInt(this._permissions ?? "0");
|
|
5040
|
+
} catch {
|
|
5041
|
+
bits = 0n;
|
|
5042
|
+
}
|
|
4881
5043
|
return new PermissionsBitField3(
|
|
4882
5044
|
(bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
|
|
4883
5045
|
);
|
|
@@ -4907,14 +5069,15 @@ var Role = class _Role extends Base {
|
|
|
4907
5069
|
}
|
|
4908
5070
|
/** @internal */
|
|
4909
5071
|
_patch(data) {
|
|
4910
|
-
this.name = data.name;
|
|
4911
|
-
this.color = data.color;
|
|
4912
|
-
this.position = data.position;
|
|
4913
|
-
this._permissions = data.permissions;
|
|
4914
|
-
this.hoist = !!data.hoist;
|
|
4915
|
-
this.mentionable = !!data.mentionable;
|
|
4916
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4917
|
-
this.
|
|
5072
|
+
if (data.name !== void 0) this.name = data.name;
|
|
5073
|
+
if (data.color !== void 0) this.color = data.color;
|
|
5074
|
+
if (data.position !== void 0) this.position = data.position;
|
|
5075
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
5076
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
5077
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
5078
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5079
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
5080
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4918
5081
|
}
|
|
4919
5082
|
/**
|
|
4920
5083
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4932,6 +5095,7 @@ var Role = class _Role extends Base {
|
|
|
4932
5095
|
hoist: this.hoist,
|
|
4933
5096
|
mentionable: this.mentionable,
|
|
4934
5097
|
unicode_emoji: this.unicodeEmoji,
|
|
5098
|
+
icon: this.icon,
|
|
4935
5099
|
hoist_position: this.hoistPosition
|
|
4936
5100
|
},
|
|
4937
5101
|
this.guildId
|
|
@@ -5109,6 +5273,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5109
5273
|
});
|
|
5110
5274
|
this.client = client;
|
|
5111
5275
|
}
|
|
5276
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5112
5277
|
/**
|
|
5113
5278
|
* Remove a channel from cache. Does not delete it on the API.
|
|
5114
5279
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -5121,9 +5286,11 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5121
5286
|
}
|
|
5122
5287
|
return deleted;
|
|
5123
5288
|
}
|
|
5124
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5289
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
5125
5290
|
async resolve(channelId) {
|
|
5126
|
-
|
|
5291
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5292
|
+
const cached = this.get(id);
|
|
5293
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
5127
5294
|
}
|
|
5128
5295
|
/**
|
|
5129
5296
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5136,10 +5303,23 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5136
5303
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5137
5304
|
*/
|
|
5138
5305
|
async fetch(channelId, options) {
|
|
5139
|
-
const
|
|
5140
|
-
|
|
5306
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5307
|
+
const cached = this.get(id);
|
|
5308
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5309
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5310
|
+
}
|
|
5311
|
+
async fetchFresh(channelId) {
|
|
5141
5312
|
try {
|
|
5142
|
-
const data =
|
|
5313
|
+
const data = assertApiObjectWithId(
|
|
5314
|
+
await this.client.rest.get(Routes23.channel(channelId)),
|
|
5315
|
+
"channels.fetch()"
|
|
5316
|
+
);
|
|
5317
|
+
const existing = this.get(channelId);
|
|
5318
|
+
if (existing && existing.type === data.type) {
|
|
5319
|
+
existing._patch(data);
|
|
5320
|
+
putChannel(this.client, existing);
|
|
5321
|
+
return existing;
|
|
5322
|
+
}
|
|
5143
5323
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5144
5324
|
if (guildId) {
|
|
5145
5325
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5306,6 +5486,68 @@ async function searchMessages(client, options = {}) {
|
|
|
5306
5486
|
});
|
|
5307
5487
|
return toMessageSearchResponse(data);
|
|
5308
5488
|
}
|
|
5489
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5490
|
+
return client.rest.get(
|
|
5491
|
+
Routes24.emojiSource(emojiId),
|
|
5492
|
+
{ auth: true }
|
|
5493
|
+
);
|
|
5494
|
+
}
|
|
5495
|
+
function fetchStickerSource(client, stickerId) {
|
|
5496
|
+
return client.rest.get(
|
|
5497
|
+
Routes24.stickerSource(stickerId),
|
|
5498
|
+
{ auth: true }
|
|
5499
|
+
);
|
|
5500
|
+
}
|
|
5501
|
+
function fetchDiscoveryCategories(client) {
|
|
5502
|
+
return client.rest.get(
|
|
5503
|
+
Routes24.discoveryCategories(),
|
|
5504
|
+
{ auth: true }
|
|
5505
|
+
);
|
|
5506
|
+
}
|
|
5507
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5508
|
+
const params = new URLSearchParams();
|
|
5509
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5510
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5511
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5512
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5513
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5514
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5515
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5516
|
+
const qs2 = params.toString();
|
|
5517
|
+
return client.rest.get(
|
|
5518
|
+
qs2 ? `${Routes24.discoveryGuilds()}?${qs2}` : Routes24.discoveryGuilds(),
|
|
5519
|
+
{ auth: true }
|
|
5520
|
+
);
|
|
5521
|
+
}
|
|
5522
|
+
function fetchExperiments(client) {
|
|
5523
|
+
return client.rest.get(Routes24.experiments(), {
|
|
5524
|
+
auth: true
|
|
5525
|
+
});
|
|
5526
|
+
}
|
|
5527
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5528
|
+
return client.rest.post(
|
|
5529
|
+
Routes24.attachmentsRefreshUrls(),
|
|
5530
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5531
|
+
);
|
|
5532
|
+
}
|
|
5533
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5534
|
+
const params = new URLSearchParams();
|
|
5535
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5536
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5537
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5538
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5539
|
+
const qs2 = params.toString();
|
|
5540
|
+
return client.rest.get(
|
|
5541
|
+
qs2 ? `${Routes24.instanceBadges()}?${qs2}` : Routes24.instanceBadges(),
|
|
5542
|
+
{ auth: false }
|
|
5543
|
+
);
|
|
5544
|
+
}
|
|
5545
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5546
|
+
return client.rest.post(
|
|
5547
|
+
Routes24.channelPostData(channelId),
|
|
5548
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5549
|
+
);
|
|
5550
|
+
}
|
|
5309
5551
|
|
|
5310
5552
|
// src/ClientCore/ClientEvents.ts
|
|
5311
5553
|
function createEventMethods(client) {
|
|
@@ -5336,6 +5578,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5336
5578
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5337
5579
|
this.guild = guild;
|
|
5338
5580
|
}
|
|
5581
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5339
5582
|
/**
|
|
5340
5583
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5341
5584
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5347,7 +5590,9 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5347
5590
|
* console.log(member.displayName);
|
|
5348
5591
|
*/
|
|
5349
5592
|
async resolve(userId) {
|
|
5350
|
-
|
|
5593
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5594
|
+
const cached = this.get(id);
|
|
5595
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5351
5596
|
}
|
|
5352
5597
|
/**
|
|
5353
5598
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5375,10 +5620,11 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5375
5620
|
return this.guild.fetchMe();
|
|
5376
5621
|
}
|
|
5377
5622
|
async fetch(userIdOrOptions, options) {
|
|
5378
|
-
if (typeof userIdOrOptions === "string") {
|
|
5379
|
-
const
|
|
5380
|
-
|
|
5381
|
-
|
|
5623
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5624
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5625
|
+
const cached = this.get(id);
|
|
5626
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5627
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5382
5628
|
}
|
|
5383
5629
|
return this.fetchMany(userIdOrOptions);
|
|
5384
5630
|
}
|
|
@@ -5388,9 +5634,13 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5388
5634
|
if (options?.after) params.set("after", options.after);
|
|
5389
5635
|
const qs2 = params.toString();
|
|
5390
5636
|
const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5391
|
-
const data =
|
|
5637
|
+
const data = assertApiArray(
|
|
5638
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5639
|
+
"members.fetch()"
|
|
5640
|
+
);
|
|
5392
5641
|
const members = [];
|
|
5393
5642
|
for (const m of data) {
|
|
5643
|
+
if (!m?.user?.id) continue;
|
|
5394
5644
|
const member = new GuildMember(
|
|
5395
5645
|
this.guild.client,
|
|
5396
5646
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5556,7 +5806,12 @@ async function createChannel(guild, options) {
|
|
|
5556
5806
|
return cacheChannel(guild, created);
|
|
5557
5807
|
}
|
|
5558
5808
|
async function fetchChannels(guild) {
|
|
5559
|
-
const
|
|
5809
|
+
const raw = await guild.client.rest.get(Routes27.guildChannels(guild.id));
|
|
5810
|
+
if (!Array.isArray(raw))
|
|
5811
|
+
throw new TypeError(
|
|
5812
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
5813
|
+
);
|
|
5814
|
+
const data = raw;
|
|
5560
5815
|
const channels = [];
|
|
5561
5816
|
for (const ch of data) {
|
|
5562
5817
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5651,16 +5906,20 @@ var GuildRoleManager = class extends LimitedCollection3 {
|
|
|
5651
5906
|
// src/Domain/Guild/MemberHttp.ts
|
|
5652
5907
|
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
5653
5908
|
async function fetchMember(guild, userId) {
|
|
5909
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5654
5910
|
try {
|
|
5655
5911
|
const data = await guild.client.rest.get(
|
|
5656
|
-
Routes29.guildMember(guild.id,
|
|
5912
|
+
Routes29.guildMember(guild.id, id)
|
|
5657
5913
|
);
|
|
5914
|
+
if (!data?.user?.id) {
|
|
5915
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
5916
|
+
}
|
|
5658
5917
|
return cacheMember(guild, data);
|
|
5659
5918
|
} catch (err) {
|
|
5660
5919
|
rethrowMapped(err, {
|
|
5661
5920
|
notFound: {
|
|
5662
5921
|
code: ErrorCodes.MemberNotFound,
|
|
5663
|
-
message: `Member ${
|
|
5922
|
+
message: `Member ${id} not found in guild`
|
|
5664
5923
|
},
|
|
5665
5924
|
fallback: "Failed to fetch guild member"
|
|
5666
5925
|
});
|
|
@@ -5671,6 +5930,9 @@ async function fetchMe(guild) {
|
|
|
5671
5930
|
Routes29.guildMemberMe(guild.id),
|
|
5672
5931
|
{ auth: true }
|
|
5673
5932
|
);
|
|
5933
|
+
if (!data?.user?.id) {
|
|
5934
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
5935
|
+
}
|
|
5674
5936
|
return cacheMember(guild, data);
|
|
5675
5937
|
}
|
|
5676
5938
|
|
|
@@ -5721,6 +5983,10 @@ async function ban(guild, userId, options) {
|
|
|
5721
5983
|
...auditReasonHeaders(options?.reason)
|
|
5722
5984
|
});
|
|
5723
5985
|
}
|
|
5986
|
+
async function fetchBan(guild, userId) {
|
|
5987
|
+
const data = await guild.client.rest.get(Routes31.guildBan(guild.id, userId));
|
|
5988
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
5989
|
+
}
|
|
5724
5990
|
async function fetchBans(guild) {
|
|
5725
5991
|
const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
|
|
5726
5992
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
@@ -5752,6 +6018,8 @@ async function createRole(guild, options = {}) {
|
|
|
5752
6018
|
}
|
|
5753
6019
|
async function fetchRoles(guild) {
|
|
5754
6020
|
const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
|
|
6021
|
+
if (!Array.isArray(data))
|
|
6022
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5755
6023
|
return data.map((r) => cacheRole(guild, r));
|
|
5756
6024
|
}
|
|
5757
6025
|
async function fetchRole(guild, roleId2) {
|
|
@@ -5851,6 +6119,11 @@ var Guild = class extends Base {
|
|
|
5851
6119
|
id;
|
|
5852
6120
|
/** Whether the guild is currently available through the gateway. */
|
|
5853
6121
|
available = true;
|
|
6122
|
+
/**
|
|
6123
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6124
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6125
|
+
*/
|
|
6126
|
+
partial = true;
|
|
5854
6127
|
/** Guild name. */
|
|
5855
6128
|
name;
|
|
5856
6129
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -6145,6 +6418,10 @@ var Guild = class extends Base {
|
|
|
6145
6418
|
ban(userId, options) {
|
|
6146
6419
|
return ban(this, userId, options);
|
|
6147
6420
|
}
|
|
6421
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6422
|
+
fetchBan(userId) {
|
|
6423
|
+
return fetchBan(this, userId);
|
|
6424
|
+
}
|
|
6148
6425
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6149
6426
|
fetchBans() {
|
|
6150
6427
|
return fetchBans(this);
|
|
@@ -6325,6 +6602,7 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6325
6602
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6326
6603
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6327
6604
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6605
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6328
6606
|
return { guild, created, recovered };
|
|
6329
6607
|
}
|
|
6330
6608
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6408,15 +6686,7 @@ var ClientUser = class extends User {
|
|
|
6408
6686
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6409
6687
|
import { asRecord, num, str } from "@fluxerjs/util";
|
|
6410
6688
|
function unknownUser(id) {
|
|
6411
|
-
return {
|
|
6412
|
-
id,
|
|
6413
|
-
username: "Unknown",
|
|
6414
|
-
discriminator: "0",
|
|
6415
|
-
global_name: null,
|
|
6416
|
-
avatar: null,
|
|
6417
|
-
avatar_color: null,
|
|
6418
|
-
flags: 0
|
|
6419
|
-
};
|
|
6689
|
+
return { id };
|
|
6420
6690
|
}
|
|
6421
6691
|
function indexMember(_client, guild, data) {
|
|
6422
6692
|
if (!data.user?.id) return null;
|
|
@@ -7100,6 +7370,9 @@ var passthroughHandlers = {
|
|
|
7100
7370
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7101
7371
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7102
7372
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7373
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7374
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7375
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7103
7376
|
TYPING_START(client, d) {
|
|
7104
7377
|
const data = d;
|
|
7105
7378
|
const payload = {
|
|
@@ -7290,29 +7563,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7290
7563
|
}
|
|
7291
7564
|
return dispatchGatewayPayload(client, payload);
|
|
7292
7565
|
}
|
|
7293
|
-
|
|
7566
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7567
|
+
function queueFor(client) {
|
|
7568
|
+
let queue = dispatchQueues.get(client);
|
|
7569
|
+
if (!queue) {
|
|
7570
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7571
|
+
dispatchQueues.set(client, queue);
|
|
7572
|
+
}
|
|
7573
|
+
return queue;
|
|
7574
|
+
}
|
|
7575
|
+
async function runGatewayHandler(client, payload) {
|
|
7294
7576
|
const event = payload.t;
|
|
7295
|
-
if (!event) return
|
|
7577
|
+
if (!event) return;
|
|
7296
7578
|
const handler = eventHandlers.get(event);
|
|
7297
7579
|
if (!handler) {
|
|
7298
7580
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7299
|
-
return
|
|
7581
|
+
return;
|
|
7300
7582
|
}
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
}
|
|
7308
|
-
if (client.options.gatewayDeferHandlers
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
};
|
|
7313
|
-
|
|
7314
|
-
|
|
7583
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7584
|
+
client.emit(
|
|
7585
|
+
Events.Debug,
|
|
7586
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7587
|
+
);
|
|
7588
|
+
return;
|
|
7589
|
+
}
|
|
7590
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7591
|
+
await new Promise((resolve) => {
|
|
7592
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7593
|
+
else setTimeout(resolve, 0);
|
|
7594
|
+
});
|
|
7595
|
+
}
|
|
7596
|
+
try {
|
|
7597
|
+
await handler(client, payload.d);
|
|
7598
|
+
} catch (err) {
|
|
7599
|
+
emitClientError(client, err);
|
|
7600
|
+
}
|
|
7601
|
+
}
|
|
7602
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7603
|
+
const queue = queueFor(client);
|
|
7604
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7605
|
+
queue.pending++;
|
|
7606
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7607
|
+
queue.pending--;
|
|
7608
|
+
});
|
|
7609
|
+
queue.tail = run.catch(() => {
|
|
7610
|
+
});
|
|
7611
|
+
return run;
|
|
7612
|
+
}
|
|
7613
|
+
queue.pending++;
|
|
7614
|
+
const next = queue.tail.then(
|
|
7615
|
+
() => runGatewayHandler(client, payload),
|
|
7616
|
+
() => runGatewayHandler(client, payload)
|
|
7617
|
+
).finally(() => {
|
|
7618
|
+
queue.pending--;
|
|
7619
|
+
});
|
|
7620
|
+
queue.tail = next.catch(() => {
|
|
7315
7621
|
});
|
|
7622
|
+
return next;
|
|
7316
7623
|
}
|
|
7317
7624
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7318
7625
|
while (deferred.length > 0) {
|
|
@@ -7500,6 +7807,7 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7500
7807
|
});
|
|
7501
7808
|
this.client = client;
|
|
7502
7809
|
}
|
|
7810
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7503
7811
|
/**
|
|
7504
7812
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7505
7813
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7514,35 +7822,73 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7514
7822
|
}
|
|
7515
7823
|
/**
|
|
7516
7824
|
* Get a guild from cache or fetch from the API if not present.
|
|
7825
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7517
7826
|
* @param guildId - Snowflake of the guild
|
|
7518
7827
|
* @returns The guild
|
|
7519
7828
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7520
7829
|
*/
|
|
7521
7830
|
async resolve(guildId) {
|
|
7522
|
-
|
|
7831
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
7832
|
+
const cached = this.get(id);
|
|
7833
|
+
if (cached && !cached.partial) return cached;
|
|
7834
|
+
if (cached) {
|
|
7835
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7836
|
+
await this.hydrate(cached);
|
|
7837
|
+
return cached;
|
|
7838
|
+
});
|
|
7839
|
+
return cached;
|
|
7840
|
+
}
|
|
7841
|
+
const guild = await this.fetch(id);
|
|
7842
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
7843
|
+
await this.hydrate(guild);
|
|
7844
|
+
return guild;
|
|
7845
|
+
});
|
|
7846
|
+
return guild;
|
|
7523
7847
|
}
|
|
7524
7848
|
/**
|
|
7525
7849
|
* Fetch a guild by ID.
|
|
7526
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7850
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
7851
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7527
7852
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7528
7853
|
*/
|
|
7529
7854
|
async fetch(guildId, options) {
|
|
7530
|
-
const
|
|
7855
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
7856
|
+
const cached = this.get(id);
|
|
7531
7857
|
if (cached && !options?.force) return cached;
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7858
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
7859
|
+
try {
|
|
7860
|
+
const data = assertApiObjectWithId(
|
|
7861
|
+
await this.client.rest.get(Routes35.guild(id)),
|
|
7862
|
+
"guilds.fetch()"
|
|
7863
|
+
);
|
|
7864
|
+
let guild;
|
|
7865
|
+
const existing = this.get(id);
|
|
7866
|
+
if (existing) {
|
|
7867
|
+
existing._patch(data);
|
|
7868
|
+
guild = existing;
|
|
7869
|
+
} else {
|
|
7870
|
+
guild = new Guild(this.client, data);
|
|
7871
|
+
this.set(guild.id, guild);
|
|
7872
|
+
}
|
|
7873
|
+
return guild;
|
|
7874
|
+
} catch (err) {
|
|
7875
|
+
rethrowMapped(err, {
|
|
7876
|
+
notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
7877
|
+
fallback: `Failed to fetch guild ${id}`
|
|
7878
|
+
});
|
|
7537
7879
|
}
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7880
|
+
});
|
|
7881
|
+
}
|
|
7882
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
7883
|
+
async hydrate(guild) {
|
|
7884
|
+
try {
|
|
7885
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
7886
|
+
guild.partial = false;
|
|
7541
7887
|
} catch (err) {
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7888
|
+
this.client.emit(
|
|
7889
|
+
Events.Debug,
|
|
7890
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
7891
|
+
);
|
|
7546
7892
|
}
|
|
7547
7893
|
}
|
|
7548
7894
|
};
|
|
@@ -7567,6 +7913,10 @@ var MessageCache = class {
|
|
|
7567
7913
|
if (limit === false) return;
|
|
7568
7914
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7569
7915
|
let cache = this.caches.get(channelId);
|
|
7916
|
+
if (cache) {
|
|
7917
|
+
this.caches.delete(channelId);
|
|
7918
|
+
this.caches.set(channelId, cache);
|
|
7919
|
+
}
|
|
7570
7920
|
if (!cache) {
|
|
7571
7921
|
const channelLimit = this.getChannelLimit();
|
|
7572
7922
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7626,6 +7976,7 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7626
7976
|
super({ maxSize: client.cache.limits.users });
|
|
7627
7977
|
this.client = client;
|
|
7628
7978
|
}
|
|
7979
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7629
7980
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7630
7981
|
sweep(filter) {
|
|
7631
7982
|
let removed = 0;
|
|
@@ -7639,16 +7990,30 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7639
7990
|
}
|
|
7640
7991
|
return removed;
|
|
7641
7992
|
}
|
|
7642
|
-
/**
|
|
7993
|
+
/**
|
|
7994
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
7995
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
7996
|
+
*/
|
|
7643
7997
|
async fetch(userId, options) {
|
|
7644
|
-
const
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
return
|
|
7998
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
7999
|
+
const cached = this.get(id);
|
|
8000
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
8001
|
+
return dedupeFetch(
|
|
8002
|
+
this.pendingFetches,
|
|
8003
|
+
id,
|
|
8004
|
+
async () => this.client.getOrCreateUser(
|
|
8005
|
+
assertApiObjectWithId(
|
|
8006
|
+
await this.client.rest.get(Routes36.user(id)),
|
|
8007
|
+
"users.fetch()"
|
|
8008
|
+
)
|
|
8009
|
+
)
|
|
8010
|
+
);
|
|
7648
8011
|
}
|
|
7649
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8012
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7650
8013
|
async resolve(userId) {
|
|
7651
|
-
|
|
8014
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8015
|
+
const cached = this.get(id);
|
|
8016
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7652
8017
|
}
|
|
7653
8018
|
/**
|
|
7654
8019
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7789,7 +8154,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7789
8154
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7790
8155
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7791
8156
|
*
|
|
7792
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8157
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7793
8158
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7794
8159
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7795
8160
|
*/
|
|
@@ -7866,6 +8231,38 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7866
8231
|
fetchStickerMetadata(stickerId) {
|
|
7867
8232
|
return fetchStickerMetadata(this, stickerId);
|
|
7868
8233
|
}
|
|
8234
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8235
|
+
fetchEmojiSource(emojiId) {
|
|
8236
|
+
return fetchEmojiSource(this, emojiId);
|
|
8237
|
+
}
|
|
8238
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8239
|
+
fetchStickerSource(stickerId) {
|
|
8240
|
+
return fetchStickerSource(this, stickerId);
|
|
8241
|
+
}
|
|
8242
|
+
/** List discovery categories. */
|
|
8243
|
+
fetchDiscoveryCategories() {
|
|
8244
|
+
return fetchDiscoveryCategories(this);
|
|
8245
|
+
}
|
|
8246
|
+
/** Search discoverable guilds. */
|
|
8247
|
+
searchDiscoveryGuilds(options) {
|
|
8248
|
+
return searchDiscoveryGuilds(this, options);
|
|
8249
|
+
}
|
|
8250
|
+
/** Fetch experiment assignments for this account. */
|
|
8251
|
+
fetchExperiments() {
|
|
8252
|
+
return fetchExperiments(this);
|
|
8253
|
+
}
|
|
8254
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8255
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8256
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8257
|
+
}
|
|
8258
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8259
|
+
fetchInstanceBadges(options) {
|
|
8260
|
+
return fetchInstanceBadges(this, options);
|
|
8261
|
+
}
|
|
8262
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8263
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8264
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8265
|
+
}
|
|
7869
8266
|
/**
|
|
7870
8267
|
* Fetch the current application (`/applications/@me`).
|
|
7871
8268
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -7960,6 +8357,9 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7960
8357
|
* @internal
|
|
7961
8358
|
*/
|
|
7962
8359
|
getOrCreateUser(data) {
|
|
8360
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8361
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8362
|
+
}
|
|
7963
8363
|
const existing = this.users.get(data.id);
|
|
7964
8364
|
if (existing) {
|
|
7965
8365
|
existing._patch(data);
|