@fluxerjs/core 3.0.0 → 3.1.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-CjQBbVmb.d.mts → SubpathMessage-Cj_U0V19.d.mts} +64 -21
- package/dist/{SubpathMessage-DNlKq2Nj.d.ts → SubpathMessage-DaimQAd9.d.ts} +64 -21
- package/dist/{Sudo-CFfbmis3.d.mts → Sudo-fOKSPbxN.d.mts} +8 -0
- package/dist/{Sudo-CFfbmis3.d.ts → Sudo-fOKSPbxN.d.ts} +8 -0
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +282 -89
- package/dist/client.mjs +282 -89
- package/dist/cluster.d.mts +3 -3
- package/dist/cluster.d.ts +3 -3
- package/dist/cluster.js +282 -89
- package/dist/cluster.mjs +282 -89
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +286 -89
- package/dist/index.mjs +284 -89
- package/dist/internal.d.mts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/message.d.mts +2 -2
- package/dist/message.d.ts +2 -2
- package/dist/message.js +83 -3
- package/dist/message.mjs +83 -3
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -58,6 +58,7 @@ __export(src_exports, {
|
|
|
58
58
|
GuildOperations: () => import_types40.GuildOperations,
|
|
59
59
|
GuildRoleManager: () => GuildRoleManager,
|
|
60
60
|
GuildSticker: () => GuildSticker,
|
|
61
|
+
INSTANCE_DISCOVERY_PATH: () => INSTANCE_DISCOVERY_PATH,
|
|
61
62
|
Invite: () => Invite,
|
|
62
63
|
InviteType: () => import_types40.InviteType,
|
|
63
64
|
LinkChannel: () => LinkChannel,
|
|
@@ -106,6 +107,7 @@ __export(src_exports, {
|
|
|
106
107
|
cdnMemberBannerURL: () => cdnMemberBannerURL,
|
|
107
108
|
cdnStickerURL: () => cdnStickerURL,
|
|
108
109
|
createLogger: () => import_util27.createLogger,
|
|
110
|
+
instanceDiscoveryUrl: () => instanceDiscoveryUrl,
|
|
109
111
|
inviteUrl: () => inviteUrl,
|
|
110
112
|
normalizeApiOrigin: () => normalizeApiOrigin,
|
|
111
113
|
normalizeCacheLimit: () => normalizeCacheLimit,
|
|
@@ -691,6 +693,13 @@ function toSudoBody(options) {
|
|
|
691
693
|
return body;
|
|
692
694
|
}
|
|
693
695
|
|
|
696
|
+
// src/Helpers/AuditReason.ts
|
|
697
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
698
|
+
function auditReasonHeaders(reason) {
|
|
699
|
+
if (reason == null || reason === "") return {};
|
|
700
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
701
|
+
}
|
|
702
|
+
|
|
694
703
|
// src/Helpers/MessageUtils/Body.ts
|
|
695
704
|
var import_builders = require("@fluxerjs/builders");
|
|
696
705
|
var import_types = require("@fluxerjs/types");
|
|
@@ -1345,6 +1354,67 @@ var CDN_URL = "https://fluxerusercontent.com";
|
|
|
1345
1354
|
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1346
1355
|
|
|
1347
1356
|
// src/Helpers/Cdn.ts
|
|
1357
|
+
var CDN_SIZE_LADDER = [
|
|
1358
|
+
16,
|
|
1359
|
+
20,
|
|
1360
|
+
22,
|
|
1361
|
+
24,
|
|
1362
|
+
28,
|
|
1363
|
+
32,
|
|
1364
|
+
40,
|
|
1365
|
+
44,
|
|
1366
|
+
48,
|
|
1367
|
+
56,
|
|
1368
|
+
60,
|
|
1369
|
+
64,
|
|
1370
|
+
80,
|
|
1371
|
+
96,
|
|
1372
|
+
100,
|
|
1373
|
+
128,
|
|
1374
|
+
160,
|
|
1375
|
+
240,
|
|
1376
|
+
256,
|
|
1377
|
+
300,
|
|
1378
|
+
320,
|
|
1379
|
+
480,
|
|
1380
|
+
512,
|
|
1381
|
+
600,
|
|
1382
|
+
640,
|
|
1383
|
+
1024,
|
|
1384
|
+
1280,
|
|
1385
|
+
1536,
|
|
1386
|
+
2048,
|
|
1387
|
+
3072,
|
|
1388
|
+
4096,
|
|
1389
|
+
8192,
|
|
1390
|
+
16384
|
|
1391
|
+
];
|
|
1392
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
1393
|
+
icon: { min: 128, max: 1024 },
|
|
1394
|
+
banner: { min: 480, max: 2400 },
|
|
1395
|
+
emoji: { min: 32, max: 512 },
|
|
1396
|
+
sticker: { min: 128, max: 512 }
|
|
1397
|
+
};
|
|
1398
|
+
function nearestSize(requested, candidates) {
|
|
1399
|
+
let best = candidates[0];
|
|
1400
|
+
let bestDist = Math.abs(requested - best);
|
|
1401
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
1402
|
+
const step = candidates[i];
|
|
1403
|
+
const dist = Math.abs(requested - step);
|
|
1404
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1405
|
+
best = step;
|
|
1406
|
+
bestDist = dist;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return best;
|
|
1410
|
+
}
|
|
1411
|
+
function snapCdnSize(requested, assetClass) {
|
|
1412
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1413
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1414
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1415
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1416
|
+
return nearestSize(clamped, allowed);
|
|
1417
|
+
}
|
|
1348
1418
|
function mediaBase(options) {
|
|
1349
1419
|
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1350
1420
|
}
|
|
@@ -1356,13 +1426,15 @@ function getExtension(hash, options) {
|
|
|
1356
1426
|
if (hash?.startsWith("a_")) return "gif";
|
|
1357
1427
|
return ext;
|
|
1358
1428
|
}
|
|
1359
|
-
function appendSize(options) {
|
|
1360
|
-
|
|
1429
|
+
function appendSize(options, assetClass) {
|
|
1430
|
+
const size = options?.size;
|
|
1431
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1432
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1361
1433
|
}
|
|
1362
1434
|
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1363
1435
|
if (!avatarHash) return null;
|
|
1364
1436
|
const ext = getExtension(avatarHash, options);
|
|
1365
|
-
const size = appendSize(options);
|
|
1437
|
+
const size = appendSize(options, "icon");
|
|
1366
1438
|
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1367
1439
|
}
|
|
1368
1440
|
function cdnDisplayAvatarURL(userId, avatarHash, options) {
|
|
@@ -1371,19 +1443,19 @@ function cdnDisplayAvatarURL(userId, avatarHash, options) {
|
|
|
1371
1443
|
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1372
1444
|
if (!bannerHash) return null;
|
|
1373
1445
|
const ext = getExtension(bannerHash, options);
|
|
1374
|
-
const size = appendSize(options);
|
|
1446
|
+
const size = appendSize(options, "banner");
|
|
1375
1447
|
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1376
1448
|
}
|
|
1377
1449
|
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1378
1450
|
if (!avatarHash) return null;
|
|
1379
1451
|
const ext = getExtension(avatarHash, options);
|
|
1380
|
-
const size = appendSize(options);
|
|
1452
|
+
const size = appendSize(options, "icon");
|
|
1381
1453
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1382
1454
|
}
|
|
1383
1455
|
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1384
1456
|
if (!bannerHash) return null;
|
|
1385
1457
|
const ext = getExtension(bannerHash, options);
|
|
1386
|
-
const size = appendSize(options);
|
|
1458
|
+
const size = appendSize(options, "banner");
|
|
1387
1459
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1388
1460
|
}
|
|
1389
1461
|
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
@@ -1392,16 +1464,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
|
1392
1464
|
}
|
|
1393
1465
|
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1394
1466
|
if (!hash) return null;
|
|
1395
|
-
const
|
|
1467
|
+
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1468
|
+
const size = appendSize(options, assetClass);
|
|
1396
1469
|
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1397
1470
|
}
|
|
1398
1471
|
function cdnEmojiURL(emojiId, animated, options) {
|
|
1399
1472
|
const ext = animated ? "gif" : "png";
|
|
1400
|
-
|
|
1473
|
+
const size = appendSize(options, "emoji");
|
|
1474
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1401
1475
|
}
|
|
1402
1476
|
function cdnStickerURL(stickerId, animated, options) {
|
|
1403
1477
|
const ext = animated ? "gif" : "png";
|
|
1404
|
-
|
|
1478
|
+
const size = appendSize(options, "sticker");
|
|
1479
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1405
1480
|
}
|
|
1406
1481
|
|
|
1407
1482
|
// src/Domain/Message/MessageSticker.ts
|
|
@@ -1629,6 +1704,8 @@ var Message = class _Message extends Base {
|
|
|
1629
1704
|
mentionRoles;
|
|
1630
1705
|
/** Client-side nonce for deduplication. */
|
|
1631
1706
|
nonce;
|
|
1707
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
1708
|
+
nsfwEmojis;
|
|
1632
1709
|
/**
|
|
1633
1710
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1634
1711
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1703,6 +1780,7 @@ var Message = class _Message extends Base {
|
|
|
1703
1780
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1704
1781
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1705
1782
|
this.nonce = data.nonce ?? null;
|
|
1783
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1706
1784
|
}
|
|
1707
1785
|
/**
|
|
1708
1786
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
@@ -1735,6 +1813,7 @@ var Message = class _Message extends Base {
|
|
|
1735
1813
|
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1736
1814
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1737
1815
|
this.nonce = data.nonce ?? null;
|
|
1816
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1738
1817
|
}
|
|
1739
1818
|
/**
|
|
1740
1819
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1818,8 +1897,10 @@ var Message = class _Message extends Base {
|
|
|
1818
1897
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1819
1898
|
}
|
|
1820
1899
|
/** Delete this message. */
|
|
1821
|
-
async delete() {
|
|
1822
|
-
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id)
|
|
1900
|
+
async delete(reason) {
|
|
1901
|
+
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id), {
|
|
1902
|
+
...auditReasonHeaders(reason)
|
|
1903
|
+
});
|
|
1823
1904
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
1824
1905
|
}
|
|
1825
1906
|
/** Delete a specific attachment from this message. */
|
|
@@ -2123,6 +2204,29 @@ var MessageCollector = class _MessageCollector extends import_node_events2.Event
|
|
|
2123
2204
|
|
|
2124
2205
|
// src/Domain/Channel/Attachments.ts
|
|
2125
2206
|
var import_types7 = require("@fluxerjs/types");
|
|
2207
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
2208
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
2209
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
2210
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
2211
|
+
if (!rules?.length) return null;
|
|
2212
|
+
const snapshot = {};
|
|
2213
|
+
for (const rule of rules) {
|
|
2214
|
+
Object.assign(snapshot, rule.overrides);
|
|
2215
|
+
}
|
|
2216
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
2217
|
+
}
|
|
2218
|
+
function assertBotAttachmentLimits(client, files) {
|
|
2219
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
2220
|
+
for (const file of files) {
|
|
2221
|
+
const size = file.data.byteLength;
|
|
2222
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
2223
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
2224
|
+
throw new import_util4.FluxerError(
|
|
2225
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
2226
|
+
{ code: import_util3.ErrorCodes.AttachmentTooLarge }
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2126
2230
|
function asBytes(data) {
|
|
2127
2231
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
2128
2232
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -2142,6 +2246,7 @@ async function putBlob(url, body, contentType) {
|
|
|
2142
2246
|
}
|
|
2143
2247
|
}
|
|
2144
2248
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
2249
|
+
assertBotAttachmentLimits(client, files);
|
|
2145
2250
|
const plan = await client.rest.post(
|
|
2146
2251
|
import_types7.Routes.channelAttachments(channelId),
|
|
2147
2252
|
{
|
|
@@ -2438,11 +2543,12 @@ var Channel = class extends Base {
|
|
|
2438
2543
|
if (options?.silent) params.set("silent", "true");
|
|
2439
2544
|
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2440
2545
|
const qs2 = params.toString();
|
|
2441
|
-
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2546
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
2442
2547
|
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2443
2548
|
await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2444
2549
|
body,
|
|
2445
|
-
auth: true
|
|
2550
|
+
auth: true,
|
|
2551
|
+
...auditReasonHeaders(_reason)
|
|
2446
2552
|
});
|
|
2447
2553
|
this.client.channels.delete(this.id);
|
|
2448
2554
|
this.client._clearMessageCache(this.id);
|
|
@@ -2602,7 +2708,7 @@ var import_types11 = require("@fluxerjs/types");
|
|
|
2602
2708
|
// src/Helpers/Instance.ts
|
|
2603
2709
|
var import_util9 = require("@fluxerjs/util");
|
|
2604
2710
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2605
|
-
api: "https://
|
|
2711
|
+
api: "https://web.fluxer.app/api",
|
|
2606
2712
|
api_client: "https://web.fluxer.app/api",
|
|
2607
2713
|
api_public: "https://api.fluxer.app",
|
|
2608
2714
|
gateway: "wss://gateway.fluxer.app",
|
|
@@ -2636,6 +2742,10 @@ function requireString(obj, key, path) {
|
|
|
2636
2742
|
}
|
|
2637
2743
|
return value;
|
|
2638
2744
|
}
|
|
2745
|
+
var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
|
|
2746
|
+
function instanceDiscoveryUrl(origin) {
|
|
2747
|
+
return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
|
|
2748
|
+
}
|
|
2639
2749
|
function normalizeApiOrigin(api) {
|
|
2640
2750
|
const trimmed = api.trim().replace(/\/+$/, "");
|
|
2641
2751
|
return trimmed.replace(/\/v\d+$/i, "");
|
|
@@ -2664,6 +2774,8 @@ function parseInstanceDiscovery(raw) {
|
|
|
2664
2774
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2665
2775
|
}
|
|
2666
2776
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2777
|
+
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2778
|
+
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
2667
2779
|
endpoints.invite = normalizeInviteBase(endpoints.invite);
|
|
2668
2780
|
endpoints.media = endpoints.media.replace(/\/+$/, "");
|
|
2669
2781
|
endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
|
|
@@ -2741,6 +2853,11 @@ function resolveInstanceEndpoints(input) {
|
|
|
2741
2853
|
}
|
|
2742
2854
|
}
|
|
2743
2855
|
merged.api = normalizeApiOrigin(merged.api);
|
|
2856
|
+
merged.api_client = normalizeApiOrigin(merged.api_client);
|
|
2857
|
+
merged.api_public = normalizeApiOrigin(merged.api_public);
|
|
2858
|
+
if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
|
|
2859
|
+
merged.api_public = merged.api;
|
|
2860
|
+
}
|
|
2744
2861
|
merged.invite = normalizeInviteBase(merged.invite);
|
|
2745
2862
|
merged.media = merged.media.replace(/\/+$/, "");
|
|
2746
2863
|
merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
|
|
@@ -2749,13 +2866,13 @@ function resolveInstanceEndpoints(input) {
|
|
|
2749
2866
|
discovery: null
|
|
2750
2867
|
});
|
|
2751
2868
|
}
|
|
2752
|
-
function resolveRestApi(
|
|
2753
|
-
const fromInstance = normalizeApiOrigin(
|
|
2869
|
+
function resolveRestApi(instanceApiPublic, restApi) {
|
|
2870
|
+
const fromInstance = normalizeApiOrigin(instanceApiPublic);
|
|
2754
2871
|
if (restApi === void 0) return fromInstance;
|
|
2755
2872
|
const fromRest = normalizeApiOrigin(restApi);
|
|
2756
2873
|
if (fromRest !== fromInstance) {
|
|
2757
2874
|
throw new import_util4.FluxerError(
|
|
2758
|
-
`Conflicting API hosts: instance.
|
|
2875
|
+
`Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
|
|
2759
2876
|
{ code: import_util3.ErrorCodes.ConflictingInstanceConfig }
|
|
2760
2877
|
);
|
|
2761
2878
|
}
|
|
@@ -3235,7 +3352,8 @@ var GuildChannel = class extends Channel {
|
|
|
3235
3352
|
async edit(options) {
|
|
3236
3353
|
const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
|
|
3237
3354
|
body: toChannelEditBody(options),
|
|
3238
|
-
auth: true
|
|
3355
|
+
auth: true,
|
|
3356
|
+
...auditReasonHeaders(options.reason)
|
|
3239
3357
|
});
|
|
3240
3358
|
this.name = data.name ?? this.name;
|
|
3241
3359
|
this.parentId = data.parent_id ?? this.parentId;
|
|
@@ -3450,9 +3568,10 @@ var GuildEmoji = class extends Base {
|
|
|
3450
3568
|
return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
|
|
3451
3569
|
}
|
|
3452
3570
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
3453
|
-
async delete() {
|
|
3571
|
+
async delete(reason) {
|
|
3454
3572
|
await this.client.rest.delete(import_types16.Routes.guildEmoji(this.guildId, this.id), {
|
|
3455
|
-
auth: true
|
|
3573
|
+
auth: true,
|
|
3574
|
+
...auditReasonHeaders(reason)
|
|
3456
3575
|
});
|
|
3457
3576
|
const guild = this.client.guilds.get(this.guildId);
|
|
3458
3577
|
if (guild) guild.emojis.delete(this.id);
|
|
@@ -3462,9 +3581,11 @@ var GuildEmoji = class extends Base {
|
|
|
3462
3581
|
* Requires Manage Emojis and Stickers permission.
|
|
3463
3582
|
*/
|
|
3464
3583
|
async edit(options) {
|
|
3584
|
+
const { reason, name } = options;
|
|
3465
3585
|
const data = await this.client.rest.patch(import_types16.Routes.guildEmoji(this.guildId, this.id), {
|
|
3466
|
-
body:
|
|
3467
|
-
auth: true
|
|
3586
|
+
body: { name },
|
|
3587
|
+
auth: true,
|
|
3588
|
+
...auditReasonHeaders(reason)
|
|
3468
3589
|
});
|
|
3469
3590
|
this.name = data.name;
|
|
3470
3591
|
return this;
|
|
@@ -3480,6 +3601,9 @@ var import_types17 = require("@fluxerjs/types");
|
|
|
3480
3601
|
var import_util15 = require("@fluxerjs/util");
|
|
3481
3602
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
3482
3603
|
if (isOwner) return import_util15.ALL_PERMISSIONS_BIGINT;
|
|
3604
|
+
if ((basePermissions & import_util15.PermissionFlags.Administrator) !== 0n) {
|
|
3605
|
+
return import_util15.ALL_PERMISSIONS_BIGINT;
|
|
3606
|
+
}
|
|
3483
3607
|
let perms = basePermissions;
|
|
3484
3608
|
for (const overwrite of overwrites ?? []) {
|
|
3485
3609
|
const applies = overwrite.type === import_types17.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types17.OverwriteType.Member && overwrite.id === memberId;
|
|
@@ -3488,7 +3612,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
3488
3612
|
const deny = BigInt(overwrite.deny || "0");
|
|
3489
3613
|
perms = perms & ~deny | allow;
|
|
3490
3614
|
}
|
|
3491
|
-
return
|
|
3615
|
+
return perms;
|
|
3492
3616
|
}
|
|
3493
3617
|
|
|
3494
3618
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
@@ -3694,7 +3818,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3694
3818
|
const route = isMe ? import_types19.Routes.guildMemberMe(this.guild.id) : import_types19.Routes.guildMember(this.guild.id, this.id);
|
|
3695
3819
|
const data = await this.client.rest.patch(route, {
|
|
3696
3820
|
body: toMemberEditBody(options),
|
|
3697
|
-
auth: true
|
|
3821
|
+
auth: true,
|
|
3822
|
+
...auditReasonHeaders(options.reason ?? options.timeoutReason)
|
|
3698
3823
|
});
|
|
3699
3824
|
this._patch(data);
|
|
3700
3825
|
if (options.bio !== void 0) this.bio = options.bio;
|
|
@@ -3728,8 +3853,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3728
3853
|
await this.edit({ channelId, connectionId });
|
|
3729
3854
|
}
|
|
3730
3855
|
/** Kick this member. Requires Kick Members. */
|
|
3731
|
-
async kick() {
|
|
3732
|
-
await this.guild.kick(this.id);
|
|
3856
|
+
async kick(reason) {
|
|
3857
|
+
await this.guild.kick(this.id, reason);
|
|
3733
3858
|
}
|
|
3734
3859
|
/** Ban this member. Requires Ban Members. */
|
|
3735
3860
|
async ban(options) {
|
|
@@ -3853,9 +3978,10 @@ var GuildSticker = class extends Base {
|
|
|
3853
3978
|
return import_util17.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
3854
3979
|
}
|
|
3855
3980
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3856
|
-
async delete() {
|
|
3981
|
+
async delete(reason) {
|
|
3857
3982
|
await this.client.rest.delete(import_types20.Routes.guildSticker(this.guildId, this.id), {
|
|
3858
|
-
auth: true
|
|
3983
|
+
auth: true,
|
|
3984
|
+
...auditReasonHeaders(reason)
|
|
3859
3985
|
});
|
|
3860
3986
|
const guild = this.client.guilds.get(this.guildId);
|
|
3861
3987
|
if (guild) guild.stickers.delete(this.id);
|
|
@@ -3865,9 +3991,11 @@ var GuildSticker = class extends Base {
|
|
|
3865
3991
|
* Requires Manage Emojis and Stickers permission.
|
|
3866
3992
|
*/
|
|
3867
3993
|
async edit(options) {
|
|
3994
|
+
const { reason, ...body } = options;
|
|
3868
3995
|
const data = await this.client.rest.patch(import_types20.Routes.guildSticker(this.guildId, this.id), {
|
|
3869
|
-
body
|
|
3870
|
-
auth: true
|
|
3996
|
+
body,
|
|
3997
|
+
auth: true,
|
|
3998
|
+
...auditReasonHeaders(reason)
|
|
3871
3999
|
});
|
|
3872
4000
|
const s = data;
|
|
3873
4001
|
this.name = s.name;
|
|
@@ -3989,16 +4117,21 @@ var Role = class _Role extends Base {
|
|
|
3989
4117
|
const body = toRoleEditBody(options);
|
|
3990
4118
|
const data = await this.client.rest.patch(import_types21.Routes.guildRole(this.guildId, this.id), {
|
|
3991
4119
|
body: Object.keys(body).length ? body : void 0,
|
|
3992
|
-
auth: true
|
|
4120
|
+
auth: true,
|
|
4121
|
+
...auditReasonHeaders(options.reason)
|
|
3993
4122
|
});
|
|
3994
4123
|
this._patch(data);
|
|
3995
4124
|
return this;
|
|
3996
4125
|
}
|
|
3997
4126
|
/**
|
|
3998
4127
|
* DELETE role. Requires Manage Roles.
|
|
4128
|
+
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
3999
4129
|
*/
|
|
4000
|
-
async delete() {
|
|
4001
|
-
await this.client.rest.delete(import_types21.Routes.guildRole(this.guildId, this.id), {
|
|
4130
|
+
async delete(reason) {
|
|
4131
|
+
await this.client.rest.delete(import_types21.Routes.guildRole(this.guildId, this.id), {
|
|
4132
|
+
auth: true,
|
|
4133
|
+
...auditReasonHeaders(reason)
|
|
4134
|
+
});
|
|
4002
4135
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
4003
4136
|
}
|
|
4004
4137
|
};
|
|
@@ -4431,7 +4564,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4431
4564
|
return parsed.name;
|
|
4432
4565
|
}
|
|
4433
4566
|
async function fetchInstance(client) {
|
|
4434
|
-
const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
|
|
4567
|
+
const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
|
|
4568
|
+
auth: false,
|
|
4569
|
+
unversioned: true
|
|
4570
|
+
});
|
|
4435
4571
|
return parseInstanceDiscovery(raw);
|
|
4436
4572
|
}
|
|
4437
4573
|
function fetchGatewayInfo(client) {
|
|
@@ -4810,9 +4946,11 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
4810
4946
|
}
|
|
4811
4947
|
}
|
|
4812
4948
|
async function createEmoji(guild, options) {
|
|
4949
|
+
const { reason, ...body } = options;
|
|
4813
4950
|
const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
|
|
4814
|
-
body
|
|
4815
|
-
auth: true
|
|
4951
|
+
body,
|
|
4952
|
+
auth: true,
|
|
4953
|
+
...auditReasonHeaders(reason)
|
|
4816
4954
|
});
|
|
4817
4955
|
return cacheEmoji(guild, data);
|
|
4818
4956
|
}
|
|
@@ -4831,6 +4969,19 @@ async function createEmojisBulk(guild, emojis) {
|
|
|
4831
4969
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
4832
4970
|
}
|
|
4833
4971
|
|
|
4972
|
+
// src/Domain/Guild/GuildRoleManager.ts
|
|
4973
|
+
var import_collection11 = require("@fluxerjs/collection");
|
|
4974
|
+
var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
4975
|
+
constructor(guildId, options) {
|
|
4976
|
+
super(options);
|
|
4977
|
+
this.guildId = guildId;
|
|
4978
|
+
}
|
|
4979
|
+
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4980
|
+
get everyone() {
|
|
4981
|
+
return this.get(this.guildId);
|
|
4982
|
+
}
|
|
4983
|
+
};
|
|
4984
|
+
|
|
4834
4985
|
// src/Domain/Guild/MemberHttp.ts
|
|
4835
4986
|
var import_types29 = require("@fluxerjs/types");
|
|
4836
4987
|
async function fetchMember(guild, userId) {
|
|
@@ -4887,9 +5038,10 @@ var GuildBan = class extends Base {
|
|
|
4887
5038
|
* Remove this ban (unban the user).
|
|
4888
5039
|
* Requires Ban Members permission.
|
|
4889
5040
|
*/
|
|
4890
|
-
async unban() {
|
|
5041
|
+
async unban(reason) {
|
|
4891
5042
|
await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
|
|
4892
|
-
auth: true
|
|
5043
|
+
auth: true,
|
|
5044
|
+
...auditReasonHeaders(reason)
|
|
4893
5045
|
});
|
|
4894
5046
|
}
|
|
4895
5047
|
};
|
|
@@ -4899,33 +5051,27 @@ async function ban(guild, userId, options) {
|
|
|
4899
5051
|
const body = options ? toGuildBanBody(options) : {};
|
|
4900
5052
|
await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
|
|
4901
5053
|
body: Object.keys(body).length ? body : void 0,
|
|
4902
|
-
auth: true
|
|
5054
|
+
auth: true,
|
|
5055
|
+
...auditReasonHeaders(options?.reason)
|
|
4903
5056
|
});
|
|
4904
5057
|
}
|
|
4905
5058
|
async function fetchBans(guild) {
|
|
4906
5059
|
const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
|
|
4907
5060
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
4908
5061
|
}
|
|
4909
|
-
async function unban(guild, userId) {
|
|
4910
|
-
await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
|
|
5062
|
+
async function unban(guild, userId, reason) {
|
|
5063
|
+
await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
|
|
5064
|
+
auth: true,
|
|
5065
|
+
...auditReasonHeaders(reason)
|
|
5066
|
+
});
|
|
4911
5067
|
}
|
|
4912
|
-
async function kick(guild, userId) {
|
|
4913
|
-
await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
|
|
5068
|
+
async function kick(guild, userId, reason) {
|
|
5069
|
+
await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
|
|
5070
|
+
auth: true,
|
|
5071
|
+
...auditReasonHeaders(reason)
|
|
5072
|
+
});
|
|
4914
5073
|
}
|
|
4915
5074
|
|
|
4916
|
-
// src/Domain/Guild/GuildRoleManager.ts
|
|
4917
|
-
var import_collection11 = require("@fluxerjs/collection");
|
|
4918
|
-
var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
4919
|
-
constructor(guildId, options) {
|
|
4920
|
-
super(options);
|
|
4921
|
-
this.guildId = guildId;
|
|
4922
|
-
}
|
|
4923
|
-
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4924
|
-
get everyone() {
|
|
4925
|
-
return this.get(this.guildId);
|
|
4926
|
-
}
|
|
4927
|
-
};
|
|
4928
|
-
|
|
4929
5075
|
// src/Domain/Guild/Roles.ts
|
|
4930
5076
|
var import_types32 = require("@fluxerjs/types");
|
|
4931
5077
|
var import_util21 = require("@fluxerjs/util");
|
|
@@ -4933,7 +5079,8 @@ async function createRole(guild, options = {}) {
|
|
|
4933
5079
|
const body = toRoleCreateBody(options);
|
|
4934
5080
|
const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
|
|
4935
5081
|
body: Object.keys(body).length ? body : void 0,
|
|
4936
|
-
auth: true
|
|
5082
|
+
auth: true,
|
|
5083
|
+
...auditReasonHeaders(options.reason)
|
|
4937
5084
|
});
|
|
4938
5085
|
return cacheRole(guild, data);
|
|
4939
5086
|
}
|
|
@@ -4999,9 +5146,11 @@ async function resetRoleHoistPositions(guild) {
|
|
|
4999
5146
|
// src/Domain/Guild/Stickers.ts
|
|
5000
5147
|
var import_types33 = require("@fluxerjs/types");
|
|
5001
5148
|
async function createSticker(guild, options) {
|
|
5149
|
+
const { reason, ...body } = options;
|
|
5002
5150
|
const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
|
|
5003
|
-
body
|
|
5004
|
-
auth: true
|
|
5151
|
+
body,
|
|
5152
|
+
auth: true,
|
|
5153
|
+
...auditReasonHeaders(reason)
|
|
5005
5154
|
});
|
|
5006
5155
|
return cacheSticker(guild, data);
|
|
5007
5156
|
}
|
|
@@ -5331,12 +5480,12 @@ var Guild = class extends Base {
|
|
|
5331
5480
|
return fetchBans(this);
|
|
5332
5481
|
}
|
|
5333
5482
|
/** Unban a user from the guild. Requires Ban Members. */
|
|
5334
|
-
unban(userId) {
|
|
5335
|
-
return unban(this, userId);
|
|
5483
|
+
unban(userId, reason) {
|
|
5484
|
+
return unban(this, userId, reason);
|
|
5336
5485
|
}
|
|
5337
5486
|
/** Kick a user from the guild. Requires Kick Members. */
|
|
5338
|
-
kick(userId) {
|
|
5339
|
-
return kick(this, userId);
|
|
5487
|
+
kick(userId, reason) {
|
|
5488
|
+
return kick(this, userId, reason);
|
|
5340
5489
|
}
|
|
5341
5490
|
/** Fetch all emojis in this guild from the API. */
|
|
5342
5491
|
fetchEmojis() {
|
|
@@ -5786,7 +5935,14 @@ function markGuildUnavailable(client, id) {
|
|
|
5786
5935
|
guild.available = false;
|
|
5787
5936
|
client.emit(Events.GuildUnavailable, guild);
|
|
5788
5937
|
}
|
|
5938
|
+
function isStartupGuildHydration(client) {
|
|
5939
|
+
return client._guildStreamSettleTimeout !== null;
|
|
5940
|
+
}
|
|
5789
5941
|
var guildHandlers = {
|
|
5942
|
+
/**
|
|
5943
|
+
* Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
|
|
5944
|
+
* {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
|
|
5945
|
+
*/
|
|
5790
5946
|
GUILD_CREATE(client, d) {
|
|
5791
5947
|
const raw = d;
|
|
5792
5948
|
if (raw.unavailable === true) {
|
|
@@ -5799,11 +5955,32 @@ var guildHandlers = {
|
|
|
5799
5955
|
}
|
|
5800
5956
|
return;
|
|
5801
5957
|
}
|
|
5958
|
+
const startupHydration = isStartupGuildHydration(client);
|
|
5959
|
+
if (startupHydration) {
|
|
5960
|
+
resetGuildStreamSettle(client);
|
|
5961
|
+
}
|
|
5802
5962
|
const result = applyGuildSnapshotFromGateway(client, d);
|
|
5803
5963
|
if (!result) return;
|
|
5804
5964
|
const { guild, recovered } = result;
|
|
5805
|
-
|
|
5806
|
-
|
|
5965
|
+
const legacyStartup = client.options.emitGuildCreateOnStartup === true;
|
|
5966
|
+
const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
|
|
5967
|
+
const isStartupBackfill = wasReadyStub || startupHydration;
|
|
5968
|
+
if (recovered) {
|
|
5969
|
+
guild.available = true;
|
|
5970
|
+
if (legacyStartup && isStartupBackfill) {
|
|
5971
|
+
client.emit(Events.GuildCreate, guild);
|
|
5972
|
+
} else {
|
|
5973
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5974
|
+
}
|
|
5975
|
+
} else if (startupHydration) {
|
|
5976
|
+
if (legacyStartup) {
|
|
5977
|
+
client.emit(Events.GuildCreate, guild);
|
|
5978
|
+
} else {
|
|
5979
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5980
|
+
}
|
|
5981
|
+
} else {
|
|
5982
|
+
client.emit(Events.GuildCreate, guild);
|
|
5983
|
+
}
|
|
5807
5984
|
client._onGuildReceived(guild.id);
|
|
5808
5985
|
},
|
|
5809
5986
|
GUILD_UPDATE(client, d) {
|
|
@@ -5842,6 +6019,7 @@ var guildHandlers = {
|
|
|
5842
6019
|
markGuildUnavailable(client, id);
|
|
5843
6020
|
return;
|
|
5844
6021
|
}
|
|
6022
|
+
client._readyStubGuildIds.delete(id);
|
|
5845
6023
|
const guild = client.guilds.get(id);
|
|
5846
6024
|
if (!guild) return;
|
|
5847
6025
|
client.guilds.delete(id);
|
|
@@ -6357,10 +6535,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
|
|
|
6357
6535
|
for (const g of guilds ?? []) {
|
|
6358
6536
|
if (g.unavailable === true) {
|
|
6359
6537
|
if (typeof g.id === "string") {
|
|
6360
|
-
|
|
6361
|
-
if (
|
|
6362
|
-
|
|
6538
|
+
let guild = client.guilds.get(g.id);
|
|
6539
|
+
if (!guild) {
|
|
6540
|
+
guild = new Guild(client, { id: g.id });
|
|
6541
|
+
guild.available = false;
|
|
6542
|
+
client.guilds.set(g.id, guild);
|
|
6543
|
+
} else if (guild.available !== false) {
|
|
6544
|
+
guild.available = false;
|
|
6363
6545
|
}
|
|
6546
|
+
client._readyStubGuildIds.add(g.id);
|
|
6364
6547
|
if (pending !== null) pending.add(g.id);
|
|
6365
6548
|
}
|
|
6366
6549
|
continue;
|
|
@@ -6388,6 +6571,13 @@ function clearGuildStreamSettle(client) {
|
|
|
6388
6571
|
clearTimeout(client._guildStreamSettleTimeout);
|
|
6389
6572
|
client._guildStreamSettleTimeout = null;
|
|
6390
6573
|
}
|
|
6574
|
+
function resetGuildStreamSettle(client) {
|
|
6575
|
+
clearGuildStreamSettle(client);
|
|
6576
|
+
client._guildStreamSettleTimeout = setTimeout(() => {
|
|
6577
|
+
client._guildStreamSettleTimeout = null;
|
|
6578
|
+
if (client.readyAt === null) finalizeClientReady(client);
|
|
6579
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
6580
|
+
}
|
|
6391
6581
|
function handleReadyPayload(client, data) {
|
|
6392
6582
|
client.user = new ClientUser(client, data.user);
|
|
6393
6583
|
const waitForGuilds = client.options.waitForGuilds === true;
|
|
@@ -6407,14 +6597,9 @@ function handleReadyPayload(client, data) {
|
|
|
6407
6597
|
client._pendingGuildIds = existing;
|
|
6408
6598
|
return;
|
|
6409
6599
|
}
|
|
6410
|
-
if (
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
client._guildStreamSettleTimeout = null;
|
|
6414
|
-
if (client.readyAt === null) finalizeClientReady(client);
|
|
6415
|
-
}, GUILD_STREAM_SETTLE_MS);
|
|
6416
|
-
}
|
|
6417
|
-
return;
|
|
6600
|
+
if (guilds.length === 0) {
|
|
6601
|
+
resetGuildStreamSettle(client);
|
|
6602
|
+
if (waitForGuilds) return;
|
|
6418
6603
|
}
|
|
6419
6604
|
finalizeClientReady(client);
|
|
6420
6605
|
}
|
|
@@ -6747,7 +6932,12 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6747
6932
|
_ws = null;
|
|
6748
6933
|
/** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
|
|
6749
6934
|
_pendingGuildIds = null;
|
|
6750
|
-
/**
|
|
6935
|
+
/** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
|
|
6936
|
+
_readyStubGuildIds = /* @__PURE__ */ new Set();
|
|
6937
|
+
/**
|
|
6938
|
+
* @internal Empty-READY guild stream window.
|
|
6939
|
+
* Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
|
|
6940
|
+
*/
|
|
6751
6941
|
_guildStreamSettleTimeout = null;
|
|
6752
6942
|
/** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
|
|
6753
6943
|
_deferredGatewayDispatches = [];
|
|
@@ -6778,7 +6968,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6778
6968
|
const restApi = options.rest?.api;
|
|
6779
6969
|
if (options.instance !== void 0) {
|
|
6780
6970
|
this.instance = resolveInstanceEndpoints(options.instance);
|
|
6781
|
-
resolveRestApi(this.instance.endpoints.
|
|
6971
|
+
resolveRestApi(this.instance.endpoints.api_public, restApi);
|
|
6782
6972
|
} else {
|
|
6783
6973
|
this.instance = resolveInstanceEndpoints(
|
|
6784
6974
|
restApi !== void 0 ? { api: restApi } : void 0
|
|
@@ -6791,27 +6981,31 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6791
6981
|
}
|
|
6792
6982
|
this.rest = new import_rest3.REST({
|
|
6793
6983
|
...this.options.rest,
|
|
6794
|
-
api: this.instance.endpoints.
|
|
6795
|
-
version: this.options.rest?.version ?? "1"
|
|
6984
|
+
api: this.instance.endpoints.api_public,
|
|
6985
|
+
version: this.options.rest?.version ?? "1",
|
|
6986
|
+
locale: this.options.locale ?? this.options.rest?.locale
|
|
6796
6987
|
});
|
|
6797
6988
|
}
|
|
6798
6989
|
/**
|
|
6799
6990
|
* Create a client from instance discovery (`GET /.well-known/fluxer`).
|
|
6800
|
-
*
|
|
6991
|
+
* Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
|
|
6992
|
+
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
6993
|
+
* Does not log in. Call {@link login} with a token afterward.
|
|
6801
6994
|
*
|
|
6802
|
-
* @param origin -
|
|
6803
|
-
* @param options - Client options (must not conflict with discovered `endpoints.
|
|
6995
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
|
|
6996
|
+
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
6804
6997
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
6805
6998
|
*/
|
|
6806
6999
|
static async fromDiscovery(origin, options = {}, connectOptions) {
|
|
6807
|
-
const
|
|
7000
|
+
const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
|
|
6808
7001
|
const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
|
|
6809
7002
|
const bootstrap = new import_rest3.REST({
|
|
6810
7003
|
...options.rest ?? {},
|
|
6811
|
-
api:
|
|
6812
|
-
version
|
|
7004
|
+
api: bootstrapOrigin,
|
|
7005
|
+
version,
|
|
7006
|
+
locale: options.locale ?? options.rest?.locale
|
|
6813
7007
|
});
|
|
6814
|
-
const raw = await bootstrap.get(
|
|
7008
|
+
const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
|
|
6815
7009
|
auth: false,
|
|
6816
7010
|
...connectOptions?.signal ? { signal: connectOptions.signal } : {}
|
|
6817
7011
|
});
|
|
@@ -6819,7 +7013,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6819
7013
|
const { rest, ...restOptions } = options;
|
|
6820
7014
|
return new _Client({
|
|
6821
7015
|
...restOptions,
|
|
6822
|
-
// Drop rest.api so discovered endpoints.
|
|
7016
|
+
// Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
|
|
6823
7017
|
...rest ? { rest: { ...rest, api: void 0 } } : {},
|
|
6824
7018
|
instance: discovery
|
|
6825
7019
|
});
|
|
@@ -6846,7 +7040,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6846
7040
|
return resolveClientEmoji(this, emoji, guildId);
|
|
6847
7041
|
}
|
|
6848
7042
|
/**
|
|
6849
|
-
* Fetch instance discovery document (
|
|
7043
|
+
* Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
|
|
6850
7044
|
* @returns Instance configuration (endpoints, features, metadata)
|
|
6851
7045
|
*/
|
|
6852
7046
|
fetchInstance() {
|
|
@@ -7115,6 +7309,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7115
7309
|
this.user = null;
|
|
7116
7310
|
this.readyAt = null;
|
|
7117
7311
|
this._pendingGuildIds = null;
|
|
7312
|
+
this._readyStubGuildIds.clear();
|
|
7118
7313
|
this.guilds.clear();
|
|
7119
7314
|
this.channels.clear();
|
|
7120
7315
|
this.users.clear();
|
|
@@ -7534,6 +7729,7 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
|
|
|
7534
7729
|
GuildOperations,
|
|
7535
7730
|
GuildRoleManager,
|
|
7536
7731
|
GuildSticker,
|
|
7732
|
+
INSTANCE_DISCOVERY_PATH,
|
|
7537
7733
|
Invite,
|
|
7538
7734
|
InviteType,
|
|
7539
7735
|
LinkChannel,
|
|
@@ -7582,6 +7778,7 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
|
|
|
7582
7778
|
cdnMemberBannerURL,
|
|
7583
7779
|
cdnStickerURL,
|
|
7584
7780
|
createLogger,
|
|
7781
|
+
instanceDiscoveryUrl,
|
|
7585
7782
|
inviteUrl,
|
|
7586
7783
|
normalizeApiOrigin,
|
|
7587
7784
|
normalizeCacheLimit,
|