@fluxerjs/core 3.0.0 → 3.2.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-DHo7ltTz.d.ts} +78 -24
- package/dist/{SubpathMessage-DNlKq2Nj.d.ts → SubpathMessage-DW9TgPNl.d.mts} +78 -24
- package/dist/{Sudo-CFfbmis3.d.mts → Sudo-DwxTf-jj.d.mts} +14 -1
- package/dist/{Sudo-CFfbmis3.d.ts → Sudo-DwxTf-jj.d.ts} +14 -1
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +294 -93
- package/dist/client.mjs +294 -93
- package/dist/cluster.d.mts +3 -3
- package/dist/cluster.d.ts +3 -3
- package/dist/cluster.js +294 -93
- package/dist/cluster.mjs +294 -93
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +300 -93
- package/dist/index.mjs +297 -93
- package/dist/internal.d.mts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -0
- package/dist/internal.mjs +1 -0
- 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 +6 -6
package/dist/cluster.mjs
CHANGED
|
@@ -160,6 +160,7 @@ function toOverwriteWire(overwrite) {
|
|
|
160
160
|
}
|
|
161
161
|
function toChannelEditBody(options) {
|
|
162
162
|
const body = {};
|
|
163
|
+
if (options.type !== void 0) body.type = options.type;
|
|
163
164
|
if (options.name !== void 0) body.name = options.name;
|
|
164
165
|
if (options.topic !== void 0) body.topic = options.topic;
|
|
165
166
|
if (options.url !== void 0) body.url = options.url;
|
|
@@ -495,6 +496,13 @@ function toSudoBody(options) {
|
|
|
495
496
|
return body;
|
|
496
497
|
}
|
|
497
498
|
|
|
499
|
+
// src/Helpers/AuditReason.ts
|
|
500
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
501
|
+
function auditReasonHeaders(reason) {
|
|
502
|
+
if (reason == null || reason === "") return {};
|
|
503
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
504
|
+
}
|
|
505
|
+
|
|
498
506
|
// src/Helpers/MessageUtils/Body.ts
|
|
499
507
|
import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
500
508
|
import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
|
|
@@ -1074,6 +1082,67 @@ var CDN_URL = "https://fluxerusercontent.com";
|
|
|
1074
1082
|
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1075
1083
|
|
|
1076
1084
|
// src/Helpers/Cdn.ts
|
|
1085
|
+
var CDN_SIZE_LADDER = [
|
|
1086
|
+
16,
|
|
1087
|
+
20,
|
|
1088
|
+
22,
|
|
1089
|
+
24,
|
|
1090
|
+
28,
|
|
1091
|
+
32,
|
|
1092
|
+
40,
|
|
1093
|
+
44,
|
|
1094
|
+
48,
|
|
1095
|
+
56,
|
|
1096
|
+
60,
|
|
1097
|
+
64,
|
|
1098
|
+
80,
|
|
1099
|
+
96,
|
|
1100
|
+
100,
|
|
1101
|
+
128,
|
|
1102
|
+
160,
|
|
1103
|
+
240,
|
|
1104
|
+
256,
|
|
1105
|
+
300,
|
|
1106
|
+
320,
|
|
1107
|
+
480,
|
|
1108
|
+
512,
|
|
1109
|
+
600,
|
|
1110
|
+
640,
|
|
1111
|
+
1024,
|
|
1112
|
+
1280,
|
|
1113
|
+
1536,
|
|
1114
|
+
2048,
|
|
1115
|
+
3072,
|
|
1116
|
+
4096,
|
|
1117
|
+
8192,
|
|
1118
|
+
16384
|
|
1119
|
+
];
|
|
1120
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
1121
|
+
icon: { min: 128, max: 1024 },
|
|
1122
|
+
banner: { min: 480, max: 2400 },
|
|
1123
|
+
emoji: { min: 32, max: 512 },
|
|
1124
|
+
sticker: { min: 128, max: 512 }
|
|
1125
|
+
};
|
|
1126
|
+
function nearestSize(requested, candidates) {
|
|
1127
|
+
let best = candidates[0];
|
|
1128
|
+
let bestDist = Math.abs(requested - best);
|
|
1129
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
1130
|
+
const step = candidates[i];
|
|
1131
|
+
const dist = Math.abs(requested - step);
|
|
1132
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1133
|
+
best = step;
|
|
1134
|
+
bestDist = dist;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return best;
|
|
1138
|
+
}
|
|
1139
|
+
function snapCdnSize(requested, assetClass) {
|
|
1140
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1141
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1142
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1143
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1144
|
+
return nearestSize(clamped, allowed);
|
|
1145
|
+
}
|
|
1077
1146
|
function mediaBase(options) {
|
|
1078
1147
|
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1079
1148
|
}
|
|
@@ -1085,31 +1154,33 @@ function getExtension(hash, options) {
|
|
|
1085
1154
|
if (hash?.startsWith("a_")) return "gif";
|
|
1086
1155
|
return ext;
|
|
1087
1156
|
}
|
|
1088
|
-
function appendSize(options) {
|
|
1089
|
-
|
|
1157
|
+
function appendSize(options, assetClass) {
|
|
1158
|
+
const size = options?.size;
|
|
1159
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1160
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1090
1161
|
}
|
|
1091
1162
|
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1092
1163
|
if (!avatarHash) return null;
|
|
1093
1164
|
const ext = getExtension(avatarHash, options);
|
|
1094
|
-
const size = appendSize(options);
|
|
1165
|
+
const size = appendSize(options, "icon");
|
|
1095
1166
|
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1096
1167
|
}
|
|
1097
1168
|
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1098
1169
|
if (!bannerHash) return null;
|
|
1099
1170
|
const ext = getExtension(bannerHash, options);
|
|
1100
|
-
const size = appendSize(options);
|
|
1171
|
+
const size = appendSize(options, "banner");
|
|
1101
1172
|
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1102
1173
|
}
|
|
1103
1174
|
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1104
1175
|
if (!avatarHash) return null;
|
|
1105
1176
|
const ext = getExtension(avatarHash, options);
|
|
1106
|
-
const size = appendSize(options);
|
|
1177
|
+
const size = appendSize(options, "icon");
|
|
1107
1178
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1108
1179
|
}
|
|
1109
1180
|
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1110
1181
|
if (!bannerHash) return null;
|
|
1111
1182
|
const ext = getExtension(bannerHash, options);
|
|
1112
|
-
const size = appendSize(options);
|
|
1183
|
+
const size = appendSize(options, "banner");
|
|
1113
1184
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1114
1185
|
}
|
|
1115
1186
|
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
@@ -1118,16 +1189,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
|
1118
1189
|
}
|
|
1119
1190
|
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1120
1191
|
if (!hash) return null;
|
|
1121
|
-
const
|
|
1192
|
+
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1193
|
+
const size = appendSize(options, assetClass);
|
|
1122
1194
|
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1123
1195
|
}
|
|
1124
1196
|
function cdnEmojiURL(emojiId, animated, options) {
|
|
1125
1197
|
const ext = animated ? "gif" : "png";
|
|
1126
|
-
|
|
1198
|
+
const size = appendSize(options, "emoji");
|
|
1199
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1127
1200
|
}
|
|
1128
1201
|
function cdnStickerURL(stickerId, animated, options) {
|
|
1129
1202
|
const ext = animated ? "gif" : "png";
|
|
1130
|
-
|
|
1203
|
+
const size = appendSize(options, "sticker");
|
|
1204
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1131
1205
|
}
|
|
1132
1206
|
|
|
1133
1207
|
// src/Domain/Message/MessageSticker.ts
|
|
@@ -1355,6 +1429,8 @@ var Message = class _Message extends Base {
|
|
|
1355
1429
|
mentionRoles;
|
|
1356
1430
|
/** Client-side nonce for deduplication. */
|
|
1357
1431
|
nonce;
|
|
1432
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
1433
|
+
nsfwEmojis;
|
|
1358
1434
|
/**
|
|
1359
1435
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1360
1436
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1429,6 +1505,7 @@ var Message = class _Message extends Base {
|
|
|
1429
1505
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1430
1506
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1431
1507
|
this.nonce = data.nonce ?? null;
|
|
1508
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1432
1509
|
}
|
|
1433
1510
|
/**
|
|
1434
1511
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
@@ -1461,6 +1538,7 @@ var Message = class _Message extends Base {
|
|
|
1461
1538
|
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1462
1539
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1463
1540
|
this.nonce = data.nonce ?? null;
|
|
1541
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1464
1542
|
}
|
|
1465
1543
|
/**
|
|
1466
1544
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1544,8 +1622,10 @@ var Message = class _Message extends Base {
|
|
|
1544
1622
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1545
1623
|
}
|
|
1546
1624
|
/** Delete this message. */
|
|
1547
|
-
async delete() {
|
|
1548
|
-
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id)
|
|
1625
|
+
async delete(reason) {
|
|
1626
|
+
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
|
|
1627
|
+
...auditReasonHeaders(reason)
|
|
1628
|
+
});
|
|
1549
1629
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
1550
1630
|
}
|
|
1551
1631
|
/** Delete a specific attachment from this message. */
|
|
@@ -1859,6 +1939,29 @@ var MessageCollector = class _MessageCollector extends EventEmitter2 {
|
|
|
1859
1939
|
|
|
1860
1940
|
// src/Domain/Channel/Attachments.ts
|
|
1861
1941
|
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
1942
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
1943
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
1944
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
1945
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
1946
|
+
if (!rules?.length) return null;
|
|
1947
|
+
const snapshot = {};
|
|
1948
|
+
for (const rule of rules) {
|
|
1949
|
+
Object.assign(snapshot, rule.overrides);
|
|
1950
|
+
}
|
|
1951
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
1952
|
+
}
|
|
1953
|
+
function assertBotAttachmentLimits(client, files) {
|
|
1954
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
1955
|
+
for (const file of files) {
|
|
1956
|
+
const size = file.data.byteLength;
|
|
1957
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
1958
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
1959
|
+
throw new FluxerError(
|
|
1960
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
1961
|
+
{ code: ErrorCodes.AttachmentTooLarge }
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1862
1965
|
function asBytes(data) {
|
|
1863
1966
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
1864
1967
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -1878,6 +1981,7 @@ async function putBlob(url, body, contentType) {
|
|
|
1878
1981
|
}
|
|
1879
1982
|
}
|
|
1880
1983
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
1984
|
+
assertBotAttachmentLimits(client, files);
|
|
1881
1985
|
const plan = await client.rest.post(
|
|
1882
1986
|
Routes6.channelAttachments(channelId),
|
|
1883
1987
|
{
|
|
@@ -1990,20 +2094,24 @@ var Channel = class extends Base {
|
|
|
1990
2094
|
throw new Error("Channel.createDM not initialized");
|
|
1991
2095
|
}
|
|
1992
2096
|
/**
|
|
1993
|
-
* Whether this channel type can carry messages (text, voice, DM, group DM, notes).
|
|
2097
|
+
* Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
|
|
1994
2098
|
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
1995
2099
|
*/
|
|
1996
2100
|
isTextBased() {
|
|
1997
|
-
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
|
|
2101
|
+
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildAnnouncement || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
|
|
1998
2102
|
}
|
|
1999
|
-
/** Check if this is a guild channel (text, voice, category, or link). */
|
|
2103
|
+
/** Check if this is a guild channel (text, announcement, voice, category, or link). */
|
|
2000
2104
|
isGuild() {
|
|
2001
|
-
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
|
|
2105
|
+
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildAnnouncement || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
|
|
2002
2106
|
}
|
|
2003
2107
|
/** Check if this is a guild text channel. */
|
|
2004
2108
|
isText() {
|
|
2005
2109
|
return this.type === ChannelType.GuildText;
|
|
2006
2110
|
}
|
|
2111
|
+
/** Check if this is a guild announcement channel. */
|
|
2112
|
+
isAnnouncement() {
|
|
2113
|
+
return this.type === ChannelType.GuildAnnouncement;
|
|
2114
|
+
}
|
|
2007
2115
|
/** Check if this is a category channel. */
|
|
2008
2116
|
isCategory() {
|
|
2009
2117
|
return this.type === ChannelType.GuildCategory;
|
|
@@ -2174,11 +2282,12 @@ var Channel = class extends Base {
|
|
|
2174
2282
|
if (options?.silent) params.set("silent", "true");
|
|
2175
2283
|
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2176
2284
|
const qs2 = params.toString();
|
|
2177
|
-
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2285
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
2178
2286
|
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2179
2287
|
await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2180
2288
|
body,
|
|
2181
|
-
auth: true
|
|
2289
|
+
auth: true,
|
|
2290
|
+
...auditReasonHeaders(_reason)
|
|
2182
2291
|
});
|
|
2183
2292
|
this.client.channels.delete(this.id);
|
|
2184
2293
|
this.client._clearMessageCache(this.id);
|
|
@@ -2343,7 +2452,7 @@ import {
|
|
|
2343
2452
|
// src/Helpers/Instance.ts
|
|
2344
2453
|
import { isRecord } from "@fluxerjs/util";
|
|
2345
2454
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2346
|
-
api: "https://
|
|
2455
|
+
api: "https://web.fluxer.app/api",
|
|
2347
2456
|
api_client: "https://web.fluxer.app/api",
|
|
2348
2457
|
api_public: "https://api.fluxer.app",
|
|
2349
2458
|
gateway: "wss://gateway.fluxer.app",
|
|
@@ -2377,6 +2486,10 @@ function requireString(obj, key, path) {
|
|
|
2377
2486
|
}
|
|
2378
2487
|
return value;
|
|
2379
2488
|
}
|
|
2489
|
+
var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
|
|
2490
|
+
function instanceDiscoveryUrl(origin) {
|
|
2491
|
+
return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
|
|
2492
|
+
}
|
|
2380
2493
|
function normalizeApiOrigin(api) {
|
|
2381
2494
|
const trimmed = api.trim().replace(/\/+$/, "");
|
|
2382
2495
|
return trimmed.replace(/\/v\d+$/i, "");
|
|
@@ -2405,6 +2518,8 @@ function parseInstanceDiscovery(raw) {
|
|
|
2405
2518
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2406
2519
|
}
|
|
2407
2520
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2521
|
+
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2522
|
+
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
2408
2523
|
endpoints.invite = normalizeInviteBase(endpoints.invite);
|
|
2409
2524
|
endpoints.media = endpoints.media.replace(/\/+$/, "");
|
|
2410
2525
|
endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
|
|
@@ -2482,6 +2597,11 @@ function resolveInstanceEndpoints(input) {
|
|
|
2482
2597
|
}
|
|
2483
2598
|
}
|
|
2484
2599
|
merged.api = normalizeApiOrigin(merged.api);
|
|
2600
|
+
merged.api_client = normalizeApiOrigin(merged.api_client);
|
|
2601
|
+
merged.api_public = normalizeApiOrigin(merged.api_public);
|
|
2602
|
+
if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
|
|
2603
|
+
merged.api_public = merged.api;
|
|
2604
|
+
}
|
|
2485
2605
|
merged.invite = normalizeInviteBase(merged.invite);
|
|
2486
2606
|
merged.media = merged.media.replace(/\/+$/, "");
|
|
2487
2607
|
merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
|
|
@@ -2490,13 +2610,13 @@ function resolveInstanceEndpoints(input) {
|
|
|
2490
2610
|
discovery: null
|
|
2491
2611
|
});
|
|
2492
2612
|
}
|
|
2493
|
-
function resolveRestApi(
|
|
2494
|
-
const fromInstance = normalizeApiOrigin(
|
|
2613
|
+
function resolveRestApi(instanceApiPublic, restApi) {
|
|
2614
|
+
const fromInstance = normalizeApiOrigin(instanceApiPublic);
|
|
2495
2615
|
if (restApi === void 0) return fromInstance;
|
|
2496
2616
|
const fromRest = normalizeApiOrigin(restApi);
|
|
2497
2617
|
if (fromRest !== fromInstance) {
|
|
2498
2618
|
throw new FluxerError(
|
|
2499
|
-
`Conflicting API hosts: instance.
|
|
2619
|
+
`Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
|
|
2500
2620
|
{ code: ErrorCodes.ConflictingInstanceConfig }
|
|
2501
2621
|
);
|
|
2502
2622
|
}
|
|
@@ -2978,7 +3098,8 @@ var GuildChannel = class extends Channel {
|
|
|
2978
3098
|
async edit(options) {
|
|
2979
3099
|
const data = await this.client.rest.patch(Routes13.channel(this.id), {
|
|
2980
3100
|
body: toChannelEditBody(options),
|
|
2981
|
-
auth: true
|
|
3101
|
+
auth: true,
|
|
3102
|
+
...auditReasonHeaders(options.reason)
|
|
2982
3103
|
});
|
|
2983
3104
|
this.name = data.name ?? this.name;
|
|
2984
3105
|
this.parentId = data.parent_id ?? this.parentId;
|
|
@@ -3037,6 +3158,8 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3037
3158
|
}
|
|
3038
3159
|
}
|
|
3039
3160
|
};
|
|
3161
|
+
var AnnouncementChannel = class extends TextChannel {
|
|
3162
|
+
};
|
|
3040
3163
|
var CategoryChannel = class extends GuildChannel {
|
|
3041
3164
|
};
|
|
3042
3165
|
var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
@@ -3119,6 +3242,7 @@ var LinkChannel = class extends GuildChannel {
|
|
|
3119
3242
|
import { ChannelType as ChannelType3 } from "@fluxerjs/types";
|
|
3120
3243
|
var GUILD_FACTORIES = {
|
|
3121
3244
|
[ChannelType3.GuildText]: (c, d) => new TextChannel(c, d),
|
|
3245
|
+
[ChannelType3.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
|
|
3122
3246
|
[ChannelType3.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
3123
3247
|
[ChannelType3.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
3124
3248
|
[ChannelType3.GuildLink]: (c, d) => new LinkChannel(c, d)
|
|
@@ -3510,9 +3634,10 @@ var GuildEmoji = class extends Base {
|
|
|
3510
3634
|
return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
|
|
3511
3635
|
}
|
|
3512
3636
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
3513
|
-
async delete() {
|
|
3637
|
+
async delete(reason) {
|
|
3514
3638
|
await this.client.rest.delete(Routes15.guildEmoji(this.guildId, this.id), {
|
|
3515
|
-
auth: true
|
|
3639
|
+
auth: true,
|
|
3640
|
+
...auditReasonHeaders(reason)
|
|
3516
3641
|
});
|
|
3517
3642
|
const guild = this.client.guilds.get(this.guildId);
|
|
3518
3643
|
if (guild) guild.emojis.delete(this.id);
|
|
@@ -3522,9 +3647,11 @@ var GuildEmoji = class extends Base {
|
|
|
3522
3647
|
* Requires Manage Emojis and Stickers permission.
|
|
3523
3648
|
*/
|
|
3524
3649
|
async edit(options) {
|
|
3650
|
+
const { reason, name } = options;
|
|
3525
3651
|
const data = await this.client.rest.patch(Routes15.guildEmoji(this.guildId, this.id), {
|
|
3526
|
-
body:
|
|
3527
|
-
auth: true
|
|
3652
|
+
body: { name },
|
|
3653
|
+
auth: true,
|
|
3654
|
+
...auditReasonHeaders(reason)
|
|
3528
3655
|
});
|
|
3529
3656
|
this.name = data.name;
|
|
3530
3657
|
return this;
|
|
@@ -3540,6 +3667,9 @@ import { OverwriteType } from "@fluxerjs/types";
|
|
|
3540
3667
|
import { ALL_PERMISSIONS_BIGINT, PermissionFlags as PermissionFlags2 } from "@fluxerjs/util";
|
|
3541
3668
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
3542
3669
|
if (isOwner) return ALL_PERMISSIONS_BIGINT;
|
|
3670
|
+
if ((basePermissions & PermissionFlags2.Administrator) !== 0n) {
|
|
3671
|
+
return ALL_PERMISSIONS_BIGINT;
|
|
3672
|
+
}
|
|
3543
3673
|
let perms = basePermissions;
|
|
3544
3674
|
for (const overwrite of overwrites ?? []) {
|
|
3545
3675
|
const applies = overwrite.type === OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === OverwriteType.Member && overwrite.id === memberId;
|
|
@@ -3548,7 +3678,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
3548
3678
|
const deny = BigInt(overwrite.deny || "0");
|
|
3549
3679
|
perms = perms & ~deny | allow;
|
|
3550
3680
|
}
|
|
3551
|
-
return
|
|
3681
|
+
return perms;
|
|
3552
3682
|
}
|
|
3553
3683
|
|
|
3554
3684
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
@@ -3754,7 +3884,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3754
3884
|
const route = isMe ? Routes17.guildMemberMe(this.guild.id) : Routes17.guildMember(this.guild.id, this.id);
|
|
3755
3885
|
const data = await this.client.rest.patch(route, {
|
|
3756
3886
|
body: toMemberEditBody(options),
|
|
3757
|
-
auth: true
|
|
3887
|
+
auth: true,
|
|
3888
|
+
...auditReasonHeaders(options.reason ?? options.timeoutReason)
|
|
3758
3889
|
});
|
|
3759
3890
|
this._patch(data);
|
|
3760
3891
|
if (options.bio !== void 0) this.bio = options.bio;
|
|
@@ -3788,8 +3919,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3788
3919
|
await this.edit({ channelId, connectionId });
|
|
3789
3920
|
}
|
|
3790
3921
|
/** Kick this member. Requires Kick Members. */
|
|
3791
|
-
async kick() {
|
|
3792
|
-
await this.guild.kick(this.id);
|
|
3922
|
+
async kick(reason) {
|
|
3923
|
+
await this.guild.kick(this.id, reason);
|
|
3793
3924
|
}
|
|
3794
3925
|
/** Ban this member. Requires Ban Members. */
|
|
3795
3926
|
async ban(options) {
|
|
@@ -3913,9 +4044,10 @@ var GuildSticker = class extends Base {
|
|
|
3913
4044
|
return SnowflakeUtil7.dateFromSnowflake(this.id);
|
|
3914
4045
|
}
|
|
3915
4046
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3916
|
-
async delete() {
|
|
4047
|
+
async delete(reason) {
|
|
3917
4048
|
await this.client.rest.delete(Routes18.guildSticker(this.guildId, this.id), {
|
|
3918
|
-
auth: true
|
|
4049
|
+
auth: true,
|
|
4050
|
+
...auditReasonHeaders(reason)
|
|
3919
4051
|
});
|
|
3920
4052
|
const guild = this.client.guilds.get(this.guildId);
|
|
3921
4053
|
if (guild) guild.stickers.delete(this.id);
|
|
@@ -3925,9 +4057,11 @@ var GuildSticker = class extends Base {
|
|
|
3925
4057
|
* Requires Manage Emojis and Stickers permission.
|
|
3926
4058
|
*/
|
|
3927
4059
|
async edit(options) {
|
|
4060
|
+
const { reason, ...body } = options;
|
|
3928
4061
|
const data = await this.client.rest.patch(Routes18.guildSticker(this.guildId, this.id), {
|
|
3929
|
-
body
|
|
3930
|
-
auth: true
|
|
4062
|
+
body,
|
|
4063
|
+
auth: true,
|
|
4064
|
+
...auditReasonHeaders(reason)
|
|
3931
4065
|
});
|
|
3932
4066
|
const s = data;
|
|
3933
4067
|
this.name = s.name;
|
|
@@ -4054,16 +4188,21 @@ var Role = class _Role extends Base {
|
|
|
4054
4188
|
const body = toRoleEditBody(options);
|
|
4055
4189
|
const data = await this.client.rest.patch(Routes19.guildRole(this.guildId, this.id), {
|
|
4056
4190
|
body: Object.keys(body).length ? body : void 0,
|
|
4057
|
-
auth: true
|
|
4191
|
+
auth: true,
|
|
4192
|
+
...auditReasonHeaders(options.reason)
|
|
4058
4193
|
});
|
|
4059
4194
|
this._patch(data);
|
|
4060
4195
|
return this;
|
|
4061
4196
|
}
|
|
4062
4197
|
/**
|
|
4063
4198
|
* DELETE role. Requires Manage Roles.
|
|
4199
|
+
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
4064
4200
|
*/
|
|
4065
|
-
async delete() {
|
|
4066
|
-
await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), {
|
|
4201
|
+
async delete(reason) {
|
|
4202
|
+
await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), {
|
|
4203
|
+
auth: true,
|
|
4204
|
+
...auditReasonHeaders(reason)
|
|
4205
|
+
});
|
|
4067
4206
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
4068
4207
|
}
|
|
4069
4208
|
};
|
|
@@ -4314,7 +4453,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4314
4453
|
return parsed.name;
|
|
4315
4454
|
}
|
|
4316
4455
|
async function fetchInstance(client) {
|
|
4317
|
-
const raw = await client.rest.get(Routes21.instanceDiscovery(), {
|
|
4456
|
+
const raw = await client.rest.get(Routes21.instanceDiscovery(), {
|
|
4457
|
+
auth: false,
|
|
4458
|
+
unversioned: true
|
|
4459
|
+
});
|
|
4318
4460
|
return parseInstanceDiscovery(raw);
|
|
4319
4461
|
}
|
|
4320
4462
|
function fetchGatewayInfo(client) {
|
|
@@ -4693,9 +4835,11 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
4693
4835
|
}
|
|
4694
4836
|
}
|
|
4695
4837
|
async function createEmoji(guild, options) {
|
|
4838
|
+
const { reason, ...body } = options;
|
|
4696
4839
|
const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
|
|
4697
|
-
body
|
|
4698
|
-
auth: true
|
|
4840
|
+
body,
|
|
4841
|
+
auth: true,
|
|
4842
|
+
...auditReasonHeaders(reason)
|
|
4699
4843
|
});
|
|
4700
4844
|
return cacheEmoji(guild, data);
|
|
4701
4845
|
}
|
|
@@ -4714,6 +4858,19 @@ async function createEmojisBulk(guild, emojis) {
|
|
|
4714
4858
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
4715
4859
|
}
|
|
4716
4860
|
|
|
4861
|
+
// src/Domain/Guild/GuildRoleManager.ts
|
|
4862
|
+
import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
|
|
4863
|
+
var GuildRoleManager = class extends LimitedCollection3 {
|
|
4864
|
+
constructor(guildId, options) {
|
|
4865
|
+
super(options);
|
|
4866
|
+
this.guildId = guildId;
|
|
4867
|
+
}
|
|
4868
|
+
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4869
|
+
get everyone() {
|
|
4870
|
+
return this.get(this.guildId);
|
|
4871
|
+
}
|
|
4872
|
+
};
|
|
4873
|
+
|
|
4717
4874
|
// src/Domain/Guild/MemberHttp.ts
|
|
4718
4875
|
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
4719
4876
|
async function fetchMember(guild, userId) {
|
|
@@ -4770,9 +4927,10 @@ var GuildBan = class extends Base {
|
|
|
4770
4927
|
* Remove this ban (unban the user).
|
|
4771
4928
|
* Requires Ban Members permission.
|
|
4772
4929
|
*/
|
|
4773
|
-
async unban() {
|
|
4930
|
+
async unban(reason) {
|
|
4774
4931
|
await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
|
|
4775
|
-
auth: true
|
|
4932
|
+
auth: true,
|
|
4933
|
+
...auditReasonHeaders(reason)
|
|
4776
4934
|
});
|
|
4777
4935
|
}
|
|
4778
4936
|
};
|
|
@@ -4782,33 +4940,27 @@ async function ban(guild, userId, options) {
|
|
|
4782
4940
|
const body = options ? toGuildBanBody(options) : {};
|
|
4783
4941
|
await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
|
|
4784
4942
|
body: Object.keys(body).length ? body : void 0,
|
|
4785
|
-
auth: true
|
|
4943
|
+
auth: true,
|
|
4944
|
+
...auditReasonHeaders(options?.reason)
|
|
4786
4945
|
});
|
|
4787
4946
|
}
|
|
4788
4947
|
async function fetchBans(guild) {
|
|
4789
4948
|
const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
|
|
4790
4949
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
4791
4950
|
}
|
|
4792
|
-
async function unban(guild, userId) {
|
|
4793
|
-
await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
|
|
4951
|
+
async function unban(guild, userId, reason) {
|
|
4952
|
+
await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
|
|
4953
|
+
auth: true,
|
|
4954
|
+
...auditReasonHeaders(reason)
|
|
4955
|
+
});
|
|
4794
4956
|
}
|
|
4795
|
-
async function kick(guild, userId) {
|
|
4796
|
-
await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
|
|
4957
|
+
async function kick(guild, userId, reason) {
|
|
4958
|
+
await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
|
|
4959
|
+
auth: true,
|
|
4960
|
+
...auditReasonHeaders(reason)
|
|
4961
|
+
});
|
|
4797
4962
|
}
|
|
4798
4963
|
|
|
4799
|
-
// src/Domain/Guild/GuildRoleManager.ts
|
|
4800
|
-
import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
|
|
4801
|
-
var GuildRoleManager = class extends LimitedCollection3 {
|
|
4802
|
-
constructor(guildId, options) {
|
|
4803
|
-
super(options);
|
|
4804
|
-
this.guildId = guildId;
|
|
4805
|
-
}
|
|
4806
|
-
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4807
|
-
get everyone() {
|
|
4808
|
-
return this.get(this.guildId);
|
|
4809
|
-
}
|
|
4810
|
-
};
|
|
4811
|
-
|
|
4812
4964
|
// src/Domain/Guild/Roles.ts
|
|
4813
4965
|
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
4814
4966
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
@@ -4816,7 +4968,8 @@ async function createRole(guild, options = {}) {
|
|
|
4816
4968
|
const body = toRoleCreateBody(options);
|
|
4817
4969
|
const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
|
|
4818
4970
|
body: Object.keys(body).length ? body : void 0,
|
|
4819
|
-
auth: true
|
|
4971
|
+
auth: true,
|
|
4972
|
+
...auditReasonHeaders(options.reason)
|
|
4820
4973
|
});
|
|
4821
4974
|
return cacheRole(guild, data);
|
|
4822
4975
|
}
|
|
@@ -4882,9 +5035,11 @@ async function resetRoleHoistPositions(guild) {
|
|
|
4882
5035
|
// src/Domain/Guild/Stickers.ts
|
|
4883
5036
|
import { Routes as Routes30 } from "@fluxerjs/types";
|
|
4884
5037
|
async function createSticker(guild, options) {
|
|
5038
|
+
const { reason, ...body } = options;
|
|
4885
5039
|
const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
|
|
4886
|
-
body
|
|
4887
|
-
auth: true
|
|
5040
|
+
body,
|
|
5041
|
+
auth: true,
|
|
5042
|
+
...auditReasonHeaders(reason)
|
|
4888
5043
|
});
|
|
4889
5044
|
return cacheSticker(guild, data);
|
|
4890
5045
|
}
|
|
@@ -5214,12 +5369,12 @@ var Guild = class extends Base {
|
|
|
5214
5369
|
return fetchBans(this);
|
|
5215
5370
|
}
|
|
5216
5371
|
/** Unban a user from the guild. Requires Ban Members. */
|
|
5217
|
-
unban(userId) {
|
|
5218
|
-
return unban(this, userId);
|
|
5372
|
+
unban(userId, reason) {
|
|
5373
|
+
return unban(this, userId, reason);
|
|
5219
5374
|
}
|
|
5220
5375
|
/** Kick a user from the guild. Requires Kick Members. */
|
|
5221
|
-
kick(userId) {
|
|
5222
|
-
return kick(this, userId);
|
|
5376
|
+
kick(userId, reason) {
|
|
5377
|
+
return kick(this, userId, reason);
|
|
5223
5378
|
}
|
|
5224
5379
|
/** Fetch all emojis in this guild from the API. */
|
|
5225
5380
|
fetchEmojis() {
|
|
@@ -5669,7 +5824,14 @@ function markGuildUnavailable(client, id) {
|
|
|
5669
5824
|
guild.available = false;
|
|
5670
5825
|
client.emit(Events.GuildUnavailable, guild);
|
|
5671
5826
|
}
|
|
5827
|
+
function isStartupGuildHydration(client) {
|
|
5828
|
+
return client._guildStreamSettleTimeout !== null;
|
|
5829
|
+
}
|
|
5672
5830
|
var guildHandlers = {
|
|
5831
|
+
/**
|
|
5832
|
+
* Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
|
|
5833
|
+
* {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
|
|
5834
|
+
*/
|
|
5673
5835
|
GUILD_CREATE(client, d) {
|
|
5674
5836
|
const raw = d;
|
|
5675
5837
|
if (raw.unavailable === true) {
|
|
@@ -5682,11 +5844,32 @@ var guildHandlers = {
|
|
|
5682
5844
|
}
|
|
5683
5845
|
return;
|
|
5684
5846
|
}
|
|
5847
|
+
const startupHydration = isStartupGuildHydration(client);
|
|
5848
|
+
if (startupHydration) {
|
|
5849
|
+
resetGuildStreamSettle(client);
|
|
5850
|
+
}
|
|
5685
5851
|
const result = applyGuildSnapshotFromGateway(client, d);
|
|
5686
5852
|
if (!result) return;
|
|
5687
5853
|
const { guild, recovered } = result;
|
|
5688
|
-
|
|
5689
|
-
|
|
5854
|
+
const legacyStartup = client.options.emitGuildCreateOnStartup === true;
|
|
5855
|
+
const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
|
|
5856
|
+
const isStartupBackfill = wasReadyStub || startupHydration;
|
|
5857
|
+
if (recovered) {
|
|
5858
|
+
guild.available = true;
|
|
5859
|
+
if (legacyStartup && isStartupBackfill) {
|
|
5860
|
+
client.emit(Events.GuildCreate, guild);
|
|
5861
|
+
} else {
|
|
5862
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5863
|
+
}
|
|
5864
|
+
} else if (startupHydration) {
|
|
5865
|
+
if (legacyStartup) {
|
|
5866
|
+
client.emit(Events.GuildCreate, guild);
|
|
5867
|
+
} else {
|
|
5868
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5869
|
+
}
|
|
5870
|
+
} else {
|
|
5871
|
+
client.emit(Events.GuildCreate, guild);
|
|
5872
|
+
}
|
|
5690
5873
|
client._onGuildReceived(guild.id);
|
|
5691
5874
|
},
|
|
5692
5875
|
GUILD_UPDATE(client, d) {
|
|
@@ -5725,6 +5908,7 @@ var guildHandlers = {
|
|
|
5725
5908
|
markGuildUnavailable(client, id);
|
|
5726
5909
|
return;
|
|
5727
5910
|
}
|
|
5911
|
+
client._readyStubGuildIds.delete(id);
|
|
5728
5912
|
const guild = client.guilds.get(id);
|
|
5729
5913
|
if (!guild) return;
|
|
5730
5914
|
client.guilds.delete(id);
|
|
@@ -6243,10 +6427,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
|
|
|
6243
6427
|
for (const g of guilds ?? []) {
|
|
6244
6428
|
if (g.unavailable === true) {
|
|
6245
6429
|
if (typeof g.id === "string") {
|
|
6246
|
-
|
|
6247
|
-
if (
|
|
6248
|
-
|
|
6430
|
+
let guild = client.guilds.get(g.id);
|
|
6431
|
+
if (!guild) {
|
|
6432
|
+
guild = new Guild(client, { id: g.id });
|
|
6433
|
+
guild.available = false;
|
|
6434
|
+
client.guilds.set(g.id, guild);
|
|
6435
|
+
} else if (guild.available !== false) {
|
|
6436
|
+
guild.available = false;
|
|
6249
6437
|
}
|
|
6438
|
+
client._readyStubGuildIds.add(g.id);
|
|
6250
6439
|
if (pending !== null) pending.add(g.id);
|
|
6251
6440
|
}
|
|
6252
6441
|
continue;
|
|
@@ -6274,6 +6463,13 @@ function clearGuildStreamSettle(client) {
|
|
|
6274
6463
|
clearTimeout(client._guildStreamSettleTimeout);
|
|
6275
6464
|
client._guildStreamSettleTimeout = null;
|
|
6276
6465
|
}
|
|
6466
|
+
function resetGuildStreamSettle(client) {
|
|
6467
|
+
clearGuildStreamSettle(client);
|
|
6468
|
+
client._guildStreamSettleTimeout = setTimeout(() => {
|
|
6469
|
+
client._guildStreamSettleTimeout = null;
|
|
6470
|
+
if (client.readyAt === null) finalizeClientReady(client);
|
|
6471
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
6472
|
+
}
|
|
6277
6473
|
function handleReadyPayload(client, data) {
|
|
6278
6474
|
client.user = new ClientUser(client, data.user);
|
|
6279
6475
|
const waitForGuilds = client.options.waitForGuilds === true;
|
|
@@ -6293,14 +6489,9 @@ function handleReadyPayload(client, data) {
|
|
|
6293
6489
|
client._pendingGuildIds = existing;
|
|
6294
6490
|
return;
|
|
6295
6491
|
}
|
|
6296
|
-
if (
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
client._guildStreamSettleTimeout = null;
|
|
6300
|
-
if (client.readyAt === null) finalizeClientReady(client);
|
|
6301
|
-
}, GUILD_STREAM_SETTLE_MS);
|
|
6302
|
-
}
|
|
6303
|
-
return;
|
|
6492
|
+
if (guilds.length === 0) {
|
|
6493
|
+
resetGuildStreamSettle(client);
|
|
6494
|
+
if (waitForGuilds) return;
|
|
6304
6495
|
}
|
|
6305
6496
|
finalizeClientReady(client);
|
|
6306
6497
|
}
|
|
@@ -6635,7 +6826,12 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6635
6826
|
_ws = null;
|
|
6636
6827
|
/** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
|
|
6637
6828
|
_pendingGuildIds = null;
|
|
6638
|
-
/**
|
|
6829
|
+
/** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
|
|
6830
|
+
_readyStubGuildIds = /* @__PURE__ */ new Set();
|
|
6831
|
+
/**
|
|
6832
|
+
* @internal Empty-READY guild stream window.
|
|
6833
|
+
* Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
|
|
6834
|
+
*/
|
|
6639
6835
|
_guildStreamSettleTimeout = null;
|
|
6640
6836
|
/** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
|
|
6641
6837
|
_deferredGatewayDispatches = [];
|
|
@@ -6666,7 +6862,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6666
6862
|
const restApi = options.rest?.api;
|
|
6667
6863
|
if (options.instance !== void 0) {
|
|
6668
6864
|
this.instance = resolveInstanceEndpoints(options.instance);
|
|
6669
|
-
resolveRestApi(this.instance.endpoints.
|
|
6865
|
+
resolveRestApi(this.instance.endpoints.api_public, restApi);
|
|
6670
6866
|
} else {
|
|
6671
6867
|
this.instance = resolveInstanceEndpoints(
|
|
6672
6868
|
restApi !== void 0 ? { api: restApi } : void 0
|
|
@@ -6679,27 +6875,31 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6679
6875
|
}
|
|
6680
6876
|
this.rest = new REST({
|
|
6681
6877
|
...this.options.rest,
|
|
6682
|
-
api: this.instance.endpoints.
|
|
6683
|
-
version: this.options.rest?.version ?? "1"
|
|
6878
|
+
api: this.instance.endpoints.api_public,
|
|
6879
|
+
version: this.options.rest?.version ?? "1",
|
|
6880
|
+
locale: this.options.locale ?? this.options.rest?.locale
|
|
6684
6881
|
});
|
|
6685
6882
|
}
|
|
6686
6883
|
/**
|
|
6687
6884
|
* Create a client from instance discovery (`GET /.well-known/fluxer`).
|
|
6688
|
-
*
|
|
6885
|
+
* Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
|
|
6886
|
+
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
6887
|
+
* Does not log in. Call {@link login} with a token afterward.
|
|
6689
6888
|
*
|
|
6690
|
-
* @param origin -
|
|
6691
|
-
* @param options - Client options (must not conflict with discovered `endpoints.
|
|
6889
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
|
|
6890
|
+
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
6692
6891
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
6693
6892
|
*/
|
|
6694
6893
|
static async fromDiscovery(origin, options = {}, connectOptions) {
|
|
6695
|
-
const
|
|
6894
|
+
const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
|
|
6696
6895
|
const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
|
|
6697
6896
|
const bootstrap = new REST({
|
|
6698
6897
|
...options.rest ?? {},
|
|
6699
|
-
api:
|
|
6700
|
-
version
|
|
6898
|
+
api: bootstrapOrigin,
|
|
6899
|
+
version,
|
|
6900
|
+
locale: options.locale ?? options.rest?.locale
|
|
6701
6901
|
});
|
|
6702
|
-
const raw = await bootstrap.get(
|
|
6902
|
+
const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
|
|
6703
6903
|
auth: false,
|
|
6704
6904
|
...connectOptions?.signal ? { signal: connectOptions.signal } : {}
|
|
6705
6905
|
});
|
|
@@ -6707,7 +6907,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6707
6907
|
const { rest, ...restOptions } = options;
|
|
6708
6908
|
return new _Client({
|
|
6709
6909
|
...restOptions,
|
|
6710
|
-
// Drop rest.api so discovered endpoints.
|
|
6910
|
+
// Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
|
|
6711
6911
|
...rest ? { rest: { ...rest, api: void 0 } } : {},
|
|
6712
6912
|
instance: discovery
|
|
6713
6913
|
});
|
|
@@ -6734,7 +6934,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6734
6934
|
return resolveClientEmoji(this, emoji, guildId);
|
|
6735
6935
|
}
|
|
6736
6936
|
/**
|
|
6737
|
-
* Fetch instance discovery document (
|
|
6937
|
+
* Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
|
|
6738
6938
|
* @returns Instance configuration (endpoints, features, metadata)
|
|
6739
6939
|
*/
|
|
6740
6940
|
fetchInstance() {
|
|
@@ -7003,6 +7203,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7003
7203
|
this.user = null;
|
|
7004
7204
|
this.readyAt = null;
|
|
7005
7205
|
this._pendingGuildIds = null;
|
|
7206
|
+
this._readyStubGuildIds.clear();
|
|
7006
7207
|
this.guilds.clear();
|
|
7007
7208
|
this.channels.clear();
|
|
7008
7209
|
this.users.clear();
|