@fluxerjs/core 3.3.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SubpathMessage-CNJlnR6y.d.mts → SubpathMessage-3ykAJr_F.d.mts} +250 -12
- package/dist/{SubpathMessage-DjLo6il5.d.ts → SubpathMessage-nY2WQ8V1.d.ts} +250 -12
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1039 -358
- package/dist/client.mjs +959 -278
- package/dist/cluster.d.mts +1 -1
- package/dist/cluster.d.ts +1 -1
- package/dist/cluster.js +1039 -358
- package/dist/cluster.mjs +959 -278
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1078 -395
- package/dist/index.mjs +961 -280
- package/dist/message.d.mts +1 -1
- package/dist/message.d.ts +1 -1
- package/dist/message.js +159 -44
- package/dist/message.mjs +159 -44
- package/package.json +7 -7
package/dist/cluster.js
CHANGED
|
@@ -53,6 +53,7 @@ var Events = {
|
|
|
53
53
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
54
54
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
55
55
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
56
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
56
57
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
57
58
|
GuildMemberAdd: "guildMemberAdd",
|
|
58
59
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -87,7 +88,16 @@ var Events = {
|
|
|
87
88
|
VoiceStateAck: "voiceStateAck",
|
|
88
89
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
89
90
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
91
|
+
VoiceSignal: "voiceSignal",
|
|
92
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
90
93
|
VoiceStatesSync: "voiceStatesSync",
|
|
94
|
+
VoiceJoinQueued: "voiceJoinQueued",
|
|
95
|
+
StageInstanceCreate: "stageInstanceCreate",
|
|
96
|
+
StageInstanceUpdate: "stageInstanceUpdate",
|
|
97
|
+
StageInstanceDelete: "stageInstanceDelete",
|
|
98
|
+
StageCountsUpdate: "stageCountsUpdate",
|
|
99
|
+
StageVoiceStatesSync: "stageVoiceStatesSync",
|
|
100
|
+
StageAudienceListUpdate: "stageAudienceListUpdate",
|
|
91
101
|
WebhooksUpdate: "webhooksUpdate",
|
|
92
102
|
Resumed: "resumed",
|
|
93
103
|
Error: "error",
|
|
@@ -109,8 +119,8 @@ var import_util2 = require("@fluxerjs/util");
|
|
|
109
119
|
// src/ClientCore/Client.ts
|
|
110
120
|
var import_node_events3 = require("events");
|
|
111
121
|
var import_rest3 = require("@fluxerjs/rest");
|
|
112
|
-
var
|
|
113
|
-
var
|
|
122
|
+
var import_types46 = require("@fluxerjs/types");
|
|
123
|
+
var import_util27 = require("@fluxerjs/util");
|
|
114
124
|
|
|
115
125
|
// src/Domain/Message/Message.ts
|
|
116
126
|
var import_builders3 = require("@fluxerjs/builders");
|
|
@@ -1137,6 +1147,45 @@ var import_util5 = require("@fluxerjs/util");
|
|
|
1137
1147
|
// src/ClientCore/MessageManager.ts
|
|
1138
1148
|
var import_collection2 = require("@fluxerjs/collection");
|
|
1139
1149
|
var import_types5 = require("@fluxerjs/types");
|
|
1150
|
+
|
|
1151
|
+
// src/ClientCore/Resolve.ts
|
|
1152
|
+
function normalizeSnowflakeId(value, label) {
|
|
1153
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1154
|
+
throw new TypeError(
|
|
1155
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
1159
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
1160
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
1161
|
+
}
|
|
1162
|
+
return id;
|
|
1163
|
+
}
|
|
1164
|
+
function assertApiObjectWithId(data, label) {
|
|
1165
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
1166
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
1167
|
+
}
|
|
1168
|
+
return data;
|
|
1169
|
+
}
|
|
1170
|
+
function assertApiArray(data, label) {
|
|
1171
|
+
if (!Array.isArray(data)) {
|
|
1172
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
1173
|
+
}
|
|
1174
|
+
return data;
|
|
1175
|
+
}
|
|
1176
|
+
async function dedupeFetch(pending, key, fn) {
|
|
1177
|
+
const existing = pending.get(key);
|
|
1178
|
+
if (existing) return existing;
|
|
1179
|
+
const request = fn();
|
|
1180
|
+
pending.set(key, request);
|
|
1181
|
+
try {
|
|
1182
|
+
return await request;
|
|
1183
|
+
} finally {
|
|
1184
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// src/ClientCore/MessageManager.ts
|
|
1140
1189
|
var BULK = {
|
|
1141
1190
|
requests: { min: 1, max: 25 },
|
|
1142
1191
|
limit: { min: 1, max: 25 },
|
|
@@ -1172,25 +1221,32 @@ var MessageManager = class {
|
|
|
1172
1221
|
}
|
|
1173
1222
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1174
1223
|
_structures = new import_collection2.Collection();
|
|
1224
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
1175
1225
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1176
1226
|
get(messageId) {
|
|
1177
|
-
const
|
|
1227
|
+
const id = String(messageId ?? "").trim();
|
|
1228
|
+
if (!id) return void 0;
|
|
1229
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
1178
1230
|
if (!data) {
|
|
1179
|
-
this._structures.delete(
|
|
1231
|
+
this._structures.delete(id);
|
|
1180
1232
|
return void 0;
|
|
1181
1233
|
}
|
|
1182
|
-
const existing = this._structures.get(
|
|
1183
|
-
if (existing)
|
|
1234
|
+
const existing = this._structures.get(id);
|
|
1235
|
+
if (existing) {
|
|
1236
|
+
existing._patch(data);
|
|
1237
|
+
return existing;
|
|
1238
|
+
}
|
|
1184
1239
|
const message = new Message(this.client, data);
|
|
1185
|
-
this._structures.set(
|
|
1240
|
+
this._structures.set(id, message);
|
|
1186
1241
|
return message;
|
|
1187
1242
|
}
|
|
1188
1243
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1189
1244
|
async resolve(messageId) {
|
|
1190
|
-
|
|
1245
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
1246
|
+
return this.get(id) ?? this.fetch(id);
|
|
1191
1247
|
}
|
|
1192
1248
|
async fetch(idOrOptions) {
|
|
1193
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1249
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
1194
1250
|
}
|
|
1195
1251
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1196
1252
|
wrap(data) {
|
|
@@ -1207,9 +1263,13 @@ var MessageManager = class {
|
|
|
1207
1263
|
}
|
|
1208
1264
|
/** Fetch a single message from the API. */
|
|
1209
1265
|
async fetchOne(messageId) {
|
|
1266
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
1267
|
+
}
|
|
1268
|
+
async fetchOneFresh(messageId) {
|
|
1210
1269
|
try {
|
|
1211
|
-
const data =
|
|
1212
|
-
import_types5.Routes.channelMessage(this.channelId, messageId)
|
|
1270
|
+
const data = assertApiObjectWithId(
|
|
1271
|
+
await this.client.rest.get(import_types5.Routes.channelMessage(this.channelId, messageId)),
|
|
1272
|
+
"messages.fetch()"
|
|
1213
1273
|
);
|
|
1214
1274
|
return this.wrap(data);
|
|
1215
1275
|
} catch (err) {
|
|
@@ -1235,9 +1295,15 @@ var MessageManager = class {
|
|
|
1235
1295
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1236
1296
|
}
|
|
1237
1297
|
const base = import_types5.Routes.channelMessages(this.channelId);
|
|
1238
|
-
const data =
|
|
1298
|
+
const data = assertApiArray(
|
|
1299
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
1300
|
+
"messages.fetch()"
|
|
1301
|
+
);
|
|
1239
1302
|
const collection = new import_collection2.Collection();
|
|
1240
|
-
for (const msg of data)
|
|
1303
|
+
for (const msg of data) {
|
|
1304
|
+
if (!msg?.id) continue;
|
|
1305
|
+
collection.set(msg.id, this.wrap(msg));
|
|
1306
|
+
}
|
|
1241
1307
|
return collection;
|
|
1242
1308
|
}
|
|
1243
1309
|
};
|
|
@@ -1441,6 +1507,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1441
1507
|
}
|
|
1442
1508
|
|
|
1443
1509
|
// src/Domain/Channel/Base.ts
|
|
1510
|
+
function isFullChannelData(data) {
|
|
1511
|
+
return "guild_id" in data || "permission_overwrites" in data || "position" in data || "last_message_id" in data || "topic" in data || "thread_metadata" in data || "available_tags" in data;
|
|
1512
|
+
}
|
|
1444
1513
|
var Channel = class extends Base {
|
|
1445
1514
|
#messages;
|
|
1446
1515
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -1455,6 +1524,11 @@ var Channel = class extends Base {
|
|
|
1455
1524
|
icon;
|
|
1456
1525
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
1457
1526
|
lastPinTimestamp;
|
|
1527
|
+
/**
|
|
1528
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
1529
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
1530
|
+
*/
|
|
1531
|
+
partial;
|
|
1458
1532
|
constructor(client, data) {
|
|
1459
1533
|
super();
|
|
1460
1534
|
this.client = client;
|
|
@@ -1463,6 +1537,7 @@ var Channel = class extends Base {
|
|
|
1463
1537
|
this.name = data.name ?? null;
|
|
1464
1538
|
this.icon = data.icon ?? null;
|
|
1465
1539
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1540
|
+
this.partial = !isFullChannelData(data);
|
|
1466
1541
|
}
|
|
1467
1542
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1468
1543
|
get createdTimestamp() {
|
|
@@ -1483,6 +1558,7 @@ var Channel = class extends Base {
|
|
|
1483
1558
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1484
1559
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1485
1560
|
}
|
|
1561
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
1486
1562
|
}
|
|
1487
1563
|
/** @internal Factory wired after subclasses load. */
|
|
1488
1564
|
static from(_c, _d) {
|
|
@@ -1502,11 +1578,11 @@ var Channel = class extends Base {
|
|
|
1502
1578
|
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
1503
1579
|
*/
|
|
1504
1580
|
isTextBased() {
|
|
1505
|
-
return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.DM || this.type === import_types7.ChannelType.GroupDM || this.type === import_types7.ChannelType.DMPersonalNotes || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread;
|
|
1581
|
+
return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildStageVoice || this.type === import_types7.ChannelType.DM || this.type === import_types7.ChannelType.GroupDM || this.type === import_types7.ChannelType.DMPersonalNotes || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread;
|
|
1506
1582
|
}
|
|
1507
1583
|
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
1508
1584
|
isGuild() {
|
|
1509
|
-
return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildCategory || this.type === import_types7.ChannelType.GuildLink || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread || this.type === import_types7.ChannelType.GuildForum || this.type === import_types7.ChannelType.GuildMedia;
|
|
1585
|
+
return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildStageVoice || this.type === import_types7.ChannelType.GuildCategory || this.type === import_types7.ChannelType.GuildLink || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread || this.type === import_types7.ChannelType.GuildForum || this.type === import_types7.ChannelType.GuildMedia;
|
|
1510
1586
|
}
|
|
1511
1587
|
/** Check if this is a thread (public, private, or announcement). */
|
|
1512
1588
|
isThread() {
|
|
@@ -1540,10 +1616,18 @@ var Channel = class extends Base {
|
|
|
1540
1616
|
isPersonalNotes() {
|
|
1541
1617
|
return this.type === import_types7.ChannelType.DMPersonalNotes;
|
|
1542
1618
|
}
|
|
1543
|
-
/** Check if this is a voice channel. */
|
|
1619
|
+
/** Check if this is a voice channel (type 2 only; see {@link isVoiceBased} to include stages). */
|
|
1544
1620
|
isVoice() {
|
|
1545
1621
|
return this.type === import_types7.ChannelType.GuildVoice;
|
|
1546
1622
|
}
|
|
1623
|
+
/** Check if this is a stage channel (type 13). */
|
|
1624
|
+
isStage() {
|
|
1625
|
+
return this.type === import_types7.ChannelType.GuildStageVoice;
|
|
1626
|
+
}
|
|
1627
|
+
/** Check if this is a voice or stage channel, i.e. one `@fluxerjs/voice` can join. */
|
|
1628
|
+
isVoiceBased() {
|
|
1629
|
+
return this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildStageVoice;
|
|
1630
|
+
}
|
|
1547
1631
|
/** Check if this is a link channel. */
|
|
1548
1632
|
isLink() {
|
|
1549
1633
|
return this.type === import_types7.ChannelType.GuildLink;
|
|
@@ -2258,10 +2342,10 @@ var Message = class _Message extends Base {
|
|
|
2258
2342
|
this.channelId = data.channel_id;
|
|
2259
2343
|
this.guildId = data.guild_id ?? null;
|
|
2260
2344
|
this.author = client.getOrCreateUser(data.author);
|
|
2261
|
-
this.content = data.content;
|
|
2262
|
-
this.createdAt = new Date(data.timestamp);
|
|
2345
|
+
this.content = data.content ?? "";
|
|
2346
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
2263
2347
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2264
|
-
this.pinned = data.pinned;
|
|
2348
|
+
this.pinned = data.pinned ?? false;
|
|
2265
2349
|
this.attachments = new import_collection5.Collection();
|
|
2266
2350
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2267
2351
|
this.type = data.type ?? import_types10.MessageType.Default;
|
|
@@ -2293,33 +2377,47 @@ var Message = class _Message extends Base {
|
|
|
2293
2377
|
* @internal
|
|
2294
2378
|
*/
|
|
2295
2379
|
_patch(data) {
|
|
2296
|
-
this.content = data.content;
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
this.
|
|
2307
|
-
this.
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2380
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
2381
|
+
if (data.edited_timestamp !== void 0) {
|
|
2382
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2383
|
+
}
|
|
2384
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
2385
|
+
if (data.attachments !== void 0) {
|
|
2386
|
+
this.attachments.clear();
|
|
2387
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2388
|
+
}
|
|
2389
|
+
if (data.flags !== void 0) this.flags = new import_util7.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
2390
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
2391
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
2392
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
2393
|
+
if (data.stickers !== void 0) {
|
|
2394
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
2395
|
+
}
|
|
2396
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
2397
|
+
if (data.message_reference !== void 0) {
|
|
2398
|
+
this.messageReference = data.message_reference ? {
|
|
2399
|
+
channelId: data.message_reference.channel_id,
|
|
2400
|
+
messageId: data.message_reference.message_id,
|
|
2401
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
2402
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
2403
|
+
} : null;
|
|
2404
|
+
}
|
|
2405
|
+
if (data.message_snapshots !== void 0) {
|
|
2406
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
2407
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
2408
|
+
);
|
|
2409
|
+
}
|
|
2410
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
2411
|
+
if (data.referenced_message !== void 0) {
|
|
2412
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
2413
|
+
}
|
|
2414
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
2415
|
+
if (data.mentions !== void 0) {
|
|
2416
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2417
|
+
}
|
|
2418
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
2419
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
2420
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
2323
2421
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
2324
2422
|
}
|
|
2325
2423
|
/**
|
|
@@ -2420,6 +2518,23 @@ var Message = class _Message extends Base {
|
|
|
2420
2518
|
async fetch() {
|
|
2421
2519
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2422
2520
|
}
|
|
2521
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2522
|
+
async crosspost() {
|
|
2523
|
+
const data = await this.client.rest.post(
|
|
2524
|
+
import_types10.Routes.channelMessageCrosspost(this.channelId, this.id),
|
|
2525
|
+
{ auth: true }
|
|
2526
|
+
);
|
|
2527
|
+
const published = new _Message(this.client, data);
|
|
2528
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2529
|
+
return published;
|
|
2530
|
+
}
|
|
2531
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2532
|
+
async fetchCrosspostSource() {
|
|
2533
|
+
return this.client.rest.get(
|
|
2534
|
+
import_types10.Routes.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2535
|
+
{ auth: true }
|
|
2536
|
+
);
|
|
2537
|
+
}
|
|
2423
2538
|
/** Delete this message. */
|
|
2424
2539
|
async delete(reason) {
|
|
2425
2540
|
await this.client.rest.delete(import_types10.Routes.channelMessage(this.channelId, this.id), {
|
|
@@ -2523,8 +2638,8 @@ var PartialMessage = class {
|
|
|
2523
2638
|
};
|
|
2524
2639
|
|
|
2525
2640
|
// src/Domain/User.ts
|
|
2526
|
-
var
|
|
2527
|
-
var
|
|
2641
|
+
var import_types22 = require("@fluxerjs/types");
|
|
2642
|
+
var import_util15 = require("@fluxerjs/util");
|
|
2528
2643
|
|
|
2529
2644
|
// src/Domain/Channel/Dm.ts
|
|
2530
2645
|
var import_types12 = require("@fluxerjs/types");
|
|
@@ -2583,7 +2698,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2583
2698
|
const full = data;
|
|
2584
2699
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2585
2700
|
this.ownerId = full.owner_id ?? null;
|
|
2586
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2701
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2587
2702
|
this.nicks = full.nicks ?? {};
|
|
2588
2703
|
}
|
|
2589
2704
|
/**
|
|
@@ -2598,7 +2713,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2598
2713
|
}
|
|
2599
2714
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2600
2715
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2601
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2716
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2602
2717
|
}
|
|
2603
2718
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2604
2719
|
}
|
|
@@ -2663,11 +2778,11 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2663
2778
|
};
|
|
2664
2779
|
|
|
2665
2780
|
// src/Domain/Channel/Forum.ts
|
|
2666
|
-
var
|
|
2781
|
+
var import_types20 = require("@fluxerjs/types");
|
|
2667
2782
|
|
|
2668
2783
|
// src/Domain/Channel/Guild.ts
|
|
2669
|
-
var
|
|
2670
|
-
var
|
|
2784
|
+
var import_types17 = require("@fluxerjs/types");
|
|
2785
|
+
var import_util14 = require("@fluxerjs/util");
|
|
2671
2786
|
|
|
2672
2787
|
// src/Domain/Invite.ts
|
|
2673
2788
|
var import_types13 = require("@fluxerjs/types");
|
|
@@ -2675,17 +2790,19 @@ var import_types13 = require("@fluxerjs/types");
|
|
|
2675
2790
|
// src/Helpers/Instance.ts
|
|
2676
2791
|
var import_util9 = require("@fluxerjs/util");
|
|
2677
2792
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2678
|
-
api: "https://
|
|
2679
|
-
api_client: "https://
|
|
2680
|
-
api_public: "https://
|
|
2681
|
-
gateway: "wss://gateway.fluxer.
|
|
2793
|
+
api: "https://fluxer.com/api",
|
|
2794
|
+
api_client: "https://fluxer.com/api",
|
|
2795
|
+
api_public: "https://fluxer.com/api",
|
|
2796
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2682
2797
|
media: CDN_URL,
|
|
2798
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2683
2799
|
static_cdn: STATIC_CDN_URL,
|
|
2684
|
-
marketing: "https://fluxer.
|
|
2800
|
+
marketing: "https://fluxer.com",
|
|
2801
|
+
docs: "https://docs.fluxer.com",
|
|
2685
2802
|
admin: "https://admin.fluxer.app",
|
|
2686
2803
|
invite: "https://fluxer.gg",
|
|
2687
2804
|
gift: "https://fluxer.gift",
|
|
2688
|
-
webapp: "https://
|
|
2805
|
+
webapp: "https://fluxer.com"
|
|
2689
2806
|
});
|
|
2690
2807
|
var ENDPOINT_KEYS = [
|
|
2691
2808
|
"api",
|
|
@@ -2700,6 +2817,11 @@ var ENDPOINT_KEYS = [
|
|
|
2700
2817
|
"gift",
|
|
2701
2818
|
"webapp"
|
|
2702
2819
|
];
|
|
2820
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
2821
|
+
"api_transport",
|
|
2822
|
+
"upload_relay",
|
|
2823
|
+
"docs"
|
|
2824
|
+
];
|
|
2703
2825
|
function requireString(obj, key, path) {
|
|
2704
2826
|
const value = obj[key];
|
|
2705
2827
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2740,6 +2862,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2740
2862
|
for (const key of ENDPOINT_KEYS) {
|
|
2741
2863
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2742
2864
|
}
|
|
2865
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
2866
|
+
const value = raw.endpoints[key];
|
|
2867
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
2868
|
+
}
|
|
2743
2869
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2744
2870
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2745
2871
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -2793,7 +2919,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
2793
2919
|
defaultsHash: ""
|
|
2794
2920
|
},
|
|
2795
2921
|
push: raw.push ?? { public_vapid_key: null },
|
|
2796
|
-
app_public: raw.app_public ?? {}
|
|
2922
|
+
app_public: raw.app_public ?? {},
|
|
2923
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
2924
|
+
age_policy: (0, import_util9.isRecord)(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
2925
|
+
...raw.notice === null || (0, import_util9.isRecord)(raw.notice) ? { notice: raw.notice } : {},
|
|
2926
|
+
...(0, import_util9.isRecord)(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
2927
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
2928
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
2929
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
2930
|
+
...(0, import_util9.isRecord)(raw.built_in_guild_badge_images) ? {
|
|
2931
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
2932
|
+
} : {},
|
|
2933
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
2934
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
2935
|
+
} : {},
|
|
2936
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
2797
2937
|
};
|
|
2798
2938
|
}
|
|
2799
2939
|
function resolveInstanceEndpoints(input) {
|
|
@@ -2813,7 +2953,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
2813
2953
|
}
|
|
2814
2954
|
const partial = input;
|
|
2815
2955
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
2816
|
-
for (const key of ENDPOINT_KEYS) {
|
|
2956
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
2817
2957
|
const value = partial[key];
|
|
2818
2958
|
if (typeof value === "string" && value.length > 0) {
|
|
2819
2959
|
merged[key] = value;
|
|
@@ -3232,6 +3372,127 @@ var PermissionOverwriteManager = class {
|
|
|
3232
3372
|
}
|
|
3233
3373
|
};
|
|
3234
3374
|
|
|
3375
|
+
// src/Domain/StageInstance.ts
|
|
3376
|
+
var import_types16 = require("@fluxerjs/types");
|
|
3377
|
+
var import_util13 = require("@fluxerjs/util");
|
|
3378
|
+
var StageInstance = class extends Base {
|
|
3379
|
+
client;
|
|
3380
|
+
id;
|
|
3381
|
+
guildId;
|
|
3382
|
+
channelId;
|
|
3383
|
+
topic;
|
|
3384
|
+
/** Always {@link StageInstancePrivacyLevel.GuildOnly} on Fluxer. */
|
|
3385
|
+
privacyLevel;
|
|
3386
|
+
/** Always `true` on Fluxer. */
|
|
3387
|
+
discoverableDisabled;
|
|
3388
|
+
/** Always null on Fluxer. */
|
|
3389
|
+
guildScheduledEventId;
|
|
3390
|
+
constructor(client, data) {
|
|
3391
|
+
super();
|
|
3392
|
+
this.client = client;
|
|
3393
|
+
this.id = data.id;
|
|
3394
|
+
this.guildId = data.guild_id;
|
|
3395
|
+
this.channelId = data.channel_id;
|
|
3396
|
+
this.topic = data.topic;
|
|
3397
|
+
this.privacyLevel = data.privacy_level ?? import_types16.StageInstancePrivacyLevel.GuildOnly;
|
|
3398
|
+
this.discoverableDisabled = data.discoverable_disabled ?? true;
|
|
3399
|
+
this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
|
|
3400
|
+
}
|
|
3401
|
+
/** @internal Patch in place from a newer payload. */
|
|
3402
|
+
_patch(data) {
|
|
3403
|
+
if (data.topic !== void 0) this.topic = data.topic;
|
|
3404
|
+
if (data.privacy_level !== void 0) this.privacyLevel = data.privacy_level;
|
|
3405
|
+
if (data.discoverable_disabled !== void 0) {
|
|
3406
|
+
this.discoverableDisabled = data.discoverable_disabled;
|
|
3407
|
+
}
|
|
3408
|
+
if (data.guild_scheduled_event_id !== void 0) {
|
|
3409
|
+
this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
get guild() {
|
|
3413
|
+
return this.client.guilds.get(this.guildId) ?? null;
|
|
3414
|
+
}
|
|
3415
|
+
get channel() {
|
|
3416
|
+
const channel = this.client.channels.get(this.channelId);
|
|
3417
|
+
return channel?.isStage() ? channel : null;
|
|
3418
|
+
}
|
|
3419
|
+
/** Unix timestamp (ms) when the stage started, from its snowflake ID. */
|
|
3420
|
+
get createdTimestamp() {
|
|
3421
|
+
return import_util13.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
3422
|
+
}
|
|
3423
|
+
get createdAt() {
|
|
3424
|
+
return import_util13.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
3425
|
+
}
|
|
3426
|
+
/**
|
|
3427
|
+
* Change the live stage. Needs a stage moderator.
|
|
3428
|
+
* Fires `STAGE_INSTANCE_UPDATE`.
|
|
3429
|
+
*/
|
|
3430
|
+
async edit(options) {
|
|
3431
|
+
const body = {};
|
|
3432
|
+
if (options.topic !== void 0) body.topic = options.topic;
|
|
3433
|
+
const data = await this.client.rest.patch(
|
|
3434
|
+
import_types16.Routes.stageInstance(this.channelId),
|
|
3435
|
+
{ body, auth: true, ...auditReasonHeaders(options.reason) }
|
|
3436
|
+
);
|
|
3437
|
+
this._patch(data);
|
|
3438
|
+
return this;
|
|
3439
|
+
}
|
|
3440
|
+
/** Change the stage topic. Shorthand for {@link edit}. */
|
|
3441
|
+
async setTopic(topic, reason) {
|
|
3442
|
+
return this.edit({ topic, reason });
|
|
3443
|
+
}
|
|
3444
|
+
/**
|
|
3445
|
+
* End the stage. Needs a stage moderator. Speakers move to the audience, raised hands are
|
|
3446
|
+
* lowered, and everyone stays connected unless `disconnectAll` is set.
|
|
3447
|
+
*/
|
|
3448
|
+
async delete(options = {}) {
|
|
3449
|
+
const route = import_types16.Routes.stageInstance(this.channelId) + (options.disconnectAll ? "?disconnect_all=true" : "");
|
|
3450
|
+
await this.client.rest.delete(route, { auth: true, ...auditReasonHeaders(options.reason) });
|
|
3451
|
+
}
|
|
3452
|
+
toJSON() {
|
|
3453
|
+
return {
|
|
3454
|
+
id: this.id,
|
|
3455
|
+
guild_id: this.guildId,
|
|
3456
|
+
channel_id: this.channelId,
|
|
3457
|
+
topic: this.topic,
|
|
3458
|
+
privacy_level: this.privacyLevel,
|
|
3459
|
+
discoverable_disabled: this.discoverableDisabled,
|
|
3460
|
+
guild_scheduled_event_id: this.guildScheduledEventId
|
|
3461
|
+
};
|
|
3462
|
+
}
|
|
3463
|
+
};
|
|
3464
|
+
|
|
3465
|
+
// src/Domain/Channel/StageSync.ts
|
|
3466
|
+
function syncStageInstances(guild, instances) {
|
|
3467
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3468
|
+
for (const data of instances) {
|
|
3469
|
+
seen.add(data.id);
|
|
3470
|
+
const existing = guild.stageInstances.get(data.id);
|
|
3471
|
+
if (existing) existing._patch(data);
|
|
3472
|
+
else guild.stageInstances.set(data.id, new StageInstance(guild.client, data));
|
|
3473
|
+
}
|
|
3474
|
+
for (const id of [...guild.stageInstances.keys()]) {
|
|
3475
|
+
if (!seen.has(id)) guild.stageInstances.delete(id);
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
function applyStageCounts(guild, counts) {
|
|
3479
|
+
for (const count of counts) {
|
|
3480
|
+
const channel = guild.channels.get(count.channel_id);
|
|
3481
|
+
if (channel?.isStage()) channel._patchCounts(count);
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
function cacheStageInstance(client, data) {
|
|
3485
|
+
const guild = client.guilds.get(data.guild_id);
|
|
3486
|
+
const existing = guild?.stageInstances.get(data.id);
|
|
3487
|
+
if (existing) {
|
|
3488
|
+
existing._patch(data);
|
|
3489
|
+
return existing;
|
|
3490
|
+
}
|
|
3491
|
+
const instance = new StageInstance(client, data);
|
|
3492
|
+
guild?.stageInstances.set(instance.id, instance);
|
|
3493
|
+
return instance;
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3235
3496
|
// src/Domain/Channel/ThreadBind.ts
|
|
3236
3497
|
var factory;
|
|
3237
3498
|
var managers = /* @__PURE__ */ new WeakMap();
|
|
@@ -3286,7 +3547,7 @@ var GuildChannel = class extends Channel {
|
|
|
3286
3547
|
}
|
|
3287
3548
|
/** Create a webhook for this channel. Requires Manage Webhooks. */
|
|
3288
3549
|
async createWebhook(options) {
|
|
3289
|
-
const data = await this.client.rest.post(
|
|
3550
|
+
const data = await this.client.rest.post(import_types17.Routes.channelWebhooks(this.id), {
|
|
3290
3551
|
body: options,
|
|
3291
3552
|
auth: true
|
|
3292
3553
|
});
|
|
@@ -3294,13 +3555,13 @@ var GuildChannel = class extends Channel {
|
|
|
3294
3555
|
}
|
|
3295
3556
|
/** Fetch all webhooks in this channel. Requires Manage Webhooks. */
|
|
3296
3557
|
async fetchWebhooks() {
|
|
3297
|
-
const data = await this.client.rest.get(
|
|
3558
|
+
const data = await this.client.rest.get(import_types17.Routes.channelWebhooks(this.id));
|
|
3298
3559
|
return data.map((w) => new Webhook(this.client, w));
|
|
3299
3560
|
}
|
|
3300
3561
|
/** Create an invite for this channel. Requires Create Instant Invite. */
|
|
3301
3562
|
async createInvite(options) {
|
|
3302
3563
|
const body = options ? toChannelInviteBody(options) : {};
|
|
3303
|
-
const data = await this.client.rest.post(
|
|
3564
|
+
const data = await this.client.rest.post(import_types17.Routes.channelInvites(this.id), {
|
|
3304
3565
|
body: Object.keys(body).length ? body : void 0,
|
|
3305
3566
|
auth: true
|
|
3306
3567
|
});
|
|
@@ -3308,7 +3569,7 @@ var GuildChannel = class extends Channel {
|
|
|
3308
3569
|
}
|
|
3309
3570
|
/** Fetch all invites for this channel. Requires Manage Channels. */
|
|
3310
3571
|
async fetchInvites() {
|
|
3311
|
-
const data = await this.client.rest.get(
|
|
3572
|
+
const data = await this.client.rest.get(import_types17.Routes.channelInvites(this.id));
|
|
3312
3573
|
return data.map((i) => new Invite(this.client, i));
|
|
3313
3574
|
}
|
|
3314
3575
|
/** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
|
|
@@ -3317,7 +3578,7 @@ var GuildChannel = class extends Channel {
|
|
|
3317
3578
|
const me = this.client.guilds.get(this.guildId)?.members.me;
|
|
3318
3579
|
if (!me) return false;
|
|
3319
3580
|
const perms = me.permissionsIn(this);
|
|
3320
|
-
return perms.has(
|
|
3581
|
+
return perms.has(import_util14.PermissionFlags.ViewChannel) && perms.has(import_util14.PermissionFlags.SendMessages);
|
|
3321
3582
|
}
|
|
3322
3583
|
/**
|
|
3323
3584
|
* Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
|
|
@@ -3338,7 +3599,7 @@ var GuildChannel = class extends Channel {
|
|
|
3338
3599
|
}
|
|
3339
3600
|
/** Edit this channel's settings. Requires Manage Channels. */
|
|
3340
3601
|
async edit(options) {
|
|
3341
|
-
const data = await this.client.rest.patch(
|
|
3602
|
+
const data = await this.client.rest.patch(import_types17.Routes.channel(this.id), {
|
|
3342
3603
|
body: toChannelEditBody(options),
|
|
3343
3604
|
auth: true,
|
|
3344
3605
|
...auditReasonHeaders(options.reason)
|
|
@@ -3420,7 +3681,7 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3420
3681
|
* Sends only those fields. The thread-parent update body does not accept a channel rename.
|
|
3421
3682
|
*/
|
|
3422
3683
|
async editThreadDefaults(options) {
|
|
3423
|
-
const data = await this.client.rest.patch(
|
|
3684
|
+
const data = await this.client.rest.patch(import_types17.Routes.channel(this.id), {
|
|
3424
3685
|
body: toThreadParentEditBody(options),
|
|
3425
3686
|
auth: true,
|
|
3426
3687
|
...auditReasonHeaders(options.reason)
|
|
@@ -3430,6 +3691,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3430
3691
|
}
|
|
3431
3692
|
};
|
|
3432
3693
|
var AnnouncementChannel = class extends TextChannel {
|
|
3694
|
+
/**
|
|
3695
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3696
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3697
|
+
*/
|
|
3698
|
+
async follow(webhookChannelId) {
|
|
3699
|
+
return this.client.rest.post(
|
|
3700
|
+
import_types17.Routes.channelFollowers(this.id),
|
|
3701
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3702
|
+
);
|
|
3703
|
+
}
|
|
3704
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3705
|
+
async fetchFollowerStats() {
|
|
3706
|
+
return this.client.rest.get(
|
|
3707
|
+
import_types17.Routes.channelFollowerStats(this.id),
|
|
3708
|
+
{ auth: true }
|
|
3709
|
+
);
|
|
3710
|
+
}
|
|
3433
3711
|
};
|
|
3434
3712
|
var CategoryChannel = class extends GuildChannel {
|
|
3435
3713
|
};
|
|
@@ -3456,6 +3734,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3456
3734
|
voiceConnectionLimit;
|
|
3457
3735
|
/** RTC region override for this channel. */
|
|
3458
3736
|
rtcRegion;
|
|
3737
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3738
|
+
rtcP2p;
|
|
3459
3739
|
constructor(client, data) {
|
|
3460
3740
|
super(client, data);
|
|
3461
3741
|
this.topic = data.topic ?? null;
|
|
@@ -3469,6 +3749,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3469
3749
|
this.userLimit = data.user_limit ?? null;
|
|
3470
3750
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3471
3751
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3752
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3472
3753
|
}
|
|
3473
3754
|
/**
|
|
3474
3755
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3495,6 +3776,97 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3495
3776
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3496
3777
|
}
|
|
3497
3778
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3779
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3780
|
+
}
|
|
3781
|
+
};
|
|
3782
|
+
var StageChannel = class extends VoiceChannel {
|
|
3783
|
+
/** Last known stage counts, or null until Fluxer sends them. */
|
|
3784
|
+
counts = null;
|
|
3785
|
+
/** The cached live stage of this channel, or null when the stage isn't live (or not cached). */
|
|
3786
|
+
get stageInstance() {
|
|
3787
|
+
const guild = this.client.guilds.get(this.guildId);
|
|
3788
|
+
if (!guild) return null;
|
|
3789
|
+
for (const instance of guild.stageInstances.values()) {
|
|
3790
|
+
if (instance.channelId === this.id) return instance;
|
|
3791
|
+
}
|
|
3792
|
+
return null;
|
|
3793
|
+
}
|
|
3794
|
+
/** Whether the stage is live according to the cache. */
|
|
3795
|
+
get isLive() {
|
|
3796
|
+
return this.stageInstance !== null;
|
|
3797
|
+
}
|
|
3798
|
+
/**
|
|
3799
|
+
* Start a stage in this channel. Needs a stage moderator (`MANAGE_CHANNELS`, `MUTE_MEMBERS` and
|
|
3800
|
+
* `MOVE_MEMBERS`). When the caller is connected to the stage, they become a speaker.
|
|
3801
|
+
*/
|
|
3802
|
+
async createStageInstance(options) {
|
|
3803
|
+
const body = { channel_id: this.id, topic: options.topic };
|
|
3804
|
+
if (options.sendStartNotification !== void 0) {
|
|
3805
|
+
body.send_start_notification = options.sendStartNotification;
|
|
3806
|
+
}
|
|
3807
|
+
const data = await this.client.rest.post(import_types17.Routes.stageInstances(), {
|
|
3808
|
+
body,
|
|
3809
|
+
auth: true,
|
|
3810
|
+
...auditReasonHeaders(options.reason)
|
|
3811
|
+
});
|
|
3812
|
+
return cacheStageInstance(this.client, data);
|
|
3813
|
+
}
|
|
3814
|
+
/** Fetch the live stage of this channel. Rejects with `UNKNOWN_STAGE_INSTANCE` when not live. */
|
|
3815
|
+
async fetchStageInstance() {
|
|
3816
|
+
const data = await this.client.rest.get(import_types17.Routes.stageInstance(this.id), {
|
|
3817
|
+
auth: true
|
|
3818
|
+
});
|
|
3819
|
+
return cacheStageInstance(this.client, data);
|
|
3820
|
+
}
|
|
3821
|
+
/**
|
|
3822
|
+
* Move a member (or yourself when `user` is omitted) between the audience and the speakers.
|
|
3823
|
+
*
|
|
3824
|
+
* - Yourself, `false`: become a speaker (needs `MUTE_MEMBERS`), or accept an open invite.
|
|
3825
|
+
* - Yourself, `true`: move to the audience, or decline an invite.
|
|
3826
|
+
* - Another member, `false`: invite them to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`.
|
|
3827
|
+
* - Another member, `true`: move them to the audience and clear a raised hand or invite.
|
|
3828
|
+
*/
|
|
3829
|
+
async setSuppressed(suppressed, user) {
|
|
3830
|
+
const userId = user === void 0 ? "@me" : typeof user === "string" ? user : user.id;
|
|
3831
|
+
const body = {
|
|
3832
|
+
channel_id: this.id,
|
|
3833
|
+
suppress: suppressed
|
|
3834
|
+
};
|
|
3835
|
+
await this.client.rest.patch(import_types17.Routes.guildVoiceState(this.guildId, userId), {
|
|
3836
|
+
body,
|
|
3837
|
+
auth: true
|
|
3838
|
+
});
|
|
3839
|
+
}
|
|
3840
|
+
/** Invite a member to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`. */
|
|
3841
|
+
async inviteToSpeak(user) {
|
|
3842
|
+
await this.setSuppressed(false, user);
|
|
3843
|
+
}
|
|
3844
|
+
/** Move a speaker (or yourself when `user` is omitted) to the audience. */
|
|
3845
|
+
async moveToAudience(user) {
|
|
3846
|
+
await this.setSuppressed(true, user);
|
|
3847
|
+
}
|
|
3848
|
+
/**
|
|
3849
|
+
* Raise (`true`) or lower (`false`) your hand. Raising needs a live stage and
|
|
3850
|
+
* `REQUEST_TO_SPEAK`; lowering also accepts an open invite to speak.
|
|
3851
|
+
*/
|
|
3852
|
+
async setRequestToSpeak(raised = true) {
|
|
3853
|
+
const body = {
|
|
3854
|
+
channel_id: this.id,
|
|
3855
|
+
request_to_speak_timestamp: raised ? (/* @__PURE__ */ new Date()).toISOString() : null
|
|
3856
|
+
};
|
|
3857
|
+
await this.client.rest.patch(import_types17.Routes.guildVoiceState(this.guildId, "@me"), {
|
|
3858
|
+
body,
|
|
3859
|
+
auth: true
|
|
3860
|
+
});
|
|
3861
|
+
}
|
|
3862
|
+
/** @internal Apply a stage count object. */
|
|
3863
|
+
_patchCounts(data) {
|
|
3864
|
+
this.counts = {
|
|
3865
|
+
listenerCount: data.listener_count,
|
|
3866
|
+
speakerCount: data.speaker_count,
|
|
3867
|
+
requestCount: data.request_count,
|
|
3868
|
+
videoEnabled: data.video_enabled ?? null
|
|
3869
|
+
};
|
|
3498
3870
|
}
|
|
3499
3871
|
};
|
|
3500
3872
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -3510,10 +3882,10 @@ var LinkChannel = class extends GuildChannel {
|
|
|
3510
3882
|
};
|
|
3511
3883
|
|
|
3512
3884
|
// src/Domain/Channel/ThreadManager.ts
|
|
3513
|
-
var
|
|
3885
|
+
var import_types19 = require("@fluxerjs/types");
|
|
3514
3886
|
|
|
3515
3887
|
// src/Domain/Channel/ThreadChannel.ts
|
|
3516
|
-
var
|
|
3888
|
+
var import_types18 = require("@fluxerjs/types");
|
|
3517
3889
|
var ThreadMember = class {
|
|
3518
3890
|
/** Thread ID. */
|
|
3519
3891
|
id;
|
|
@@ -3640,7 +4012,7 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
|
|
|
3640
4012
|
* `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
|
|
3641
4013
|
*/
|
|
3642
4014
|
async edit(options) {
|
|
3643
|
-
const data = await this.client.rest.patch(
|
|
4015
|
+
const data = await this.client.rest.patch(import_types18.Routes.channel(this.id), {
|
|
3644
4016
|
body: toThreadEditBody(this.type, threadEditFields(options)),
|
|
3645
4017
|
auth: true,
|
|
3646
4018
|
...auditReasonHeaders(options.reason)
|
|
@@ -3658,16 +4030,16 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
|
|
|
3658
4030
|
}
|
|
3659
4031
|
/** Join this thread. */
|
|
3660
4032
|
async join() {
|
|
3661
|
-
await this.client.rest.put(
|
|
4033
|
+
await this.client.rest.put(import_types18.Routes.channelThreadMemberMe(this.id), { auth: true });
|
|
3662
4034
|
}
|
|
3663
4035
|
/** Leave this thread. */
|
|
3664
4036
|
async leave() {
|
|
3665
|
-
await this.client.rest.delete(
|
|
4037
|
+
await this.client.rest.delete(import_types18.Routes.channelThreadMemberMe(this.id), { auth: true });
|
|
3666
4038
|
}
|
|
3667
4039
|
/** Update the current user's notification settings for this thread. */
|
|
3668
4040
|
async editSelf(options) {
|
|
3669
4041
|
const data = await this.client.rest.patch(
|
|
3670
|
-
|
|
4042
|
+
import_types18.Routes.channelThreadMemberMeSettings(this.id),
|
|
3671
4043
|
{ body: toThreadMemberSettingsBody(options), auth: true }
|
|
3672
4044
|
);
|
|
3673
4045
|
this.member = data ? new ThreadMember(data) : null;
|
|
@@ -3681,7 +4053,7 @@ var ThreadMemberManager = class {
|
|
|
3681
4053
|
/** List members of this thread. */
|
|
3682
4054
|
async fetch(options) {
|
|
3683
4055
|
const data = await this.thread.client.rest.get(
|
|
3684
|
-
withQuery(
|
|
4056
|
+
withQuery(import_types18.Routes.channelThreadMembers(this.thread.id), {
|
|
3685
4057
|
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
|
|
3686
4058
|
after: options?.after,
|
|
3687
4059
|
limit: options?.limit
|
|
@@ -3692,7 +4064,7 @@ var ThreadMemberManager = class {
|
|
|
3692
4064
|
/** Fetch one member of this thread. */
|
|
3693
4065
|
async fetchOne(userId, options) {
|
|
3694
4066
|
const data = await this.thread.client.rest.get(
|
|
3695
|
-
withQuery(
|
|
4067
|
+
withQuery(import_types18.Routes.channelThreadMember(this.thread.id, userId), {
|
|
3696
4068
|
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
|
|
3697
4069
|
})
|
|
3698
4070
|
);
|
|
@@ -3700,19 +4072,19 @@ var ThreadMemberManager = class {
|
|
|
3700
4072
|
}
|
|
3701
4073
|
/** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
|
|
3702
4074
|
async add(userId) {
|
|
3703
|
-
await this.thread.client.rest.put(
|
|
4075
|
+
await this.thread.client.rest.put(import_types18.Routes.channelThreadMember(this.thread.id, userId), {
|
|
3704
4076
|
auth: true
|
|
3705
4077
|
});
|
|
3706
4078
|
}
|
|
3707
4079
|
/** Remove a user from this thread. */
|
|
3708
4080
|
async remove(userId) {
|
|
3709
|
-
await this.thread.client.rest.delete(
|
|
4081
|
+
await this.thread.client.rest.delete(import_types18.Routes.channelThreadMember(this.thread.id, userId), {
|
|
3710
4082
|
auth: true
|
|
3711
4083
|
});
|
|
3712
4084
|
}
|
|
3713
4085
|
};
|
|
3714
4086
|
function isThreadType(type) {
|
|
3715
|
-
return type ===
|
|
4087
|
+
return type === import_types18.ChannelType.AnnouncementThread || type === import_types18.ChannelType.PublicThread || type === import_types18.ChannelType.PrivateThread;
|
|
3716
4088
|
}
|
|
3717
4089
|
|
|
3718
4090
|
// src/Domain/Channel/ThreadManager.ts
|
|
@@ -3725,13 +4097,13 @@ var ThreadManager = class {
|
|
|
3725
4097
|
* Forum and media channels must use {@link createPost}.
|
|
3726
4098
|
*/
|
|
3727
4099
|
async create(options) {
|
|
3728
|
-
if (this.channel.type ===
|
|
4100
|
+
if (this.channel.type === import_types19.ChannelType.GuildForum || this.channel.type === import_types19.ChannelType.GuildMedia) {
|
|
3729
4101
|
throw new import_util2.FluxerError("Forum and media channels start posts with createPost", {
|
|
3730
4102
|
code: import_util.ErrorCodes.InvalidChannelType
|
|
3731
4103
|
});
|
|
3732
4104
|
}
|
|
3733
4105
|
const data = await this.channel.client.rest.post(
|
|
3734
|
-
|
|
4106
|
+
import_types19.Routes.channelThreads(this.channel.id),
|
|
3735
4107
|
{
|
|
3736
4108
|
body: toStartThreadBody(this.channel.type, options),
|
|
3737
4109
|
auth: true,
|
|
@@ -3745,7 +4117,7 @@ var ThreadManager = class {
|
|
|
3745
4117
|
* The post is a public thread. `message` is its first message.
|
|
3746
4118
|
*/
|
|
3747
4119
|
async createPost(options) {
|
|
3748
|
-
if (this.channel.type !==
|
|
4120
|
+
if (this.channel.type !== import_types19.ChannelType.GuildForum && this.channel.type !== import_types19.ChannelType.GuildMedia) {
|
|
3749
4121
|
throw new import_util2.FluxerError("createPost is for forum and media channels", {
|
|
3750
4122
|
code: import_util.ErrorCodes.InvalidChannelType
|
|
3751
4123
|
});
|
|
@@ -3755,7 +4127,7 @@ var ThreadManager = class {
|
|
|
3755
4127
|
});
|
|
3756
4128
|
const body = {
|
|
3757
4129
|
name: options.name,
|
|
3758
|
-
type:
|
|
4130
|
+
type: import_types19.ChannelType.PublicThread,
|
|
3759
4131
|
message: toForumThreadMessage(prepared.body)
|
|
3760
4132
|
};
|
|
3761
4133
|
if (options.autoArchiveDuration !== void 0) {
|
|
@@ -3764,7 +4136,7 @@ var ThreadManager = class {
|
|
|
3764
4136
|
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
3765
4137
|
if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
|
|
3766
4138
|
const data = await this.channel.client.rest.post(
|
|
3767
|
-
|
|
4139
|
+
import_types19.Routes.channelThreads(this.channel.id),
|
|
3768
4140
|
{
|
|
3769
4141
|
body,
|
|
3770
4142
|
files: prepared.files,
|
|
@@ -3783,7 +4155,7 @@ var ThreadManager = class {
|
|
|
3783
4155
|
* `before` is an ISO-8601 archive timestamp.
|
|
3784
4156
|
*/
|
|
3785
4157
|
async fetchArchived(options) {
|
|
3786
|
-
const path = options.type === "private" ?
|
|
4158
|
+
const path = options.type === "private" ? import_types19.Routes.channelThreadsArchivedPrivate(this.channel.id) : import_types19.Routes.channelThreadsArchivedPublic(this.channel.id);
|
|
3787
4159
|
const data = await this.channel.client.rest.get(
|
|
3788
4160
|
withQuery(path, { before: options.before, limit: options.limit })
|
|
3789
4161
|
);
|
|
@@ -3795,7 +4167,7 @@ var ThreadManager = class {
|
|
|
3795
4167
|
*/
|
|
3796
4168
|
async fetchJoinedPrivateArchived(options) {
|
|
3797
4169
|
const data = await this.channel.client.rest.get(
|
|
3798
|
-
withQuery(
|
|
4170
|
+
withQuery(import_types19.Routes.channelJoinedArchivedPrivateThreads(this.channel.id), {
|
|
3799
4171
|
before: options?.before,
|
|
3800
4172
|
limit: options?.limit
|
|
3801
4173
|
})
|
|
@@ -3808,7 +4180,7 @@ var ThreadManager = class {
|
|
|
3808
4180
|
*/
|
|
3809
4181
|
async search(options) {
|
|
3810
4182
|
const data = await this.channel.client.rest.get(
|
|
3811
|
-
withQuery(
|
|
4183
|
+
withQuery(import_types19.Routes.channelThreadSearch(this.channel.id), {
|
|
3812
4184
|
name: options?.name,
|
|
3813
4185
|
tag: options?.tag,
|
|
3814
4186
|
tag_setting: options?.tagSetting,
|
|
@@ -3836,7 +4208,7 @@ var ThreadManager = class {
|
|
|
3836
4208
|
}
|
|
3837
4209
|
/** Set the auto-archive and slowmode defaults copied onto new threads. */
|
|
3838
4210
|
async editDefaults(options) {
|
|
3839
|
-
return this.channel.client.rest.patch(
|
|
4211
|
+
return this.channel.client.rest.patch(import_types19.Routes.channel(this.channel.id), {
|
|
3840
4212
|
body: toThreadParentEditBody(options),
|
|
3841
4213
|
auth: true,
|
|
3842
4214
|
...auditReasonHeaders(options.reason)
|
|
@@ -3854,7 +4226,7 @@ function isSearchNotReady(data) {
|
|
|
3854
4226
|
return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
|
|
3855
4227
|
}
|
|
3856
4228
|
async function fetchActiveThreads(client, guildId) {
|
|
3857
|
-
const data = await client.rest.get(
|
|
4229
|
+
const data = await client.rest.get(import_types19.Routes.guildActiveThreads(guildId));
|
|
3858
4230
|
return fetchedThreadsFrom(client, data);
|
|
3859
4231
|
}
|
|
3860
4232
|
|
|
@@ -3913,10 +4285,10 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
3913
4285
|
* `defaultForumLayout` is sent only for forum channels.
|
|
3914
4286
|
*/
|
|
3915
4287
|
async edit(options) {
|
|
3916
|
-
const data = await this.client.rest.patch(
|
|
4288
|
+
const data = await this.client.rest.patch(import_types20.Routes.channel(this.id), {
|
|
3917
4289
|
body: {
|
|
3918
4290
|
...toChannelEditBody(options),
|
|
3919
|
-
...forumParentWire(options, this.type ===
|
|
4291
|
+
...forumParentWire(options, this.type === import_types20.ChannelType.GuildForum)
|
|
3920
4292
|
},
|
|
3921
4293
|
auth: true,
|
|
3922
4294
|
...auditReasonHeaders(options.reason)
|
|
@@ -3942,7 +4314,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
3942
4314
|
}
|
|
3943
4315
|
/** Set the auto-archive and slowmode defaults copied onto new posts. */
|
|
3944
4316
|
async editThreadDefaults(options) {
|
|
3945
|
-
const data = await this.client.rest.patch(
|
|
4317
|
+
const data = await this.client.rest.patch(import_types20.Routes.channel(this.id), {
|
|
3946
4318
|
body: toThreadParentEditBody(options),
|
|
3947
4319
|
auth: true,
|
|
3948
4320
|
...auditReasonHeaders(options.reason)
|
|
@@ -3952,7 +4324,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
3952
4324
|
}
|
|
3953
4325
|
/** Create a tag. The response replaces {@link availableTags}. */
|
|
3954
4326
|
async createTag(options) {
|
|
3955
|
-
const data = await this.client.rest.post(
|
|
4327
|
+
const data = await this.client.rest.post(import_types20.Routes.channelTags(this.id), {
|
|
3956
4328
|
body: toForumTagBody(options),
|
|
3957
4329
|
auth: true,
|
|
3958
4330
|
...auditReasonHeaders(options.reason)
|
|
@@ -3962,7 +4334,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
3962
4334
|
}
|
|
3963
4335
|
/** Replace a tag. The response replaces {@link availableTags}. */
|
|
3964
4336
|
async editTag(tagId, options) {
|
|
3965
|
-
const data = await this.client.rest.put(
|
|
4337
|
+
const data = await this.client.rest.put(import_types20.Routes.channelTag(this.id, tagId), {
|
|
3966
4338
|
body: toForumTagBody(options),
|
|
3967
4339
|
auth: true,
|
|
3968
4340
|
...auditReasonHeaders(options.reason)
|
|
@@ -3972,7 +4344,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
3972
4344
|
}
|
|
3973
4345
|
/** Delete a tag. The response replaces {@link availableTags}. */
|
|
3974
4346
|
async deleteTag(tagId, reason) {
|
|
3975
|
-
const data = await this.client.rest.delete(
|
|
4347
|
+
const data = await this.client.rest.delete(import_types20.Routes.channelTag(this.id, tagId), {
|
|
3976
4348
|
auth: true,
|
|
3977
4349
|
...auditReasonHeaders(reason)
|
|
3978
4350
|
});
|
|
@@ -4001,23 +4373,24 @@ var MediaChannel = class extends ThreadOnlyChannel {
|
|
|
4001
4373
|
};
|
|
4002
4374
|
|
|
4003
4375
|
// src/Domain/Channel/Factory.ts
|
|
4004
|
-
var
|
|
4376
|
+
var import_types21 = require("@fluxerjs/types");
|
|
4005
4377
|
var GUILD_FACTORIES = {
|
|
4006
|
-
[
|
|
4007
|
-
[
|
|
4008
|
-
[
|
|
4009
|
-
[
|
|
4010
|
-
[
|
|
4011
|
-
[
|
|
4012
|
-
[
|
|
4013
|
-
[
|
|
4014
|
-
[
|
|
4015
|
-
[
|
|
4378
|
+
[import_types21.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
|
|
4379
|
+
[import_types21.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
|
|
4380
|
+
[import_types21.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
4381
|
+
[import_types21.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
4382
|
+
[import_types21.ChannelType.GuildStageVoice]: (c, d) => new StageChannel(c, d),
|
|
4383
|
+
[import_types21.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d),
|
|
4384
|
+
[import_types21.ChannelType.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
|
|
4385
|
+
[import_types21.ChannelType.PublicThread]: (c, d) => new ThreadChannel(c, d),
|
|
4386
|
+
[import_types21.ChannelType.PrivateThread]: (c, d) => new ThreadChannel(c, d),
|
|
4387
|
+
[import_types21.ChannelType.GuildForum]: (c, d) => new ForumChannel(c, d),
|
|
4388
|
+
[import_types21.ChannelType.GuildMedia]: (c, d) => new MediaChannel(c, d)
|
|
4016
4389
|
};
|
|
4017
4390
|
var DM_TYPES = /* @__PURE__ */ new Set([
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4391
|
+
import_types21.ChannelType.DM,
|
|
4392
|
+
import_types21.ChannelType.GroupDM,
|
|
4393
|
+
import_types21.ChannelType.DMPersonalNotes
|
|
4021
4394
|
]);
|
|
4022
4395
|
function createDM(client, data) {
|
|
4023
4396
|
return new DMChannel(client, data);
|
|
@@ -4060,12 +4433,15 @@ var User = class extends Base {
|
|
|
4060
4433
|
system;
|
|
4061
4434
|
/** Banner hash for profile. */
|
|
4062
4435
|
banner;
|
|
4436
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
4437
|
+
partial;
|
|
4063
4438
|
constructor(client, data) {
|
|
4064
4439
|
super();
|
|
4065
4440
|
this.client = client;
|
|
4066
4441
|
this.id = data.id;
|
|
4067
|
-
this.
|
|
4068
|
-
this.
|
|
4442
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
4443
|
+
this.username = data.username ?? "Unknown";
|
|
4444
|
+
this.discriminator = data.discriminator ?? "0";
|
|
4069
4445
|
this.globalName = data.global_name ?? null;
|
|
4070
4446
|
this.avatar = data.avatar ?? null;
|
|
4071
4447
|
this.bot = !!data.bot;
|
|
@@ -4076,13 +4452,18 @@ var User = class extends Base {
|
|
|
4076
4452
|
}
|
|
4077
4453
|
/** @internal */
|
|
4078
4454
|
_patch(data) {
|
|
4079
|
-
this.username = data.username;
|
|
4080
|
-
this.discriminator = data.discriminator;
|
|
4081
|
-
this.globalName = data.global_name ?? null;
|
|
4082
|
-
this.avatar = data.avatar ?? null;
|
|
4455
|
+
if (data.username !== void 0) this.username = data.username;
|
|
4456
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
4457
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
4458
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
4083
4459
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
4084
4460
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
4085
4461
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
4462
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
4463
|
+
}
|
|
4464
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
4465
|
+
async fetch() {
|
|
4466
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
4086
4467
|
}
|
|
4087
4468
|
cdnOpts() {
|
|
4088
4469
|
return {
|
|
@@ -4120,11 +4501,11 @@ var User = class extends Base {
|
|
|
4120
4501
|
*/
|
|
4121
4502
|
/** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
|
|
4122
4503
|
get createdTimestamp() {
|
|
4123
|
-
return
|
|
4504
|
+
return import_util15.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
4124
4505
|
}
|
|
4125
4506
|
/** Date when this account was created, derived from its snowflake ID. */
|
|
4126
4507
|
get createdAt() {
|
|
4127
|
-
return
|
|
4508
|
+
return import_util15.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
4128
4509
|
}
|
|
4129
4510
|
toString() {
|
|
4130
4511
|
return `<@${this.id}>`;
|
|
@@ -4134,7 +4515,7 @@ var User = class extends Base {
|
|
|
4134
4515
|
* @returns DM channel instance (cached if already open)
|
|
4135
4516
|
*/
|
|
4136
4517
|
async createDM() {
|
|
4137
|
-
const data = await this.client.rest.post(
|
|
4518
|
+
const data = await this.client.rest.post(import_types22.Routes.userMeChannels(), {
|
|
4138
4519
|
body: { recipient_id: this.id },
|
|
4139
4520
|
auth: true
|
|
4140
4521
|
});
|
|
@@ -4351,14 +4732,14 @@ var CacheController = class {
|
|
|
4351
4732
|
|
|
4352
4733
|
// src/ClientCore/ChannelManager.ts
|
|
4353
4734
|
var import_collection8 = require("@fluxerjs/collection");
|
|
4354
|
-
var
|
|
4735
|
+
var import_types30 = require("@fluxerjs/types");
|
|
4355
4736
|
|
|
4356
4737
|
// src/Domain/Guild/Cache.ts
|
|
4357
|
-
var
|
|
4738
|
+
var import_types29 = require("@fluxerjs/types");
|
|
4358
4739
|
|
|
4359
4740
|
// src/Domain/Guild/GuildEmoji.ts
|
|
4360
|
-
var
|
|
4361
|
-
var
|
|
4741
|
+
var import_types23 = require("@fluxerjs/types");
|
|
4742
|
+
var import_util16 = require("@fluxerjs/util");
|
|
4362
4743
|
var GuildEmoji = class extends Base {
|
|
4363
4744
|
client;
|
|
4364
4745
|
id;
|
|
@@ -4394,11 +4775,11 @@ var GuildEmoji = class extends Base {
|
|
|
4394
4775
|
}
|
|
4395
4776
|
/** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
|
|
4396
4777
|
get createdTimestamp() {
|
|
4397
|
-
return
|
|
4778
|
+
return import_util16.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
4398
4779
|
}
|
|
4399
4780
|
/** Date when this emoji was created, derived from its snowflake ID. */
|
|
4400
4781
|
get createdAt() {
|
|
4401
|
-
return
|
|
4782
|
+
return import_util16.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
4402
4783
|
}
|
|
4403
4784
|
/** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
|
|
4404
4785
|
toString() {
|
|
@@ -4406,7 +4787,7 @@ var GuildEmoji = class extends Base {
|
|
|
4406
4787
|
}
|
|
4407
4788
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
4408
4789
|
async delete(reason) {
|
|
4409
|
-
await this.client.rest.delete(
|
|
4790
|
+
await this.client.rest.delete(import_types23.Routes.guildEmoji(this.guildId, this.id), {
|
|
4410
4791
|
auth: true,
|
|
4411
4792
|
...auditReasonHeaders(reason)
|
|
4412
4793
|
});
|
|
@@ -4419,7 +4800,7 @@ var GuildEmoji = class extends Base {
|
|
|
4419
4800
|
*/
|
|
4420
4801
|
async edit(options) {
|
|
4421
4802
|
const { reason, name } = options;
|
|
4422
|
-
const data = await this.client.rest.patch(
|
|
4803
|
+
const data = await this.client.rest.patch(import_types23.Routes.guildEmoji(this.guildId, this.id), {
|
|
4423
4804
|
body: { name },
|
|
4424
4805
|
auth: true,
|
|
4425
4806
|
...auditReasonHeaders(reason)
|
|
@@ -4430,20 +4811,20 @@ var GuildEmoji = class extends Base {
|
|
|
4430
4811
|
};
|
|
4431
4812
|
|
|
4432
4813
|
// src/Domain/Guild/GuildMember.ts
|
|
4433
|
-
var
|
|
4434
|
-
var
|
|
4814
|
+
var import_types26 = require("@fluxerjs/types");
|
|
4815
|
+
var import_util18 = require("@fluxerjs/util");
|
|
4435
4816
|
|
|
4436
4817
|
// src/Helpers/Permissions.ts
|
|
4437
|
-
var
|
|
4438
|
-
var
|
|
4818
|
+
var import_types24 = require("@fluxerjs/types");
|
|
4819
|
+
var import_util17 = require("@fluxerjs/util");
|
|
4439
4820
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
4440
|
-
if (isOwner) return
|
|
4441
|
-
if ((basePermissions &
|
|
4442
|
-
return
|
|
4821
|
+
if (isOwner) return import_util17.ALL_PERMISSIONS_BIGINT;
|
|
4822
|
+
if ((basePermissions & import_util17.PermissionFlags.Administrator) !== 0n) {
|
|
4823
|
+
return import_util17.ALL_PERMISSIONS_BIGINT;
|
|
4443
4824
|
}
|
|
4444
4825
|
let perms = basePermissions;
|
|
4445
4826
|
for (const overwrite of overwrites ?? []) {
|
|
4446
|
-
const applies = overwrite.type ===
|
|
4827
|
+
const applies = overwrite.type === import_types24.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types24.OverwriteType.Member && overwrite.id === memberId;
|
|
4447
4828
|
if (!applies) continue;
|
|
4448
4829
|
const allow = BigInt(overwrite.allow || "0");
|
|
4449
4830
|
const deny = BigInt(overwrite.deny || "0");
|
|
@@ -4454,7 +4835,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
4454
4835
|
|
|
4455
4836
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
4456
4837
|
var import_collection7 = require("@fluxerjs/collection");
|
|
4457
|
-
var
|
|
4838
|
+
var import_types25 = require("@fluxerjs/types");
|
|
4458
4839
|
function roleId(roleOrId) {
|
|
4459
4840
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
4460
4841
|
}
|
|
@@ -4483,7 +4864,7 @@ var GuildMemberRoleManager = class {
|
|
|
4483
4864
|
const id = roleId(roleOrId);
|
|
4484
4865
|
if (this.ids.includes(id)) return;
|
|
4485
4866
|
await this.member.client.rest.put(
|
|
4486
|
-
|
|
4867
|
+
import_types25.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
4487
4868
|
);
|
|
4488
4869
|
this.ids.push(id);
|
|
4489
4870
|
}
|
|
@@ -4492,13 +4873,13 @@ var GuildMemberRoleManager = class {
|
|
|
4492
4873
|
const idx = this.ids.indexOf(id);
|
|
4493
4874
|
if (idx === -1) return;
|
|
4494
4875
|
await this.member.client.rest.delete(
|
|
4495
|
-
|
|
4876
|
+
import_types25.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
4496
4877
|
);
|
|
4497
4878
|
this.ids.splice(idx, 1);
|
|
4498
4879
|
}
|
|
4499
4880
|
async set(roleIds) {
|
|
4500
4881
|
const data = await this.member.client.rest.patch(
|
|
4501
|
-
|
|
4882
|
+
import_types25.Routes.guildMember(this.member.guild.id, this.member.id),
|
|
4502
4883
|
{ body: { roles: roleIds }, auth: true }
|
|
4503
4884
|
);
|
|
4504
4885
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -4652,7 +5033,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
4652
5033
|
*/
|
|
4653
5034
|
async edit(options) {
|
|
4654
5035
|
const isMe = this.client.user?.id === this.id;
|
|
4655
|
-
const route = isMe ?
|
|
5036
|
+
const route = isMe ? import_types26.Routes.guildMemberMe(this.guild.id) : import_types26.Routes.guildMember(this.guild.id, this.id);
|
|
4656
5037
|
const data = await this.client.rest.patch(route, {
|
|
4657
5038
|
body: toMemberEditBody(options),
|
|
4658
5039
|
auth: true,
|
|
@@ -4669,7 +5050,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
4669
5050
|
* @see {@link permissionsIn} for channel-specific permissions
|
|
4670
5051
|
*/
|
|
4671
5052
|
get permissions() {
|
|
4672
|
-
return new
|
|
5053
|
+
return new import_util18.PermissionsBitField(this._effectivePermissions([], []));
|
|
4673
5054
|
}
|
|
4674
5055
|
/**
|
|
4675
5056
|
* Effective permissions in a channel (roles + overwrites).
|
|
@@ -4677,7 +5058,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
4677
5058
|
* @returns Computed permissions bitfield
|
|
4678
5059
|
*/
|
|
4679
5060
|
permissionsIn(channel) {
|
|
4680
|
-
return new
|
|
5061
|
+
return new import_util18.PermissionsBitField(
|
|
4681
5062
|
this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
|
|
4682
5063
|
);
|
|
4683
5064
|
}
|
|
@@ -4702,19 +5083,19 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
4702
5083
|
* False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
|
|
4703
5084
|
*/
|
|
4704
5085
|
get kickable() {
|
|
4705
|
-
return this._moderatableWith(
|
|
5086
|
+
return this._moderatableWith(import_util18.PermissionFlags.KickMembers);
|
|
4706
5087
|
}
|
|
4707
5088
|
/**
|
|
4708
5089
|
* Whether the bot can ban this member (cache-only; needs `members.me`).
|
|
4709
5090
|
*/
|
|
4710
5091
|
get bannable() {
|
|
4711
|
-
return this._moderatableWith(
|
|
5092
|
+
return this._moderatableWith(import_util18.PermissionFlags.BanMembers);
|
|
4712
5093
|
}
|
|
4713
5094
|
/**
|
|
4714
5095
|
* Whether the bot can timeout this member (cache-only; needs `members.me`).
|
|
4715
5096
|
*/
|
|
4716
5097
|
get moderatable() {
|
|
4717
|
-
return this._moderatableWith(
|
|
5098
|
+
return this._moderatableWith(import_util18.PermissionFlags.ModerateMembers);
|
|
4718
5099
|
}
|
|
4719
5100
|
_moderatableWith(flag) {
|
|
4720
5101
|
const me = this.guild.members.me;
|
|
@@ -4765,8 +5146,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
4765
5146
|
};
|
|
4766
5147
|
|
|
4767
5148
|
// src/Domain/Guild/GuildSticker.ts
|
|
4768
|
-
var
|
|
4769
|
-
var
|
|
5149
|
+
var import_types27 = require("@fluxerjs/types");
|
|
5150
|
+
var import_util19 = require("@fluxerjs/util");
|
|
4770
5151
|
var GuildSticker = class extends Base {
|
|
4771
5152
|
client;
|
|
4772
5153
|
id;
|
|
@@ -4808,15 +5189,15 @@ var GuildSticker = class extends Base {
|
|
|
4808
5189
|
}
|
|
4809
5190
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
4810
5191
|
get createdTimestamp() {
|
|
4811
|
-
return
|
|
5192
|
+
return import_util19.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
4812
5193
|
}
|
|
4813
5194
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
4814
5195
|
get createdAt() {
|
|
4815
|
-
return
|
|
5196
|
+
return import_util19.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
4816
5197
|
}
|
|
4817
5198
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
4818
5199
|
async delete(reason) {
|
|
4819
|
-
await this.client.rest.delete(
|
|
5200
|
+
await this.client.rest.delete(import_types27.Routes.guildSticker(this.guildId, this.id), {
|
|
4820
5201
|
auth: true,
|
|
4821
5202
|
...auditReasonHeaders(reason)
|
|
4822
5203
|
});
|
|
@@ -4829,7 +5210,7 @@ var GuildSticker = class extends Base {
|
|
|
4829
5210
|
*/
|
|
4830
5211
|
async edit(options) {
|
|
4831
5212
|
const { reason, ...body } = options;
|
|
4832
|
-
const data = await this.client.rest.patch(
|
|
5213
|
+
const data = await this.client.rest.patch(import_types27.Routes.guildSticker(this.guildId, this.id), {
|
|
4833
5214
|
body,
|
|
4834
5215
|
auth: true,
|
|
4835
5216
|
...auditReasonHeaders(reason)
|
|
@@ -4842,8 +5223,8 @@ var GuildSticker = class extends Base {
|
|
|
4842
5223
|
};
|
|
4843
5224
|
|
|
4844
5225
|
// src/Domain/Guild/Role.ts
|
|
4845
|
-
var
|
|
4846
|
-
var
|
|
5226
|
+
var import_types28 = require("@fluxerjs/types");
|
|
5227
|
+
var import_util20 = require("@fluxerjs/util");
|
|
4847
5228
|
var Role = class _Role extends Base {
|
|
4848
5229
|
/** Parent client instance. */
|
|
4849
5230
|
client;
|
|
@@ -4865,6 +5246,8 @@ var Role = class _Role extends Base {
|
|
|
4865
5246
|
mentionable;
|
|
4866
5247
|
/** Unicode emoji for this role (null = none). */
|
|
4867
5248
|
unicodeEmoji;
|
|
5249
|
+
/** Role icon image hash (null = none). */
|
|
5250
|
+
icon;
|
|
4868
5251
|
/** Hoist position (null = not hoisted). */
|
|
4869
5252
|
hoistPosition;
|
|
4870
5253
|
constructor(client, data, guildId) {
|
|
@@ -4872,22 +5255,28 @@ var Role = class _Role extends Base {
|
|
|
4872
5255
|
this.client = client;
|
|
4873
5256
|
this.id = data.id;
|
|
4874
5257
|
this.guildId = guildId;
|
|
4875
|
-
this.name = data.name;
|
|
4876
|
-
this.color = data.color;
|
|
4877
|
-
this.position = data.position;
|
|
4878
|
-
this._permissions = data.permissions;
|
|
5258
|
+
this.name = data.name ?? "";
|
|
5259
|
+
this.color = data.color ?? 0;
|
|
5260
|
+
this.position = data.position ?? 0;
|
|
5261
|
+
this._permissions = data.permissions ?? "0";
|
|
4879
5262
|
this.hoist = !!data.hoist;
|
|
4880
5263
|
this.mentionable = !!data.mentionable;
|
|
4881
5264
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5265
|
+
this.icon = data.icon ?? null;
|
|
4882
5266
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4883
5267
|
}
|
|
4884
5268
|
/**
|
|
4885
5269
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4886
5270
|
*/
|
|
4887
5271
|
get permissions() {
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
5272
|
+
let bits;
|
|
5273
|
+
try {
|
|
5274
|
+
bits = BigInt(this._permissions ?? "0");
|
|
5275
|
+
} catch {
|
|
5276
|
+
bits = 0n;
|
|
5277
|
+
}
|
|
5278
|
+
return new import_util20.PermissionsBitField(
|
|
5279
|
+
(bits & import_util20.PermissionFlags.Administrator) !== 0n ? import_util20.ALL_PERMISSIONS_BIGINT : bits
|
|
4891
5280
|
);
|
|
4892
5281
|
}
|
|
4893
5282
|
/**
|
|
@@ -4904,25 +5293,26 @@ var Role = class _Role extends Base {
|
|
|
4904
5293
|
*/
|
|
4905
5294
|
/** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
|
|
4906
5295
|
get createdTimestamp() {
|
|
4907
|
-
return
|
|
5296
|
+
return import_util20.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
4908
5297
|
}
|
|
4909
5298
|
/** Date when this role was created, derived from its snowflake ID. */
|
|
4910
5299
|
get createdAt() {
|
|
4911
|
-
return
|
|
5300
|
+
return import_util20.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
4912
5301
|
}
|
|
4913
5302
|
toString() {
|
|
4914
5303
|
return `<@&${this.id}>`;
|
|
4915
5304
|
}
|
|
4916
5305
|
/** @internal */
|
|
4917
5306
|
_patch(data) {
|
|
4918
|
-
this.name = data.name;
|
|
4919
|
-
this.color = data.color;
|
|
4920
|
-
this.position = data.position;
|
|
4921
|
-
this._permissions = data.permissions;
|
|
4922
|
-
this.hoist = !!data.hoist;
|
|
4923
|
-
this.mentionable = !!data.mentionable;
|
|
4924
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4925
|
-
this.
|
|
5307
|
+
if (data.name !== void 0) this.name = data.name;
|
|
5308
|
+
if (data.color !== void 0) this.color = data.color;
|
|
5309
|
+
if (data.position !== void 0) this.position = data.position;
|
|
5310
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
5311
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
5312
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
5313
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5314
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
5315
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4926
5316
|
}
|
|
4927
5317
|
/**
|
|
4928
5318
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4940,6 +5330,7 @@ var Role = class _Role extends Base {
|
|
|
4940
5330
|
hoist: this.hoist,
|
|
4941
5331
|
mentionable: this.mentionable,
|
|
4942
5332
|
unicode_emoji: this.unicodeEmoji,
|
|
5333
|
+
icon: this.icon,
|
|
4943
5334
|
hoist_position: this.hoistPosition
|
|
4944
5335
|
},
|
|
4945
5336
|
this.guildId
|
|
@@ -4952,7 +5343,7 @@ var Role = class _Role extends Base {
|
|
|
4952
5343
|
*/
|
|
4953
5344
|
async edit(options) {
|
|
4954
5345
|
const body = toRoleEditBody(options);
|
|
4955
|
-
const data = await this.client.rest.patch(
|
|
5346
|
+
const data = await this.client.rest.patch(import_types28.Routes.guildRole(this.guildId, this.id), {
|
|
4956
5347
|
body: Object.keys(body).length ? body : void 0,
|
|
4957
5348
|
auth: true,
|
|
4958
5349
|
...auditReasonHeaders(options.reason)
|
|
@@ -4965,7 +5356,7 @@ var Role = class _Role extends Base {
|
|
|
4965
5356
|
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
4966
5357
|
*/
|
|
4967
5358
|
async delete(reason) {
|
|
4968
|
-
await this.client.rest.delete(
|
|
5359
|
+
await this.client.rest.delete(import_types28.Routes.guildRole(this.guildId, this.id), {
|
|
4969
5360
|
auth: true,
|
|
4970
5361
|
...auditReasonHeaders(reason)
|
|
4971
5362
|
});
|
|
@@ -5066,7 +5457,7 @@ function syncChannels(guild, channels) {
|
|
|
5066
5457
|
}
|
|
5067
5458
|
}
|
|
5068
5459
|
function isThreadChannelType(type) {
|
|
5069
|
-
return type ===
|
|
5460
|
+
return type === import_types29.ChannelType.AnnouncementThread || type === import_types29.ChannelType.PublicThread || type === import_types29.ChannelType.PrivateThread;
|
|
5070
5461
|
}
|
|
5071
5462
|
function syncThreads(guild, threads, alsoKeep = /* @__PURE__ */ new Set()) {
|
|
5072
5463
|
const keep = new Set(alsoKeep);
|
|
@@ -5117,6 +5508,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5117
5508
|
});
|
|
5118
5509
|
this.client = client;
|
|
5119
5510
|
}
|
|
5511
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5120
5512
|
/**
|
|
5121
5513
|
* Remove a channel from cache. Does not delete it on the API.
|
|
5122
5514
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -5129,9 +5521,11 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5129
5521
|
}
|
|
5130
5522
|
return deleted;
|
|
5131
5523
|
}
|
|
5132
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5524
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
5133
5525
|
async resolve(channelId) {
|
|
5134
|
-
|
|
5526
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5527
|
+
const cached = this.get(id);
|
|
5528
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
5135
5529
|
}
|
|
5136
5530
|
/**
|
|
5137
5531
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5144,10 +5538,23 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5144
5538
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5145
5539
|
*/
|
|
5146
5540
|
async fetch(channelId, options) {
|
|
5147
|
-
const
|
|
5148
|
-
|
|
5541
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5542
|
+
const cached = this.get(id);
|
|
5543
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5544
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5545
|
+
}
|
|
5546
|
+
async fetchFresh(channelId) {
|
|
5149
5547
|
try {
|
|
5150
|
-
const data =
|
|
5548
|
+
const data = assertApiObjectWithId(
|
|
5549
|
+
await this.client.rest.get(import_types30.Routes.channel(channelId)),
|
|
5550
|
+
"channels.fetch()"
|
|
5551
|
+
);
|
|
5552
|
+
const existing = this.get(channelId);
|
|
5553
|
+
if (existing && existing.type === data.type) {
|
|
5554
|
+
existing._patch(data);
|
|
5555
|
+
putChannel(this.client, existing);
|
|
5556
|
+
return existing;
|
|
5557
|
+
}
|
|
5151
5558
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5152
5559
|
if (guildId) {
|
|
5153
5560
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5192,7 +5599,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5192
5599
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
5193
5600
|
});
|
|
5194
5601
|
const data = await this.client.rest.post(
|
|
5195
|
-
|
|
5602
|
+
import_types30.Routes.channelMessages(channelId),
|
|
5196
5603
|
postPayload
|
|
5197
5604
|
);
|
|
5198
5605
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -5202,28 +5609,28 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
|
5202
5609
|
|
|
5203
5610
|
// src/ClientCore/ClientEmoji.ts
|
|
5204
5611
|
var import_collection9 = require("@fluxerjs/collection");
|
|
5205
|
-
var
|
|
5206
|
-
var
|
|
5612
|
+
var import_types31 = require("@fluxerjs/types");
|
|
5613
|
+
var import_util21 = require("@fluxerjs/util");
|
|
5207
5614
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
5208
5615
|
if (typeof emoji === "object" && emoji.id) {
|
|
5209
|
-
return (0,
|
|
5616
|
+
return (0, import_util21.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
|
|
5210
5617
|
}
|
|
5211
|
-
const parsed = (0,
|
|
5618
|
+
const parsed = (0, import_util21.parseEmoji)(
|
|
5212
5619
|
typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
|
|
5213
5620
|
);
|
|
5214
5621
|
if (!parsed) {
|
|
5215
5622
|
throw new import_util2.FluxerError("Invalid emoji", { code: import_util.ErrorCodes.InvalidEmoji });
|
|
5216
5623
|
}
|
|
5217
5624
|
if (parsed.id) {
|
|
5218
|
-
return (0,
|
|
5625
|
+
return (0, import_util21.formatEmoji)(parsed);
|
|
5219
5626
|
}
|
|
5220
5627
|
if (!/^\w+$/.test(parsed.name)) return parsed.name;
|
|
5221
|
-
const unicodeFromShortcode = (0,
|
|
5628
|
+
const unicodeFromShortcode = (0, import_util21.getUnicodeFromShortcode)(parsed.name);
|
|
5222
5629
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
5223
5630
|
if (guildId) {
|
|
5224
|
-
const emojis = await client.rest.get(
|
|
5631
|
+
const emojis = await client.rest.get(import_types31.Routes.guildEmojis(guildId));
|
|
5225
5632
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
5226
|
-
if (found) return (0,
|
|
5633
|
+
if (found) return (0, import_util21.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
|
|
5227
5634
|
throw new import_util2.FluxerError(
|
|
5228
5635
|
`Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format.`,
|
|
5229
5636
|
{ code: import_util.ErrorCodes.EmojiNotFound }
|
|
@@ -5238,26 +5645,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
5238
5645
|
return parsed.name;
|
|
5239
5646
|
}
|
|
5240
5647
|
async function fetchInstance(client) {
|
|
5241
|
-
const raw = await client.rest.get(
|
|
5648
|
+
const raw = await client.rest.get(import_types31.Routes.instanceDiscovery(), {
|
|
5242
5649
|
auth: false,
|
|
5243
5650
|
unversioned: true
|
|
5244
5651
|
});
|
|
5245
5652
|
return parseInstanceDiscovery(raw);
|
|
5246
5653
|
}
|
|
5247
5654
|
function fetchGatewayInfo(client) {
|
|
5248
|
-
return client.rest.get(
|
|
5655
|
+
return client.rest.get(import_types31.Routes.gatewayBot());
|
|
5249
5656
|
}
|
|
5250
5657
|
function fetchEmojiMetadata(client, emojiId) {
|
|
5251
|
-
return client.rest.get(
|
|
5658
|
+
return client.rest.get(import_types31.Routes.emojiMetadata(emojiId), { auth: true });
|
|
5252
5659
|
}
|
|
5253
5660
|
function fetchStickerMetadata(client, stickerId) {
|
|
5254
|
-
return client.rest.get(
|
|
5661
|
+
return client.rest.get(import_types31.Routes.stickerMetadata(stickerId), { auth: true });
|
|
5255
5662
|
}
|
|
5256
5663
|
function fetchApplication(client) {
|
|
5257
|
-
return client.rest.get(
|
|
5664
|
+
return client.rest.get(import_types31.Routes.applicationsMe(), { auth: true });
|
|
5258
5665
|
}
|
|
5259
5666
|
async function fetchOAuthApplications(client) {
|
|
5260
|
-
const data = await client.rest.get(
|
|
5667
|
+
const data = await client.rest.get(import_types31.Routes.oauth2ApplicationsMe(), { auth: true });
|
|
5261
5668
|
if (Array.isArray(data)) return data;
|
|
5262
5669
|
if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
|
|
5263
5670
|
return data.applications;
|
|
@@ -5276,14 +5683,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
5276
5683
|
}
|
|
5277
5684
|
function preloadMessages(client, channelIds) {
|
|
5278
5685
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
5279
|
-
return client.rest.post(
|
|
5686
|
+
return client.rest.post(import_types31.Routes.preloadMessages(), {
|
|
5280
5687
|
body: { channels: channelIds },
|
|
5281
5688
|
auth: true
|
|
5282
5689
|
});
|
|
5283
5690
|
}
|
|
5284
5691
|
function preloadMessagesAlt(client, channelIds) {
|
|
5285
5692
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
5286
|
-
return client.rest.post(
|
|
5693
|
+
return client.rest.post(import_types31.Routes.preloadMessagesAlt(), {
|
|
5287
5694
|
body: { channels: channelIds },
|
|
5288
5695
|
auth: true
|
|
5289
5696
|
});
|
|
@@ -5291,7 +5698,7 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
5291
5698
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
5292
5699
|
validateBulkMessageFetchRequests(requests);
|
|
5293
5700
|
const wire = toBulkFetchWire(requests);
|
|
5294
|
-
const data = await client.rest.post(
|
|
5701
|
+
const data = await client.rest.post(import_types31.Routes.channelsMessagesBulk(), {
|
|
5295
5702
|
body: { requests: wire },
|
|
5296
5703
|
auth: true
|
|
5297
5704
|
});
|
|
@@ -5308,12 +5715,74 @@ async function bulkFetchMessages(client, requests, options = {}) {
|
|
|
5308
5715
|
};
|
|
5309
5716
|
}
|
|
5310
5717
|
async function searchMessages(client, options = {}) {
|
|
5311
|
-
const data = await client.rest.post(
|
|
5718
|
+
const data = await client.rest.post(import_types31.Routes.searchMessages(), {
|
|
5312
5719
|
body: toMessageSearchBody(options),
|
|
5313
5720
|
auth: true
|
|
5314
5721
|
});
|
|
5315
5722
|
return toMessageSearchResponse(data);
|
|
5316
5723
|
}
|
|
5724
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5725
|
+
return client.rest.get(
|
|
5726
|
+
import_types31.Routes.emojiSource(emojiId),
|
|
5727
|
+
{ auth: true }
|
|
5728
|
+
);
|
|
5729
|
+
}
|
|
5730
|
+
function fetchStickerSource(client, stickerId) {
|
|
5731
|
+
return client.rest.get(
|
|
5732
|
+
import_types31.Routes.stickerSource(stickerId),
|
|
5733
|
+
{ auth: true }
|
|
5734
|
+
);
|
|
5735
|
+
}
|
|
5736
|
+
function fetchDiscoveryCategories(client) {
|
|
5737
|
+
return client.rest.get(
|
|
5738
|
+
import_types31.Routes.discoveryCategories(),
|
|
5739
|
+
{ auth: true }
|
|
5740
|
+
);
|
|
5741
|
+
}
|
|
5742
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5743
|
+
const params = new URLSearchParams();
|
|
5744
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5745
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5746
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5747
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5748
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5749
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5750
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5751
|
+
const qs2 = params.toString();
|
|
5752
|
+
return client.rest.get(
|
|
5753
|
+
qs2 ? `${import_types31.Routes.discoveryGuilds()}?${qs2}` : import_types31.Routes.discoveryGuilds(),
|
|
5754
|
+
{ auth: true }
|
|
5755
|
+
);
|
|
5756
|
+
}
|
|
5757
|
+
function fetchExperiments(client) {
|
|
5758
|
+
return client.rest.get(import_types31.Routes.experiments(), {
|
|
5759
|
+
auth: true
|
|
5760
|
+
});
|
|
5761
|
+
}
|
|
5762
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5763
|
+
return client.rest.post(
|
|
5764
|
+
import_types31.Routes.attachmentsRefreshUrls(),
|
|
5765
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5766
|
+
);
|
|
5767
|
+
}
|
|
5768
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5769
|
+
const params = new URLSearchParams();
|
|
5770
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5771
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5772
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5773
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5774
|
+
const qs2 = params.toString();
|
|
5775
|
+
return client.rest.get(
|
|
5776
|
+
qs2 ? `${import_types31.Routes.instanceBadges()}?${qs2}` : import_types31.Routes.instanceBadges(),
|
|
5777
|
+
{ auth: false }
|
|
5778
|
+
);
|
|
5779
|
+
}
|
|
5780
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5781
|
+
return client.rest.post(
|
|
5782
|
+
import_types31.Routes.channelPostData(channelId),
|
|
5783
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5784
|
+
);
|
|
5785
|
+
}
|
|
5317
5786
|
|
|
5318
5787
|
// src/ClientCore/ClientEvents.ts
|
|
5319
5788
|
function createEventMethods(client) {
|
|
@@ -5333,17 +5802,18 @@ var import_ws = require("@fluxerjs/ws");
|
|
|
5333
5802
|
|
|
5334
5803
|
// src/Domain/Guild/Guild.ts
|
|
5335
5804
|
var import_collection12 = require("@fluxerjs/collection");
|
|
5336
|
-
var
|
|
5337
|
-
var
|
|
5805
|
+
var import_types41 = require("@fluxerjs/types");
|
|
5806
|
+
var import_util23 = require("@fluxerjs/util");
|
|
5338
5807
|
|
|
5339
5808
|
// src/ClientCore/GuildMemberManager.ts
|
|
5340
5809
|
var import_collection10 = require("@fluxerjs/collection");
|
|
5341
|
-
var
|
|
5810
|
+
var import_types32 = require("@fluxerjs/types");
|
|
5342
5811
|
var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
5343
5812
|
constructor(guild) {
|
|
5344
5813
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5345
5814
|
this.guild = guild;
|
|
5346
5815
|
}
|
|
5816
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5347
5817
|
/**
|
|
5348
5818
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5349
5819
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5355,7 +5825,9 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5355
5825
|
* console.log(member.displayName);
|
|
5356
5826
|
*/
|
|
5357
5827
|
async resolve(userId) {
|
|
5358
|
-
|
|
5828
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5829
|
+
const cached = this.get(id);
|
|
5830
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5359
5831
|
}
|
|
5360
5832
|
/**
|
|
5361
5833
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5383,10 +5855,11 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5383
5855
|
return this.guild.fetchMe();
|
|
5384
5856
|
}
|
|
5385
5857
|
async fetch(userIdOrOptions, options) {
|
|
5386
|
-
if (typeof userIdOrOptions === "string") {
|
|
5387
|
-
const
|
|
5388
|
-
|
|
5389
|
-
|
|
5858
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5859
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5860
|
+
const cached = this.get(id);
|
|
5861
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5862
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5390
5863
|
}
|
|
5391
5864
|
return this.fetchMany(userIdOrOptions);
|
|
5392
5865
|
}
|
|
@@ -5395,10 +5868,14 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5395
5868
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
5396
5869
|
if (options?.after) params.set("after", options.after);
|
|
5397
5870
|
const qs2 = params.toString();
|
|
5398
|
-
const url =
|
|
5399
|
-
const data =
|
|
5871
|
+
const url = import_types32.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5872
|
+
const data = assertApiArray(
|
|
5873
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5874
|
+
"members.fetch()"
|
|
5875
|
+
);
|
|
5400
5876
|
const members = [];
|
|
5401
5877
|
for (const m of data) {
|
|
5878
|
+
if (!m?.user?.id) continue;
|
|
5402
5879
|
const member = new GuildMember(
|
|
5403
5880
|
this.guild.client,
|
|
5404
5881
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5418,7 +5895,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5418
5895
|
*/
|
|
5419
5896
|
async search(options = {}) {
|
|
5420
5897
|
const data = await this.guild.client.rest.post(
|
|
5421
|
-
|
|
5898
|
+
import_types32.Routes.guildMembersSearch(this.guild.id),
|
|
5422
5899
|
{ body: toMemberSearchBody(options), auth: true }
|
|
5423
5900
|
);
|
|
5424
5901
|
const offset = options.offset ?? 0;
|
|
@@ -5444,7 +5921,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
|
5444
5921
|
};
|
|
5445
5922
|
|
|
5446
5923
|
// src/Domain/Guild/Admin.ts
|
|
5447
|
-
var
|
|
5924
|
+
var import_types33 = require("@fluxerjs/types");
|
|
5448
5925
|
function toAuditLogEntryPayload(entry, guildId) {
|
|
5449
5926
|
return {
|
|
5450
5927
|
id: entry.id,
|
|
@@ -5465,7 +5942,7 @@ function toVanityPayload(data) {
|
|
|
5465
5942
|
return { code: data.code ?? null, uses: data.uses };
|
|
5466
5943
|
}
|
|
5467
5944
|
async function fetchAuditLogs(guild, options) {
|
|
5468
|
-
const url =
|
|
5945
|
+
const url = import_types33.Routes.guildAuditLogs(guild.id) + qs({
|
|
5469
5946
|
limit: options?.limit,
|
|
5470
5947
|
before: options?.before,
|
|
5471
5948
|
after: options?.after,
|
|
@@ -5489,7 +5966,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
5489
5966
|
};
|
|
5490
5967
|
}
|
|
5491
5968
|
async function editGuild(guild, options) {
|
|
5492
|
-
const data = await guild.client.rest.patch(
|
|
5969
|
+
const data = await guild.client.rest.patch(import_types33.Routes.guild(guild.id), {
|
|
5493
5970
|
body: toGuildEditBody(options),
|
|
5494
5971
|
auth: true
|
|
5495
5972
|
});
|
|
@@ -5497,13 +5974,13 @@ async function editGuild(guild, options) {
|
|
|
5497
5974
|
return guild;
|
|
5498
5975
|
}
|
|
5499
5976
|
async function fetchVanityURL(guild) {
|
|
5500
|
-
const data = await guild.client.rest.get(
|
|
5977
|
+
const data = await guild.client.rest.get(import_types33.Routes.guildVanityUrl(guild.id), {
|
|
5501
5978
|
auth: true
|
|
5502
5979
|
});
|
|
5503
5980
|
return toVanityPayload(data);
|
|
5504
5981
|
}
|
|
5505
5982
|
async function editVanityURL(guild, code) {
|
|
5506
|
-
const data = await guild.client.rest.patch(
|
|
5983
|
+
const data = await guild.client.rest.patch(import_types33.Routes.guildVanityUrl(guild.id), {
|
|
5507
5984
|
body: { code },
|
|
5508
5985
|
auth: true
|
|
5509
5986
|
});
|
|
@@ -5511,14 +5988,14 @@ async function editVanityURL(guild, code) {
|
|
|
5511
5988
|
return toVanityPayload(data);
|
|
5512
5989
|
}
|
|
5513
5990
|
async function fetchDiscoveryStatus(guild) {
|
|
5514
|
-
const data = await guild.client.rest.get(
|
|
5991
|
+
const data = await guild.client.rest.get(import_types33.Routes.guildDiscovery(guild.id), {
|
|
5515
5992
|
auth: true
|
|
5516
5993
|
});
|
|
5517
5994
|
return toDiscoveryStatusPayload(data);
|
|
5518
5995
|
}
|
|
5519
5996
|
async function applyForDiscovery(guild, options) {
|
|
5520
5997
|
const data = await guild.client.rest.post(
|
|
5521
|
-
|
|
5998
|
+
import_types33.Routes.guildDiscovery(guild.id),
|
|
5522
5999
|
{
|
|
5523
6000
|
body: toDiscoveryBody(options),
|
|
5524
6001
|
auth: true
|
|
@@ -5528,7 +6005,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
5528
6005
|
}
|
|
5529
6006
|
async function editDiscoveryApplication(guild, options) {
|
|
5530
6007
|
const data = await guild.client.rest.patch(
|
|
5531
|
-
|
|
6008
|
+
import_types33.Routes.guildDiscovery(guild.id),
|
|
5532
6009
|
{
|
|
5533
6010
|
body: toDiscoveryBody(options),
|
|
5534
6011
|
auth: true
|
|
@@ -5537,34 +6014,39 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
5537
6014
|
return toDiscoveryApplicationPayload(data);
|
|
5538
6015
|
}
|
|
5539
6016
|
async function withdrawDiscoveryApplication(guild) {
|
|
5540
|
-
await guild.client.rest.delete(
|
|
6017
|
+
await guild.client.rest.delete(import_types33.Routes.guildDiscovery(guild.id), { auth: true });
|
|
5541
6018
|
}
|
|
5542
6019
|
async function deleteGuild(guild, options) {
|
|
5543
6020
|
const body = options ? toSudoBody(options) : {};
|
|
5544
|
-
await guild.client.rest.post(
|
|
6021
|
+
await guild.client.rest.post(import_types33.Routes.guildDelete(guild.id), {
|
|
5545
6022
|
body,
|
|
5546
6023
|
auth: true
|
|
5547
6024
|
});
|
|
5548
6025
|
guild.client.guilds.delete(guild.id);
|
|
5549
6026
|
}
|
|
5550
6027
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
5551
|
-
await guild.client.rest.post(
|
|
6028
|
+
await guild.client.rest.post(import_types33.Routes.guildTransferOwnership(guild.id), {
|
|
5552
6029
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
5553
6030
|
auth: true
|
|
5554
6031
|
});
|
|
5555
6032
|
}
|
|
5556
6033
|
|
|
5557
6034
|
// src/Domain/Guild/Channels.ts
|
|
5558
|
-
var
|
|
6035
|
+
var import_types34 = require("@fluxerjs/types");
|
|
5559
6036
|
async function createChannel(guild, options) {
|
|
5560
|
-
const created = await guild.client.rest.post(
|
|
6037
|
+
const created = await guild.client.rest.post(import_types34.Routes.guildChannels(guild.id), {
|
|
5561
6038
|
body: toChannelCreateBody(options),
|
|
5562
6039
|
auth: true
|
|
5563
6040
|
});
|
|
5564
6041
|
return cacheChannel(guild, created);
|
|
5565
6042
|
}
|
|
5566
6043
|
async function fetchChannels(guild) {
|
|
5567
|
-
const
|
|
6044
|
+
const raw = await guild.client.rest.get(import_types34.Routes.guildChannels(guild.id));
|
|
6045
|
+
if (!Array.isArray(raw))
|
|
6046
|
+
throw new TypeError(
|
|
6047
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
6048
|
+
);
|
|
6049
|
+
const data = raw;
|
|
5568
6050
|
const channels = [];
|
|
5569
6051
|
for (const ch of data) {
|
|
5570
6052
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5573,17 +6055,17 @@ async function fetchChannels(guild) {
|
|
|
5573
6055
|
return channels;
|
|
5574
6056
|
}
|
|
5575
6057
|
async function setChannelPositions(guild, updates) {
|
|
5576
|
-
await guild.client.rest.patch(
|
|
6058
|
+
await guild.client.rest.patch(import_types34.Routes.guildChannels(guild.id), {
|
|
5577
6059
|
body: toChannelPositionBody(updates),
|
|
5578
6060
|
auth: true
|
|
5579
6061
|
});
|
|
5580
6062
|
}
|
|
5581
6063
|
async function fetchWebhooks(guild) {
|
|
5582
|
-
const data = await guild.client.rest.get(
|
|
6064
|
+
const data = await guild.client.rest.get(import_types34.Routes.guildWebhooks(guild.id));
|
|
5583
6065
|
return data.map((w) => new Webhook(guild.client, w));
|
|
5584
6066
|
}
|
|
5585
6067
|
async function fetchInvites(guild) {
|
|
5586
|
-
const data = await guild.client.rest.get(
|
|
6068
|
+
const data = await guild.client.rest.get(import_types34.Routes.guildInvites(guild.id));
|
|
5587
6069
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
5588
6070
|
}
|
|
5589
6071
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -5603,14 +6085,14 @@ function resolveGuildOnlineCount(data) {
|
|
|
5603
6085
|
}
|
|
5604
6086
|
|
|
5605
6087
|
// src/Domain/Guild/Emojis.ts
|
|
5606
|
-
var
|
|
6088
|
+
var import_types35 = require("@fluxerjs/types");
|
|
5607
6089
|
async function fetchEmojis(guild) {
|
|
5608
|
-
const data = await guild.client.rest.get(
|
|
6090
|
+
const data = await guild.client.rest.get(import_types35.Routes.guildEmojis(guild.id));
|
|
5609
6091
|
return data.map((e) => cacheEmoji(guild, e));
|
|
5610
6092
|
}
|
|
5611
6093
|
async function fetchEmoji(guild, emojiId) {
|
|
5612
6094
|
try {
|
|
5613
|
-
const data = await guild.client.rest.get(
|
|
6095
|
+
const data = await guild.client.rest.get(import_types35.Routes.guildEmoji(guild.id, emojiId));
|
|
5614
6096
|
return cacheEmoji(guild, data);
|
|
5615
6097
|
} catch (err) {
|
|
5616
6098
|
rethrowMapped(err, {
|
|
@@ -5621,7 +6103,7 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
5621
6103
|
}
|
|
5622
6104
|
async function createEmoji(guild, options) {
|
|
5623
6105
|
const { reason, ...body } = options;
|
|
5624
|
-
const data = await guild.client.rest.post(
|
|
6106
|
+
const data = await guild.client.rest.post(import_types35.Routes.guildEmojis(guild.id), {
|
|
5625
6107
|
body,
|
|
5626
6108
|
auth: true,
|
|
5627
6109
|
...auditReasonHeaders(reason)
|
|
@@ -5629,7 +6111,7 @@ async function createEmoji(guild, options) {
|
|
|
5629
6111
|
return cacheEmoji(guild, data);
|
|
5630
6112
|
}
|
|
5631
6113
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
5632
|
-
const data = await guild.client.rest.post(
|
|
6114
|
+
const data = await guild.client.rest.post(import_types35.Routes.guildEmojisClone(guild.id), {
|
|
5633
6115
|
body: { source_emoji_id: sourceEmojiId },
|
|
5634
6116
|
auth: true
|
|
5635
6117
|
});
|
|
@@ -5637,7 +6119,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
5637
6119
|
}
|
|
5638
6120
|
async function createEmojisBulk(guild, emojis) {
|
|
5639
6121
|
const data = await guild.client.rest.post(
|
|
5640
|
-
|
|
6122
|
+
import_types35.Routes.guildEmojisBulk(guild.id),
|
|
5641
6123
|
{ body: { emojis }, auth: true }
|
|
5642
6124
|
);
|
|
5643
6125
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
@@ -5657,18 +6139,22 @@ var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
|
5657
6139
|
};
|
|
5658
6140
|
|
|
5659
6141
|
// src/Domain/Guild/MemberHttp.ts
|
|
5660
|
-
var
|
|
6142
|
+
var import_types36 = require("@fluxerjs/types");
|
|
5661
6143
|
async function fetchMember(guild, userId) {
|
|
6144
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5662
6145
|
try {
|
|
5663
6146
|
const data = await guild.client.rest.get(
|
|
5664
|
-
|
|
6147
|
+
import_types36.Routes.guildMember(guild.id, id)
|
|
5665
6148
|
);
|
|
6149
|
+
if (!data?.user?.id) {
|
|
6150
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
6151
|
+
}
|
|
5666
6152
|
return cacheMember(guild, data);
|
|
5667
6153
|
} catch (err) {
|
|
5668
6154
|
rethrowMapped(err, {
|
|
5669
6155
|
notFound: {
|
|
5670
6156
|
code: import_util.ErrorCodes.MemberNotFound,
|
|
5671
|
-
message: `Member ${
|
|
6157
|
+
message: `Member ${id} not found in guild`
|
|
5672
6158
|
},
|
|
5673
6159
|
fallback: "Failed to fetch guild member"
|
|
5674
6160
|
});
|
|
@@ -5676,17 +6162,20 @@ async function fetchMember(guild, userId) {
|
|
|
5676
6162
|
}
|
|
5677
6163
|
async function fetchMe(guild) {
|
|
5678
6164
|
const data = await guild.client.rest.get(
|
|
5679
|
-
|
|
6165
|
+
import_types36.Routes.guildMemberMe(guild.id),
|
|
5680
6166
|
{ auth: true }
|
|
5681
6167
|
);
|
|
6168
|
+
if (!data?.user?.id) {
|
|
6169
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
6170
|
+
}
|
|
5682
6171
|
return cacheMember(guild, data);
|
|
5683
6172
|
}
|
|
5684
6173
|
|
|
5685
6174
|
// src/Domain/Guild/Moderation.ts
|
|
5686
|
-
var
|
|
6175
|
+
var import_types38 = require("@fluxerjs/types");
|
|
5687
6176
|
|
|
5688
6177
|
// src/Domain/Guild/GuildBan.ts
|
|
5689
|
-
var
|
|
6178
|
+
var import_types37 = require("@fluxerjs/types");
|
|
5690
6179
|
function parseOptionalDate2(value) {
|
|
5691
6180
|
if (value == null || value === "") return null;
|
|
5692
6181
|
const date = new Date(value);
|
|
@@ -5713,7 +6202,7 @@ var GuildBan = class extends Base {
|
|
|
5713
6202
|
* Requires Ban Members permission.
|
|
5714
6203
|
*/
|
|
5715
6204
|
async unban(reason) {
|
|
5716
|
-
await this.client.rest.delete(
|
|
6205
|
+
await this.client.rest.delete(import_types37.Routes.guildBan(this.guildId, this.user.id), {
|
|
5717
6206
|
auth: true,
|
|
5718
6207
|
...auditReasonHeaders(reason)
|
|
5719
6208
|
});
|
|
@@ -5723,35 +6212,39 @@ var GuildBan = class extends Base {
|
|
|
5723
6212
|
// src/Domain/Guild/Moderation.ts
|
|
5724
6213
|
async function ban(guild, userId, options) {
|
|
5725
6214
|
const body = options ? toGuildBanBody(options) : {};
|
|
5726
|
-
await guild.client.rest.put(
|
|
6215
|
+
await guild.client.rest.put(import_types38.Routes.guildBan(guild.id, userId), {
|
|
5727
6216
|
body: Object.keys(body).length ? body : void 0,
|
|
5728
6217
|
auth: true,
|
|
5729
6218
|
...auditReasonHeaders(options?.reason)
|
|
5730
6219
|
});
|
|
5731
6220
|
}
|
|
6221
|
+
async function fetchBan(guild, userId) {
|
|
6222
|
+
const data = await guild.client.rest.get(import_types38.Routes.guildBan(guild.id, userId));
|
|
6223
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
6224
|
+
}
|
|
5732
6225
|
async function fetchBans(guild) {
|
|
5733
|
-
const data = await guild.client.rest.get(
|
|
6226
|
+
const data = await guild.client.rest.get(import_types38.Routes.guildBans(guild.id));
|
|
5734
6227
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
5735
6228
|
}
|
|
5736
6229
|
async function unban(guild, userId, reason) {
|
|
5737
|
-
await guild.client.rest.delete(
|
|
6230
|
+
await guild.client.rest.delete(import_types38.Routes.guildBan(guild.id, userId), {
|
|
5738
6231
|
auth: true,
|
|
5739
6232
|
...auditReasonHeaders(reason)
|
|
5740
6233
|
});
|
|
5741
6234
|
}
|
|
5742
6235
|
async function kick(guild, userId, reason) {
|
|
5743
|
-
await guild.client.rest.delete(
|
|
6236
|
+
await guild.client.rest.delete(import_types38.Routes.guildMember(guild.id, userId), {
|
|
5744
6237
|
auth: true,
|
|
5745
6238
|
...auditReasonHeaders(reason)
|
|
5746
6239
|
});
|
|
5747
6240
|
}
|
|
5748
6241
|
|
|
5749
6242
|
// src/Domain/Guild/Roles.ts
|
|
5750
|
-
var
|
|
5751
|
-
var
|
|
6243
|
+
var import_types39 = require("@fluxerjs/types");
|
|
6244
|
+
var import_util22 = require("@fluxerjs/util");
|
|
5752
6245
|
async function createRole(guild, options = {}) {
|
|
5753
6246
|
const body = toRoleCreateBody(options);
|
|
5754
|
-
const data = await guild.client.rest.post(
|
|
6247
|
+
const data = await guild.client.rest.post(import_types39.Routes.guildRoles(guild.id), {
|
|
5755
6248
|
body: Object.keys(body).length ? body : void 0,
|
|
5756
6249
|
auth: true,
|
|
5757
6250
|
...auditReasonHeaders(options.reason)
|
|
@@ -5759,12 +6252,14 @@ async function createRole(guild, options = {}) {
|
|
|
5759
6252
|
return cacheRole(guild, data);
|
|
5760
6253
|
}
|
|
5761
6254
|
async function fetchRoles(guild) {
|
|
5762
|
-
const data = await guild.client.rest.get(
|
|
6255
|
+
const data = await guild.client.rest.get(import_types39.Routes.guildRoles(guild.id));
|
|
6256
|
+
if (!Array.isArray(data))
|
|
6257
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5763
6258
|
return data.map((r) => cacheRole(guild, r));
|
|
5764
6259
|
}
|
|
5765
6260
|
async function fetchRole(guild, roleId2) {
|
|
5766
6261
|
try {
|
|
5767
|
-
const data = await guild.client.rest.get(
|
|
6262
|
+
const data = await guild.client.rest.get(import_types39.Routes.guildRole(guild.id, roleId2));
|
|
5768
6263
|
return cacheRole(guild, data);
|
|
5769
6264
|
} catch (err) {
|
|
5770
6265
|
rethrowMapped(err, {
|
|
@@ -5774,14 +6269,14 @@ async function fetchRole(guild, roleId2) {
|
|
|
5774
6269
|
}
|
|
5775
6270
|
}
|
|
5776
6271
|
async function resolveRoleId(guild, arg) {
|
|
5777
|
-
const parsed = (0,
|
|
6272
|
+
const parsed = (0, import_util22.parseRoleMention)(arg);
|
|
5778
6273
|
if (parsed) return parsed;
|
|
5779
6274
|
const trimmed = arg.trim();
|
|
5780
6275
|
if (/^\d{17,19}$/.test(trimmed)) return trimmed;
|
|
5781
6276
|
const needle = trimmed.toLowerCase();
|
|
5782
6277
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
5783
6278
|
if (cached) return cached.id;
|
|
5784
|
-
const roles = await guild.client.rest.get(
|
|
6279
|
+
const roles = await guild.client.rest.get(import_types39.Routes.guildRoles(guild.id));
|
|
5785
6280
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
5786
6281
|
if (!role) return null;
|
|
5787
6282
|
cacheRole(guild, role);
|
|
@@ -5790,7 +6285,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
5790
6285
|
async function setRolePositions(guild, updates) {
|
|
5791
6286
|
return replaceRoles(
|
|
5792
6287
|
guild,
|
|
5793
|
-
await guild.client.rest.patch(
|
|
6288
|
+
await guild.client.rest.patch(import_types39.Routes.guildRoles(guild.id), {
|
|
5794
6289
|
body: updates,
|
|
5795
6290
|
auth: true
|
|
5796
6291
|
})
|
|
@@ -5799,7 +6294,7 @@ async function setRolePositions(guild, updates) {
|
|
|
5799
6294
|
async function setRoleHoistPositions(guild, updates) {
|
|
5800
6295
|
return replaceRoles(
|
|
5801
6296
|
guild,
|
|
5802
|
-
await guild.client.rest.patch(
|
|
6297
|
+
await guild.client.rest.patch(import_types39.Routes.guildRolesHoistPositions(guild.id), {
|
|
5803
6298
|
body: updates.map((u) => ({
|
|
5804
6299
|
id: u.id,
|
|
5805
6300
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -5811,17 +6306,17 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
5811
6306
|
async function resetRoleHoistPositions(guild) {
|
|
5812
6307
|
return replaceRoles(
|
|
5813
6308
|
guild,
|
|
5814
|
-
await guild.client.rest.delete(
|
|
6309
|
+
await guild.client.rest.delete(import_types39.Routes.guildRolesHoistPositions(guild.id), {
|
|
5815
6310
|
auth: true
|
|
5816
6311
|
})
|
|
5817
6312
|
);
|
|
5818
6313
|
}
|
|
5819
6314
|
|
|
5820
6315
|
// src/Domain/Guild/Stickers.ts
|
|
5821
|
-
var
|
|
6316
|
+
var import_types40 = require("@fluxerjs/types");
|
|
5822
6317
|
async function createSticker(guild, options) {
|
|
5823
6318
|
const { reason, ...body } = options;
|
|
5824
|
-
const data = await guild.client.rest.post(
|
|
6319
|
+
const data = await guild.client.rest.post(import_types40.Routes.guildStickers(guild.id), {
|
|
5825
6320
|
body,
|
|
5826
6321
|
auth: true,
|
|
5827
6322
|
...auditReasonHeaders(reason)
|
|
@@ -5829,7 +6324,7 @@ async function createSticker(guild, options) {
|
|
|
5829
6324
|
return cacheSticker(guild, data);
|
|
5830
6325
|
}
|
|
5831
6326
|
async function cloneSticker(guild, sourceStickerId) {
|
|
5832
|
-
const data = await guild.client.rest.post(
|
|
6327
|
+
const data = await guild.client.rest.post(import_types40.Routes.guildStickersClone(guild.id), {
|
|
5833
6328
|
body: { source_sticker_id: sourceStickerId },
|
|
5834
6329
|
auth: true
|
|
5835
6330
|
});
|
|
@@ -5837,17 +6332,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
5837
6332
|
}
|
|
5838
6333
|
async function createStickersBulk(guild, stickers) {
|
|
5839
6334
|
const data = await guild.client.rest.post(
|
|
5840
|
-
|
|
6335
|
+
import_types40.Routes.guildStickersBulk(guild.id),
|
|
5841
6336
|
{ body: { stickers }, auth: true }
|
|
5842
6337
|
);
|
|
5843
6338
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
5844
6339
|
}
|
|
5845
6340
|
async function fetchStickers(guild) {
|
|
5846
|
-
const data = await guild.client.rest.get(
|
|
6341
|
+
const data = await guild.client.rest.get(import_types40.Routes.guildStickers(guild.id));
|
|
5847
6342
|
return data.map((s) => cacheSticker(guild, s));
|
|
5848
6343
|
}
|
|
5849
6344
|
async function fetchSticker(guild, stickerId) {
|
|
5850
|
-
const data = await guild.client.rest.get(
|
|
6345
|
+
const data = await guild.client.rest.get(import_types40.Routes.guildSticker(guild.id, stickerId));
|
|
5851
6346
|
return cacheSticker(guild, data);
|
|
5852
6347
|
}
|
|
5853
6348
|
|
|
@@ -5859,6 +6354,11 @@ var Guild = class extends Base {
|
|
|
5859
6354
|
id;
|
|
5860
6355
|
/** Whether the guild is currently available through the gateway. */
|
|
5861
6356
|
available = true;
|
|
6357
|
+
/**
|
|
6358
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6359
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6360
|
+
*/
|
|
6361
|
+
partial = true;
|
|
5862
6362
|
/** Guild name. */
|
|
5863
6363
|
name;
|
|
5864
6364
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -5931,6 +6431,10 @@ var Guild = class extends Base {
|
|
|
5931
6431
|
emojis;
|
|
5932
6432
|
/** Cached stickers in this guild. */
|
|
5933
6433
|
stickers;
|
|
6434
|
+
/** Live stages in this guild's stage channels, keyed by stage instance ID. */
|
|
6435
|
+
stageInstances;
|
|
6436
|
+
/** Most participants a stage can have while speakers use video, or null if unknown. */
|
|
6437
|
+
maxStageVideoChannelUsers;
|
|
5934
6438
|
/**
|
|
5935
6439
|
* Construct a guild from API data.
|
|
5936
6440
|
* @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE
|
|
@@ -5947,6 +6451,7 @@ var Guild = class extends Base {
|
|
|
5947
6451
|
this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
|
|
5948
6452
|
this.emojis = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.emojis });
|
|
5949
6453
|
this.stickers = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.stickers });
|
|
6454
|
+
this.stageInstances = new import_collection12.Collection();
|
|
5950
6455
|
this.name = data.name ?? "";
|
|
5951
6456
|
this.icon = data.icon ?? null;
|
|
5952
6457
|
this.banner = data.banner ?? null;
|
|
@@ -5964,7 +6469,7 @@ var Guild = class extends Base {
|
|
|
5964
6469
|
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
5965
6470
|
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
5966
6471
|
this.embedSplash = data.embed_splash ?? null;
|
|
5967
|
-
this.nsfwLevel = data.nsfw_level ??
|
|
6472
|
+
this.nsfwLevel = data.nsfw_level ?? import_types41.GuildNSFWLevel.Safe;
|
|
5968
6473
|
this.nsfw = data.nsfw ?? false;
|
|
5969
6474
|
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
5970
6475
|
this.contentWarningText = data.content_warning_text ?? null;
|
|
@@ -5976,6 +6481,7 @@ var Guild = class extends Base {
|
|
|
5976
6481
|
this.bannerHeight = data.banner_height ?? null;
|
|
5977
6482
|
this.splashWidth = data.splash_width ?? null;
|
|
5978
6483
|
this.splashHeight = data.splash_height ?? null;
|
|
6484
|
+
this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
|
|
5979
6485
|
this.memberCount = resolveGuildMemberCount(data) ?? null;
|
|
5980
6486
|
this.onlineCount = resolveGuildOnlineCount(data) ?? null;
|
|
5981
6487
|
for (const r of data.roles ?? []) {
|
|
@@ -6012,7 +6518,7 @@ var Guild = class extends Base {
|
|
|
6012
6518
|
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
6013
6519
|
}
|
|
6014
6520
|
if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
|
|
6015
|
-
if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ??
|
|
6521
|
+
if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types41.GuildNSFWLevel.Safe;
|
|
6016
6522
|
if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
|
|
6017
6523
|
if (data.content_warning_level !== void 0) {
|
|
6018
6524
|
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
@@ -6032,6 +6538,9 @@ var Guild = class extends Base {
|
|
|
6032
6538
|
if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
|
|
6033
6539
|
if (data.splash_width !== void 0) this.splashWidth = data.splash_width ?? null;
|
|
6034
6540
|
if (data.splash_height !== void 0) this.splashHeight = data.splash_height ?? null;
|
|
6541
|
+
if (data.max_stage_video_channel_users !== void 0) {
|
|
6542
|
+
this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
|
|
6543
|
+
}
|
|
6035
6544
|
const memberCount = resolveGuildMemberCount(data);
|
|
6036
6545
|
if (memberCount !== void 0) this.memberCount = memberCount;
|
|
6037
6546
|
const onlineCount = resolveGuildOnlineCount(data);
|
|
@@ -6047,11 +6556,11 @@ var Guild = class extends Base {
|
|
|
6047
6556
|
}
|
|
6048
6557
|
/** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
|
|
6049
6558
|
get createdTimestamp() {
|
|
6050
|
-
return
|
|
6559
|
+
return import_util23.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
6051
6560
|
}
|
|
6052
6561
|
/** Date when this guild was created, derived from its snowflake ID. */
|
|
6053
6562
|
get createdAt() {
|
|
6054
|
-
return
|
|
6563
|
+
return import_util23.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
6055
6564
|
}
|
|
6056
6565
|
/** The guild's name. */
|
|
6057
6566
|
toString() {
|
|
@@ -6153,6 +6662,10 @@ var Guild = class extends Base {
|
|
|
6153
6662
|
ban(userId, options) {
|
|
6154
6663
|
return ban(this, userId, options);
|
|
6155
6664
|
}
|
|
6665
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6666
|
+
fetchBan(userId) {
|
|
6667
|
+
return fetchBan(this, userId);
|
|
6668
|
+
}
|
|
6156
6669
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6157
6670
|
fetchBans() {
|
|
6158
6671
|
return fetchBans(this);
|
|
@@ -6248,7 +6761,7 @@ var Guild = class extends Base {
|
|
|
6248
6761
|
};
|
|
6249
6762
|
|
|
6250
6763
|
// src/Domain/Guild/Payload.ts
|
|
6251
|
-
var
|
|
6764
|
+
var import_util24 = require("@fluxerjs/util");
|
|
6252
6765
|
var TOP_LEVEL_COUNT_KEYS = [
|
|
6253
6766
|
"member_count",
|
|
6254
6767
|
"online_count",
|
|
@@ -6288,10 +6801,10 @@ function mergeTopLevelSnapshotFields(properties, raw) {
|
|
|
6288
6801
|
return out;
|
|
6289
6802
|
}
|
|
6290
6803
|
function normalizeGuildSnapshotPayload(raw) {
|
|
6291
|
-
if (!(0,
|
|
6804
|
+
if (!(0, import_util24.isRecord)(raw)) return null;
|
|
6292
6805
|
const flatPayload = isHydratableGuildPayload(raw) && (raw.roles === void 0 || Array.isArray(raw.roles)) ? raw : null;
|
|
6293
6806
|
let nestedPayload = null;
|
|
6294
|
-
if (Object.hasOwn(raw, "properties") && (0,
|
|
6807
|
+
if (Object.hasOwn(raw, "properties") && (0, import_util24.isRecord)(raw.properties)) {
|
|
6295
6808
|
const properties = raw.properties;
|
|
6296
6809
|
const rolesValid = raw.roles === void 0 || Array.isArray(raw.roles);
|
|
6297
6810
|
if (rolesValid && isHydratableGuildPayload(properties) && raw.id === properties.id) {
|
|
@@ -6303,7 +6816,7 @@ function normalizeGuildSnapshotPayload(raw) {
|
|
|
6303
6816
|
return flatPayload ?? nestedPayload;
|
|
6304
6817
|
}
|
|
6305
6818
|
function normalizeGuildUpdatePayload(raw) {
|
|
6306
|
-
if (!(0,
|
|
6819
|
+
if (!(0, import_util24.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
|
|
6307
6820
|
return raw;
|
|
6308
6821
|
}
|
|
6309
6822
|
|
|
@@ -6333,6 +6846,9 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6333
6846
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6334
6847
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6335
6848
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6849
|
+
if (resources.stageInstances !== void 0) syncStageInstances(guild, resources.stageInstances);
|
|
6850
|
+
if (resources.stageCounts !== void 0) applyStageCounts(guild, resources.stageCounts);
|
|
6851
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6336
6852
|
return { guild, created, recovered };
|
|
6337
6853
|
}
|
|
6338
6854
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6346,7 +6862,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
6346
6862
|
emojis: g.emojis,
|
|
6347
6863
|
stickers: g.stickers,
|
|
6348
6864
|
// A channel list without `threads` means this session has no viewable threads.
|
|
6349
|
-
threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
|
|
6865
|
+
threads: g.channels !== void 0 ? g.threads ?? [] : g.threads,
|
|
6866
|
+
stageInstances: g.stage_instances,
|
|
6867
|
+
stageCounts: g.stage_counts
|
|
6350
6868
|
});
|
|
6351
6869
|
if (g.voice_states?.length) {
|
|
6352
6870
|
client.emit(Events.VoiceStatesSync, {
|
|
@@ -6358,23 +6876,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
6358
6876
|
}
|
|
6359
6877
|
|
|
6360
6878
|
// src/ClientCore/ClientUser.ts
|
|
6361
|
-
var
|
|
6879
|
+
var import_types42 = require("@fluxerjs/types");
|
|
6362
6880
|
var ClientUser = class extends User {
|
|
6363
6881
|
/** Broadcast presence (gateway opcode 3) on all shards. */
|
|
6364
6882
|
setPresence(presence) {
|
|
6365
6883
|
this.client.options.presence = presence;
|
|
6366
6884
|
const wire = toPresenceWire(presence);
|
|
6367
|
-
this.client._sendToAllShards({ op:
|
|
6885
|
+
this.client._sendToAllShards({ op: import_types42.GatewayOpcodes.PresenceUpdate, d: wire });
|
|
6368
6886
|
}
|
|
6369
6887
|
/** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
|
|
6370
6888
|
async fetch() {
|
|
6371
|
-
const data = await this.client.rest.get(
|
|
6889
|
+
const data = await this.client.rest.get(import_types42.Routes.currentUser(), { auth: true });
|
|
6372
6890
|
this._patch(data);
|
|
6373
6891
|
return this;
|
|
6374
6892
|
}
|
|
6375
6893
|
/** GET /users/@me/guilds — returns camelCase partial guilds. */
|
|
6376
6894
|
async fetchGuilds(options) {
|
|
6377
|
-
const path =
|
|
6895
|
+
const path = import_types42.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
|
|
6378
6896
|
const data = await this.client.rest.get(path, { auth: true });
|
|
6379
6897
|
return data.map((g) => ({
|
|
6380
6898
|
id: g.id,
|
|
@@ -6398,7 +6916,7 @@ var ClientUser = class extends User {
|
|
|
6398
6916
|
*/
|
|
6399
6917
|
async leaveGuild(guildId, options) {
|
|
6400
6918
|
const body = options ? toSudoBody(options) : void 0;
|
|
6401
|
-
await this.client.rest.delete(
|
|
6919
|
+
await this.client.rest.delete(import_types42.Routes.leaveGuild(guildId), {
|
|
6402
6920
|
body: body && Object.keys(body).length ? body : void 0,
|
|
6403
6921
|
auth: true
|
|
6404
6922
|
});
|
|
@@ -6406,7 +6924,7 @@ var ClientUser = class extends User {
|
|
|
6406
6924
|
/** Delete every message authored by the caller across a guild (sudo). */
|
|
6407
6925
|
async bulkDeleteMyMessagesInGuild(guildId, options) {
|
|
6408
6926
|
const body = options ? toSudoBody(options) : void 0;
|
|
6409
|
-
await this.client.rest.post(
|
|
6927
|
+
await this.client.rest.post(import_types42.Routes.guildBulkDeleteMine(guildId), {
|
|
6410
6928
|
body: body && Object.keys(body).length ? body : void 0,
|
|
6411
6929
|
auth: true
|
|
6412
6930
|
});
|
|
@@ -6414,17 +6932,9 @@ var ClientUser = class extends User {
|
|
|
6414
6932
|
};
|
|
6415
6933
|
|
|
6416
6934
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6417
|
-
var
|
|
6935
|
+
var import_util25 = require("@fluxerjs/util");
|
|
6418
6936
|
function unknownUser(id) {
|
|
6419
|
-
return {
|
|
6420
|
-
id,
|
|
6421
|
-
username: "Unknown",
|
|
6422
|
-
discriminator: "0",
|
|
6423
|
-
global_name: null,
|
|
6424
|
-
avatar: null,
|
|
6425
|
-
avatar_color: null,
|
|
6426
|
-
flags: 0
|
|
6427
|
-
};
|
|
6937
|
+
return { id };
|
|
6428
6938
|
}
|
|
6429
6939
|
function indexMember(_client, guild, data) {
|
|
6430
6940
|
if (!data.user?.id) return null;
|
|
@@ -6729,50 +7239,50 @@ var guildHandlers = {
|
|
|
6729
7239
|
};
|
|
6730
7240
|
|
|
6731
7241
|
// src/ClientCore/EventHandlers/Invites.ts
|
|
6732
|
-
var
|
|
7242
|
+
var import_types43 = require("@fluxerjs/types");
|
|
6733
7243
|
function normalizeInviteCreate(client, payload) {
|
|
6734
|
-
const raw = (0,
|
|
6735
|
-
const code = (0,
|
|
7244
|
+
const raw = (0, import_util25.asRecord)(payload);
|
|
7245
|
+
const code = (0, import_util25.str)(raw?.code);
|
|
6736
7246
|
if (!raw || !code) return null;
|
|
6737
|
-
const typeNum = (0,
|
|
6738
|
-
const type = typeNum ===
|
|
7247
|
+
const typeNum = (0, import_util25.num)(raw.type);
|
|
7248
|
+
const type = typeNum === import_types43.InviteType.GroupDM ? import_types43.InviteType.GroupDM : import_types43.InviteType.Guild;
|
|
6739
7249
|
const shared = {
|
|
6740
7250
|
code,
|
|
6741
7251
|
inviter: raw.inviter ?? null,
|
|
6742
|
-
member_count: (0,
|
|
7252
|
+
member_count: (0, import_util25.num)(raw.member_count),
|
|
6743
7253
|
expires_at: raw.expires_at ?? void 0,
|
|
6744
7254
|
temporary: typeof raw.temporary === "boolean" ? raw.temporary : void 0,
|
|
6745
|
-
created_at: (0,
|
|
6746
|
-
uses: (0,
|
|
6747
|
-
max_uses: (0,
|
|
6748
|
-
max_age: (0,
|
|
7255
|
+
created_at: (0, import_util25.str)(raw.created_at),
|
|
7256
|
+
uses: (0, import_util25.num)(raw.uses),
|
|
7257
|
+
max_uses: (0, import_util25.num)(raw.max_uses),
|
|
7258
|
+
max_age: (0, import_util25.num)(raw.max_age)
|
|
6749
7259
|
};
|
|
6750
|
-
const guildObj = (0,
|
|
6751
|
-
const channelObj = (0,
|
|
6752
|
-
const guildId = (0,
|
|
6753
|
-
const channelId = (0,
|
|
7260
|
+
const guildObj = (0, import_util25.asRecord)(raw.guild);
|
|
7261
|
+
const channelObj = (0, import_util25.asRecord)(raw.channel);
|
|
7262
|
+
const guildId = (0, import_util25.str)(guildObj?.id) ?? (0, import_util25.str)(raw.guild_id) ?? "0";
|
|
7263
|
+
const channelId = (0, import_util25.str)(channelObj?.id) ?? (0, import_util25.str)(raw.channel_id) ?? "0";
|
|
6754
7264
|
const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
|
|
6755
7265
|
const cachedChannel2 = channelId !== "0" ? client.channels.get(channelId) : null;
|
|
6756
7266
|
const channel = {
|
|
6757
7267
|
id: channelId,
|
|
6758
|
-
type: (0,
|
|
6759
|
-
name: (0,
|
|
7268
|
+
type: (0, import_util25.num)(channelObj?.type) ?? cachedChannel2?.type ?? import_types43.ChannelType.GuildText,
|
|
7269
|
+
name: (0, import_util25.str)(channelObj?.name) ?? cachedChannel2?.name ?? null,
|
|
6760
7270
|
icon: channelObj?.icon ?? null
|
|
6761
7271
|
};
|
|
6762
|
-
if (type ===
|
|
7272
|
+
if (type === import_types43.InviteType.GroupDM) return { ...shared, type, channel };
|
|
6763
7273
|
return {
|
|
6764
7274
|
...shared,
|
|
6765
|
-
type:
|
|
7275
|
+
type: import_types43.InviteType.Guild,
|
|
6766
7276
|
guild: {
|
|
6767
7277
|
id: guildId,
|
|
6768
|
-
name: (0,
|
|
7278
|
+
name: (0, import_util25.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
|
|
6769
7279
|
icon: guildObj?.icon ?? null,
|
|
6770
7280
|
banner: guildObj?.banner ?? null,
|
|
6771
7281
|
splash: guildObj?.splash ?? null,
|
|
6772
7282
|
features: Array.isArray(guildObj?.features) ? guildObj.features : void 0
|
|
6773
7283
|
},
|
|
6774
7284
|
channel,
|
|
6775
|
-
presence_count: (0,
|
|
7285
|
+
presence_count: (0, import_util25.num)(raw.presence_count)
|
|
6776
7286
|
};
|
|
6777
7287
|
}
|
|
6778
7288
|
var inviteHandlers = {
|
|
@@ -6883,7 +7393,7 @@ var memberHandlers = {
|
|
|
6883
7393
|
};
|
|
6884
7394
|
|
|
6885
7395
|
// src/ClientCore/EventHandlers/Messages.ts
|
|
6886
|
-
var
|
|
7396
|
+
var import_util26 = require("@fluxerjs/util");
|
|
6887
7397
|
function cachedTextChannel(client, channelId) {
|
|
6888
7398
|
const channel = client.channels.get(channelId);
|
|
6889
7399
|
return channel?.isTextBased() ? channel : null;
|
|
@@ -6899,7 +7409,7 @@ function toPartialMessage(client, args) {
|
|
|
6899
7409
|
const cached = args.cached;
|
|
6900
7410
|
const authorId = args.authorId ?? cached?.author?.id ?? null;
|
|
6901
7411
|
const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
|
|
6902
|
-
const createdAt = cached?.timestamp ? new Date(cached.timestamp) :
|
|
7412
|
+
const createdAt = cached?.timestamp ? new Date(cached.timestamp) : import_util26.SnowflakeUtil.isValid(args.id) ? import_util26.SnowflakeUtil.dateFromSnowflake(args.id) : null;
|
|
6903
7413
|
return new PartialMessage(client, {
|
|
6904
7414
|
id: args.id,
|
|
6905
7415
|
channelId: args.channelId,
|
|
@@ -7105,6 +7615,9 @@ var passthroughHandlers = {
|
|
|
7105
7615
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7106
7616
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7107
7617
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7618
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7619
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7620
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7108
7621
|
TYPING_START(client, d) {
|
|
7109
7622
|
const data = d;
|
|
7110
7623
|
const payload = {
|
|
@@ -7160,6 +7673,46 @@ var passthroughHandlers = {
|
|
|
7160
7673
|
WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
|
|
7161
7674
|
};
|
|
7162
7675
|
|
|
7676
|
+
// src/ClientCore/EventHandlers/Stages.ts
|
|
7677
|
+
var stageHandlers = {
|
|
7678
|
+
STAGE_INSTANCE_CREATE(client, d) {
|
|
7679
|
+
const instance = cacheStageInstance(client, d);
|
|
7680
|
+
client.emit(Events.StageInstanceCreate, instance);
|
|
7681
|
+
},
|
|
7682
|
+
STAGE_INSTANCE_UPDATE(client, d) {
|
|
7683
|
+
const data = d;
|
|
7684
|
+
const cached = client.guilds.get(data.guild_id)?.stageInstances.get(data.id);
|
|
7685
|
+
const old = cached ? new StageInstance(client, cached.toJSON()) : null;
|
|
7686
|
+
const instance = cacheStageInstance(client, data);
|
|
7687
|
+
client.emit(Events.StageInstanceUpdate, old, instance);
|
|
7688
|
+
},
|
|
7689
|
+
STAGE_INSTANCE_DELETE(client, d) {
|
|
7690
|
+
const data = d;
|
|
7691
|
+
const guild = client.guilds.get(data.guild_id);
|
|
7692
|
+
const instance = guild?.stageInstances.get(data.id) ?? new StageInstance(client, data);
|
|
7693
|
+
instance._patch(data);
|
|
7694
|
+
guild?.stageInstances.delete(data.id);
|
|
7695
|
+
client.emit(Events.StageInstanceDelete, instance);
|
|
7696
|
+
},
|
|
7697
|
+
STAGE_COUNTS_UPDATE(client, d) {
|
|
7698
|
+
const data = d;
|
|
7699
|
+
const channel = client.channels.get(data.channel_id);
|
|
7700
|
+
if (channel?.isStage()) channel._patchCounts(data);
|
|
7701
|
+
const payload = {
|
|
7702
|
+
guildId: data.guild_id,
|
|
7703
|
+
channelId: data.channel_id,
|
|
7704
|
+
listenerCount: data.listener_count,
|
|
7705
|
+
speakerCount: data.speaker_count,
|
|
7706
|
+
requestCount: data.request_count,
|
|
7707
|
+
videoEnabled: data.video_enabled ?? null
|
|
7708
|
+
};
|
|
7709
|
+
client.emit(Events.StageCountsUpdate, payload);
|
|
7710
|
+
},
|
|
7711
|
+
STAGE_VOICE_STATES_SYNC: pass(Events.StageVoiceStatesSync),
|
|
7712
|
+
STAGE_AUDIENCE_LIST_UPDATE: pass(Events.StageAudienceListUpdate),
|
|
7713
|
+
VOICE_JOIN_QUEUED: pass(Events.VoiceJoinQueued)
|
|
7714
|
+
};
|
|
7715
|
+
|
|
7163
7716
|
// src/ClientCore/EventHandlers/Threads.ts
|
|
7164
7717
|
function cachedChannel(client, id) {
|
|
7165
7718
|
const direct = client.channels.get(id);
|
|
@@ -7270,7 +7823,8 @@ var eventHandlers = buildRegistry(
|
|
|
7270
7823
|
inviteHandlers,
|
|
7271
7824
|
guildResourceHandlers,
|
|
7272
7825
|
passthroughHandlers,
|
|
7273
|
-
threadHandlers
|
|
7826
|
+
threadHandlers,
|
|
7827
|
+
stageHandlers
|
|
7274
7828
|
);
|
|
7275
7829
|
|
|
7276
7830
|
// src/ClientCore/GatewayDispatch.ts
|
|
@@ -7295,29 +7849,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7295
7849
|
}
|
|
7296
7850
|
return dispatchGatewayPayload(client, payload);
|
|
7297
7851
|
}
|
|
7298
|
-
|
|
7852
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7853
|
+
function queueFor(client) {
|
|
7854
|
+
let queue = dispatchQueues.get(client);
|
|
7855
|
+
if (!queue) {
|
|
7856
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7857
|
+
dispatchQueues.set(client, queue);
|
|
7858
|
+
}
|
|
7859
|
+
return queue;
|
|
7860
|
+
}
|
|
7861
|
+
async function runGatewayHandler(client, payload) {
|
|
7299
7862
|
const event = payload.t;
|
|
7300
|
-
if (!event) return
|
|
7863
|
+
if (!event) return;
|
|
7301
7864
|
const handler = eventHandlers.get(event);
|
|
7302
7865
|
if (!handler) {
|
|
7303
7866
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7304
|
-
return
|
|
7867
|
+
return;
|
|
7305
7868
|
}
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
}
|
|
7313
|
-
if (client.options.gatewayDeferHandlers
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
};
|
|
7318
|
-
|
|
7319
|
-
|
|
7869
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7870
|
+
client.emit(
|
|
7871
|
+
Events.Debug,
|
|
7872
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7873
|
+
);
|
|
7874
|
+
return;
|
|
7875
|
+
}
|
|
7876
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7877
|
+
await new Promise((resolve) => {
|
|
7878
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7879
|
+
else setTimeout(resolve, 0);
|
|
7880
|
+
});
|
|
7881
|
+
}
|
|
7882
|
+
try {
|
|
7883
|
+
await handler(client, payload.d);
|
|
7884
|
+
} catch (err) {
|
|
7885
|
+
emitClientError(client, err);
|
|
7886
|
+
}
|
|
7887
|
+
}
|
|
7888
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7889
|
+
const queue = queueFor(client);
|
|
7890
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7891
|
+
queue.pending++;
|
|
7892
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7893
|
+
queue.pending--;
|
|
7894
|
+
});
|
|
7895
|
+
queue.tail = run.catch(() => {
|
|
7896
|
+
});
|
|
7897
|
+
return run;
|
|
7898
|
+
}
|
|
7899
|
+
queue.pending++;
|
|
7900
|
+
const next = queue.tail.then(
|
|
7901
|
+
() => runGatewayHandler(client, payload),
|
|
7902
|
+
() => runGatewayHandler(client, payload)
|
|
7903
|
+
).finally(() => {
|
|
7904
|
+
queue.pending--;
|
|
7905
|
+
});
|
|
7906
|
+
queue.tail = next.catch(() => {
|
|
7320
7907
|
});
|
|
7908
|
+
return next;
|
|
7321
7909
|
}
|
|
7322
7910
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7323
7911
|
while (deferred.length > 0) {
|
|
@@ -7496,7 +8084,7 @@ async function connectClientGateway(client, token, signal) {
|
|
|
7496
8084
|
|
|
7497
8085
|
// src/ClientCore/GuildManager.ts
|
|
7498
8086
|
var import_collection13 = require("@fluxerjs/collection");
|
|
7499
|
-
var
|
|
8087
|
+
var import_types44 = require("@fluxerjs/types");
|
|
7500
8088
|
var GuildManager = class extends import_collection13.LimitedCollection {
|
|
7501
8089
|
constructor(client) {
|
|
7502
8090
|
super({
|
|
@@ -7505,6 +8093,7 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7505
8093
|
});
|
|
7506
8094
|
this.client = client;
|
|
7507
8095
|
}
|
|
8096
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7508
8097
|
/**
|
|
7509
8098
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7510
8099
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7519,35 +8108,73 @@ var GuildManager = class extends import_collection13.LimitedCollection {
|
|
|
7519
8108
|
}
|
|
7520
8109
|
/**
|
|
7521
8110
|
* Get a guild from cache or fetch from the API if not present.
|
|
8111
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7522
8112
|
* @param guildId - Snowflake of the guild
|
|
7523
8113
|
* @returns The guild
|
|
7524
8114
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7525
8115
|
*/
|
|
7526
8116
|
async resolve(guildId) {
|
|
7527
|
-
|
|
8117
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
8118
|
+
const cached = this.get(id);
|
|
8119
|
+
if (cached && !cached.partial) return cached;
|
|
8120
|
+
if (cached) {
|
|
8121
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
8122
|
+
await this.hydrate(cached);
|
|
8123
|
+
return cached;
|
|
8124
|
+
});
|
|
8125
|
+
return cached;
|
|
8126
|
+
}
|
|
8127
|
+
const guild = await this.fetch(id);
|
|
8128
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
8129
|
+
await this.hydrate(guild);
|
|
8130
|
+
return guild;
|
|
8131
|
+
});
|
|
8132
|
+
return guild;
|
|
7528
8133
|
}
|
|
7529
8134
|
/**
|
|
7530
8135
|
* Fetch a guild by ID.
|
|
7531
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
8136
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
8137
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7532
8138
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7533
8139
|
*/
|
|
7534
8140
|
async fetch(guildId, options) {
|
|
7535
|
-
const
|
|
8141
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
8142
|
+
const cached = this.get(id);
|
|
7536
8143
|
if (cached && !options?.force) return cached;
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
8144
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
8145
|
+
try {
|
|
8146
|
+
const data = assertApiObjectWithId(
|
|
8147
|
+
await this.client.rest.get(import_types44.Routes.guild(id)),
|
|
8148
|
+
"guilds.fetch()"
|
|
8149
|
+
);
|
|
8150
|
+
let guild;
|
|
8151
|
+
const existing = this.get(id);
|
|
8152
|
+
if (existing) {
|
|
8153
|
+
existing._patch(data);
|
|
8154
|
+
guild = existing;
|
|
8155
|
+
} else {
|
|
8156
|
+
guild = new Guild(this.client, data);
|
|
8157
|
+
this.set(guild.id, guild);
|
|
8158
|
+
}
|
|
8159
|
+
return guild;
|
|
8160
|
+
} catch (err) {
|
|
8161
|
+
rethrowMapped(err, {
|
|
8162
|
+
notFound: { code: import_util.ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
8163
|
+
fallback: `Failed to fetch guild ${id}`
|
|
8164
|
+
});
|
|
7542
8165
|
}
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
8166
|
+
});
|
|
8167
|
+
}
|
|
8168
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
8169
|
+
async hydrate(guild) {
|
|
8170
|
+
try {
|
|
8171
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
8172
|
+
guild.partial = false;
|
|
7546
8173
|
} catch (err) {
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
8174
|
+
this.client.emit(
|
|
8175
|
+
Events.Debug,
|
|
8176
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
8177
|
+
);
|
|
7551
8178
|
}
|
|
7552
8179
|
}
|
|
7553
8180
|
};
|
|
@@ -7572,6 +8199,10 @@ var MessageCache = class {
|
|
|
7572
8199
|
if (limit === false) return;
|
|
7573
8200
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7574
8201
|
let cache = this.caches.get(channelId);
|
|
8202
|
+
if (cache) {
|
|
8203
|
+
this.caches.delete(channelId);
|
|
8204
|
+
this.caches.set(channelId, cache);
|
|
8205
|
+
}
|
|
7575
8206
|
if (!cache) {
|
|
7576
8207
|
const channelLimit = this.getChannelLimit();
|
|
7577
8208
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7622,13 +8253,14 @@ var MessageCache = class {
|
|
|
7622
8253
|
|
|
7623
8254
|
// src/ClientCore/UserManager.ts
|
|
7624
8255
|
var import_collection14 = require("@fluxerjs/collection");
|
|
7625
|
-
var
|
|
8256
|
+
var import_types45 = require("@fluxerjs/types");
|
|
7626
8257
|
var soft = (p) => p.catch(() => null);
|
|
7627
8258
|
var UserManager = class extends import_collection14.LimitedCollection {
|
|
7628
8259
|
constructor(client) {
|
|
7629
8260
|
super({ maxSize: client.cache.limits.users });
|
|
7630
8261
|
this.client = client;
|
|
7631
8262
|
}
|
|
8263
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7632
8264
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7633
8265
|
sweep(filter) {
|
|
7634
8266
|
let removed = 0;
|
|
@@ -7642,16 +8274,30 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7642
8274
|
}
|
|
7643
8275
|
return removed;
|
|
7644
8276
|
}
|
|
7645
|
-
/**
|
|
8277
|
+
/**
|
|
8278
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
8279
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
8280
|
+
*/
|
|
7646
8281
|
async fetch(userId, options) {
|
|
7647
|
-
const
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
return
|
|
8282
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
8283
|
+
const cached = this.get(id);
|
|
8284
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
8285
|
+
return dedupeFetch(
|
|
8286
|
+
this.pendingFetches,
|
|
8287
|
+
id,
|
|
8288
|
+
async () => this.client.getOrCreateUser(
|
|
8289
|
+
assertApiObjectWithId(
|
|
8290
|
+
await this.client.rest.get(import_types45.Routes.user(id)),
|
|
8291
|
+
"users.fetch()"
|
|
8292
|
+
)
|
|
8293
|
+
)
|
|
8294
|
+
);
|
|
7651
8295
|
}
|
|
7652
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8296
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7653
8297
|
async resolve(userId) {
|
|
7654
|
-
|
|
8298
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8299
|
+
const cached = this.get(id);
|
|
8300
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7655
8301
|
}
|
|
7656
8302
|
/**
|
|
7657
8303
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7664,10 +8310,10 @@ var UserManager = class extends import_collection14.LimitedCollection {
|
|
|
7664
8310
|
async fetchWithProfile(userId, options) {
|
|
7665
8311
|
const guildId = options?.guildId ?? void 0;
|
|
7666
8312
|
const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
|
|
7667
|
-
this.client.rest.get(
|
|
7668
|
-
soft(this.client.rest.get(
|
|
7669
|
-
guildId ? soft(this.client.rest.get(
|
|
7670
|
-
guildId ? soft(this.client.rest.get(
|
|
8313
|
+
this.client.rest.get(import_types45.Routes.user(userId)),
|
|
8314
|
+
soft(this.client.rest.get(import_types45.Routes.userProfile(userId))),
|
|
8315
|
+
guildId ? soft(this.client.rest.get(import_types45.Routes.userProfile(userId, guildId))) : null,
|
|
8316
|
+
guildId ? soft(this.client.rest.get(import_types45.Routes.guildMember(guildId, userId))) : null
|
|
7671
8317
|
]);
|
|
7672
8318
|
const user = this.client.getOrCreateUser(userData);
|
|
7673
8319
|
let member = null;
|
|
@@ -7754,7 +8400,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7754
8400
|
cache: resolved.cache,
|
|
7755
8401
|
defaultReplyPing: options.defaultReplyPing ?? true
|
|
7756
8402
|
};
|
|
7757
|
-
this.logger = options.logger ?? (0,
|
|
8403
|
+
this.logger = options.logger ?? (0, import_util27.createLogger)({
|
|
7758
8404
|
level: options.logLevel ?? "warn"
|
|
7759
8405
|
});
|
|
7760
8406
|
this.cache = new CacheController(this, resolved.limits);
|
|
@@ -7792,7 +8438,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7792
8438
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7793
8439
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7794
8440
|
*
|
|
7795
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8441
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7796
8442
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7797
8443
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7798
8444
|
*/
|
|
@@ -7869,6 +8515,38 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7869
8515
|
fetchStickerMetadata(stickerId) {
|
|
7870
8516
|
return fetchStickerMetadata(this, stickerId);
|
|
7871
8517
|
}
|
|
8518
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8519
|
+
fetchEmojiSource(emojiId) {
|
|
8520
|
+
return fetchEmojiSource(this, emojiId);
|
|
8521
|
+
}
|
|
8522
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8523
|
+
fetchStickerSource(stickerId) {
|
|
8524
|
+
return fetchStickerSource(this, stickerId);
|
|
8525
|
+
}
|
|
8526
|
+
/** List discovery categories. */
|
|
8527
|
+
fetchDiscoveryCategories() {
|
|
8528
|
+
return fetchDiscoveryCategories(this);
|
|
8529
|
+
}
|
|
8530
|
+
/** Search discoverable guilds. */
|
|
8531
|
+
searchDiscoveryGuilds(options) {
|
|
8532
|
+
return searchDiscoveryGuilds(this, options);
|
|
8533
|
+
}
|
|
8534
|
+
/** Fetch experiment assignments for this account. */
|
|
8535
|
+
fetchExperiments() {
|
|
8536
|
+
return fetchExperiments(this);
|
|
8537
|
+
}
|
|
8538
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8539
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8540
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8541
|
+
}
|
|
8542
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8543
|
+
fetchInstanceBadges(options) {
|
|
8544
|
+
return fetchInstanceBadges(this, options);
|
|
8545
|
+
}
|
|
8546
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8547
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8548
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8549
|
+
}
|
|
7872
8550
|
/**
|
|
7873
8551
|
* Fetch the current application (`/applications/@me`).
|
|
7874
8552
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -7963,6 +8641,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
7963
8641
|
* @internal
|
|
7964
8642
|
*/
|
|
7965
8643
|
getOrCreateUser(data) {
|
|
8644
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8645
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8646
|
+
}
|
|
7966
8647
|
const existing = this.users.get(data.id);
|
|
7967
8648
|
if (existing) {
|
|
7968
8649
|
existing._patch(data);
|
|
@@ -8013,7 +8694,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
8013
8694
|
if (options.userIds !== void 0) data.user_ids = [...new Set(options.userIds)];
|
|
8014
8695
|
if (options.presences !== void 0) data.presences = options.presences;
|
|
8015
8696
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
8016
|
-
this._sendToAllShards({ op:
|
|
8697
|
+
this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestGuildMembers, d: data });
|
|
8017
8698
|
}
|
|
8018
8699
|
/**
|
|
8019
8700
|
* Request guild member/online counts via gateway opcode 15.
|
|
@@ -8028,7 +8709,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
8028
8709
|
}
|
|
8029
8710
|
const data = { guild_ids: guildIds };
|
|
8030
8711
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
8031
|
-
this._sendToAllShards({ op:
|
|
8712
|
+
this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestGuildCounts, d: data });
|
|
8032
8713
|
}
|
|
8033
8714
|
/**
|
|
8034
8715
|
* Request per-channel member counts via gateway opcode 16.
|
|
@@ -8044,7 +8725,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
8044
8725
|
if (options.channelId !== void 0) data.channel_id = options.channelId;
|
|
8045
8726
|
if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
|
|
8046
8727
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
8047
|
-
this._sendToAllShards({ op:
|
|
8728
|
+
this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestChannelMemberCounts, d: data });
|
|
8048
8729
|
}
|
|
8049
8730
|
/**
|
|
8050
8731
|
* Request unread counts for posts in one forum or media channel (opcode 28).
|
|
@@ -8080,7 +8761,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
8080
8761
|
channel_id: options.channelId,
|
|
8081
8762
|
threads
|
|
8082
8763
|
};
|
|
8083
|
-
this._sendToAllShards({ op:
|
|
8764
|
+
this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestForumUnreads, d: data });
|
|
8084
8765
|
}
|
|
8085
8766
|
/**
|
|
8086
8767
|
* Subscribe to thread traffic in a guild (opcode 14).
|
|
@@ -8110,7 +8791,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
8110
8791
|
subscription.thread_member_lists = threadIds;
|
|
8111
8792
|
}
|
|
8112
8793
|
const data = { subscriptions: { [options.guildId]: subscription } };
|
|
8113
|
-
this._sendToAllShards({ op:
|
|
8794
|
+
this._sendToAllShards({ op: import_types46.GatewayOpcodes.LazyRequest, d: data });
|
|
8114
8795
|
}
|
|
8115
8796
|
/**
|
|
8116
8797
|
* Broadcast a gateway payload to all shards.
|
|
@@ -8215,7 +8896,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
8215
8896
|
* @see {@link Routes}
|
|
8216
8897
|
*/
|
|
8217
8898
|
static get Routes() {
|
|
8218
|
-
return
|
|
8899
|
+
return import_types46.Routes;
|
|
8219
8900
|
}
|
|
8220
8901
|
};
|
|
8221
8902
|
|