@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/client.mjs
CHANGED
|
@@ -89,6 +89,7 @@ function toOverwriteWire(overwrite) {
|
|
|
89
89
|
}
|
|
90
90
|
function toChannelEditBody(options) {
|
|
91
91
|
const body = {};
|
|
92
|
+
if (options.type !== void 0) body.type = options.type;
|
|
92
93
|
if (options.name !== void 0) body.name = options.name;
|
|
93
94
|
if (options.topic !== void 0) body.topic = options.topic;
|
|
94
95
|
if (options.url !== void 0) body.url = options.url;
|
|
@@ -424,6 +425,13 @@ function toSudoBody(options) {
|
|
|
424
425
|
return body;
|
|
425
426
|
}
|
|
426
427
|
|
|
428
|
+
// src/Helpers/AuditReason.ts
|
|
429
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
430
|
+
function auditReasonHeaders(reason) {
|
|
431
|
+
if (reason == null || reason === "") return {};
|
|
432
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
433
|
+
}
|
|
434
|
+
|
|
427
435
|
// src/Helpers/MessageUtils/Body.ts
|
|
428
436
|
import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
429
437
|
import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
|
|
@@ -1071,6 +1079,67 @@ var CDN_URL = "https://fluxerusercontent.com";
|
|
|
1071
1079
|
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1072
1080
|
|
|
1073
1081
|
// src/Helpers/Cdn.ts
|
|
1082
|
+
var CDN_SIZE_LADDER = [
|
|
1083
|
+
16,
|
|
1084
|
+
20,
|
|
1085
|
+
22,
|
|
1086
|
+
24,
|
|
1087
|
+
28,
|
|
1088
|
+
32,
|
|
1089
|
+
40,
|
|
1090
|
+
44,
|
|
1091
|
+
48,
|
|
1092
|
+
56,
|
|
1093
|
+
60,
|
|
1094
|
+
64,
|
|
1095
|
+
80,
|
|
1096
|
+
96,
|
|
1097
|
+
100,
|
|
1098
|
+
128,
|
|
1099
|
+
160,
|
|
1100
|
+
240,
|
|
1101
|
+
256,
|
|
1102
|
+
300,
|
|
1103
|
+
320,
|
|
1104
|
+
480,
|
|
1105
|
+
512,
|
|
1106
|
+
600,
|
|
1107
|
+
640,
|
|
1108
|
+
1024,
|
|
1109
|
+
1280,
|
|
1110
|
+
1536,
|
|
1111
|
+
2048,
|
|
1112
|
+
3072,
|
|
1113
|
+
4096,
|
|
1114
|
+
8192,
|
|
1115
|
+
16384
|
|
1116
|
+
];
|
|
1117
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
1118
|
+
icon: { min: 128, max: 1024 },
|
|
1119
|
+
banner: { min: 480, max: 2400 },
|
|
1120
|
+
emoji: { min: 32, max: 512 },
|
|
1121
|
+
sticker: { min: 128, max: 512 }
|
|
1122
|
+
};
|
|
1123
|
+
function nearestSize(requested, candidates) {
|
|
1124
|
+
let best = candidates[0];
|
|
1125
|
+
let bestDist = Math.abs(requested - best);
|
|
1126
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
1127
|
+
const step = candidates[i];
|
|
1128
|
+
const dist = Math.abs(requested - step);
|
|
1129
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1130
|
+
best = step;
|
|
1131
|
+
bestDist = dist;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return best;
|
|
1135
|
+
}
|
|
1136
|
+
function snapCdnSize(requested, assetClass) {
|
|
1137
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1138
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1139
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1140
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1141
|
+
return nearestSize(clamped, allowed);
|
|
1142
|
+
}
|
|
1074
1143
|
function mediaBase(options) {
|
|
1075
1144
|
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1076
1145
|
}
|
|
@@ -1082,31 +1151,33 @@ function getExtension(hash, options) {
|
|
|
1082
1151
|
if (hash?.startsWith("a_")) return "gif";
|
|
1083
1152
|
return ext;
|
|
1084
1153
|
}
|
|
1085
|
-
function appendSize(options) {
|
|
1086
|
-
|
|
1154
|
+
function appendSize(options, assetClass) {
|
|
1155
|
+
const size = options?.size;
|
|
1156
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1157
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1087
1158
|
}
|
|
1088
1159
|
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1089
1160
|
if (!avatarHash) return null;
|
|
1090
1161
|
const ext = getExtension(avatarHash, options);
|
|
1091
|
-
const size = appendSize(options);
|
|
1162
|
+
const size = appendSize(options, "icon");
|
|
1092
1163
|
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1093
1164
|
}
|
|
1094
1165
|
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1095
1166
|
if (!bannerHash) return null;
|
|
1096
1167
|
const ext = getExtension(bannerHash, options);
|
|
1097
|
-
const size = appendSize(options);
|
|
1168
|
+
const size = appendSize(options, "banner");
|
|
1098
1169
|
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1099
1170
|
}
|
|
1100
1171
|
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1101
1172
|
if (!avatarHash) return null;
|
|
1102
1173
|
const ext = getExtension(avatarHash, options);
|
|
1103
|
-
const size = appendSize(options);
|
|
1174
|
+
const size = appendSize(options, "icon");
|
|
1104
1175
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1105
1176
|
}
|
|
1106
1177
|
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1107
1178
|
if (!bannerHash) return null;
|
|
1108
1179
|
const ext = getExtension(bannerHash, options);
|
|
1109
|
-
const size = appendSize(options);
|
|
1180
|
+
const size = appendSize(options, "banner");
|
|
1110
1181
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1111
1182
|
}
|
|
1112
1183
|
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
@@ -1115,16 +1186,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
|
1115
1186
|
}
|
|
1116
1187
|
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1117
1188
|
if (!hash) return null;
|
|
1118
|
-
const
|
|
1189
|
+
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1190
|
+
const size = appendSize(options, assetClass);
|
|
1119
1191
|
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1120
1192
|
}
|
|
1121
1193
|
function cdnEmojiURL(emojiId, animated, options) {
|
|
1122
1194
|
const ext = animated ? "gif" : "png";
|
|
1123
|
-
|
|
1195
|
+
const size = appendSize(options, "emoji");
|
|
1196
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1124
1197
|
}
|
|
1125
1198
|
function cdnStickerURL(stickerId, animated, options) {
|
|
1126
1199
|
const ext = animated ? "gif" : "png";
|
|
1127
|
-
|
|
1200
|
+
const size = appendSize(options, "sticker");
|
|
1201
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1128
1202
|
}
|
|
1129
1203
|
|
|
1130
1204
|
// src/Domain/Message/MessageSticker.ts
|
|
@@ -1352,6 +1426,8 @@ var Message = class _Message extends Base {
|
|
|
1352
1426
|
mentionRoles;
|
|
1353
1427
|
/** Client-side nonce for deduplication. */
|
|
1354
1428
|
nonce;
|
|
1429
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
1430
|
+
nsfwEmojis;
|
|
1355
1431
|
/**
|
|
1356
1432
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1357
1433
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1426,6 +1502,7 @@ var Message = class _Message extends Base {
|
|
|
1426
1502
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1427
1503
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1428
1504
|
this.nonce = data.nonce ?? null;
|
|
1505
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1429
1506
|
}
|
|
1430
1507
|
/**
|
|
1431
1508
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
@@ -1458,6 +1535,7 @@ var Message = class _Message extends Base {
|
|
|
1458
1535
|
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1459
1536
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1460
1537
|
this.nonce = data.nonce ?? null;
|
|
1538
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1461
1539
|
}
|
|
1462
1540
|
/**
|
|
1463
1541
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1541,8 +1619,10 @@ var Message = class _Message extends Base {
|
|
|
1541
1619
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1542
1620
|
}
|
|
1543
1621
|
/** Delete this message. */
|
|
1544
|
-
async delete() {
|
|
1545
|
-
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id)
|
|
1622
|
+
async delete(reason) {
|
|
1623
|
+
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
|
|
1624
|
+
...auditReasonHeaders(reason)
|
|
1625
|
+
});
|
|
1546
1626
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
1547
1627
|
}
|
|
1548
1628
|
/** Delete a specific attachment from this message. */
|
|
@@ -1856,6 +1936,29 @@ var MessageCollector = class _MessageCollector extends EventEmitter2 {
|
|
|
1856
1936
|
|
|
1857
1937
|
// src/Domain/Channel/Attachments.ts
|
|
1858
1938
|
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
1939
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
1940
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
1941
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
1942
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
1943
|
+
if (!rules?.length) return null;
|
|
1944
|
+
const snapshot = {};
|
|
1945
|
+
for (const rule of rules) {
|
|
1946
|
+
Object.assign(snapshot, rule.overrides);
|
|
1947
|
+
}
|
|
1948
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
1949
|
+
}
|
|
1950
|
+
function assertBotAttachmentLimits(client, files) {
|
|
1951
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
1952
|
+
for (const file of files) {
|
|
1953
|
+
const size = file.data.byteLength;
|
|
1954
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
1955
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
1956
|
+
throw new FluxerError(
|
|
1957
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
1958
|
+
{ code: ErrorCodes.AttachmentTooLarge }
|
|
1959
|
+
);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1859
1962
|
function asBytes(data) {
|
|
1860
1963
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
1861
1964
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -1875,6 +1978,7 @@ async function putBlob(url, body, contentType) {
|
|
|
1875
1978
|
}
|
|
1876
1979
|
}
|
|
1877
1980
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
1981
|
+
assertBotAttachmentLimits(client, files);
|
|
1878
1982
|
const plan = await client.rest.post(
|
|
1879
1983
|
Routes6.channelAttachments(channelId),
|
|
1880
1984
|
{
|
|
@@ -1987,20 +2091,24 @@ var Channel = class extends Base {
|
|
|
1987
2091
|
throw new Error("Channel.createDM not initialized");
|
|
1988
2092
|
}
|
|
1989
2093
|
/**
|
|
1990
|
-
* Whether this channel type can carry messages (text, voice, DM, group DM, notes).
|
|
2094
|
+
* Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
|
|
1991
2095
|
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
1992
2096
|
*/
|
|
1993
2097
|
isTextBased() {
|
|
1994
|
-
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
|
|
2098
|
+
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;
|
|
1995
2099
|
}
|
|
1996
|
-
/** Check if this is a guild channel (text, voice, category, or link). */
|
|
2100
|
+
/** Check if this is a guild channel (text, announcement, voice, category, or link). */
|
|
1997
2101
|
isGuild() {
|
|
1998
|
-
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
|
|
2102
|
+
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildAnnouncement || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
|
|
1999
2103
|
}
|
|
2000
2104
|
/** Check if this is a guild text channel. */
|
|
2001
2105
|
isText() {
|
|
2002
2106
|
return this.type === ChannelType.GuildText;
|
|
2003
2107
|
}
|
|
2108
|
+
/** Check if this is a guild announcement channel. */
|
|
2109
|
+
isAnnouncement() {
|
|
2110
|
+
return this.type === ChannelType.GuildAnnouncement;
|
|
2111
|
+
}
|
|
2004
2112
|
/** Check if this is a category channel. */
|
|
2005
2113
|
isCategory() {
|
|
2006
2114
|
return this.type === ChannelType.GuildCategory;
|
|
@@ -2171,11 +2279,12 @@ var Channel = class extends Base {
|
|
|
2171
2279
|
if (options?.silent) params.set("silent", "true");
|
|
2172
2280
|
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2173
2281
|
const qs2 = params.toString();
|
|
2174
|
-
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2282
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
2175
2283
|
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2176
2284
|
await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2177
2285
|
body,
|
|
2178
|
-
auth: true
|
|
2286
|
+
auth: true,
|
|
2287
|
+
...auditReasonHeaders(_reason)
|
|
2179
2288
|
});
|
|
2180
2289
|
this.client.channels.delete(this.id);
|
|
2181
2290
|
this.client._clearMessageCache(this.id);
|
|
@@ -2340,7 +2449,7 @@ import {
|
|
|
2340
2449
|
// src/Helpers/Instance.ts
|
|
2341
2450
|
import { isRecord } from "@fluxerjs/util";
|
|
2342
2451
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2343
|
-
api: "https://
|
|
2452
|
+
api: "https://web.fluxer.app/api",
|
|
2344
2453
|
api_client: "https://web.fluxer.app/api",
|
|
2345
2454
|
api_public: "https://api.fluxer.app",
|
|
2346
2455
|
gateway: "wss://gateway.fluxer.app",
|
|
@@ -2374,6 +2483,10 @@ function requireString(obj, key, path) {
|
|
|
2374
2483
|
}
|
|
2375
2484
|
return value;
|
|
2376
2485
|
}
|
|
2486
|
+
var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
|
|
2487
|
+
function instanceDiscoveryUrl(origin) {
|
|
2488
|
+
return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
|
|
2489
|
+
}
|
|
2377
2490
|
function normalizeApiOrigin(api) {
|
|
2378
2491
|
const trimmed = api.trim().replace(/\/+$/, "");
|
|
2379
2492
|
return trimmed.replace(/\/v\d+$/i, "");
|
|
@@ -2402,6 +2515,8 @@ function parseInstanceDiscovery(raw) {
|
|
|
2402
2515
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2403
2516
|
}
|
|
2404
2517
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2518
|
+
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2519
|
+
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
2405
2520
|
endpoints.invite = normalizeInviteBase(endpoints.invite);
|
|
2406
2521
|
endpoints.media = endpoints.media.replace(/\/+$/, "");
|
|
2407
2522
|
endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
|
|
@@ -2479,6 +2594,11 @@ function resolveInstanceEndpoints(input) {
|
|
|
2479
2594
|
}
|
|
2480
2595
|
}
|
|
2481
2596
|
merged.api = normalizeApiOrigin(merged.api);
|
|
2597
|
+
merged.api_client = normalizeApiOrigin(merged.api_client);
|
|
2598
|
+
merged.api_public = normalizeApiOrigin(merged.api_public);
|
|
2599
|
+
if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
|
|
2600
|
+
merged.api_public = merged.api;
|
|
2601
|
+
}
|
|
2482
2602
|
merged.invite = normalizeInviteBase(merged.invite);
|
|
2483
2603
|
merged.media = merged.media.replace(/\/+$/, "");
|
|
2484
2604
|
merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
|
|
@@ -2487,13 +2607,13 @@ function resolveInstanceEndpoints(input) {
|
|
|
2487
2607
|
discovery: null
|
|
2488
2608
|
});
|
|
2489
2609
|
}
|
|
2490
|
-
function resolveRestApi(
|
|
2491
|
-
const fromInstance = normalizeApiOrigin(
|
|
2610
|
+
function resolveRestApi(instanceApiPublic, restApi) {
|
|
2611
|
+
const fromInstance = normalizeApiOrigin(instanceApiPublic);
|
|
2492
2612
|
if (restApi === void 0) return fromInstance;
|
|
2493
2613
|
const fromRest = normalizeApiOrigin(restApi);
|
|
2494
2614
|
if (fromRest !== fromInstance) {
|
|
2495
2615
|
throw new FluxerError(
|
|
2496
|
-
`Conflicting API hosts: instance.
|
|
2616
|
+
`Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
|
|
2497
2617
|
{ code: ErrorCodes.ConflictingInstanceConfig }
|
|
2498
2618
|
);
|
|
2499
2619
|
}
|
|
@@ -2975,7 +3095,8 @@ var GuildChannel = class extends Channel {
|
|
|
2975
3095
|
async edit(options) {
|
|
2976
3096
|
const data = await this.client.rest.patch(Routes13.channel(this.id), {
|
|
2977
3097
|
body: toChannelEditBody(options),
|
|
2978
|
-
auth: true
|
|
3098
|
+
auth: true,
|
|
3099
|
+
...auditReasonHeaders(options.reason)
|
|
2979
3100
|
});
|
|
2980
3101
|
this.name = data.name ?? this.name;
|
|
2981
3102
|
this.parentId = data.parent_id ?? this.parentId;
|
|
@@ -3034,6 +3155,8 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3034
3155
|
}
|
|
3035
3156
|
}
|
|
3036
3157
|
};
|
|
3158
|
+
var AnnouncementChannel = class extends TextChannel {
|
|
3159
|
+
};
|
|
3037
3160
|
var CategoryChannel = class extends GuildChannel {
|
|
3038
3161
|
};
|
|
3039
3162
|
var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
@@ -3116,6 +3239,7 @@ var LinkChannel = class extends GuildChannel {
|
|
|
3116
3239
|
import { ChannelType as ChannelType3 } from "@fluxerjs/types";
|
|
3117
3240
|
var GUILD_FACTORIES = {
|
|
3118
3241
|
[ChannelType3.GuildText]: (c, d) => new TextChannel(c, d),
|
|
3242
|
+
[ChannelType3.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
|
|
3119
3243
|
[ChannelType3.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
3120
3244
|
[ChannelType3.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
3121
3245
|
[ChannelType3.GuildLink]: (c, d) => new LinkChannel(c, d)
|
|
@@ -3507,9 +3631,10 @@ var GuildEmoji = class extends Base {
|
|
|
3507
3631
|
return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
|
|
3508
3632
|
}
|
|
3509
3633
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
3510
|
-
async delete() {
|
|
3634
|
+
async delete(reason) {
|
|
3511
3635
|
await this.client.rest.delete(Routes15.guildEmoji(this.guildId, this.id), {
|
|
3512
|
-
auth: true
|
|
3636
|
+
auth: true,
|
|
3637
|
+
...auditReasonHeaders(reason)
|
|
3513
3638
|
});
|
|
3514
3639
|
const guild = this.client.guilds.get(this.guildId);
|
|
3515
3640
|
if (guild) guild.emojis.delete(this.id);
|
|
@@ -3519,9 +3644,11 @@ var GuildEmoji = class extends Base {
|
|
|
3519
3644
|
* Requires Manage Emojis and Stickers permission.
|
|
3520
3645
|
*/
|
|
3521
3646
|
async edit(options) {
|
|
3647
|
+
const { reason, name } = options;
|
|
3522
3648
|
const data = await this.client.rest.patch(Routes15.guildEmoji(this.guildId, this.id), {
|
|
3523
|
-
body:
|
|
3524
|
-
auth: true
|
|
3649
|
+
body: { name },
|
|
3650
|
+
auth: true,
|
|
3651
|
+
...auditReasonHeaders(reason)
|
|
3525
3652
|
});
|
|
3526
3653
|
this.name = data.name;
|
|
3527
3654
|
return this;
|
|
@@ -3537,6 +3664,9 @@ import { OverwriteType } from "@fluxerjs/types";
|
|
|
3537
3664
|
import { ALL_PERMISSIONS_BIGINT, PermissionFlags as PermissionFlags2 } from "@fluxerjs/util";
|
|
3538
3665
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
3539
3666
|
if (isOwner) return ALL_PERMISSIONS_BIGINT;
|
|
3667
|
+
if ((basePermissions & PermissionFlags2.Administrator) !== 0n) {
|
|
3668
|
+
return ALL_PERMISSIONS_BIGINT;
|
|
3669
|
+
}
|
|
3540
3670
|
let perms = basePermissions;
|
|
3541
3671
|
for (const overwrite of overwrites ?? []) {
|
|
3542
3672
|
const applies = overwrite.type === OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === OverwriteType.Member && overwrite.id === memberId;
|
|
@@ -3545,7 +3675,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
3545
3675
|
const deny = BigInt(overwrite.deny || "0");
|
|
3546
3676
|
perms = perms & ~deny | allow;
|
|
3547
3677
|
}
|
|
3548
|
-
return
|
|
3678
|
+
return perms;
|
|
3549
3679
|
}
|
|
3550
3680
|
|
|
3551
3681
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
@@ -3751,7 +3881,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3751
3881
|
const route = isMe ? Routes17.guildMemberMe(this.guild.id) : Routes17.guildMember(this.guild.id, this.id);
|
|
3752
3882
|
const data = await this.client.rest.patch(route, {
|
|
3753
3883
|
body: toMemberEditBody(options),
|
|
3754
|
-
auth: true
|
|
3884
|
+
auth: true,
|
|
3885
|
+
...auditReasonHeaders(options.reason ?? options.timeoutReason)
|
|
3755
3886
|
});
|
|
3756
3887
|
this._patch(data);
|
|
3757
3888
|
if (options.bio !== void 0) this.bio = options.bio;
|
|
@@ -3785,8 +3916,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3785
3916
|
await this.edit({ channelId, connectionId });
|
|
3786
3917
|
}
|
|
3787
3918
|
/** Kick this member. Requires Kick Members. */
|
|
3788
|
-
async kick() {
|
|
3789
|
-
await this.guild.kick(this.id);
|
|
3919
|
+
async kick(reason) {
|
|
3920
|
+
await this.guild.kick(this.id, reason);
|
|
3790
3921
|
}
|
|
3791
3922
|
/** Ban this member. Requires Ban Members. */
|
|
3792
3923
|
async ban(options) {
|
|
@@ -3910,9 +4041,10 @@ var GuildSticker = class extends Base {
|
|
|
3910
4041
|
return SnowflakeUtil7.dateFromSnowflake(this.id);
|
|
3911
4042
|
}
|
|
3912
4043
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3913
|
-
async delete() {
|
|
4044
|
+
async delete(reason) {
|
|
3914
4045
|
await this.client.rest.delete(Routes18.guildSticker(this.guildId, this.id), {
|
|
3915
|
-
auth: true
|
|
4046
|
+
auth: true,
|
|
4047
|
+
...auditReasonHeaders(reason)
|
|
3916
4048
|
});
|
|
3917
4049
|
const guild = this.client.guilds.get(this.guildId);
|
|
3918
4050
|
if (guild) guild.stickers.delete(this.id);
|
|
@@ -3922,9 +4054,11 @@ var GuildSticker = class extends Base {
|
|
|
3922
4054
|
* Requires Manage Emojis and Stickers permission.
|
|
3923
4055
|
*/
|
|
3924
4056
|
async edit(options) {
|
|
4057
|
+
const { reason, ...body } = options;
|
|
3925
4058
|
const data = await this.client.rest.patch(Routes18.guildSticker(this.guildId, this.id), {
|
|
3926
|
-
body
|
|
3927
|
-
auth: true
|
|
4059
|
+
body,
|
|
4060
|
+
auth: true,
|
|
4061
|
+
...auditReasonHeaders(reason)
|
|
3928
4062
|
});
|
|
3929
4063
|
const s = data;
|
|
3930
4064
|
this.name = s.name;
|
|
@@ -4051,16 +4185,21 @@ var Role = class _Role extends Base {
|
|
|
4051
4185
|
const body = toRoleEditBody(options);
|
|
4052
4186
|
const data = await this.client.rest.patch(Routes19.guildRole(this.guildId, this.id), {
|
|
4053
4187
|
body: Object.keys(body).length ? body : void 0,
|
|
4054
|
-
auth: true
|
|
4188
|
+
auth: true,
|
|
4189
|
+
...auditReasonHeaders(options.reason)
|
|
4055
4190
|
});
|
|
4056
4191
|
this._patch(data);
|
|
4057
4192
|
return this;
|
|
4058
4193
|
}
|
|
4059
4194
|
/**
|
|
4060
4195
|
* DELETE role. Requires Manage Roles.
|
|
4196
|
+
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
4061
4197
|
*/
|
|
4062
|
-
async delete() {
|
|
4063
|
-
await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), {
|
|
4198
|
+
async delete(reason) {
|
|
4199
|
+
await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), {
|
|
4200
|
+
auth: true,
|
|
4201
|
+
...auditReasonHeaders(reason)
|
|
4202
|
+
});
|
|
4064
4203
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
4065
4204
|
}
|
|
4066
4205
|
};
|
|
@@ -4311,7 +4450,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4311
4450
|
return parsed.name;
|
|
4312
4451
|
}
|
|
4313
4452
|
async function fetchInstance(client) {
|
|
4314
|
-
const raw = await client.rest.get(Routes21.instanceDiscovery(), {
|
|
4453
|
+
const raw = await client.rest.get(Routes21.instanceDiscovery(), {
|
|
4454
|
+
auth: false,
|
|
4455
|
+
unversioned: true
|
|
4456
|
+
});
|
|
4315
4457
|
return parseInstanceDiscovery(raw);
|
|
4316
4458
|
}
|
|
4317
4459
|
function fetchGatewayInfo(client) {
|
|
@@ -4690,9 +4832,11 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
4690
4832
|
}
|
|
4691
4833
|
}
|
|
4692
4834
|
async function createEmoji(guild, options) {
|
|
4835
|
+
const { reason, ...body } = options;
|
|
4693
4836
|
const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
|
|
4694
|
-
body
|
|
4695
|
-
auth: true
|
|
4837
|
+
body,
|
|
4838
|
+
auth: true,
|
|
4839
|
+
...auditReasonHeaders(reason)
|
|
4696
4840
|
});
|
|
4697
4841
|
return cacheEmoji(guild, data);
|
|
4698
4842
|
}
|
|
@@ -4711,6 +4855,19 @@ async function createEmojisBulk(guild, emojis) {
|
|
|
4711
4855
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
4712
4856
|
}
|
|
4713
4857
|
|
|
4858
|
+
// src/Domain/Guild/GuildRoleManager.ts
|
|
4859
|
+
import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
|
|
4860
|
+
var GuildRoleManager = class extends LimitedCollection3 {
|
|
4861
|
+
constructor(guildId, options) {
|
|
4862
|
+
super(options);
|
|
4863
|
+
this.guildId = guildId;
|
|
4864
|
+
}
|
|
4865
|
+
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4866
|
+
get everyone() {
|
|
4867
|
+
return this.get(this.guildId);
|
|
4868
|
+
}
|
|
4869
|
+
};
|
|
4870
|
+
|
|
4714
4871
|
// src/Domain/Guild/MemberHttp.ts
|
|
4715
4872
|
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
4716
4873
|
async function fetchMember(guild, userId) {
|
|
@@ -4767,9 +4924,10 @@ var GuildBan = class extends Base {
|
|
|
4767
4924
|
* Remove this ban (unban the user).
|
|
4768
4925
|
* Requires Ban Members permission.
|
|
4769
4926
|
*/
|
|
4770
|
-
async unban() {
|
|
4927
|
+
async unban(reason) {
|
|
4771
4928
|
await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
|
|
4772
|
-
auth: true
|
|
4929
|
+
auth: true,
|
|
4930
|
+
...auditReasonHeaders(reason)
|
|
4773
4931
|
});
|
|
4774
4932
|
}
|
|
4775
4933
|
};
|
|
@@ -4779,33 +4937,27 @@ async function ban(guild, userId, options) {
|
|
|
4779
4937
|
const body = options ? toGuildBanBody(options) : {};
|
|
4780
4938
|
await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
|
|
4781
4939
|
body: Object.keys(body).length ? body : void 0,
|
|
4782
|
-
auth: true
|
|
4940
|
+
auth: true,
|
|
4941
|
+
...auditReasonHeaders(options?.reason)
|
|
4783
4942
|
});
|
|
4784
4943
|
}
|
|
4785
4944
|
async function fetchBans(guild) {
|
|
4786
4945
|
const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
|
|
4787
4946
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
4788
4947
|
}
|
|
4789
|
-
async function unban(guild, userId) {
|
|
4790
|
-
await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
|
|
4948
|
+
async function unban(guild, userId, reason) {
|
|
4949
|
+
await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
|
|
4950
|
+
auth: true,
|
|
4951
|
+
...auditReasonHeaders(reason)
|
|
4952
|
+
});
|
|
4791
4953
|
}
|
|
4792
|
-
async function kick(guild, userId) {
|
|
4793
|
-
await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
|
|
4954
|
+
async function kick(guild, userId, reason) {
|
|
4955
|
+
await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
|
|
4956
|
+
auth: true,
|
|
4957
|
+
...auditReasonHeaders(reason)
|
|
4958
|
+
});
|
|
4794
4959
|
}
|
|
4795
4960
|
|
|
4796
|
-
// src/Domain/Guild/GuildRoleManager.ts
|
|
4797
|
-
import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
|
|
4798
|
-
var GuildRoleManager = class extends LimitedCollection3 {
|
|
4799
|
-
constructor(guildId, options) {
|
|
4800
|
-
super(options);
|
|
4801
|
-
this.guildId = guildId;
|
|
4802
|
-
}
|
|
4803
|
-
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4804
|
-
get everyone() {
|
|
4805
|
-
return this.get(this.guildId);
|
|
4806
|
-
}
|
|
4807
|
-
};
|
|
4808
|
-
|
|
4809
4961
|
// src/Domain/Guild/Roles.ts
|
|
4810
4962
|
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
4811
4963
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
@@ -4813,7 +4965,8 @@ async function createRole(guild, options = {}) {
|
|
|
4813
4965
|
const body = toRoleCreateBody(options);
|
|
4814
4966
|
const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
|
|
4815
4967
|
body: Object.keys(body).length ? body : void 0,
|
|
4816
|
-
auth: true
|
|
4968
|
+
auth: true,
|
|
4969
|
+
...auditReasonHeaders(options.reason)
|
|
4817
4970
|
});
|
|
4818
4971
|
return cacheRole(guild, data);
|
|
4819
4972
|
}
|
|
@@ -4879,9 +5032,11 @@ async function resetRoleHoistPositions(guild) {
|
|
|
4879
5032
|
// src/Domain/Guild/Stickers.ts
|
|
4880
5033
|
import { Routes as Routes30 } from "@fluxerjs/types";
|
|
4881
5034
|
async function createSticker(guild, options) {
|
|
5035
|
+
const { reason, ...body } = options;
|
|
4882
5036
|
const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
|
|
4883
|
-
body
|
|
4884
|
-
auth: true
|
|
5037
|
+
body,
|
|
5038
|
+
auth: true,
|
|
5039
|
+
...auditReasonHeaders(reason)
|
|
4885
5040
|
});
|
|
4886
5041
|
return cacheSticker(guild, data);
|
|
4887
5042
|
}
|
|
@@ -5211,12 +5366,12 @@ var Guild = class extends Base {
|
|
|
5211
5366
|
return fetchBans(this);
|
|
5212
5367
|
}
|
|
5213
5368
|
/** Unban a user from the guild. Requires Ban Members. */
|
|
5214
|
-
unban(userId) {
|
|
5215
|
-
return unban(this, userId);
|
|
5369
|
+
unban(userId, reason) {
|
|
5370
|
+
return unban(this, userId, reason);
|
|
5216
5371
|
}
|
|
5217
5372
|
/** Kick a user from the guild. Requires Kick Members. */
|
|
5218
|
-
kick(userId) {
|
|
5219
|
-
return kick(this, userId);
|
|
5373
|
+
kick(userId, reason) {
|
|
5374
|
+
return kick(this, userId, reason);
|
|
5220
5375
|
}
|
|
5221
5376
|
/** Fetch all emojis in this guild from the API. */
|
|
5222
5377
|
fetchEmojis() {
|
|
@@ -5666,7 +5821,14 @@ function markGuildUnavailable(client, id) {
|
|
|
5666
5821
|
guild.available = false;
|
|
5667
5822
|
client.emit(Events.GuildUnavailable, guild);
|
|
5668
5823
|
}
|
|
5824
|
+
function isStartupGuildHydration(client) {
|
|
5825
|
+
return client._guildStreamSettleTimeout !== null;
|
|
5826
|
+
}
|
|
5669
5827
|
var guildHandlers = {
|
|
5828
|
+
/**
|
|
5829
|
+
* Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
|
|
5830
|
+
* {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
|
|
5831
|
+
*/
|
|
5670
5832
|
GUILD_CREATE(client, d) {
|
|
5671
5833
|
const raw = d;
|
|
5672
5834
|
if (raw.unavailable === true) {
|
|
@@ -5679,11 +5841,32 @@ var guildHandlers = {
|
|
|
5679
5841
|
}
|
|
5680
5842
|
return;
|
|
5681
5843
|
}
|
|
5844
|
+
const startupHydration = isStartupGuildHydration(client);
|
|
5845
|
+
if (startupHydration) {
|
|
5846
|
+
resetGuildStreamSettle(client);
|
|
5847
|
+
}
|
|
5682
5848
|
const result = applyGuildSnapshotFromGateway(client, d);
|
|
5683
5849
|
if (!result) return;
|
|
5684
5850
|
const { guild, recovered } = result;
|
|
5685
|
-
|
|
5686
|
-
|
|
5851
|
+
const legacyStartup = client.options.emitGuildCreateOnStartup === true;
|
|
5852
|
+
const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
|
|
5853
|
+
const isStartupBackfill = wasReadyStub || startupHydration;
|
|
5854
|
+
if (recovered) {
|
|
5855
|
+
guild.available = true;
|
|
5856
|
+
if (legacyStartup && isStartupBackfill) {
|
|
5857
|
+
client.emit(Events.GuildCreate, guild);
|
|
5858
|
+
} else {
|
|
5859
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5860
|
+
}
|
|
5861
|
+
} else if (startupHydration) {
|
|
5862
|
+
if (legacyStartup) {
|
|
5863
|
+
client.emit(Events.GuildCreate, guild);
|
|
5864
|
+
} else {
|
|
5865
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5866
|
+
}
|
|
5867
|
+
} else {
|
|
5868
|
+
client.emit(Events.GuildCreate, guild);
|
|
5869
|
+
}
|
|
5687
5870
|
client._onGuildReceived(guild.id);
|
|
5688
5871
|
},
|
|
5689
5872
|
GUILD_UPDATE(client, d) {
|
|
@@ -5722,6 +5905,7 @@ var guildHandlers = {
|
|
|
5722
5905
|
markGuildUnavailable(client, id);
|
|
5723
5906
|
return;
|
|
5724
5907
|
}
|
|
5908
|
+
client._readyStubGuildIds.delete(id);
|
|
5725
5909
|
const guild = client.guilds.get(id);
|
|
5726
5910
|
if (!guild) return;
|
|
5727
5911
|
client.guilds.delete(id);
|
|
@@ -6240,10 +6424,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
|
|
|
6240
6424
|
for (const g of guilds ?? []) {
|
|
6241
6425
|
if (g.unavailable === true) {
|
|
6242
6426
|
if (typeof g.id === "string") {
|
|
6243
|
-
|
|
6244
|
-
if (
|
|
6245
|
-
|
|
6427
|
+
let guild = client.guilds.get(g.id);
|
|
6428
|
+
if (!guild) {
|
|
6429
|
+
guild = new Guild(client, { id: g.id });
|
|
6430
|
+
guild.available = false;
|
|
6431
|
+
client.guilds.set(g.id, guild);
|
|
6432
|
+
} else if (guild.available !== false) {
|
|
6433
|
+
guild.available = false;
|
|
6246
6434
|
}
|
|
6435
|
+
client._readyStubGuildIds.add(g.id);
|
|
6247
6436
|
if (pending !== null) pending.add(g.id);
|
|
6248
6437
|
}
|
|
6249
6438
|
continue;
|
|
@@ -6271,6 +6460,13 @@ function clearGuildStreamSettle(client) {
|
|
|
6271
6460
|
clearTimeout(client._guildStreamSettleTimeout);
|
|
6272
6461
|
client._guildStreamSettleTimeout = null;
|
|
6273
6462
|
}
|
|
6463
|
+
function resetGuildStreamSettle(client) {
|
|
6464
|
+
clearGuildStreamSettle(client);
|
|
6465
|
+
client._guildStreamSettleTimeout = setTimeout(() => {
|
|
6466
|
+
client._guildStreamSettleTimeout = null;
|
|
6467
|
+
if (client.readyAt === null) finalizeClientReady(client);
|
|
6468
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
6469
|
+
}
|
|
6274
6470
|
function handleReadyPayload(client, data) {
|
|
6275
6471
|
client.user = new ClientUser(client, data.user);
|
|
6276
6472
|
const waitForGuilds = client.options.waitForGuilds === true;
|
|
@@ -6290,14 +6486,9 @@ function handleReadyPayload(client, data) {
|
|
|
6290
6486
|
client._pendingGuildIds = existing;
|
|
6291
6487
|
return;
|
|
6292
6488
|
}
|
|
6293
|
-
if (
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
client._guildStreamSettleTimeout = null;
|
|
6297
|
-
if (client.readyAt === null) finalizeClientReady(client);
|
|
6298
|
-
}, GUILD_STREAM_SETTLE_MS);
|
|
6299
|
-
}
|
|
6300
|
-
return;
|
|
6489
|
+
if (guilds.length === 0) {
|
|
6490
|
+
resetGuildStreamSettle(client);
|
|
6491
|
+
if (waitForGuilds) return;
|
|
6301
6492
|
}
|
|
6302
6493
|
finalizeClientReady(client);
|
|
6303
6494
|
}
|
|
@@ -6632,7 +6823,12 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6632
6823
|
_ws = null;
|
|
6633
6824
|
/** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
|
|
6634
6825
|
_pendingGuildIds = null;
|
|
6635
|
-
/**
|
|
6826
|
+
/** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
|
|
6827
|
+
_readyStubGuildIds = /* @__PURE__ */ new Set();
|
|
6828
|
+
/**
|
|
6829
|
+
* @internal Empty-READY guild stream window.
|
|
6830
|
+
* Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
|
|
6831
|
+
*/
|
|
6636
6832
|
_guildStreamSettleTimeout = null;
|
|
6637
6833
|
/** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
|
|
6638
6834
|
_deferredGatewayDispatches = [];
|
|
@@ -6663,7 +6859,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6663
6859
|
const restApi = options.rest?.api;
|
|
6664
6860
|
if (options.instance !== void 0) {
|
|
6665
6861
|
this.instance = resolveInstanceEndpoints(options.instance);
|
|
6666
|
-
resolveRestApi(this.instance.endpoints.
|
|
6862
|
+
resolveRestApi(this.instance.endpoints.api_public, restApi);
|
|
6667
6863
|
} else {
|
|
6668
6864
|
this.instance = resolveInstanceEndpoints(
|
|
6669
6865
|
restApi !== void 0 ? { api: restApi } : void 0
|
|
@@ -6676,27 +6872,31 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6676
6872
|
}
|
|
6677
6873
|
this.rest = new REST({
|
|
6678
6874
|
...this.options.rest,
|
|
6679
|
-
api: this.instance.endpoints.
|
|
6680
|
-
version: this.options.rest?.version ?? "1"
|
|
6875
|
+
api: this.instance.endpoints.api_public,
|
|
6876
|
+
version: this.options.rest?.version ?? "1",
|
|
6877
|
+
locale: this.options.locale ?? this.options.rest?.locale
|
|
6681
6878
|
});
|
|
6682
6879
|
}
|
|
6683
6880
|
/**
|
|
6684
6881
|
* Create a client from instance discovery (`GET /.well-known/fluxer`).
|
|
6685
|
-
*
|
|
6882
|
+
* Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
|
|
6883
|
+
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
6884
|
+
* Does not log in. Call {@link login} with a token afterward.
|
|
6686
6885
|
*
|
|
6687
|
-
* @param origin -
|
|
6688
|
-
* @param options - Client options (must not conflict with discovered `endpoints.
|
|
6886
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
|
|
6887
|
+
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
6689
6888
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
6690
6889
|
*/
|
|
6691
6890
|
static async fromDiscovery(origin, options = {}, connectOptions) {
|
|
6692
|
-
const
|
|
6891
|
+
const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
|
|
6693
6892
|
const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
|
|
6694
6893
|
const bootstrap = new REST({
|
|
6695
6894
|
...options.rest ?? {},
|
|
6696
|
-
api:
|
|
6697
|
-
version
|
|
6895
|
+
api: bootstrapOrigin,
|
|
6896
|
+
version,
|
|
6897
|
+
locale: options.locale ?? options.rest?.locale
|
|
6698
6898
|
});
|
|
6699
|
-
const raw = await bootstrap.get(
|
|
6899
|
+
const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
|
|
6700
6900
|
auth: false,
|
|
6701
6901
|
...connectOptions?.signal ? { signal: connectOptions.signal } : {}
|
|
6702
6902
|
});
|
|
@@ -6704,7 +6904,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6704
6904
|
const { rest, ...restOptions } = options;
|
|
6705
6905
|
return new _Client({
|
|
6706
6906
|
...restOptions,
|
|
6707
|
-
// Drop rest.api so discovered endpoints.
|
|
6907
|
+
// Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
|
|
6708
6908
|
...rest ? { rest: { ...rest, api: void 0 } } : {},
|
|
6709
6909
|
instance: discovery
|
|
6710
6910
|
});
|
|
@@ -6731,7 +6931,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6731
6931
|
return resolveClientEmoji(this, emoji, guildId);
|
|
6732
6932
|
}
|
|
6733
6933
|
/**
|
|
6734
|
-
* Fetch instance discovery document (
|
|
6934
|
+
* Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
|
|
6735
6935
|
* @returns Instance configuration (endpoints, features, metadata)
|
|
6736
6936
|
*/
|
|
6737
6937
|
fetchInstance() {
|
|
@@ -7000,6 +7200,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7000
7200
|
this.user = null;
|
|
7001
7201
|
this.readyAt = null;
|
|
7002
7202
|
this._pendingGuildIds = null;
|
|
7203
|
+
this._readyStubGuildIds.clear();
|
|
7003
7204
|
this.guilds.clear();
|
|
7004
7205
|
this.channels.clear();
|
|
7005
7206
|
this.users.clear();
|