@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.js
CHANGED
|
@@ -113,6 +113,7 @@ function toOverwriteWire(overwrite) {
|
|
|
113
113
|
}
|
|
114
114
|
function toChannelEditBody(options) {
|
|
115
115
|
const body = {};
|
|
116
|
+
if (options.type !== void 0) body.type = options.type;
|
|
116
117
|
if (options.name !== void 0) body.name = options.name;
|
|
117
118
|
if (options.topic !== void 0) body.topic = options.topic;
|
|
118
119
|
if (options.url !== void 0) body.url = options.url;
|
|
@@ -448,6 +449,13 @@ function toSudoBody(options) {
|
|
|
448
449
|
return body;
|
|
449
450
|
}
|
|
450
451
|
|
|
452
|
+
// src/Helpers/AuditReason.ts
|
|
453
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
454
|
+
function auditReasonHeaders(reason) {
|
|
455
|
+
if (reason == null || reason === "") return {};
|
|
456
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
457
|
+
}
|
|
458
|
+
|
|
451
459
|
// src/Helpers/MessageUtils/Body.ts
|
|
452
460
|
var import_builders = require("@fluxerjs/builders");
|
|
453
461
|
var import_types = require("@fluxerjs/types");
|
|
@@ -1095,6 +1103,67 @@ var CDN_URL = "https://fluxerusercontent.com";
|
|
|
1095
1103
|
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1096
1104
|
|
|
1097
1105
|
// src/Helpers/Cdn.ts
|
|
1106
|
+
var CDN_SIZE_LADDER = [
|
|
1107
|
+
16,
|
|
1108
|
+
20,
|
|
1109
|
+
22,
|
|
1110
|
+
24,
|
|
1111
|
+
28,
|
|
1112
|
+
32,
|
|
1113
|
+
40,
|
|
1114
|
+
44,
|
|
1115
|
+
48,
|
|
1116
|
+
56,
|
|
1117
|
+
60,
|
|
1118
|
+
64,
|
|
1119
|
+
80,
|
|
1120
|
+
96,
|
|
1121
|
+
100,
|
|
1122
|
+
128,
|
|
1123
|
+
160,
|
|
1124
|
+
240,
|
|
1125
|
+
256,
|
|
1126
|
+
300,
|
|
1127
|
+
320,
|
|
1128
|
+
480,
|
|
1129
|
+
512,
|
|
1130
|
+
600,
|
|
1131
|
+
640,
|
|
1132
|
+
1024,
|
|
1133
|
+
1280,
|
|
1134
|
+
1536,
|
|
1135
|
+
2048,
|
|
1136
|
+
3072,
|
|
1137
|
+
4096,
|
|
1138
|
+
8192,
|
|
1139
|
+
16384
|
|
1140
|
+
];
|
|
1141
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
1142
|
+
icon: { min: 128, max: 1024 },
|
|
1143
|
+
banner: { min: 480, max: 2400 },
|
|
1144
|
+
emoji: { min: 32, max: 512 },
|
|
1145
|
+
sticker: { min: 128, max: 512 }
|
|
1146
|
+
};
|
|
1147
|
+
function nearestSize(requested, candidates) {
|
|
1148
|
+
let best = candidates[0];
|
|
1149
|
+
let bestDist = Math.abs(requested - best);
|
|
1150
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
1151
|
+
const step = candidates[i];
|
|
1152
|
+
const dist = Math.abs(requested - step);
|
|
1153
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1154
|
+
best = step;
|
|
1155
|
+
bestDist = dist;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return best;
|
|
1159
|
+
}
|
|
1160
|
+
function snapCdnSize(requested, assetClass) {
|
|
1161
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1162
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1163
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1164
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1165
|
+
return nearestSize(clamped, allowed);
|
|
1166
|
+
}
|
|
1098
1167
|
function mediaBase(options) {
|
|
1099
1168
|
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1100
1169
|
}
|
|
@@ -1106,31 +1175,33 @@ function getExtension(hash, options) {
|
|
|
1106
1175
|
if (hash?.startsWith("a_")) return "gif";
|
|
1107
1176
|
return ext;
|
|
1108
1177
|
}
|
|
1109
|
-
function appendSize(options) {
|
|
1110
|
-
|
|
1178
|
+
function appendSize(options, assetClass) {
|
|
1179
|
+
const size = options?.size;
|
|
1180
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1181
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1111
1182
|
}
|
|
1112
1183
|
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1113
1184
|
if (!avatarHash) return null;
|
|
1114
1185
|
const ext = getExtension(avatarHash, options);
|
|
1115
|
-
const size = appendSize(options);
|
|
1186
|
+
const size = appendSize(options, "icon");
|
|
1116
1187
|
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1117
1188
|
}
|
|
1118
1189
|
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1119
1190
|
if (!bannerHash) return null;
|
|
1120
1191
|
const ext = getExtension(bannerHash, options);
|
|
1121
|
-
const size = appendSize(options);
|
|
1192
|
+
const size = appendSize(options, "banner");
|
|
1122
1193
|
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1123
1194
|
}
|
|
1124
1195
|
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1125
1196
|
if (!avatarHash) return null;
|
|
1126
1197
|
const ext = getExtension(avatarHash, options);
|
|
1127
|
-
const size = appendSize(options);
|
|
1198
|
+
const size = appendSize(options, "icon");
|
|
1128
1199
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1129
1200
|
}
|
|
1130
1201
|
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1131
1202
|
if (!bannerHash) return null;
|
|
1132
1203
|
const ext = getExtension(bannerHash, options);
|
|
1133
|
-
const size = appendSize(options);
|
|
1204
|
+
const size = appendSize(options, "banner");
|
|
1134
1205
|
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1135
1206
|
}
|
|
1136
1207
|
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
@@ -1139,16 +1210,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
|
1139
1210
|
}
|
|
1140
1211
|
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1141
1212
|
if (!hash) return null;
|
|
1142
|
-
const
|
|
1213
|
+
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1214
|
+
const size = appendSize(options, assetClass);
|
|
1143
1215
|
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1144
1216
|
}
|
|
1145
1217
|
function cdnEmojiURL(emojiId, animated, options) {
|
|
1146
1218
|
const ext = animated ? "gif" : "png";
|
|
1147
|
-
|
|
1219
|
+
const size = appendSize(options, "emoji");
|
|
1220
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1148
1221
|
}
|
|
1149
1222
|
function cdnStickerURL(stickerId, animated, options) {
|
|
1150
1223
|
const ext = animated ? "gif" : "png";
|
|
1151
|
-
|
|
1224
|
+
const size = appendSize(options, "sticker");
|
|
1225
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1152
1226
|
}
|
|
1153
1227
|
|
|
1154
1228
|
// src/Domain/Message/MessageSticker.ts
|
|
@@ -1376,6 +1450,8 @@ var Message = class _Message extends Base {
|
|
|
1376
1450
|
mentionRoles;
|
|
1377
1451
|
/** Client-side nonce for deduplication. */
|
|
1378
1452
|
nonce;
|
|
1453
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
1454
|
+
nsfwEmojis;
|
|
1379
1455
|
/**
|
|
1380
1456
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1381
1457
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1450,6 +1526,7 @@ var Message = class _Message extends Base {
|
|
|
1450
1526
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1451
1527
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1452
1528
|
this.nonce = data.nonce ?? null;
|
|
1529
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1453
1530
|
}
|
|
1454
1531
|
/**
|
|
1455
1532
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
@@ -1482,6 +1559,7 @@ var Message = class _Message extends Base {
|
|
|
1482
1559
|
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1483
1560
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1484
1561
|
this.nonce = data.nonce ?? null;
|
|
1562
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1485
1563
|
}
|
|
1486
1564
|
/**
|
|
1487
1565
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1565,8 +1643,10 @@ var Message = class _Message extends Base {
|
|
|
1565
1643
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1566
1644
|
}
|
|
1567
1645
|
/** Delete this message. */
|
|
1568
|
-
async delete() {
|
|
1569
|
-
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id)
|
|
1646
|
+
async delete(reason) {
|
|
1647
|
+
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id), {
|
|
1648
|
+
...auditReasonHeaders(reason)
|
|
1649
|
+
});
|
|
1570
1650
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
1571
1651
|
}
|
|
1572
1652
|
/** Delete a specific attachment from this message. */
|
|
@@ -1880,6 +1960,29 @@ var MessageCollector = class _MessageCollector extends import_node_events2.Event
|
|
|
1880
1960
|
|
|
1881
1961
|
// src/Domain/Channel/Attachments.ts
|
|
1882
1962
|
var import_types7 = require("@fluxerjs/types");
|
|
1963
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
1964
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
1965
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
1966
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
1967
|
+
if (!rules?.length) return null;
|
|
1968
|
+
const snapshot = {};
|
|
1969
|
+
for (const rule of rules) {
|
|
1970
|
+
Object.assign(snapshot, rule.overrides);
|
|
1971
|
+
}
|
|
1972
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
1973
|
+
}
|
|
1974
|
+
function assertBotAttachmentLimits(client, files) {
|
|
1975
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
1976
|
+
for (const file of files) {
|
|
1977
|
+
const size = file.data.byteLength;
|
|
1978
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
1979
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
1980
|
+
throw new import_util4.FluxerError(
|
|
1981
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
1982
|
+
{ code: import_util3.ErrorCodes.AttachmentTooLarge }
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1883
1986
|
function asBytes(data) {
|
|
1884
1987
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
1885
1988
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -1899,6 +2002,7 @@ async function putBlob(url, body, contentType) {
|
|
|
1899
2002
|
}
|
|
1900
2003
|
}
|
|
1901
2004
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
2005
|
+
assertBotAttachmentLimits(client, files);
|
|
1902
2006
|
const plan = await client.rest.post(
|
|
1903
2007
|
import_types7.Routes.channelAttachments(channelId),
|
|
1904
2008
|
{
|
|
@@ -2011,20 +2115,24 @@ var Channel = class extends Base {
|
|
|
2011
2115
|
throw new Error("Channel.createDM not initialized");
|
|
2012
2116
|
}
|
|
2013
2117
|
/**
|
|
2014
|
-
* Whether this channel type can carry messages (text, voice, DM, group DM, notes).
|
|
2118
|
+
* Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
|
|
2015
2119
|
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
2016
2120
|
*/
|
|
2017
2121
|
isTextBased() {
|
|
2018
|
-
return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
|
|
2122
|
+
return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildAnnouncement || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
|
|
2019
2123
|
}
|
|
2020
|
-
/** Check if this is a guild channel (text, voice, category, or link). */
|
|
2124
|
+
/** Check if this is a guild channel (text, announcement, voice, category, or link). */
|
|
2021
2125
|
isGuild() {
|
|
2022
|
-
return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.GuildCategory || this.type === import_types8.ChannelType.GuildLink;
|
|
2126
|
+
return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildAnnouncement || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.GuildCategory || this.type === import_types8.ChannelType.GuildLink;
|
|
2023
2127
|
}
|
|
2024
2128
|
/** Check if this is a guild text channel. */
|
|
2025
2129
|
isText() {
|
|
2026
2130
|
return this.type === import_types8.ChannelType.GuildText;
|
|
2027
2131
|
}
|
|
2132
|
+
/** Check if this is a guild announcement channel. */
|
|
2133
|
+
isAnnouncement() {
|
|
2134
|
+
return this.type === import_types8.ChannelType.GuildAnnouncement;
|
|
2135
|
+
}
|
|
2028
2136
|
/** Check if this is a category channel. */
|
|
2029
2137
|
isCategory() {
|
|
2030
2138
|
return this.type === import_types8.ChannelType.GuildCategory;
|
|
@@ -2195,11 +2303,12 @@ var Channel = class extends Base {
|
|
|
2195
2303
|
if (options?.silent) params.set("silent", "true");
|
|
2196
2304
|
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2197
2305
|
const qs2 = params.toString();
|
|
2198
|
-
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2306
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
2199
2307
|
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2200
2308
|
await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2201
2309
|
body,
|
|
2202
|
-
auth: true
|
|
2310
|
+
auth: true,
|
|
2311
|
+
...auditReasonHeaders(_reason)
|
|
2203
2312
|
});
|
|
2204
2313
|
this.client.channels.delete(this.id);
|
|
2205
2314
|
this.client._clearMessageCache(this.id);
|
|
@@ -2359,7 +2468,7 @@ var import_types11 = require("@fluxerjs/types");
|
|
|
2359
2468
|
// src/Helpers/Instance.ts
|
|
2360
2469
|
var import_util9 = require("@fluxerjs/util");
|
|
2361
2470
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2362
|
-
api: "https://
|
|
2471
|
+
api: "https://web.fluxer.app/api",
|
|
2363
2472
|
api_client: "https://web.fluxer.app/api",
|
|
2364
2473
|
api_public: "https://api.fluxer.app",
|
|
2365
2474
|
gateway: "wss://gateway.fluxer.app",
|
|
@@ -2393,6 +2502,10 @@ function requireString(obj, key, path) {
|
|
|
2393
2502
|
}
|
|
2394
2503
|
return value;
|
|
2395
2504
|
}
|
|
2505
|
+
var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
|
|
2506
|
+
function instanceDiscoveryUrl(origin) {
|
|
2507
|
+
return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
|
|
2508
|
+
}
|
|
2396
2509
|
function normalizeApiOrigin(api) {
|
|
2397
2510
|
const trimmed = api.trim().replace(/\/+$/, "");
|
|
2398
2511
|
return trimmed.replace(/\/v\d+$/i, "");
|
|
@@ -2421,6 +2534,8 @@ function parseInstanceDiscovery(raw) {
|
|
|
2421
2534
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2422
2535
|
}
|
|
2423
2536
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2537
|
+
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2538
|
+
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
2424
2539
|
endpoints.invite = normalizeInviteBase(endpoints.invite);
|
|
2425
2540
|
endpoints.media = endpoints.media.replace(/\/+$/, "");
|
|
2426
2541
|
endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
|
|
@@ -2498,6 +2613,11 @@ function resolveInstanceEndpoints(input) {
|
|
|
2498
2613
|
}
|
|
2499
2614
|
}
|
|
2500
2615
|
merged.api = normalizeApiOrigin(merged.api);
|
|
2616
|
+
merged.api_client = normalizeApiOrigin(merged.api_client);
|
|
2617
|
+
merged.api_public = normalizeApiOrigin(merged.api_public);
|
|
2618
|
+
if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
|
|
2619
|
+
merged.api_public = merged.api;
|
|
2620
|
+
}
|
|
2501
2621
|
merged.invite = normalizeInviteBase(merged.invite);
|
|
2502
2622
|
merged.media = merged.media.replace(/\/+$/, "");
|
|
2503
2623
|
merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
|
|
@@ -2506,13 +2626,13 @@ function resolveInstanceEndpoints(input) {
|
|
|
2506
2626
|
discovery: null
|
|
2507
2627
|
});
|
|
2508
2628
|
}
|
|
2509
|
-
function resolveRestApi(
|
|
2510
|
-
const fromInstance = normalizeApiOrigin(
|
|
2629
|
+
function resolveRestApi(instanceApiPublic, restApi) {
|
|
2630
|
+
const fromInstance = normalizeApiOrigin(instanceApiPublic);
|
|
2511
2631
|
if (restApi === void 0) return fromInstance;
|
|
2512
2632
|
const fromRest = normalizeApiOrigin(restApi);
|
|
2513
2633
|
if (fromRest !== fromInstance) {
|
|
2514
2634
|
throw new import_util4.FluxerError(
|
|
2515
|
-
`Conflicting API hosts: instance.
|
|
2635
|
+
`Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
|
|
2516
2636
|
{ code: import_util3.ErrorCodes.ConflictingInstanceConfig }
|
|
2517
2637
|
);
|
|
2518
2638
|
}
|
|
@@ -2992,7 +3112,8 @@ var GuildChannel = class extends Channel {
|
|
|
2992
3112
|
async edit(options) {
|
|
2993
3113
|
const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
|
|
2994
3114
|
body: toChannelEditBody(options),
|
|
2995
|
-
auth: true
|
|
3115
|
+
auth: true,
|
|
3116
|
+
...auditReasonHeaders(options.reason)
|
|
2996
3117
|
});
|
|
2997
3118
|
this.name = data.name ?? this.name;
|
|
2998
3119
|
this.parentId = data.parent_id ?? this.parentId;
|
|
@@ -3051,6 +3172,8 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3051
3172
|
}
|
|
3052
3173
|
}
|
|
3053
3174
|
};
|
|
3175
|
+
var AnnouncementChannel = class extends TextChannel {
|
|
3176
|
+
};
|
|
3054
3177
|
var CategoryChannel = class extends GuildChannel {
|
|
3055
3178
|
};
|
|
3056
3179
|
var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
@@ -3133,6 +3256,7 @@ var LinkChannel = class extends GuildChannel {
|
|
|
3133
3256
|
var import_types15 = require("@fluxerjs/types");
|
|
3134
3257
|
var GUILD_FACTORIES = {
|
|
3135
3258
|
[import_types15.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
|
|
3259
|
+
[import_types15.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
|
|
3136
3260
|
[import_types15.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
3137
3261
|
[import_types15.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
3138
3262
|
[import_types15.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
|
|
@@ -3524,9 +3648,10 @@ var GuildEmoji = class extends Base {
|
|
|
3524
3648
|
return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
|
|
3525
3649
|
}
|
|
3526
3650
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
3527
|
-
async delete() {
|
|
3651
|
+
async delete(reason) {
|
|
3528
3652
|
await this.client.rest.delete(import_types17.Routes.guildEmoji(this.guildId, this.id), {
|
|
3529
|
-
auth: true
|
|
3653
|
+
auth: true,
|
|
3654
|
+
...auditReasonHeaders(reason)
|
|
3530
3655
|
});
|
|
3531
3656
|
const guild = this.client.guilds.get(this.guildId);
|
|
3532
3657
|
if (guild) guild.emojis.delete(this.id);
|
|
@@ -3536,9 +3661,11 @@ var GuildEmoji = class extends Base {
|
|
|
3536
3661
|
* Requires Manage Emojis and Stickers permission.
|
|
3537
3662
|
*/
|
|
3538
3663
|
async edit(options) {
|
|
3664
|
+
const { reason, name } = options;
|
|
3539
3665
|
const data = await this.client.rest.patch(import_types17.Routes.guildEmoji(this.guildId, this.id), {
|
|
3540
|
-
body:
|
|
3541
|
-
auth: true
|
|
3666
|
+
body: { name },
|
|
3667
|
+
auth: true,
|
|
3668
|
+
...auditReasonHeaders(reason)
|
|
3542
3669
|
});
|
|
3543
3670
|
this.name = data.name;
|
|
3544
3671
|
return this;
|
|
@@ -3554,6 +3681,9 @@ var import_types18 = require("@fluxerjs/types");
|
|
|
3554
3681
|
var import_util16 = require("@fluxerjs/util");
|
|
3555
3682
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
3556
3683
|
if (isOwner) return import_util16.ALL_PERMISSIONS_BIGINT;
|
|
3684
|
+
if ((basePermissions & import_util16.PermissionFlags.Administrator) !== 0n) {
|
|
3685
|
+
return import_util16.ALL_PERMISSIONS_BIGINT;
|
|
3686
|
+
}
|
|
3557
3687
|
let perms = basePermissions;
|
|
3558
3688
|
for (const overwrite of overwrites ?? []) {
|
|
3559
3689
|
const applies = overwrite.type === import_types18.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types18.OverwriteType.Member && overwrite.id === memberId;
|
|
@@ -3562,7 +3692,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
3562
3692
|
const deny = BigInt(overwrite.deny || "0");
|
|
3563
3693
|
perms = perms & ~deny | allow;
|
|
3564
3694
|
}
|
|
3565
|
-
return
|
|
3695
|
+
return perms;
|
|
3566
3696
|
}
|
|
3567
3697
|
|
|
3568
3698
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
@@ -3768,7 +3898,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3768
3898
|
const route = isMe ? import_types20.Routes.guildMemberMe(this.guild.id) : import_types20.Routes.guildMember(this.guild.id, this.id);
|
|
3769
3899
|
const data = await this.client.rest.patch(route, {
|
|
3770
3900
|
body: toMemberEditBody(options),
|
|
3771
|
-
auth: true
|
|
3901
|
+
auth: true,
|
|
3902
|
+
...auditReasonHeaders(options.reason ?? options.timeoutReason)
|
|
3772
3903
|
});
|
|
3773
3904
|
this._patch(data);
|
|
3774
3905
|
if (options.bio !== void 0) this.bio = options.bio;
|
|
@@ -3802,8 +3933,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3802
3933
|
await this.edit({ channelId, connectionId });
|
|
3803
3934
|
}
|
|
3804
3935
|
/** Kick this member. Requires Kick Members. */
|
|
3805
|
-
async kick() {
|
|
3806
|
-
await this.guild.kick(this.id);
|
|
3936
|
+
async kick(reason) {
|
|
3937
|
+
await this.guild.kick(this.id, reason);
|
|
3807
3938
|
}
|
|
3808
3939
|
/** Ban this member. Requires Ban Members. */
|
|
3809
3940
|
async ban(options) {
|
|
@@ -3927,9 +4058,10 @@ var GuildSticker = class extends Base {
|
|
|
3927
4058
|
return import_util18.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
3928
4059
|
}
|
|
3929
4060
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3930
|
-
async delete() {
|
|
4061
|
+
async delete(reason) {
|
|
3931
4062
|
await this.client.rest.delete(import_types21.Routes.guildSticker(this.guildId, this.id), {
|
|
3932
|
-
auth: true
|
|
4063
|
+
auth: true,
|
|
4064
|
+
...auditReasonHeaders(reason)
|
|
3933
4065
|
});
|
|
3934
4066
|
const guild = this.client.guilds.get(this.guildId);
|
|
3935
4067
|
if (guild) guild.stickers.delete(this.id);
|
|
@@ -3939,9 +4071,11 @@ var GuildSticker = class extends Base {
|
|
|
3939
4071
|
* Requires Manage Emojis and Stickers permission.
|
|
3940
4072
|
*/
|
|
3941
4073
|
async edit(options) {
|
|
4074
|
+
const { reason, ...body } = options;
|
|
3942
4075
|
const data = await this.client.rest.patch(import_types21.Routes.guildSticker(this.guildId, this.id), {
|
|
3943
|
-
body
|
|
3944
|
-
auth: true
|
|
4076
|
+
body,
|
|
4077
|
+
auth: true,
|
|
4078
|
+
...auditReasonHeaders(reason)
|
|
3945
4079
|
});
|
|
3946
4080
|
const s = data;
|
|
3947
4081
|
this.name = s.name;
|
|
@@ -4063,16 +4197,21 @@ var Role = class _Role extends Base {
|
|
|
4063
4197
|
const body = toRoleEditBody(options);
|
|
4064
4198
|
const data = await this.client.rest.patch(import_types22.Routes.guildRole(this.guildId, this.id), {
|
|
4065
4199
|
body: Object.keys(body).length ? body : void 0,
|
|
4066
|
-
auth: true
|
|
4200
|
+
auth: true,
|
|
4201
|
+
...auditReasonHeaders(options.reason)
|
|
4067
4202
|
});
|
|
4068
4203
|
this._patch(data);
|
|
4069
4204
|
return this;
|
|
4070
4205
|
}
|
|
4071
4206
|
/**
|
|
4072
4207
|
* DELETE role. Requires Manage Roles.
|
|
4208
|
+
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
4073
4209
|
*/
|
|
4074
|
-
async delete() {
|
|
4075
|
-
await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), {
|
|
4210
|
+
async delete(reason) {
|
|
4211
|
+
await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), {
|
|
4212
|
+
auth: true,
|
|
4213
|
+
...auditReasonHeaders(reason)
|
|
4214
|
+
});
|
|
4076
4215
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
4077
4216
|
}
|
|
4078
4217
|
};
|
|
@@ -4323,7 +4462,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4323
4462
|
return parsed.name;
|
|
4324
4463
|
}
|
|
4325
4464
|
async function fetchInstance(client) {
|
|
4326
|
-
const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
|
|
4465
|
+
const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
|
|
4466
|
+
auth: false,
|
|
4467
|
+
unversioned: true
|
|
4468
|
+
});
|
|
4327
4469
|
return parseInstanceDiscovery(raw);
|
|
4328
4470
|
}
|
|
4329
4471
|
function fetchGatewayInfo(client) {
|
|
@@ -4702,9 +4844,11 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
4702
4844
|
}
|
|
4703
4845
|
}
|
|
4704
4846
|
async function createEmoji(guild, options) {
|
|
4847
|
+
const { reason, ...body } = options;
|
|
4705
4848
|
const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
|
|
4706
|
-
body
|
|
4707
|
-
auth: true
|
|
4849
|
+
body,
|
|
4850
|
+
auth: true,
|
|
4851
|
+
...auditReasonHeaders(reason)
|
|
4708
4852
|
});
|
|
4709
4853
|
return cacheEmoji(guild, data);
|
|
4710
4854
|
}
|
|
@@ -4723,6 +4867,19 @@ async function createEmojisBulk(guild, emojis) {
|
|
|
4723
4867
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
4724
4868
|
}
|
|
4725
4869
|
|
|
4870
|
+
// src/Domain/Guild/GuildRoleManager.ts
|
|
4871
|
+
var import_collection11 = require("@fluxerjs/collection");
|
|
4872
|
+
var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
4873
|
+
constructor(guildId, options) {
|
|
4874
|
+
super(options);
|
|
4875
|
+
this.guildId = guildId;
|
|
4876
|
+
}
|
|
4877
|
+
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4878
|
+
get everyone() {
|
|
4879
|
+
return this.get(this.guildId);
|
|
4880
|
+
}
|
|
4881
|
+
};
|
|
4882
|
+
|
|
4726
4883
|
// src/Domain/Guild/MemberHttp.ts
|
|
4727
4884
|
var import_types29 = require("@fluxerjs/types");
|
|
4728
4885
|
async function fetchMember(guild, userId) {
|
|
@@ -4779,9 +4936,10 @@ var GuildBan = class extends Base {
|
|
|
4779
4936
|
* Remove this ban (unban the user).
|
|
4780
4937
|
* Requires Ban Members permission.
|
|
4781
4938
|
*/
|
|
4782
|
-
async unban() {
|
|
4939
|
+
async unban(reason) {
|
|
4783
4940
|
await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
|
|
4784
|
-
auth: true
|
|
4941
|
+
auth: true,
|
|
4942
|
+
...auditReasonHeaders(reason)
|
|
4785
4943
|
});
|
|
4786
4944
|
}
|
|
4787
4945
|
};
|
|
@@ -4791,33 +4949,27 @@ async function ban(guild, userId, options) {
|
|
|
4791
4949
|
const body = options ? toGuildBanBody(options) : {};
|
|
4792
4950
|
await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
|
|
4793
4951
|
body: Object.keys(body).length ? body : void 0,
|
|
4794
|
-
auth: true
|
|
4952
|
+
auth: true,
|
|
4953
|
+
...auditReasonHeaders(options?.reason)
|
|
4795
4954
|
});
|
|
4796
4955
|
}
|
|
4797
4956
|
async function fetchBans(guild) {
|
|
4798
4957
|
const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
|
|
4799
4958
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
4800
4959
|
}
|
|
4801
|
-
async function unban(guild, userId) {
|
|
4802
|
-
await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
|
|
4960
|
+
async function unban(guild, userId, reason) {
|
|
4961
|
+
await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
|
|
4962
|
+
auth: true,
|
|
4963
|
+
...auditReasonHeaders(reason)
|
|
4964
|
+
});
|
|
4803
4965
|
}
|
|
4804
|
-
async function kick(guild, userId) {
|
|
4805
|
-
await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
|
|
4966
|
+
async function kick(guild, userId, reason) {
|
|
4967
|
+
await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
|
|
4968
|
+
auth: true,
|
|
4969
|
+
...auditReasonHeaders(reason)
|
|
4970
|
+
});
|
|
4806
4971
|
}
|
|
4807
4972
|
|
|
4808
|
-
// src/Domain/Guild/GuildRoleManager.ts
|
|
4809
|
-
var import_collection11 = require("@fluxerjs/collection");
|
|
4810
|
-
var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
4811
|
-
constructor(guildId, options) {
|
|
4812
|
-
super(options);
|
|
4813
|
-
this.guildId = guildId;
|
|
4814
|
-
}
|
|
4815
|
-
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4816
|
-
get everyone() {
|
|
4817
|
-
return this.get(this.guildId);
|
|
4818
|
-
}
|
|
4819
|
-
};
|
|
4820
|
-
|
|
4821
4973
|
// src/Domain/Guild/Roles.ts
|
|
4822
4974
|
var import_types32 = require("@fluxerjs/types");
|
|
4823
4975
|
var import_util21 = require("@fluxerjs/util");
|
|
@@ -4825,7 +4977,8 @@ async function createRole(guild, options = {}) {
|
|
|
4825
4977
|
const body = toRoleCreateBody(options);
|
|
4826
4978
|
const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
|
|
4827
4979
|
body: Object.keys(body).length ? body : void 0,
|
|
4828
|
-
auth: true
|
|
4980
|
+
auth: true,
|
|
4981
|
+
...auditReasonHeaders(options.reason)
|
|
4829
4982
|
});
|
|
4830
4983
|
return cacheRole(guild, data);
|
|
4831
4984
|
}
|
|
@@ -4891,9 +5044,11 @@ async function resetRoleHoistPositions(guild) {
|
|
|
4891
5044
|
// src/Domain/Guild/Stickers.ts
|
|
4892
5045
|
var import_types33 = require("@fluxerjs/types");
|
|
4893
5046
|
async function createSticker(guild, options) {
|
|
5047
|
+
const { reason, ...body } = options;
|
|
4894
5048
|
const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
|
|
4895
|
-
body
|
|
4896
|
-
auth: true
|
|
5049
|
+
body,
|
|
5050
|
+
auth: true,
|
|
5051
|
+
...auditReasonHeaders(reason)
|
|
4897
5052
|
});
|
|
4898
5053
|
return cacheSticker(guild, data);
|
|
4899
5054
|
}
|
|
@@ -5223,12 +5378,12 @@ var Guild = class extends Base {
|
|
|
5223
5378
|
return fetchBans(this);
|
|
5224
5379
|
}
|
|
5225
5380
|
/** Unban a user from the guild. Requires Ban Members. */
|
|
5226
|
-
unban(userId) {
|
|
5227
|
-
return unban(this, userId);
|
|
5381
|
+
unban(userId, reason) {
|
|
5382
|
+
return unban(this, userId, reason);
|
|
5228
5383
|
}
|
|
5229
5384
|
/** Kick a user from the guild. Requires Kick Members. */
|
|
5230
|
-
kick(userId) {
|
|
5231
|
-
return kick(this, userId);
|
|
5385
|
+
kick(userId, reason) {
|
|
5386
|
+
return kick(this, userId, reason);
|
|
5232
5387
|
}
|
|
5233
5388
|
/** Fetch all emojis in this guild from the API. */
|
|
5234
5389
|
fetchEmojis() {
|
|
@@ -5678,7 +5833,14 @@ function markGuildUnavailable(client, id) {
|
|
|
5678
5833
|
guild.available = false;
|
|
5679
5834
|
client.emit(Events.GuildUnavailable, guild);
|
|
5680
5835
|
}
|
|
5836
|
+
function isStartupGuildHydration(client) {
|
|
5837
|
+
return client._guildStreamSettleTimeout !== null;
|
|
5838
|
+
}
|
|
5681
5839
|
var guildHandlers = {
|
|
5840
|
+
/**
|
|
5841
|
+
* Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
|
|
5842
|
+
* {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
|
|
5843
|
+
*/
|
|
5682
5844
|
GUILD_CREATE(client, d) {
|
|
5683
5845
|
const raw = d;
|
|
5684
5846
|
if (raw.unavailable === true) {
|
|
@@ -5691,11 +5853,32 @@ var guildHandlers = {
|
|
|
5691
5853
|
}
|
|
5692
5854
|
return;
|
|
5693
5855
|
}
|
|
5856
|
+
const startupHydration = isStartupGuildHydration(client);
|
|
5857
|
+
if (startupHydration) {
|
|
5858
|
+
resetGuildStreamSettle(client);
|
|
5859
|
+
}
|
|
5694
5860
|
const result = applyGuildSnapshotFromGateway(client, d);
|
|
5695
5861
|
if (!result) return;
|
|
5696
5862
|
const { guild, recovered } = result;
|
|
5697
|
-
|
|
5698
|
-
|
|
5863
|
+
const legacyStartup = client.options.emitGuildCreateOnStartup === true;
|
|
5864
|
+
const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
|
|
5865
|
+
const isStartupBackfill = wasReadyStub || startupHydration;
|
|
5866
|
+
if (recovered) {
|
|
5867
|
+
guild.available = true;
|
|
5868
|
+
if (legacyStartup && isStartupBackfill) {
|
|
5869
|
+
client.emit(Events.GuildCreate, guild);
|
|
5870
|
+
} else {
|
|
5871
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5872
|
+
}
|
|
5873
|
+
} else if (startupHydration) {
|
|
5874
|
+
if (legacyStartup) {
|
|
5875
|
+
client.emit(Events.GuildCreate, guild);
|
|
5876
|
+
} else {
|
|
5877
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5878
|
+
}
|
|
5879
|
+
} else {
|
|
5880
|
+
client.emit(Events.GuildCreate, guild);
|
|
5881
|
+
}
|
|
5699
5882
|
client._onGuildReceived(guild.id);
|
|
5700
5883
|
},
|
|
5701
5884
|
GUILD_UPDATE(client, d) {
|
|
@@ -5734,6 +5917,7 @@ var guildHandlers = {
|
|
|
5734
5917
|
markGuildUnavailable(client, id);
|
|
5735
5918
|
return;
|
|
5736
5919
|
}
|
|
5920
|
+
client._readyStubGuildIds.delete(id);
|
|
5737
5921
|
const guild = client.guilds.get(id);
|
|
5738
5922
|
if (!guild) return;
|
|
5739
5923
|
client.guilds.delete(id);
|
|
@@ -6249,10 +6433,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
|
|
|
6249
6433
|
for (const g of guilds ?? []) {
|
|
6250
6434
|
if (g.unavailable === true) {
|
|
6251
6435
|
if (typeof g.id === "string") {
|
|
6252
|
-
|
|
6253
|
-
if (
|
|
6254
|
-
|
|
6436
|
+
let guild = client.guilds.get(g.id);
|
|
6437
|
+
if (!guild) {
|
|
6438
|
+
guild = new Guild(client, { id: g.id });
|
|
6439
|
+
guild.available = false;
|
|
6440
|
+
client.guilds.set(g.id, guild);
|
|
6441
|
+
} else if (guild.available !== false) {
|
|
6442
|
+
guild.available = false;
|
|
6255
6443
|
}
|
|
6444
|
+
client._readyStubGuildIds.add(g.id);
|
|
6256
6445
|
if (pending !== null) pending.add(g.id);
|
|
6257
6446
|
}
|
|
6258
6447
|
continue;
|
|
@@ -6280,6 +6469,13 @@ function clearGuildStreamSettle(client) {
|
|
|
6280
6469
|
clearTimeout(client._guildStreamSettleTimeout);
|
|
6281
6470
|
client._guildStreamSettleTimeout = null;
|
|
6282
6471
|
}
|
|
6472
|
+
function resetGuildStreamSettle(client) {
|
|
6473
|
+
clearGuildStreamSettle(client);
|
|
6474
|
+
client._guildStreamSettleTimeout = setTimeout(() => {
|
|
6475
|
+
client._guildStreamSettleTimeout = null;
|
|
6476
|
+
if (client.readyAt === null) finalizeClientReady(client);
|
|
6477
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
6478
|
+
}
|
|
6283
6479
|
function handleReadyPayload(client, data) {
|
|
6284
6480
|
client.user = new ClientUser(client, data.user);
|
|
6285
6481
|
const waitForGuilds = client.options.waitForGuilds === true;
|
|
@@ -6299,14 +6495,9 @@ function handleReadyPayload(client, data) {
|
|
|
6299
6495
|
client._pendingGuildIds = existing;
|
|
6300
6496
|
return;
|
|
6301
6497
|
}
|
|
6302
|
-
if (
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
client._guildStreamSettleTimeout = null;
|
|
6306
|
-
if (client.readyAt === null) finalizeClientReady(client);
|
|
6307
|
-
}, GUILD_STREAM_SETTLE_MS);
|
|
6308
|
-
}
|
|
6309
|
-
return;
|
|
6498
|
+
if (guilds.length === 0) {
|
|
6499
|
+
resetGuildStreamSettle(client);
|
|
6500
|
+
if (waitForGuilds) return;
|
|
6310
6501
|
}
|
|
6311
6502
|
finalizeClientReady(client);
|
|
6312
6503
|
}
|
|
@@ -6639,7 +6830,12 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6639
6830
|
_ws = null;
|
|
6640
6831
|
/** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
|
|
6641
6832
|
_pendingGuildIds = null;
|
|
6642
|
-
/**
|
|
6833
|
+
/** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
|
|
6834
|
+
_readyStubGuildIds = /* @__PURE__ */ new Set();
|
|
6835
|
+
/**
|
|
6836
|
+
* @internal Empty-READY guild stream window.
|
|
6837
|
+
* Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
|
|
6838
|
+
*/
|
|
6643
6839
|
_guildStreamSettleTimeout = null;
|
|
6644
6840
|
/** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
|
|
6645
6841
|
_deferredGatewayDispatches = [];
|
|
@@ -6670,7 +6866,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6670
6866
|
const restApi = options.rest?.api;
|
|
6671
6867
|
if (options.instance !== void 0) {
|
|
6672
6868
|
this.instance = resolveInstanceEndpoints(options.instance);
|
|
6673
|
-
resolveRestApi(this.instance.endpoints.
|
|
6869
|
+
resolveRestApi(this.instance.endpoints.api_public, restApi);
|
|
6674
6870
|
} else {
|
|
6675
6871
|
this.instance = resolveInstanceEndpoints(
|
|
6676
6872
|
restApi !== void 0 ? { api: restApi } : void 0
|
|
@@ -6683,27 +6879,31 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6683
6879
|
}
|
|
6684
6880
|
this.rest = new import_rest3.REST({
|
|
6685
6881
|
...this.options.rest,
|
|
6686
|
-
api: this.instance.endpoints.
|
|
6687
|
-
version: this.options.rest?.version ?? "1"
|
|
6882
|
+
api: this.instance.endpoints.api_public,
|
|
6883
|
+
version: this.options.rest?.version ?? "1",
|
|
6884
|
+
locale: this.options.locale ?? this.options.rest?.locale
|
|
6688
6885
|
});
|
|
6689
6886
|
}
|
|
6690
6887
|
/**
|
|
6691
6888
|
* Create a client from instance discovery (`GET /.well-known/fluxer`).
|
|
6692
|
-
*
|
|
6889
|
+
* Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
|
|
6890
|
+
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
6891
|
+
* Does not log in. Call {@link login} with a token afterward.
|
|
6693
6892
|
*
|
|
6694
|
-
* @param origin -
|
|
6695
|
-
* @param options - Client options (must not conflict with discovered `endpoints.
|
|
6893
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
|
|
6894
|
+
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
6696
6895
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
6697
6896
|
*/
|
|
6698
6897
|
static async fromDiscovery(origin, options = {}, connectOptions) {
|
|
6699
|
-
const
|
|
6898
|
+
const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
|
|
6700
6899
|
const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
|
|
6701
6900
|
const bootstrap = new import_rest3.REST({
|
|
6702
6901
|
...options.rest ?? {},
|
|
6703
|
-
api:
|
|
6704
|
-
version
|
|
6902
|
+
api: bootstrapOrigin,
|
|
6903
|
+
version,
|
|
6904
|
+
locale: options.locale ?? options.rest?.locale
|
|
6705
6905
|
});
|
|
6706
|
-
const raw = await bootstrap.get(
|
|
6906
|
+
const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
|
|
6707
6907
|
auth: false,
|
|
6708
6908
|
...connectOptions?.signal ? { signal: connectOptions.signal } : {}
|
|
6709
6909
|
});
|
|
@@ -6711,7 +6911,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6711
6911
|
const { rest, ...restOptions } = options;
|
|
6712
6912
|
return new _Client({
|
|
6713
6913
|
...restOptions,
|
|
6714
|
-
// Drop rest.api so discovered endpoints.
|
|
6914
|
+
// Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
|
|
6715
6915
|
...rest ? { rest: { ...rest, api: void 0 } } : {},
|
|
6716
6916
|
instance: discovery
|
|
6717
6917
|
});
|
|
@@ -6738,7 +6938,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6738
6938
|
return resolveClientEmoji(this, emoji, guildId);
|
|
6739
6939
|
}
|
|
6740
6940
|
/**
|
|
6741
|
-
* Fetch instance discovery document (
|
|
6941
|
+
* Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
|
|
6742
6942
|
* @returns Instance configuration (endpoints, features, metadata)
|
|
6743
6943
|
*/
|
|
6744
6944
|
fetchInstance() {
|
|
@@ -7007,6 +7207,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7007
7207
|
this.user = null;
|
|
7008
7208
|
this.readyAt = null;
|
|
7009
7209
|
this._pendingGuildIds = null;
|
|
7210
|
+
this._readyStubGuildIds.clear();
|
|
7010
7211
|
this.guilds.clear();
|
|
7011
7212
|
this.channels.clear();
|
|
7012
7213
|
this.users.clear();
|