@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/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
OverwriteType as OverwriteType2,
|
|
25
25
|
PublicUserFlags,
|
|
26
26
|
RelationshipType,
|
|
27
|
-
Routes as
|
|
27
|
+
Routes as Routes39,
|
|
28
28
|
SplashCardAlignment,
|
|
29
29
|
SystemChannelFlags,
|
|
30
30
|
ThreadAutoArchiveDuration,
|
|
@@ -186,7 +186,7 @@ var CacheController = class {
|
|
|
186
186
|
|
|
187
187
|
// src/ClientCore/ChannelManager.ts
|
|
188
188
|
import { LimitedCollection } from "@fluxerjs/collection";
|
|
189
|
-
import { Routes as
|
|
189
|
+
import { Routes as Routes23 } from "@fluxerjs/types";
|
|
190
190
|
|
|
191
191
|
// src/Domain/Channel/Base.ts
|
|
192
192
|
import { ChannelType as ChannelType3, Routes as Routes7 } from "@fluxerjs/types";
|
|
@@ -1146,6 +1146,7 @@ var Events = {
|
|
|
1146
1146
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
1147
1147
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
1148
1148
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
1149
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
1149
1150
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
1150
1151
|
GuildMemberAdd: "guildMemberAdd",
|
|
1151
1152
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -1180,7 +1181,16 @@ var Events = {
|
|
|
1180
1181
|
VoiceStateAck: "voiceStateAck",
|
|
1181
1182
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
1182
1183
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
1184
|
+
VoiceSignal: "voiceSignal",
|
|
1185
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
1183
1186
|
VoiceStatesSync: "voiceStatesSync",
|
|
1187
|
+
VoiceJoinQueued: "voiceJoinQueued",
|
|
1188
|
+
StageInstanceCreate: "stageInstanceCreate",
|
|
1189
|
+
StageInstanceUpdate: "stageInstanceUpdate",
|
|
1190
|
+
StageInstanceDelete: "stageInstanceDelete",
|
|
1191
|
+
StageCountsUpdate: "stageCountsUpdate",
|
|
1192
|
+
StageVoiceStatesSync: "stageVoiceStatesSync",
|
|
1193
|
+
StageAudienceListUpdate: "stageAudienceListUpdate",
|
|
1184
1194
|
WebhooksUpdate: "webhooksUpdate",
|
|
1185
1195
|
Resumed: "resumed",
|
|
1186
1196
|
Error: "error",
|
|
@@ -1846,10 +1856,10 @@ var Message = class _Message extends Base {
|
|
|
1846
1856
|
this.channelId = data.channel_id;
|
|
1847
1857
|
this.guildId = data.guild_id ?? null;
|
|
1848
1858
|
this.author = client.getOrCreateUser(data.author);
|
|
1849
|
-
this.content = data.content;
|
|
1850
|
-
this.createdAt = new Date(data.timestamp);
|
|
1859
|
+
this.content = data.content ?? "";
|
|
1860
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
1851
1861
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1852
|
-
this.pinned = data.pinned;
|
|
1862
|
+
this.pinned = data.pinned ?? false;
|
|
1853
1863
|
this.attachments = new Collection3();
|
|
1854
1864
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1855
1865
|
this.type = data.type ?? MessageType.Default;
|
|
@@ -1881,33 +1891,47 @@ var Message = class _Message extends Base {
|
|
|
1881
1891
|
* @internal
|
|
1882
1892
|
*/
|
|
1883
1893
|
_patch(data) {
|
|
1884
|
-
this.content = data.content;
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
this.
|
|
1895
|
-
this.
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1894
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
1895
|
+
if (data.edited_timestamp !== void 0) {
|
|
1896
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1897
|
+
}
|
|
1898
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
1899
|
+
if (data.attachments !== void 0) {
|
|
1900
|
+
this.attachments.clear();
|
|
1901
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1902
|
+
}
|
|
1903
|
+
if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1904
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
1905
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
1906
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1907
|
+
if (data.stickers !== void 0) {
|
|
1908
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1909
|
+
}
|
|
1910
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
1911
|
+
if (data.message_reference !== void 0) {
|
|
1912
|
+
this.messageReference = data.message_reference ? {
|
|
1913
|
+
channelId: data.message_reference.channel_id,
|
|
1914
|
+
messageId: data.message_reference.message_id,
|
|
1915
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1916
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1917
|
+
} : null;
|
|
1918
|
+
}
|
|
1919
|
+
if (data.message_snapshots !== void 0) {
|
|
1920
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1921
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1922
|
+
);
|
|
1923
|
+
}
|
|
1924
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
1925
|
+
if (data.referenced_message !== void 0) {
|
|
1926
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1927
|
+
}
|
|
1928
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
1929
|
+
if (data.mentions !== void 0) {
|
|
1930
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1931
|
+
}
|
|
1932
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
1933
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
1934
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1911
1935
|
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1912
1936
|
}
|
|
1913
1937
|
/**
|
|
@@ -2008,6 +2032,23 @@ var Message = class _Message extends Base {
|
|
|
2008
2032
|
async fetch() {
|
|
2009
2033
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2010
2034
|
}
|
|
2035
|
+
/** Publish this announcement message to channels following its channel. */
|
|
2036
|
+
async crosspost() {
|
|
2037
|
+
const data = await this.client.rest.post(
|
|
2038
|
+
Routes4.channelMessageCrosspost(this.channelId, this.id),
|
|
2039
|
+
{ auth: true }
|
|
2040
|
+
);
|
|
2041
|
+
const published = new _Message(this.client, data);
|
|
2042
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2043
|
+
return published;
|
|
2044
|
+
}
|
|
2045
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
2046
|
+
async fetchCrosspostSource() {
|
|
2047
|
+
return this.client.rest.get(
|
|
2048
|
+
Routes4.channelMessageCrosspostSource(this.channelId, this.id),
|
|
2049
|
+
{ auth: true }
|
|
2050
|
+
);
|
|
2051
|
+
}
|
|
2011
2052
|
/** Delete this message. */
|
|
2012
2053
|
async delete(reason) {
|
|
2013
2054
|
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
|
|
@@ -2110,6 +2151,43 @@ var PartialMessage = class {
|
|
|
2110
2151
|
}
|
|
2111
2152
|
};
|
|
2112
2153
|
|
|
2154
|
+
// src/ClientCore/Resolve.ts
|
|
2155
|
+
function normalizeSnowflakeId(value, label) {
|
|
2156
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
2157
|
+
throw new TypeError(
|
|
2158
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
2159
|
+
);
|
|
2160
|
+
}
|
|
2161
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
2162
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
2163
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
2164
|
+
}
|
|
2165
|
+
return id;
|
|
2166
|
+
}
|
|
2167
|
+
function assertApiObjectWithId(data, label) {
|
|
2168
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
2169
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
2170
|
+
}
|
|
2171
|
+
return data;
|
|
2172
|
+
}
|
|
2173
|
+
function assertApiArray(data, label) {
|
|
2174
|
+
if (!Array.isArray(data)) {
|
|
2175
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
2176
|
+
}
|
|
2177
|
+
return data;
|
|
2178
|
+
}
|
|
2179
|
+
async function dedupeFetch(pending, key, fn) {
|
|
2180
|
+
const existing = pending.get(key);
|
|
2181
|
+
if (existing) return existing;
|
|
2182
|
+
const request = fn();
|
|
2183
|
+
pending.set(key, request);
|
|
2184
|
+
try {
|
|
2185
|
+
return await request;
|
|
2186
|
+
} finally {
|
|
2187
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2113
2191
|
// src/ClientCore/MessageManager.ts
|
|
2114
2192
|
var BULK = {
|
|
2115
2193
|
requests: { min: 1, max: 25 },
|
|
@@ -2146,25 +2224,32 @@ var MessageManager = class {
|
|
|
2146
2224
|
}
|
|
2147
2225
|
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
2148
2226
|
_structures = new Collection4();
|
|
2227
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
2149
2228
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
2150
2229
|
get(messageId) {
|
|
2151
|
-
const
|
|
2230
|
+
const id = String(messageId ?? "").trim();
|
|
2231
|
+
if (!id) return void 0;
|
|
2232
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
2152
2233
|
if (!data) {
|
|
2153
|
-
this._structures.delete(
|
|
2234
|
+
this._structures.delete(id);
|
|
2154
2235
|
return void 0;
|
|
2155
2236
|
}
|
|
2156
|
-
const existing = this._structures.get(
|
|
2157
|
-
if (existing)
|
|
2237
|
+
const existing = this._structures.get(id);
|
|
2238
|
+
if (existing) {
|
|
2239
|
+
existing._patch(data);
|
|
2240
|
+
return existing;
|
|
2241
|
+
}
|
|
2158
2242
|
const message = new Message(this.client, data);
|
|
2159
|
-
this._structures.set(
|
|
2243
|
+
this._structures.set(id, message);
|
|
2160
2244
|
return message;
|
|
2161
2245
|
}
|
|
2162
2246
|
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
2163
2247
|
async resolve(messageId) {
|
|
2164
|
-
|
|
2248
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
2249
|
+
return this.get(id) ?? this.fetch(id);
|
|
2165
2250
|
}
|
|
2166
2251
|
async fetch(idOrOptions) {
|
|
2167
|
-
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
2252
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
2168
2253
|
}
|
|
2169
2254
|
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
2170
2255
|
wrap(data) {
|
|
@@ -2181,9 +2266,13 @@ var MessageManager = class {
|
|
|
2181
2266
|
}
|
|
2182
2267
|
/** Fetch a single message from the API. */
|
|
2183
2268
|
async fetchOne(messageId) {
|
|
2269
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
2270
|
+
}
|
|
2271
|
+
async fetchOneFresh(messageId) {
|
|
2184
2272
|
try {
|
|
2185
|
-
const data =
|
|
2186
|
-
Routes5.channelMessage(this.channelId, messageId)
|
|
2273
|
+
const data = assertApiObjectWithId(
|
|
2274
|
+
await this.client.rest.get(Routes5.channelMessage(this.channelId, messageId)),
|
|
2275
|
+
"messages.fetch()"
|
|
2187
2276
|
);
|
|
2188
2277
|
return this.wrap(data);
|
|
2189
2278
|
} catch (err) {
|
|
@@ -2209,9 +2298,15 @@ var MessageManager = class {
|
|
|
2209
2298
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
2210
2299
|
}
|
|
2211
2300
|
const base = Routes5.channelMessages(this.channelId);
|
|
2212
|
-
const data =
|
|
2301
|
+
const data = assertApiArray(
|
|
2302
|
+
await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
|
|
2303
|
+
"messages.fetch()"
|
|
2304
|
+
);
|
|
2213
2305
|
const collection = new Collection4();
|
|
2214
|
-
for (const msg of data)
|
|
2306
|
+
for (const msg of data) {
|
|
2307
|
+
if (!msg?.id) continue;
|
|
2308
|
+
collection.set(msg.id, this.wrap(msg));
|
|
2309
|
+
}
|
|
2215
2310
|
return collection;
|
|
2216
2311
|
}
|
|
2217
2312
|
};
|
|
@@ -2415,6 +2510,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
2415
2510
|
}
|
|
2416
2511
|
|
|
2417
2512
|
// src/Domain/Channel/Base.ts
|
|
2513
|
+
function isFullChannelData(data) {
|
|
2514
|
+
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;
|
|
2515
|
+
}
|
|
2418
2516
|
var Channel = class extends Base {
|
|
2419
2517
|
#messages;
|
|
2420
2518
|
/** The {@link Client} that instantiated this channel. */
|
|
@@ -2429,6 +2527,11 @@ var Channel = class extends Base {
|
|
|
2429
2527
|
icon;
|
|
2430
2528
|
/** ISO8601 timestamp of the last pinned message update. */
|
|
2431
2529
|
lastPinTimestamp;
|
|
2530
|
+
/**
|
|
2531
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
2532
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
2533
|
+
*/
|
|
2534
|
+
partial;
|
|
2432
2535
|
constructor(client, data) {
|
|
2433
2536
|
super();
|
|
2434
2537
|
this.client = client;
|
|
@@ -2437,6 +2540,7 @@ var Channel = class extends Base {
|
|
|
2437
2540
|
this.name = data.name ?? null;
|
|
2438
2541
|
this.icon = data.icon ?? null;
|
|
2439
2542
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
2543
|
+
this.partial = !isFullChannelData(data);
|
|
2440
2544
|
}
|
|
2441
2545
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
2442
2546
|
get createdTimestamp() {
|
|
@@ -2457,6 +2561,7 @@ var Channel = class extends Base {
|
|
|
2457
2561
|
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
2458
2562
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
2459
2563
|
}
|
|
2564
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
2460
2565
|
}
|
|
2461
2566
|
/** @internal Factory wired after subclasses load. */
|
|
2462
2567
|
static from(_c, _d) {
|
|
@@ -2476,11 +2581,11 @@ var Channel = class extends Base {
|
|
|
2476
2581
|
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
2477
2582
|
*/
|
|
2478
2583
|
isTextBased() {
|
|
2479
|
-
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
|
|
2584
|
+
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildStageVoice || this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
|
|
2480
2585
|
}
|
|
2481
2586
|
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
2482
2587
|
isGuild() {
|
|
2483
|
-
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildCategory || this.type === ChannelType3.GuildLink || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread || this.type === ChannelType3.GuildForum || this.type === ChannelType3.GuildMedia;
|
|
2588
|
+
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildStageVoice || this.type === ChannelType3.GuildCategory || this.type === ChannelType3.GuildLink || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread || this.type === ChannelType3.GuildForum || this.type === ChannelType3.GuildMedia;
|
|
2484
2589
|
}
|
|
2485
2590
|
/** Check if this is a thread (public, private, or announcement). */
|
|
2486
2591
|
isThread() {
|
|
@@ -2514,10 +2619,18 @@ var Channel = class extends Base {
|
|
|
2514
2619
|
isPersonalNotes() {
|
|
2515
2620
|
return this.type === ChannelType3.DMPersonalNotes;
|
|
2516
2621
|
}
|
|
2517
|
-
/** Check if this is a voice channel. */
|
|
2622
|
+
/** Check if this is a voice channel (type 2 only; see {@link isVoiceBased} to include stages). */
|
|
2518
2623
|
isVoice() {
|
|
2519
2624
|
return this.type === ChannelType3.GuildVoice;
|
|
2520
2625
|
}
|
|
2626
|
+
/** Check if this is a stage channel (type 13). */
|
|
2627
|
+
isStage() {
|
|
2628
|
+
return this.type === ChannelType3.GuildStageVoice;
|
|
2629
|
+
}
|
|
2630
|
+
/** Check if this is a voice or stage channel, i.e. one `@fluxerjs/voice` can join. */
|
|
2631
|
+
isVoiceBased() {
|
|
2632
|
+
return this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildStageVoice;
|
|
2633
|
+
}
|
|
2521
2634
|
/** Check if this is a link channel. */
|
|
2522
2635
|
isLink() {
|
|
2523
2636
|
return this.type === ChannelType3.GuildLink;
|
|
@@ -2748,7 +2861,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2748
2861
|
const full = data;
|
|
2749
2862
|
this.lastMessageId = full.last_message_id ?? null;
|
|
2750
2863
|
this.ownerId = full.owner_id ?? null;
|
|
2751
|
-
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
2864
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
|
|
2752
2865
|
this.nicks = full.nicks ?? {};
|
|
2753
2866
|
}
|
|
2754
2867
|
/**
|
|
@@ -2763,7 +2876,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2763
2876
|
}
|
|
2764
2877
|
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2765
2878
|
if ("recipients" in full && full.recipients !== void 0) {
|
|
2766
|
-
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2879
|
+
this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
|
|
2767
2880
|
}
|
|
2768
2881
|
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2769
2882
|
}
|
|
@@ -2830,11 +2943,11 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2830
2943
|
// src/Domain/Channel/Forum.ts
|
|
2831
2944
|
import {
|
|
2832
2945
|
ChannelType as ChannelType7,
|
|
2833
|
-
Routes as
|
|
2946
|
+
Routes as Routes17
|
|
2834
2947
|
} from "@fluxerjs/types";
|
|
2835
2948
|
|
|
2836
2949
|
// src/Domain/Channel/Guild.ts
|
|
2837
|
-
import { Routes as
|
|
2950
|
+
import { Routes as Routes14 } from "@fluxerjs/types";
|
|
2838
2951
|
import { PermissionFlags } from "@fluxerjs/util";
|
|
2839
2952
|
|
|
2840
2953
|
// src/Domain/Invite.ts
|
|
@@ -2848,17 +2961,19 @@ import {
|
|
|
2848
2961
|
// src/Helpers/Instance.ts
|
|
2849
2962
|
import { isRecord } from "@fluxerjs/util";
|
|
2850
2963
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
2851
|
-
api: "https://
|
|
2852
|
-
api_client: "https://
|
|
2853
|
-
api_public: "https://
|
|
2854
|
-
gateway: "wss://gateway.fluxer.
|
|
2964
|
+
api: "https://fluxer.com/api",
|
|
2965
|
+
api_client: "https://fluxer.com/api",
|
|
2966
|
+
api_public: "https://fluxer.com/api",
|
|
2967
|
+
gateway: "wss://gateway.fluxer.com",
|
|
2855
2968
|
media: CDN_URL,
|
|
2969
|
+
upload_relay: "https://uploads.fluxer.app",
|
|
2856
2970
|
static_cdn: STATIC_CDN_URL,
|
|
2857
|
-
marketing: "https://fluxer.
|
|
2971
|
+
marketing: "https://fluxer.com",
|
|
2972
|
+
docs: "https://docs.fluxer.com",
|
|
2858
2973
|
admin: "https://admin.fluxer.app",
|
|
2859
2974
|
invite: "https://fluxer.gg",
|
|
2860
2975
|
gift: "https://fluxer.gift",
|
|
2861
|
-
webapp: "https://
|
|
2976
|
+
webapp: "https://fluxer.com"
|
|
2862
2977
|
});
|
|
2863
2978
|
var ENDPOINT_KEYS = [
|
|
2864
2979
|
"api",
|
|
@@ -2873,6 +2988,11 @@ var ENDPOINT_KEYS = [
|
|
|
2873
2988
|
"gift",
|
|
2874
2989
|
"webapp"
|
|
2875
2990
|
];
|
|
2991
|
+
var OPTIONAL_ENDPOINT_KEYS = [
|
|
2992
|
+
"api_transport",
|
|
2993
|
+
"upload_relay",
|
|
2994
|
+
"docs"
|
|
2995
|
+
];
|
|
2876
2996
|
function requireString(obj, key, path) {
|
|
2877
2997
|
const value = obj[key];
|
|
2878
2998
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2913,6 +3033,10 @@ function parseInstanceDiscovery(raw) {
|
|
|
2913
3033
|
for (const key of ENDPOINT_KEYS) {
|
|
2914
3034
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
2915
3035
|
}
|
|
3036
|
+
for (const key of OPTIONAL_ENDPOINT_KEYS) {
|
|
3037
|
+
const value = raw.endpoints[key];
|
|
3038
|
+
if (typeof value === "string" && value.length > 0) endpoints[key] = value;
|
|
3039
|
+
}
|
|
2916
3040
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2917
3041
|
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2918
3042
|
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
@@ -2966,7 +3090,21 @@ function parseInstanceDiscovery(raw) {
|
|
|
2966
3090
|
defaultsHash: ""
|
|
2967
3091
|
},
|
|
2968
3092
|
push: raw.push ?? { public_vapid_key: null },
|
|
2969
|
-
app_public: raw.app_public ?? {}
|
|
3093
|
+
app_public: raw.app_public ?? {},
|
|
3094
|
+
...typeof raw.codename === "string" ? { codename: raw.codename } : {},
|
|
3095
|
+
age_policy: isRecord(raw.age_policy) ? raw.age_policy : { geos: [] },
|
|
3096
|
+
...raw.notice === null || isRecord(raw.notice) ? { notice: raw.notice } : {},
|
|
3097
|
+
...isRecord(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
|
|
3098
|
+
...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
|
|
3099
|
+
...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
|
|
3100
|
+
...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
|
|
3101
|
+
...isRecord(raw.built_in_guild_badge_images) ? {
|
|
3102
|
+
built_in_guild_badge_images: raw.built_in_guild_badge_images
|
|
3103
|
+
} : {},
|
|
3104
|
+
...Array.isArray(raw.hidden_built_in_guild_badges) ? {
|
|
3105
|
+
hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
|
|
3106
|
+
} : {},
|
|
3107
|
+
...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
|
|
2970
3108
|
};
|
|
2971
3109
|
}
|
|
2972
3110
|
function resolveInstanceEndpoints(input) {
|
|
@@ -2986,7 +3124,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
2986
3124
|
}
|
|
2987
3125
|
const partial = input;
|
|
2988
3126
|
const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
|
|
2989
|
-
for (const key of ENDPOINT_KEYS) {
|
|
3127
|
+
for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
|
|
2990
3128
|
const value = partial[key];
|
|
2991
3129
|
if (typeof value === "string" && value.length > 0) {
|
|
2992
3130
|
merged[key] = value;
|
|
@@ -3408,6 +3546,127 @@ var PermissionOverwriteManager = class {
|
|
|
3408
3546
|
}
|
|
3409
3547
|
};
|
|
3410
3548
|
|
|
3549
|
+
// src/Domain/StageInstance.ts
|
|
3550
|
+
import { Routes as Routes13, StageInstancePrivacyLevel } from "@fluxerjs/types";
|
|
3551
|
+
import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
|
|
3552
|
+
var StageInstance = class extends Base {
|
|
3553
|
+
client;
|
|
3554
|
+
id;
|
|
3555
|
+
guildId;
|
|
3556
|
+
channelId;
|
|
3557
|
+
topic;
|
|
3558
|
+
/** Always {@link StageInstancePrivacyLevel.GuildOnly} on Fluxer. */
|
|
3559
|
+
privacyLevel;
|
|
3560
|
+
/** Always `true` on Fluxer. */
|
|
3561
|
+
discoverableDisabled;
|
|
3562
|
+
/** Always null on Fluxer. */
|
|
3563
|
+
guildScheduledEventId;
|
|
3564
|
+
constructor(client, data) {
|
|
3565
|
+
super();
|
|
3566
|
+
this.client = client;
|
|
3567
|
+
this.id = data.id;
|
|
3568
|
+
this.guildId = data.guild_id;
|
|
3569
|
+
this.channelId = data.channel_id;
|
|
3570
|
+
this.topic = data.topic;
|
|
3571
|
+
this.privacyLevel = data.privacy_level ?? StageInstancePrivacyLevel.GuildOnly;
|
|
3572
|
+
this.discoverableDisabled = data.discoverable_disabled ?? true;
|
|
3573
|
+
this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
|
|
3574
|
+
}
|
|
3575
|
+
/** @internal Patch in place from a newer payload. */
|
|
3576
|
+
_patch(data) {
|
|
3577
|
+
if (data.topic !== void 0) this.topic = data.topic;
|
|
3578
|
+
if (data.privacy_level !== void 0) this.privacyLevel = data.privacy_level;
|
|
3579
|
+
if (data.discoverable_disabled !== void 0) {
|
|
3580
|
+
this.discoverableDisabled = data.discoverable_disabled;
|
|
3581
|
+
}
|
|
3582
|
+
if (data.guild_scheduled_event_id !== void 0) {
|
|
3583
|
+
this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
get guild() {
|
|
3587
|
+
return this.client.guilds.get(this.guildId) ?? null;
|
|
3588
|
+
}
|
|
3589
|
+
get channel() {
|
|
3590
|
+
const channel = this.client.channels.get(this.channelId);
|
|
3591
|
+
return channel?.isStage() ? channel : null;
|
|
3592
|
+
}
|
|
3593
|
+
/** Unix timestamp (ms) when the stage started, from its snowflake ID. */
|
|
3594
|
+
get createdTimestamp() {
|
|
3595
|
+
return SnowflakeUtil5.timestampFromSnowflake(this.id);
|
|
3596
|
+
}
|
|
3597
|
+
get createdAt() {
|
|
3598
|
+
return SnowflakeUtil5.dateFromSnowflake(this.id);
|
|
3599
|
+
}
|
|
3600
|
+
/**
|
|
3601
|
+
* Change the live stage. Needs a stage moderator.
|
|
3602
|
+
* Fires `STAGE_INSTANCE_UPDATE`.
|
|
3603
|
+
*/
|
|
3604
|
+
async edit(options) {
|
|
3605
|
+
const body = {};
|
|
3606
|
+
if (options.topic !== void 0) body.topic = options.topic;
|
|
3607
|
+
const data = await this.client.rest.patch(
|
|
3608
|
+
Routes13.stageInstance(this.channelId),
|
|
3609
|
+
{ body, auth: true, ...auditReasonHeaders(options.reason) }
|
|
3610
|
+
);
|
|
3611
|
+
this._patch(data);
|
|
3612
|
+
return this;
|
|
3613
|
+
}
|
|
3614
|
+
/** Change the stage topic. Shorthand for {@link edit}. */
|
|
3615
|
+
async setTopic(topic, reason) {
|
|
3616
|
+
return this.edit({ topic, reason });
|
|
3617
|
+
}
|
|
3618
|
+
/**
|
|
3619
|
+
* End the stage. Needs a stage moderator. Speakers move to the audience, raised hands are
|
|
3620
|
+
* lowered, and everyone stays connected unless `disconnectAll` is set.
|
|
3621
|
+
*/
|
|
3622
|
+
async delete(options = {}) {
|
|
3623
|
+
const route = Routes13.stageInstance(this.channelId) + (options.disconnectAll ? "?disconnect_all=true" : "");
|
|
3624
|
+
await this.client.rest.delete(route, { auth: true, ...auditReasonHeaders(options.reason) });
|
|
3625
|
+
}
|
|
3626
|
+
toJSON() {
|
|
3627
|
+
return {
|
|
3628
|
+
id: this.id,
|
|
3629
|
+
guild_id: this.guildId,
|
|
3630
|
+
channel_id: this.channelId,
|
|
3631
|
+
topic: this.topic,
|
|
3632
|
+
privacy_level: this.privacyLevel,
|
|
3633
|
+
discoverable_disabled: this.discoverableDisabled,
|
|
3634
|
+
guild_scheduled_event_id: this.guildScheduledEventId
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
|
|
3639
|
+
// src/Domain/Channel/StageSync.ts
|
|
3640
|
+
function syncStageInstances(guild, instances) {
|
|
3641
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3642
|
+
for (const data of instances) {
|
|
3643
|
+
seen.add(data.id);
|
|
3644
|
+
const existing = guild.stageInstances.get(data.id);
|
|
3645
|
+
if (existing) existing._patch(data);
|
|
3646
|
+
else guild.stageInstances.set(data.id, new StageInstance(guild.client, data));
|
|
3647
|
+
}
|
|
3648
|
+
for (const id of [...guild.stageInstances.keys()]) {
|
|
3649
|
+
if (!seen.has(id)) guild.stageInstances.delete(id);
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
function applyStageCounts(guild, counts) {
|
|
3653
|
+
for (const count of counts) {
|
|
3654
|
+
const channel = guild.channels.get(count.channel_id);
|
|
3655
|
+
if (channel?.isStage()) channel._patchCounts(count);
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
function cacheStageInstance(client, data) {
|
|
3659
|
+
const guild = client.guilds.get(data.guild_id);
|
|
3660
|
+
const existing = guild?.stageInstances.get(data.id);
|
|
3661
|
+
if (existing) {
|
|
3662
|
+
existing._patch(data);
|
|
3663
|
+
return existing;
|
|
3664
|
+
}
|
|
3665
|
+
const instance = new StageInstance(client, data);
|
|
3666
|
+
guild?.stageInstances.set(instance.id, instance);
|
|
3667
|
+
return instance;
|
|
3668
|
+
}
|
|
3669
|
+
|
|
3411
3670
|
// src/Domain/Channel/ThreadBind.ts
|
|
3412
3671
|
var factory;
|
|
3413
3672
|
var managers = /* @__PURE__ */ new WeakMap();
|
|
@@ -3462,7 +3721,7 @@ var GuildChannel = class extends Channel {
|
|
|
3462
3721
|
}
|
|
3463
3722
|
/** Create a webhook for this channel. Requires Manage Webhooks. */
|
|
3464
3723
|
async createWebhook(options) {
|
|
3465
|
-
const data = await this.client.rest.post(
|
|
3724
|
+
const data = await this.client.rest.post(Routes14.channelWebhooks(this.id), {
|
|
3466
3725
|
body: options,
|
|
3467
3726
|
auth: true
|
|
3468
3727
|
});
|
|
@@ -3470,13 +3729,13 @@ var GuildChannel = class extends Channel {
|
|
|
3470
3729
|
}
|
|
3471
3730
|
/** Fetch all webhooks in this channel. Requires Manage Webhooks. */
|
|
3472
3731
|
async fetchWebhooks() {
|
|
3473
|
-
const data = await this.client.rest.get(
|
|
3732
|
+
const data = await this.client.rest.get(Routes14.channelWebhooks(this.id));
|
|
3474
3733
|
return data.map((w) => new Webhook(this.client, w));
|
|
3475
3734
|
}
|
|
3476
3735
|
/** Create an invite for this channel. Requires Create Instant Invite. */
|
|
3477
3736
|
async createInvite(options) {
|
|
3478
3737
|
const body = options ? toChannelInviteBody(options) : {};
|
|
3479
|
-
const data = await this.client.rest.post(
|
|
3738
|
+
const data = await this.client.rest.post(Routes14.channelInvites(this.id), {
|
|
3480
3739
|
body: Object.keys(body).length ? body : void 0,
|
|
3481
3740
|
auth: true
|
|
3482
3741
|
});
|
|
@@ -3484,7 +3743,7 @@ var GuildChannel = class extends Channel {
|
|
|
3484
3743
|
}
|
|
3485
3744
|
/** Fetch all invites for this channel. Requires Manage Channels. */
|
|
3486
3745
|
async fetchInvites() {
|
|
3487
|
-
const data = await this.client.rest.get(
|
|
3746
|
+
const data = await this.client.rest.get(Routes14.channelInvites(this.id));
|
|
3488
3747
|
return data.map((i) => new Invite(this.client, i));
|
|
3489
3748
|
}
|
|
3490
3749
|
/** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
|
|
@@ -3514,7 +3773,7 @@ var GuildChannel = class extends Channel {
|
|
|
3514
3773
|
}
|
|
3515
3774
|
/** Edit this channel's settings. Requires Manage Channels. */
|
|
3516
3775
|
async edit(options) {
|
|
3517
|
-
const data = await this.client.rest.patch(
|
|
3776
|
+
const data = await this.client.rest.patch(Routes14.channel(this.id), {
|
|
3518
3777
|
body: toChannelEditBody(options),
|
|
3519
3778
|
auth: true,
|
|
3520
3779
|
...auditReasonHeaders(options.reason)
|
|
@@ -3596,7 +3855,7 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3596
3855
|
* Sends only those fields. The thread-parent update body does not accept a channel rename.
|
|
3597
3856
|
*/
|
|
3598
3857
|
async editThreadDefaults(options) {
|
|
3599
|
-
const data = await this.client.rest.patch(
|
|
3858
|
+
const data = await this.client.rest.patch(Routes14.channel(this.id), {
|
|
3600
3859
|
body: toThreadParentEditBody(options),
|
|
3601
3860
|
auth: true,
|
|
3602
3861
|
...auditReasonHeaders(options.reason)
|
|
@@ -3606,6 +3865,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3606
3865
|
}
|
|
3607
3866
|
};
|
|
3608
3867
|
var AnnouncementChannel = class extends TextChannel {
|
|
3868
|
+
/**
|
|
3869
|
+
* Follow this announcement channel into `webhookChannelId` (a channel in a guild
|
|
3870
|
+
* where the bot can manage webhooks). Published messages are copied there.
|
|
3871
|
+
*/
|
|
3872
|
+
async follow(webhookChannelId) {
|
|
3873
|
+
return this.client.rest.post(
|
|
3874
|
+
Routes14.channelFollowers(this.id),
|
|
3875
|
+
{ body: { webhook_channel_id: webhookChannelId }, auth: true }
|
|
3876
|
+
);
|
|
3877
|
+
}
|
|
3878
|
+
/** Fetch follower counts for this announcement channel. */
|
|
3879
|
+
async fetchFollowerStats() {
|
|
3880
|
+
return this.client.rest.get(
|
|
3881
|
+
Routes14.channelFollowerStats(this.id),
|
|
3882
|
+
{ auth: true }
|
|
3883
|
+
);
|
|
3884
|
+
}
|
|
3609
3885
|
};
|
|
3610
3886
|
var CategoryChannel = class extends GuildChannel {
|
|
3611
3887
|
};
|
|
@@ -3632,6 +3908,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3632
3908
|
voiceConnectionLimit;
|
|
3633
3909
|
/** RTC region override for this channel. */
|
|
3634
3910
|
rtcRegion;
|
|
3911
|
+
/** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
|
|
3912
|
+
rtcP2p;
|
|
3635
3913
|
constructor(client, data) {
|
|
3636
3914
|
super(client, data);
|
|
3637
3915
|
this.topic = data.topic ?? null;
|
|
@@ -3645,6 +3923,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3645
3923
|
this.userLimit = data.user_limit ?? null;
|
|
3646
3924
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3647
3925
|
this.rtcRegion = data.rtc_region ?? null;
|
|
3926
|
+
this.rtcP2p = data.rtc_p2p ?? false;
|
|
3648
3927
|
}
|
|
3649
3928
|
/**
|
|
3650
3929
|
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
@@ -3671,6 +3950,97 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
|
3671
3950
|
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3672
3951
|
}
|
|
3673
3952
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3953
|
+
if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
|
|
3954
|
+
}
|
|
3955
|
+
};
|
|
3956
|
+
var StageChannel = class extends VoiceChannel {
|
|
3957
|
+
/** Last known stage counts, or null until Fluxer sends them. */
|
|
3958
|
+
counts = null;
|
|
3959
|
+
/** The cached live stage of this channel, or null when the stage isn't live (or not cached). */
|
|
3960
|
+
get stageInstance() {
|
|
3961
|
+
const guild = this.client.guilds.get(this.guildId);
|
|
3962
|
+
if (!guild) return null;
|
|
3963
|
+
for (const instance of guild.stageInstances.values()) {
|
|
3964
|
+
if (instance.channelId === this.id) return instance;
|
|
3965
|
+
}
|
|
3966
|
+
return null;
|
|
3967
|
+
}
|
|
3968
|
+
/** Whether the stage is live according to the cache. */
|
|
3969
|
+
get isLive() {
|
|
3970
|
+
return this.stageInstance !== null;
|
|
3971
|
+
}
|
|
3972
|
+
/**
|
|
3973
|
+
* Start a stage in this channel. Needs a stage moderator (`MANAGE_CHANNELS`, `MUTE_MEMBERS` and
|
|
3974
|
+
* `MOVE_MEMBERS`). When the caller is connected to the stage, they become a speaker.
|
|
3975
|
+
*/
|
|
3976
|
+
async createStageInstance(options) {
|
|
3977
|
+
const body = { channel_id: this.id, topic: options.topic };
|
|
3978
|
+
if (options.sendStartNotification !== void 0) {
|
|
3979
|
+
body.send_start_notification = options.sendStartNotification;
|
|
3980
|
+
}
|
|
3981
|
+
const data = await this.client.rest.post(Routes14.stageInstances(), {
|
|
3982
|
+
body,
|
|
3983
|
+
auth: true,
|
|
3984
|
+
...auditReasonHeaders(options.reason)
|
|
3985
|
+
});
|
|
3986
|
+
return cacheStageInstance(this.client, data);
|
|
3987
|
+
}
|
|
3988
|
+
/** Fetch the live stage of this channel. Rejects with `UNKNOWN_STAGE_INSTANCE` when not live. */
|
|
3989
|
+
async fetchStageInstance() {
|
|
3990
|
+
const data = await this.client.rest.get(Routes14.stageInstance(this.id), {
|
|
3991
|
+
auth: true
|
|
3992
|
+
});
|
|
3993
|
+
return cacheStageInstance(this.client, data);
|
|
3994
|
+
}
|
|
3995
|
+
/**
|
|
3996
|
+
* Move a member (or yourself when `user` is omitted) between the audience and the speakers.
|
|
3997
|
+
*
|
|
3998
|
+
* - Yourself, `false`: become a speaker (needs `MUTE_MEMBERS`), or accept an open invite.
|
|
3999
|
+
* - Yourself, `true`: move to the audience, or decline an invite.
|
|
4000
|
+
* - Another member, `false`: invite them to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`.
|
|
4001
|
+
* - Another member, `true`: move them to the audience and clear a raised hand or invite.
|
|
4002
|
+
*/
|
|
4003
|
+
async setSuppressed(suppressed, user) {
|
|
4004
|
+
const userId = user === void 0 ? "@me" : typeof user === "string" ? user : user.id;
|
|
4005
|
+
const body = {
|
|
4006
|
+
channel_id: this.id,
|
|
4007
|
+
suppress: suppressed
|
|
4008
|
+
};
|
|
4009
|
+
await this.client.rest.patch(Routes14.guildVoiceState(this.guildId, userId), {
|
|
4010
|
+
body,
|
|
4011
|
+
auth: true
|
|
4012
|
+
});
|
|
4013
|
+
}
|
|
4014
|
+
/** Invite a member to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`. */
|
|
4015
|
+
async inviteToSpeak(user) {
|
|
4016
|
+
await this.setSuppressed(false, user);
|
|
4017
|
+
}
|
|
4018
|
+
/** Move a speaker (or yourself when `user` is omitted) to the audience. */
|
|
4019
|
+
async moveToAudience(user) {
|
|
4020
|
+
await this.setSuppressed(true, user);
|
|
4021
|
+
}
|
|
4022
|
+
/**
|
|
4023
|
+
* Raise (`true`) or lower (`false`) your hand. Raising needs a live stage and
|
|
4024
|
+
* `REQUEST_TO_SPEAK`; lowering also accepts an open invite to speak.
|
|
4025
|
+
*/
|
|
4026
|
+
async setRequestToSpeak(raised = true) {
|
|
4027
|
+
const body = {
|
|
4028
|
+
channel_id: this.id,
|
|
4029
|
+
request_to_speak_timestamp: raised ? (/* @__PURE__ */ new Date()).toISOString() : null
|
|
4030
|
+
};
|
|
4031
|
+
await this.client.rest.patch(Routes14.guildVoiceState(this.guildId, "@me"), {
|
|
4032
|
+
body,
|
|
4033
|
+
auth: true
|
|
4034
|
+
});
|
|
4035
|
+
}
|
|
4036
|
+
/** @internal Apply a stage count object. */
|
|
4037
|
+
_patchCounts(data) {
|
|
4038
|
+
this.counts = {
|
|
4039
|
+
listenerCount: data.listener_count,
|
|
4040
|
+
speakerCount: data.speaker_count,
|
|
4041
|
+
requestCount: data.request_count,
|
|
4042
|
+
videoEnabled: data.video_enabled ?? null
|
|
4043
|
+
};
|
|
3674
4044
|
}
|
|
3675
4045
|
};
|
|
3676
4046
|
var LinkChannel = class extends GuildChannel {
|
|
@@ -3686,10 +4056,10 @@ var LinkChannel = class extends GuildChannel {
|
|
|
3686
4056
|
};
|
|
3687
4057
|
|
|
3688
4058
|
// src/Domain/Channel/ThreadManager.ts
|
|
3689
|
-
import { ChannelType as ChannelType6, Routes as
|
|
4059
|
+
import { ChannelType as ChannelType6, Routes as Routes16 } from "@fluxerjs/types";
|
|
3690
4060
|
|
|
3691
4061
|
// src/Domain/Channel/ThreadChannel.ts
|
|
3692
|
-
import { ChannelType as ChannelType5, Routes as
|
|
4062
|
+
import { ChannelType as ChannelType5, Routes as Routes15 } from "@fluxerjs/types";
|
|
3693
4063
|
var ThreadMember = class {
|
|
3694
4064
|
/** Thread ID. */
|
|
3695
4065
|
id;
|
|
@@ -3816,7 +4186,7 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
|
|
|
3816
4186
|
* `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
|
|
3817
4187
|
*/
|
|
3818
4188
|
async edit(options) {
|
|
3819
|
-
const data = await this.client.rest.patch(
|
|
4189
|
+
const data = await this.client.rest.patch(Routes15.channel(this.id), {
|
|
3820
4190
|
body: toThreadEditBody(this.type, threadEditFields(options)),
|
|
3821
4191
|
auth: true,
|
|
3822
4192
|
...auditReasonHeaders(options.reason)
|
|
@@ -3834,16 +4204,16 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
|
|
|
3834
4204
|
}
|
|
3835
4205
|
/** Join this thread. */
|
|
3836
4206
|
async join() {
|
|
3837
|
-
await this.client.rest.put(
|
|
4207
|
+
await this.client.rest.put(Routes15.channelThreadMemberMe(this.id), { auth: true });
|
|
3838
4208
|
}
|
|
3839
4209
|
/** Leave this thread. */
|
|
3840
4210
|
async leave() {
|
|
3841
|
-
await this.client.rest.delete(
|
|
4211
|
+
await this.client.rest.delete(Routes15.channelThreadMemberMe(this.id), { auth: true });
|
|
3842
4212
|
}
|
|
3843
4213
|
/** Update the current user's notification settings for this thread. */
|
|
3844
4214
|
async editSelf(options) {
|
|
3845
4215
|
const data = await this.client.rest.patch(
|
|
3846
|
-
|
|
4216
|
+
Routes15.channelThreadMemberMeSettings(this.id),
|
|
3847
4217
|
{ body: toThreadMemberSettingsBody(options), auth: true }
|
|
3848
4218
|
);
|
|
3849
4219
|
this.member = data ? new ThreadMember(data) : null;
|
|
@@ -3857,7 +4227,7 @@ var ThreadMemberManager = class {
|
|
|
3857
4227
|
/** List members of this thread. */
|
|
3858
4228
|
async fetch(options) {
|
|
3859
4229
|
const data = await this.thread.client.rest.get(
|
|
3860
|
-
withQuery(
|
|
4230
|
+
withQuery(Routes15.channelThreadMembers(this.thread.id), {
|
|
3861
4231
|
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
|
|
3862
4232
|
after: options?.after,
|
|
3863
4233
|
limit: options?.limit
|
|
@@ -3868,7 +4238,7 @@ var ThreadMemberManager = class {
|
|
|
3868
4238
|
/** Fetch one member of this thread. */
|
|
3869
4239
|
async fetchOne(userId, options) {
|
|
3870
4240
|
const data = await this.thread.client.rest.get(
|
|
3871
|
-
withQuery(
|
|
4241
|
+
withQuery(Routes15.channelThreadMember(this.thread.id, userId), {
|
|
3872
4242
|
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
|
|
3873
4243
|
})
|
|
3874
4244
|
);
|
|
@@ -3876,13 +4246,13 @@ var ThreadMemberManager = class {
|
|
|
3876
4246
|
}
|
|
3877
4247
|
/** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
|
|
3878
4248
|
async add(userId) {
|
|
3879
|
-
await this.thread.client.rest.put(
|
|
4249
|
+
await this.thread.client.rest.put(Routes15.channelThreadMember(this.thread.id, userId), {
|
|
3880
4250
|
auth: true
|
|
3881
4251
|
});
|
|
3882
4252
|
}
|
|
3883
4253
|
/** Remove a user from this thread. */
|
|
3884
4254
|
async remove(userId) {
|
|
3885
|
-
await this.thread.client.rest.delete(
|
|
4255
|
+
await this.thread.client.rest.delete(Routes15.channelThreadMember(this.thread.id, userId), {
|
|
3886
4256
|
auth: true
|
|
3887
4257
|
});
|
|
3888
4258
|
}
|
|
@@ -3907,7 +4277,7 @@ var ThreadManager = class {
|
|
|
3907
4277
|
});
|
|
3908
4278
|
}
|
|
3909
4279
|
const data = await this.channel.client.rest.post(
|
|
3910
|
-
|
|
4280
|
+
Routes16.channelThreads(this.channel.id),
|
|
3911
4281
|
{
|
|
3912
4282
|
body: toStartThreadBody(this.channel.type, options),
|
|
3913
4283
|
auth: true,
|
|
@@ -3940,7 +4310,7 @@ var ThreadManager = class {
|
|
|
3940
4310
|
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
3941
4311
|
if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
|
|
3942
4312
|
const data = await this.channel.client.rest.post(
|
|
3943
|
-
|
|
4313
|
+
Routes16.channelThreads(this.channel.id),
|
|
3944
4314
|
{
|
|
3945
4315
|
body,
|
|
3946
4316
|
files: prepared.files,
|
|
@@ -3959,7 +4329,7 @@ var ThreadManager = class {
|
|
|
3959
4329
|
* `before` is an ISO-8601 archive timestamp.
|
|
3960
4330
|
*/
|
|
3961
4331
|
async fetchArchived(options) {
|
|
3962
|
-
const path = options.type === "private" ?
|
|
4332
|
+
const path = options.type === "private" ? Routes16.channelThreadsArchivedPrivate(this.channel.id) : Routes16.channelThreadsArchivedPublic(this.channel.id);
|
|
3963
4333
|
const data = await this.channel.client.rest.get(
|
|
3964
4334
|
withQuery(path, { before: options.before, limit: options.limit })
|
|
3965
4335
|
);
|
|
@@ -3971,7 +4341,7 @@ var ThreadManager = class {
|
|
|
3971
4341
|
*/
|
|
3972
4342
|
async fetchJoinedPrivateArchived(options) {
|
|
3973
4343
|
const data = await this.channel.client.rest.get(
|
|
3974
|
-
withQuery(
|
|
4344
|
+
withQuery(Routes16.channelJoinedArchivedPrivateThreads(this.channel.id), {
|
|
3975
4345
|
before: options?.before,
|
|
3976
4346
|
limit: options?.limit
|
|
3977
4347
|
})
|
|
@@ -3984,7 +4354,7 @@ var ThreadManager = class {
|
|
|
3984
4354
|
*/
|
|
3985
4355
|
async search(options) {
|
|
3986
4356
|
const data = await this.channel.client.rest.get(
|
|
3987
|
-
withQuery(
|
|
4357
|
+
withQuery(Routes16.channelThreadSearch(this.channel.id), {
|
|
3988
4358
|
name: options?.name,
|
|
3989
4359
|
tag: options?.tag,
|
|
3990
4360
|
tag_setting: options?.tagSetting,
|
|
@@ -4012,7 +4382,7 @@ var ThreadManager = class {
|
|
|
4012
4382
|
}
|
|
4013
4383
|
/** Set the auto-archive and slowmode defaults copied onto new threads. */
|
|
4014
4384
|
async editDefaults(options) {
|
|
4015
|
-
return this.channel.client.rest.patch(
|
|
4385
|
+
return this.channel.client.rest.patch(Routes16.channel(this.channel.id), {
|
|
4016
4386
|
body: toThreadParentEditBody(options),
|
|
4017
4387
|
auth: true,
|
|
4018
4388
|
...auditReasonHeaders(options.reason)
|
|
@@ -4030,7 +4400,7 @@ function isSearchNotReady(data) {
|
|
|
4030
4400
|
return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
|
|
4031
4401
|
}
|
|
4032
4402
|
async function fetchActiveThreads(client, guildId) {
|
|
4033
|
-
const data = await client.rest.get(
|
|
4403
|
+
const data = await client.rest.get(Routes16.guildActiveThreads(guildId));
|
|
4034
4404
|
return fetchedThreadsFrom(client, data);
|
|
4035
4405
|
}
|
|
4036
4406
|
|
|
@@ -4089,7 +4459,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
4089
4459
|
* `defaultForumLayout` is sent only for forum channels.
|
|
4090
4460
|
*/
|
|
4091
4461
|
async edit(options) {
|
|
4092
|
-
const data = await this.client.rest.patch(
|
|
4462
|
+
const data = await this.client.rest.patch(Routes17.channel(this.id), {
|
|
4093
4463
|
body: {
|
|
4094
4464
|
...toChannelEditBody(options),
|
|
4095
4465
|
...forumParentWire(options, this.type === ChannelType7.GuildForum)
|
|
@@ -4118,7 +4488,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
4118
4488
|
}
|
|
4119
4489
|
/** Set the auto-archive and slowmode defaults copied onto new posts. */
|
|
4120
4490
|
async editThreadDefaults(options) {
|
|
4121
|
-
const data = await this.client.rest.patch(
|
|
4491
|
+
const data = await this.client.rest.patch(Routes17.channel(this.id), {
|
|
4122
4492
|
body: toThreadParentEditBody(options),
|
|
4123
4493
|
auth: true,
|
|
4124
4494
|
...auditReasonHeaders(options.reason)
|
|
@@ -4128,7 +4498,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
4128
4498
|
}
|
|
4129
4499
|
/** Create a tag. The response replaces {@link availableTags}. */
|
|
4130
4500
|
async createTag(options) {
|
|
4131
|
-
const data = await this.client.rest.post(
|
|
4501
|
+
const data = await this.client.rest.post(Routes17.channelTags(this.id), {
|
|
4132
4502
|
body: toForumTagBody(options),
|
|
4133
4503
|
auth: true,
|
|
4134
4504
|
...auditReasonHeaders(options.reason)
|
|
@@ -4138,7 +4508,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
4138
4508
|
}
|
|
4139
4509
|
/** Replace a tag. The response replaces {@link availableTags}. */
|
|
4140
4510
|
async editTag(tagId, options) {
|
|
4141
|
-
const data = await this.client.rest.put(
|
|
4511
|
+
const data = await this.client.rest.put(Routes17.channelTag(this.id, tagId), {
|
|
4142
4512
|
body: toForumTagBody(options),
|
|
4143
4513
|
auth: true,
|
|
4144
4514
|
...auditReasonHeaders(options.reason)
|
|
@@ -4148,7 +4518,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
|
|
|
4148
4518
|
}
|
|
4149
4519
|
/** Delete a tag. The response replaces {@link availableTags}. */
|
|
4150
4520
|
async deleteTag(tagId, reason) {
|
|
4151
|
-
const data = await this.client.rest.delete(
|
|
4521
|
+
const data = await this.client.rest.delete(Routes17.channelTag(this.id, tagId), {
|
|
4152
4522
|
auth: true,
|
|
4153
4523
|
...auditReasonHeaders(reason)
|
|
4154
4524
|
});
|
|
@@ -4183,6 +4553,7 @@ var GUILD_FACTORIES = {
|
|
|
4183
4553
|
[ChannelType8.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
|
|
4184
4554
|
[ChannelType8.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
4185
4555
|
[ChannelType8.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
4556
|
+
[ChannelType8.GuildStageVoice]: (c, d) => new StageChannel(c, d),
|
|
4186
4557
|
[ChannelType8.GuildLink]: (c, d) => new LinkChannel(c, d),
|
|
4187
4558
|
[ChannelType8.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
|
|
4188
4559
|
[ChannelType8.PublicThread]: (c, d) => new ThreadChannel(c, d),
|
|
@@ -4216,8 +4587,8 @@ bindThreadManager((channel) => new ThreadManager(channel));
|
|
|
4216
4587
|
import { ChannelType as ChannelType9 } from "@fluxerjs/types";
|
|
4217
4588
|
|
|
4218
4589
|
// src/Domain/Guild/GuildEmoji.ts
|
|
4219
|
-
import { Routes as
|
|
4220
|
-
import { SnowflakeUtil as
|
|
4590
|
+
import { Routes as Routes18 } from "@fluxerjs/types";
|
|
4591
|
+
import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
|
|
4221
4592
|
var GuildEmoji = class extends Base {
|
|
4222
4593
|
client;
|
|
4223
4594
|
id;
|
|
@@ -4253,11 +4624,11 @@ var GuildEmoji = class extends Base {
|
|
|
4253
4624
|
}
|
|
4254
4625
|
/** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
|
|
4255
4626
|
get createdTimestamp() {
|
|
4256
|
-
return
|
|
4627
|
+
return SnowflakeUtil6.timestampFromSnowflake(this.id);
|
|
4257
4628
|
}
|
|
4258
4629
|
/** Date when this emoji was created, derived from its snowflake ID. */
|
|
4259
4630
|
get createdAt() {
|
|
4260
|
-
return
|
|
4631
|
+
return SnowflakeUtil6.dateFromSnowflake(this.id);
|
|
4261
4632
|
}
|
|
4262
4633
|
/** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
|
|
4263
4634
|
toString() {
|
|
@@ -4265,7 +4636,7 @@ var GuildEmoji = class extends Base {
|
|
|
4265
4636
|
}
|
|
4266
4637
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
4267
4638
|
async delete(reason) {
|
|
4268
|
-
await this.client.rest.delete(
|
|
4639
|
+
await this.client.rest.delete(Routes18.guildEmoji(this.guildId, this.id), {
|
|
4269
4640
|
auth: true,
|
|
4270
4641
|
...auditReasonHeaders(reason)
|
|
4271
4642
|
});
|
|
@@ -4278,7 +4649,7 @@ var GuildEmoji = class extends Base {
|
|
|
4278
4649
|
*/
|
|
4279
4650
|
async edit(options) {
|
|
4280
4651
|
const { reason, name } = options;
|
|
4281
|
-
const data = await this.client.rest.patch(
|
|
4652
|
+
const data = await this.client.rest.patch(Routes18.guildEmoji(this.guildId, this.id), {
|
|
4282
4653
|
body: { name },
|
|
4283
4654
|
auth: true,
|
|
4284
4655
|
...auditReasonHeaders(reason)
|
|
@@ -4289,7 +4660,7 @@ var GuildEmoji = class extends Base {
|
|
|
4289
4660
|
};
|
|
4290
4661
|
|
|
4291
4662
|
// src/Domain/Guild/GuildMember.ts
|
|
4292
|
-
import { Routes as
|
|
4663
|
+
import { Routes as Routes20 } from "@fluxerjs/types";
|
|
4293
4664
|
import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
|
|
4294
4665
|
|
|
4295
4666
|
// src/Helpers/Permissions.ts
|
|
@@ -4313,7 +4684,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
4313
4684
|
|
|
4314
4685
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
4315
4686
|
import { Collection as Collection7 } from "@fluxerjs/collection";
|
|
4316
|
-
import { Routes as
|
|
4687
|
+
import { Routes as Routes19 } from "@fluxerjs/types";
|
|
4317
4688
|
function roleId(roleOrId) {
|
|
4318
4689
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
4319
4690
|
}
|
|
@@ -4342,7 +4713,7 @@ var GuildMemberRoleManager = class {
|
|
|
4342
4713
|
const id = roleId(roleOrId);
|
|
4343
4714
|
if (this.ids.includes(id)) return;
|
|
4344
4715
|
await this.member.client.rest.put(
|
|
4345
|
-
|
|
4716
|
+
Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
4346
4717
|
);
|
|
4347
4718
|
this.ids.push(id);
|
|
4348
4719
|
}
|
|
@@ -4351,13 +4722,13 @@ var GuildMemberRoleManager = class {
|
|
|
4351
4722
|
const idx = this.ids.indexOf(id);
|
|
4352
4723
|
if (idx === -1) return;
|
|
4353
4724
|
await this.member.client.rest.delete(
|
|
4354
|
-
|
|
4725
|
+
Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
4355
4726
|
);
|
|
4356
4727
|
this.ids.splice(idx, 1);
|
|
4357
4728
|
}
|
|
4358
4729
|
async set(roleIds) {
|
|
4359
4730
|
const data = await this.member.client.rest.patch(
|
|
4360
|
-
|
|
4731
|
+
Routes19.guildMember(this.member.guild.id, this.member.id),
|
|
4361
4732
|
{ body: { roles: roleIds }, auth: true }
|
|
4362
4733
|
);
|
|
4363
4734
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -4511,7 +4882,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
4511
4882
|
*/
|
|
4512
4883
|
async edit(options) {
|
|
4513
4884
|
const isMe = this.client.user?.id === this.id;
|
|
4514
|
-
const route = isMe ?
|
|
4885
|
+
const route = isMe ? Routes20.guildMemberMe(this.guild.id) : Routes20.guildMember(this.guild.id, this.id);
|
|
4515
4886
|
const data = await this.client.rest.patch(route, {
|
|
4516
4887
|
body: toMemberEditBody(options),
|
|
4517
4888
|
auth: true,
|
|
@@ -4624,8 +4995,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
4624
4995
|
};
|
|
4625
4996
|
|
|
4626
4997
|
// src/Domain/Guild/GuildSticker.ts
|
|
4627
|
-
import { Routes as
|
|
4628
|
-
import { SnowflakeUtil as
|
|
4998
|
+
import { Routes as Routes21 } from "@fluxerjs/types";
|
|
4999
|
+
import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
|
|
4629
5000
|
var GuildSticker = class extends Base {
|
|
4630
5001
|
client;
|
|
4631
5002
|
id;
|
|
@@ -4667,15 +5038,15 @@ var GuildSticker = class extends Base {
|
|
|
4667
5038
|
}
|
|
4668
5039
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
4669
5040
|
get createdTimestamp() {
|
|
4670
|
-
return
|
|
5041
|
+
return SnowflakeUtil7.timestampFromSnowflake(this.id);
|
|
4671
5042
|
}
|
|
4672
5043
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
4673
5044
|
get createdAt() {
|
|
4674
|
-
return
|
|
5045
|
+
return SnowflakeUtil7.dateFromSnowflake(this.id);
|
|
4675
5046
|
}
|
|
4676
5047
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
4677
5048
|
async delete(reason) {
|
|
4678
|
-
await this.client.rest.delete(
|
|
5049
|
+
await this.client.rest.delete(Routes21.guildSticker(this.guildId, this.id), {
|
|
4679
5050
|
auth: true,
|
|
4680
5051
|
...auditReasonHeaders(reason)
|
|
4681
5052
|
});
|
|
@@ -4688,7 +5059,7 @@ var GuildSticker = class extends Base {
|
|
|
4688
5059
|
*/
|
|
4689
5060
|
async edit(options) {
|
|
4690
5061
|
const { reason, ...body } = options;
|
|
4691
|
-
const data = await this.client.rest.patch(
|
|
5062
|
+
const data = await this.client.rest.patch(Routes21.guildSticker(this.guildId, this.id), {
|
|
4692
5063
|
body,
|
|
4693
5064
|
auth: true,
|
|
4694
5065
|
...auditReasonHeaders(reason)
|
|
@@ -4701,12 +5072,12 @@ var GuildSticker = class extends Base {
|
|
|
4701
5072
|
};
|
|
4702
5073
|
|
|
4703
5074
|
// src/Domain/Guild/Role.ts
|
|
4704
|
-
import { Routes as
|
|
5075
|
+
import { Routes as Routes22 } from "@fluxerjs/types";
|
|
4705
5076
|
import {
|
|
4706
5077
|
ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
|
|
4707
5078
|
PermissionFlags as PermissionFlags4,
|
|
4708
5079
|
PermissionsBitField as PermissionsBitField3,
|
|
4709
|
-
SnowflakeUtil as
|
|
5080
|
+
SnowflakeUtil as SnowflakeUtil8
|
|
4710
5081
|
} from "@fluxerjs/util";
|
|
4711
5082
|
var Role = class _Role extends Base {
|
|
4712
5083
|
/** Parent client instance. */
|
|
@@ -4729,6 +5100,8 @@ var Role = class _Role extends Base {
|
|
|
4729
5100
|
mentionable;
|
|
4730
5101
|
/** Unicode emoji for this role (null = none). */
|
|
4731
5102
|
unicodeEmoji;
|
|
5103
|
+
/** Role icon image hash (null = none). */
|
|
5104
|
+
icon;
|
|
4732
5105
|
/** Hoist position (null = not hoisted). */
|
|
4733
5106
|
hoistPosition;
|
|
4734
5107
|
constructor(client, data, guildId) {
|
|
@@ -4736,20 +5109,26 @@ var Role = class _Role extends Base {
|
|
|
4736
5109
|
this.client = client;
|
|
4737
5110
|
this.id = data.id;
|
|
4738
5111
|
this.guildId = guildId;
|
|
4739
|
-
this.name = data.name;
|
|
4740
|
-
this.color = data.color;
|
|
4741
|
-
this.position = data.position;
|
|
4742
|
-
this._permissions = data.permissions;
|
|
5112
|
+
this.name = data.name ?? "";
|
|
5113
|
+
this.color = data.color ?? 0;
|
|
5114
|
+
this.position = data.position ?? 0;
|
|
5115
|
+
this._permissions = data.permissions ?? "0";
|
|
4743
5116
|
this.hoist = !!data.hoist;
|
|
4744
5117
|
this.mentionable = !!data.mentionable;
|
|
4745
5118
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5119
|
+
this.icon = data.icon ?? null;
|
|
4746
5120
|
this.hoistPosition = data.hoist_position ?? null;
|
|
4747
5121
|
}
|
|
4748
5122
|
/**
|
|
4749
5123
|
* Permissions bitfield (Administrator grants all permissions).
|
|
4750
5124
|
*/
|
|
4751
5125
|
get permissions() {
|
|
4752
|
-
|
|
5126
|
+
let bits;
|
|
5127
|
+
try {
|
|
5128
|
+
bits = BigInt(this._permissions ?? "0");
|
|
5129
|
+
} catch {
|
|
5130
|
+
bits = 0n;
|
|
5131
|
+
}
|
|
4753
5132
|
return new PermissionsBitField3(
|
|
4754
5133
|
(bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
|
|
4755
5134
|
);
|
|
@@ -4768,25 +5147,26 @@ var Role = class _Role extends Base {
|
|
|
4768
5147
|
*/
|
|
4769
5148
|
/** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
|
|
4770
5149
|
get createdTimestamp() {
|
|
4771
|
-
return
|
|
5150
|
+
return SnowflakeUtil8.timestampFromSnowflake(this.id);
|
|
4772
5151
|
}
|
|
4773
5152
|
/** Date when this role was created, derived from its snowflake ID. */
|
|
4774
5153
|
get createdAt() {
|
|
4775
|
-
return
|
|
5154
|
+
return SnowflakeUtil8.dateFromSnowflake(this.id);
|
|
4776
5155
|
}
|
|
4777
5156
|
toString() {
|
|
4778
5157
|
return `<@&${this.id}>`;
|
|
4779
5158
|
}
|
|
4780
5159
|
/** @internal */
|
|
4781
5160
|
_patch(data) {
|
|
4782
|
-
this.name = data.name;
|
|
4783
|
-
this.color = data.color;
|
|
4784
|
-
this.position = data.position;
|
|
4785
|
-
this._permissions = data.permissions;
|
|
4786
|
-
this.hoist = !!data.hoist;
|
|
4787
|
-
this.mentionable = !!data.mentionable;
|
|
4788
|
-
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
4789
|
-
this.
|
|
5161
|
+
if (data.name !== void 0) this.name = data.name;
|
|
5162
|
+
if (data.color !== void 0) this.color = data.color;
|
|
5163
|
+
if (data.position !== void 0) this.position = data.position;
|
|
5164
|
+
if (data.permissions !== void 0) this._permissions = data.permissions;
|
|
5165
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
5166
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
5167
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
5168
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
5169
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
4790
5170
|
}
|
|
4791
5171
|
/**
|
|
4792
5172
|
* Snapshot for role-update events (before in-place patch).
|
|
@@ -4804,6 +5184,7 @@ var Role = class _Role extends Base {
|
|
|
4804
5184
|
hoist: this.hoist,
|
|
4805
5185
|
mentionable: this.mentionable,
|
|
4806
5186
|
unicode_emoji: this.unicodeEmoji,
|
|
5187
|
+
icon: this.icon,
|
|
4807
5188
|
hoist_position: this.hoistPosition
|
|
4808
5189
|
},
|
|
4809
5190
|
this.guildId
|
|
@@ -4816,7 +5197,7 @@ var Role = class _Role extends Base {
|
|
|
4816
5197
|
*/
|
|
4817
5198
|
async edit(options) {
|
|
4818
5199
|
const body = toRoleEditBody(options);
|
|
4819
|
-
const data = await this.client.rest.patch(
|
|
5200
|
+
const data = await this.client.rest.patch(Routes22.guildRole(this.guildId, this.id), {
|
|
4820
5201
|
body: Object.keys(body).length ? body : void 0,
|
|
4821
5202
|
auth: true,
|
|
4822
5203
|
...auditReasonHeaders(options.reason)
|
|
@@ -4829,7 +5210,7 @@ var Role = class _Role extends Base {
|
|
|
4829
5210
|
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
4830
5211
|
*/
|
|
4831
5212
|
async delete(reason) {
|
|
4832
|
-
await this.client.rest.delete(
|
|
5213
|
+
await this.client.rest.delete(Routes22.guildRole(this.guildId, this.id), {
|
|
4833
5214
|
auth: true,
|
|
4834
5215
|
...auditReasonHeaders(reason)
|
|
4835
5216
|
});
|
|
@@ -4981,6 +5362,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4981
5362
|
});
|
|
4982
5363
|
this.client = client;
|
|
4983
5364
|
}
|
|
5365
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
4984
5366
|
/**
|
|
4985
5367
|
* Remove a channel from cache. Does not delete it on the API.
|
|
4986
5368
|
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
@@ -4993,9 +5375,11 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4993
5375
|
}
|
|
4994
5376
|
return deleted;
|
|
4995
5377
|
}
|
|
4996
|
-
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
5378
|
+
/** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
|
|
4997
5379
|
async resolve(channelId) {
|
|
4998
|
-
|
|
5380
|
+
const id = normalizeSnowflakeId(channelId, "channels.resolve()");
|
|
5381
|
+
const cached = this.get(id);
|
|
5382
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
4999
5383
|
}
|
|
5000
5384
|
/**
|
|
5001
5385
|
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
@@ -5008,10 +5392,23 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5008
5392
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
5009
5393
|
*/
|
|
5010
5394
|
async fetch(channelId, options) {
|
|
5011
|
-
const
|
|
5012
|
-
|
|
5395
|
+
const id = normalizeSnowflakeId(channelId, "channels.fetch()");
|
|
5396
|
+
const cached = this.get(id);
|
|
5397
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
5398
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
|
|
5399
|
+
}
|
|
5400
|
+
async fetchFresh(channelId) {
|
|
5013
5401
|
try {
|
|
5014
|
-
const data =
|
|
5402
|
+
const data = assertApiObjectWithId(
|
|
5403
|
+
await this.client.rest.get(Routes23.channel(channelId)),
|
|
5404
|
+
"channels.fetch()"
|
|
5405
|
+
);
|
|
5406
|
+
const existing = this.get(channelId);
|
|
5407
|
+
if (existing && existing.type === data.type) {
|
|
5408
|
+
existing._patch(data);
|
|
5409
|
+
putChannel(this.client, existing);
|
|
5410
|
+
return existing;
|
|
5411
|
+
}
|
|
5015
5412
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
5016
5413
|
if (guildId) {
|
|
5017
5414
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -5056,7 +5453,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5056
5453
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
5057
5454
|
});
|
|
5058
5455
|
const data = await this.client.rest.post(
|
|
5059
|
-
|
|
5456
|
+
Routes23.channelMessages(channelId),
|
|
5060
5457
|
postPayload
|
|
5061
5458
|
);
|
|
5062
5459
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -5067,12 +5464,12 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
5067
5464
|
// src/ClientCore/Client.ts
|
|
5068
5465
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
5069
5466
|
import { REST } from "@fluxerjs/rest";
|
|
5070
|
-
import { GatewayOpcodes as GatewayOpcodes2, Routes as
|
|
5467
|
+
import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes38 } from "@fluxerjs/types";
|
|
5071
5468
|
import { createLogger } from "@fluxerjs/util";
|
|
5072
5469
|
|
|
5073
5470
|
// src/Domain/User.ts
|
|
5074
|
-
import { Routes as
|
|
5075
|
-
import { SnowflakeUtil as
|
|
5471
|
+
import { Routes as Routes24 } from "@fluxerjs/types";
|
|
5472
|
+
import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
|
|
5076
5473
|
var User = class extends Base {
|
|
5077
5474
|
/** Parent client instance. */
|
|
5078
5475
|
client;
|
|
@@ -5096,12 +5493,15 @@ var User = class extends Base {
|
|
|
5096
5493
|
system;
|
|
5097
5494
|
/** Banner hash for profile. */
|
|
5098
5495
|
banner;
|
|
5496
|
+
/** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
|
|
5497
|
+
partial;
|
|
5099
5498
|
constructor(client, data) {
|
|
5100
5499
|
super();
|
|
5101
5500
|
this.client = client;
|
|
5102
5501
|
this.id = data.id;
|
|
5103
|
-
this.
|
|
5104
|
-
this.
|
|
5502
|
+
this.partial = typeof data.username !== "string" || data.username.length === 0;
|
|
5503
|
+
this.username = data.username ?? "Unknown";
|
|
5504
|
+
this.discriminator = data.discriminator ?? "0";
|
|
5105
5505
|
this.globalName = data.global_name ?? null;
|
|
5106
5506
|
this.avatar = data.avatar ?? null;
|
|
5107
5507
|
this.bot = !!data.bot;
|
|
@@ -5112,13 +5512,18 @@ var User = class extends Base {
|
|
|
5112
5512
|
}
|
|
5113
5513
|
/** @internal */
|
|
5114
5514
|
_patch(data) {
|
|
5115
|
-
this.username = data.username;
|
|
5116
|
-
this.discriminator = data.discriminator;
|
|
5117
|
-
this.globalName = data.global_name ?? null;
|
|
5118
|
-
this.avatar = data.avatar ?? null;
|
|
5515
|
+
if (data.username !== void 0) this.username = data.username;
|
|
5516
|
+
if (data.discriminator !== void 0) this.discriminator = data.discriminator;
|
|
5517
|
+
if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
|
|
5518
|
+
if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
|
|
5119
5519
|
if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
|
|
5120
5520
|
if (data.flags !== void 0) this.flags = data.flags;
|
|
5121
5521
|
if (data.banner !== void 0) this.banner = data.banner;
|
|
5522
|
+
if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
|
|
5523
|
+
}
|
|
5524
|
+
/** Fetch the full user from REST when this instance is a partial stub. */
|
|
5525
|
+
async fetch() {
|
|
5526
|
+
return this.client.users.fetch(this.id, { force: true });
|
|
5122
5527
|
}
|
|
5123
5528
|
cdnOpts() {
|
|
5124
5529
|
return {
|
|
@@ -5156,11 +5561,11 @@ var User = class extends Base {
|
|
|
5156
5561
|
*/
|
|
5157
5562
|
/** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
|
|
5158
5563
|
get createdTimestamp() {
|
|
5159
|
-
return
|
|
5564
|
+
return SnowflakeUtil9.timestampFromSnowflake(this.id);
|
|
5160
5565
|
}
|
|
5161
5566
|
/** Date when this account was created, derived from its snowflake ID. */
|
|
5162
5567
|
get createdAt() {
|
|
5163
|
-
return
|
|
5568
|
+
return SnowflakeUtil9.dateFromSnowflake(this.id);
|
|
5164
5569
|
}
|
|
5165
5570
|
toString() {
|
|
5166
5571
|
return `<@${this.id}>`;
|
|
@@ -5170,7 +5575,7 @@ var User = class extends Base {
|
|
|
5170
5575
|
* @returns DM channel instance (cached if already open)
|
|
5171
5576
|
*/
|
|
5172
5577
|
async createDM() {
|
|
5173
|
-
const data = await this.client.rest.post(
|
|
5578
|
+
const data = await this.client.rest.post(Routes24.userMeChannels(), {
|
|
5174
5579
|
body: { recipient_id: this.id },
|
|
5175
5580
|
auth: true
|
|
5176
5581
|
});
|
|
@@ -5248,7 +5653,7 @@ function resolveCacheLimits(input) {
|
|
|
5248
5653
|
|
|
5249
5654
|
// src/ClientCore/ClientEmoji.ts
|
|
5250
5655
|
import { Collection as Collection8 } from "@fluxerjs/collection";
|
|
5251
|
-
import { Routes as
|
|
5656
|
+
import { Routes as Routes25 } from "@fluxerjs/types";
|
|
5252
5657
|
import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
|
|
5253
5658
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
5254
5659
|
if (typeof emoji === "object" && emoji.id) {
|
|
@@ -5267,7 +5672,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
5267
5672
|
const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
|
|
5268
5673
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
5269
5674
|
if (guildId) {
|
|
5270
|
-
const emojis = await client.rest.get(
|
|
5675
|
+
const emojis = await client.rest.get(Routes25.guildEmojis(guildId));
|
|
5271
5676
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
5272
5677
|
if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
|
|
5273
5678
|
throw new FluxerError(
|
|
@@ -5284,26 +5689,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
5284
5689
|
return parsed.name;
|
|
5285
5690
|
}
|
|
5286
5691
|
async function fetchInstance(client) {
|
|
5287
|
-
const raw = await client.rest.get(
|
|
5692
|
+
const raw = await client.rest.get(Routes25.instanceDiscovery(), {
|
|
5288
5693
|
auth: false,
|
|
5289
5694
|
unversioned: true
|
|
5290
5695
|
});
|
|
5291
5696
|
return parseInstanceDiscovery(raw);
|
|
5292
5697
|
}
|
|
5293
5698
|
function fetchGatewayInfo(client) {
|
|
5294
|
-
return client.rest.get(
|
|
5699
|
+
return client.rest.get(Routes25.gatewayBot());
|
|
5295
5700
|
}
|
|
5296
5701
|
function fetchEmojiMetadata(client, emojiId) {
|
|
5297
|
-
return client.rest.get(
|
|
5702
|
+
return client.rest.get(Routes25.emojiMetadata(emojiId), { auth: true });
|
|
5298
5703
|
}
|
|
5299
5704
|
function fetchStickerMetadata(client, stickerId) {
|
|
5300
|
-
return client.rest.get(
|
|
5705
|
+
return client.rest.get(Routes25.stickerMetadata(stickerId), { auth: true });
|
|
5301
5706
|
}
|
|
5302
5707
|
function fetchApplication(client) {
|
|
5303
|
-
return client.rest.get(
|
|
5708
|
+
return client.rest.get(Routes25.applicationsMe(), { auth: true });
|
|
5304
5709
|
}
|
|
5305
5710
|
async function fetchOAuthApplications(client) {
|
|
5306
|
-
const data = await client.rest.get(
|
|
5711
|
+
const data = await client.rest.get(Routes25.oauth2ApplicationsMe(), { auth: true });
|
|
5307
5712
|
if (Array.isArray(data)) return data;
|
|
5308
5713
|
if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
|
|
5309
5714
|
return data.applications;
|
|
@@ -5322,14 +5727,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
5322
5727
|
}
|
|
5323
5728
|
function preloadMessages(client, channelIds) {
|
|
5324
5729
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
5325
|
-
return client.rest.post(
|
|
5730
|
+
return client.rest.post(Routes25.preloadMessages(), {
|
|
5326
5731
|
body: { channels: channelIds },
|
|
5327
5732
|
auth: true
|
|
5328
5733
|
});
|
|
5329
5734
|
}
|
|
5330
5735
|
function preloadMessagesAlt(client, channelIds) {
|
|
5331
5736
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
5332
|
-
return client.rest.post(
|
|
5737
|
+
return client.rest.post(Routes25.preloadMessagesAlt(), {
|
|
5333
5738
|
body: { channels: channelIds },
|
|
5334
5739
|
auth: true
|
|
5335
5740
|
});
|
|
@@ -5337,7 +5742,7 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
5337
5742
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
5338
5743
|
validateBulkMessageFetchRequests(requests);
|
|
5339
5744
|
const wire = toBulkFetchWire(requests);
|
|
5340
|
-
const data = await client.rest.post(
|
|
5745
|
+
const data = await client.rest.post(Routes25.channelsMessagesBulk(), {
|
|
5341
5746
|
body: { requests: wire },
|
|
5342
5747
|
auth: true
|
|
5343
5748
|
});
|
|
@@ -5354,12 +5759,74 @@ async function bulkFetchMessages(client, requests, options = {}) {
|
|
|
5354
5759
|
};
|
|
5355
5760
|
}
|
|
5356
5761
|
async function searchMessages(client, options = {}) {
|
|
5357
|
-
const data = await client.rest.post(
|
|
5762
|
+
const data = await client.rest.post(Routes25.searchMessages(), {
|
|
5358
5763
|
body: toMessageSearchBody(options),
|
|
5359
5764
|
auth: true
|
|
5360
5765
|
});
|
|
5361
5766
|
return toMessageSearchResponse(data);
|
|
5362
5767
|
}
|
|
5768
|
+
function fetchEmojiSource(client, emojiId) {
|
|
5769
|
+
return client.rest.get(
|
|
5770
|
+
Routes25.emojiSource(emojiId),
|
|
5771
|
+
{ auth: true }
|
|
5772
|
+
);
|
|
5773
|
+
}
|
|
5774
|
+
function fetchStickerSource(client, stickerId) {
|
|
5775
|
+
return client.rest.get(
|
|
5776
|
+
Routes25.stickerSource(stickerId),
|
|
5777
|
+
{ auth: true }
|
|
5778
|
+
);
|
|
5779
|
+
}
|
|
5780
|
+
function fetchDiscoveryCategories(client) {
|
|
5781
|
+
return client.rest.get(
|
|
5782
|
+
Routes25.discoveryCategories(),
|
|
5783
|
+
{ auth: true }
|
|
5784
|
+
);
|
|
5785
|
+
}
|
|
5786
|
+
function searchDiscoveryGuilds(client, options = {}) {
|
|
5787
|
+
const params = new URLSearchParams();
|
|
5788
|
+
if (options.query !== void 0) params.set("query", options.query);
|
|
5789
|
+
if (options.category !== void 0) params.set("category", String(options.category));
|
|
5790
|
+
if (options.language !== void 0) params.set("language", options.language);
|
|
5791
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
5792
|
+
if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
|
|
5793
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5794
|
+
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
5795
|
+
const qs2 = params.toString();
|
|
5796
|
+
return client.rest.get(
|
|
5797
|
+
qs2 ? `${Routes25.discoveryGuilds()}?${qs2}` : Routes25.discoveryGuilds(),
|
|
5798
|
+
{ auth: true }
|
|
5799
|
+
);
|
|
5800
|
+
}
|
|
5801
|
+
function fetchExperiments(client) {
|
|
5802
|
+
return client.rest.get(Routes25.experiments(), {
|
|
5803
|
+
auth: true
|
|
5804
|
+
});
|
|
5805
|
+
}
|
|
5806
|
+
function refreshAttachmentUrls(client, attachmentUrls) {
|
|
5807
|
+
return client.rest.post(
|
|
5808
|
+
Routes25.attachmentsRefreshUrls(),
|
|
5809
|
+
{ body: { attachment_urls: attachmentUrls }, auth: true }
|
|
5810
|
+
);
|
|
5811
|
+
}
|
|
5812
|
+
function fetchInstanceBadges(client, options = {}) {
|
|
5813
|
+
const params = new URLSearchParams();
|
|
5814
|
+
if (options.ids !== void 0) params.set("ids", options.ids);
|
|
5815
|
+
if (options.after !== void 0) params.set("after", options.after);
|
|
5816
|
+
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
5817
|
+
if (options.version !== void 0) params.set("version", options.version);
|
|
5818
|
+
const qs2 = params.toString();
|
|
5819
|
+
return client.rest.get(
|
|
5820
|
+
qs2 ? `${Routes25.instanceBadges()}?${qs2}` : Routes25.instanceBadges(),
|
|
5821
|
+
{ auth: false }
|
|
5822
|
+
);
|
|
5823
|
+
}
|
|
5824
|
+
function fetchChannelPostData(client, channelId, threadIds) {
|
|
5825
|
+
return client.rest.post(
|
|
5826
|
+
Routes25.channelPostData(channelId),
|
|
5827
|
+
{ body: { thread_ids: threadIds }, auth: true }
|
|
5828
|
+
);
|
|
5829
|
+
}
|
|
5363
5830
|
|
|
5364
5831
|
// src/ClientCore/ClientEvents.ts
|
|
5365
5832
|
function createEventMethods(client) {
|
|
@@ -5378,18 +5845,19 @@ function createEventMethods(client) {
|
|
|
5378
5845
|
import { GatewayCloseCodes, WebSocketManager } from "@fluxerjs/ws";
|
|
5379
5846
|
|
|
5380
5847
|
// src/Domain/Guild/Guild.ts
|
|
5381
|
-
import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
|
|
5848
|
+
import { Collection as Collection9, LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
|
|
5382
5849
|
import { GuildNSFWLevel } from "@fluxerjs/types";
|
|
5383
|
-
import { SnowflakeUtil as
|
|
5850
|
+
import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
|
|
5384
5851
|
|
|
5385
5852
|
// src/ClientCore/GuildMemberManager.ts
|
|
5386
5853
|
import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
|
|
5387
|
-
import { Routes as
|
|
5854
|
+
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
5388
5855
|
var GuildMemberManager = class extends LimitedCollection2 {
|
|
5389
5856
|
constructor(guild) {
|
|
5390
5857
|
super({ maxSize: guild.client.cache.limits.members });
|
|
5391
5858
|
this.guild = guild;
|
|
5392
5859
|
}
|
|
5860
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
5393
5861
|
/**
|
|
5394
5862
|
* Get a guild member from cache or fetch from the API if not present.
|
|
5395
5863
|
* Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
|
|
@@ -5401,7 +5869,9 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5401
5869
|
* console.log(member.displayName);
|
|
5402
5870
|
*/
|
|
5403
5871
|
async resolve(userId) {
|
|
5404
|
-
|
|
5872
|
+
const id = normalizeSnowflakeId(userId, "members.resolve()");
|
|
5873
|
+
const cached = this.get(id);
|
|
5874
|
+
return cached && !cached.user.partial ? cached : this.fetch(id);
|
|
5405
5875
|
}
|
|
5406
5876
|
/**
|
|
5407
5877
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -5429,10 +5899,11 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5429
5899
|
return this.guild.fetchMe();
|
|
5430
5900
|
}
|
|
5431
5901
|
async fetch(userIdOrOptions, options) {
|
|
5432
|
-
if (typeof userIdOrOptions === "string") {
|
|
5433
|
-
const
|
|
5434
|
-
|
|
5435
|
-
|
|
5902
|
+
if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
|
|
5903
|
+
const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
|
|
5904
|
+
const cached = this.get(id);
|
|
5905
|
+
if (cached && !cached.user.partial && !options?.force) return cached;
|
|
5906
|
+
return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
|
|
5436
5907
|
}
|
|
5437
5908
|
return this.fetchMany(userIdOrOptions);
|
|
5438
5909
|
}
|
|
@@ -5441,10 +5912,14 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5441
5912
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
5442
5913
|
if (options?.after) params.set("after", options.after);
|
|
5443
5914
|
const qs2 = params.toString();
|
|
5444
|
-
const url =
|
|
5445
|
-
const data =
|
|
5915
|
+
const url = Routes26.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
5916
|
+
const data = assertApiArray(
|
|
5917
|
+
await this.guild.client.rest.get(url, { auth: true }),
|
|
5918
|
+
"members.fetch()"
|
|
5919
|
+
);
|
|
5446
5920
|
const members = [];
|
|
5447
5921
|
for (const m of data) {
|
|
5922
|
+
if (!m?.user?.id) continue;
|
|
5448
5923
|
const member = new GuildMember(
|
|
5449
5924
|
this.guild.client,
|
|
5450
5925
|
{ ...m, guild_id: this.guild.id },
|
|
@@ -5464,7 +5939,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5464
5939
|
*/
|
|
5465
5940
|
async search(options = {}) {
|
|
5466
5941
|
const data = await this.guild.client.rest.post(
|
|
5467
|
-
|
|
5942
|
+
Routes26.guildMembersSearch(this.guild.id),
|
|
5468
5943
|
{ body: toMemberSearchBody(options), auth: true }
|
|
5469
5944
|
);
|
|
5470
5945
|
const offset = options.offset ?? 0;
|
|
@@ -5490,7 +5965,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
5490
5965
|
};
|
|
5491
5966
|
|
|
5492
5967
|
// src/Domain/Guild/Admin.ts
|
|
5493
|
-
import { Routes as
|
|
5968
|
+
import { Routes as Routes27 } from "@fluxerjs/types";
|
|
5494
5969
|
function toAuditLogEntryPayload(entry, guildId) {
|
|
5495
5970
|
return {
|
|
5496
5971
|
id: entry.id,
|
|
@@ -5511,7 +5986,7 @@ function toVanityPayload(data) {
|
|
|
5511
5986
|
return { code: data.code ?? null, uses: data.uses };
|
|
5512
5987
|
}
|
|
5513
5988
|
async function fetchAuditLogs(guild, options) {
|
|
5514
|
-
const url =
|
|
5989
|
+
const url = Routes27.guildAuditLogs(guild.id) + qs({
|
|
5515
5990
|
limit: options?.limit,
|
|
5516
5991
|
before: options?.before,
|
|
5517
5992
|
after: options?.after,
|
|
@@ -5535,7 +6010,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
5535
6010
|
};
|
|
5536
6011
|
}
|
|
5537
6012
|
async function editGuild(guild, options) {
|
|
5538
|
-
const data = await guild.client.rest.patch(
|
|
6013
|
+
const data = await guild.client.rest.patch(Routes27.guild(guild.id), {
|
|
5539
6014
|
body: toGuildEditBody(options),
|
|
5540
6015
|
auth: true
|
|
5541
6016
|
});
|
|
@@ -5543,13 +6018,13 @@ async function editGuild(guild, options) {
|
|
|
5543
6018
|
return guild;
|
|
5544
6019
|
}
|
|
5545
6020
|
async function fetchVanityURL(guild) {
|
|
5546
|
-
const data = await guild.client.rest.get(
|
|
6021
|
+
const data = await guild.client.rest.get(Routes27.guildVanityUrl(guild.id), {
|
|
5547
6022
|
auth: true
|
|
5548
6023
|
});
|
|
5549
6024
|
return toVanityPayload(data);
|
|
5550
6025
|
}
|
|
5551
6026
|
async function editVanityURL(guild, code) {
|
|
5552
|
-
const data = await guild.client.rest.patch(
|
|
6027
|
+
const data = await guild.client.rest.patch(Routes27.guildVanityUrl(guild.id), {
|
|
5553
6028
|
body: { code },
|
|
5554
6029
|
auth: true
|
|
5555
6030
|
});
|
|
@@ -5557,14 +6032,14 @@ async function editVanityURL(guild, code) {
|
|
|
5557
6032
|
return toVanityPayload(data);
|
|
5558
6033
|
}
|
|
5559
6034
|
async function fetchDiscoveryStatus(guild) {
|
|
5560
|
-
const data = await guild.client.rest.get(
|
|
6035
|
+
const data = await guild.client.rest.get(Routes27.guildDiscovery(guild.id), {
|
|
5561
6036
|
auth: true
|
|
5562
6037
|
});
|
|
5563
6038
|
return toDiscoveryStatusPayload(data);
|
|
5564
6039
|
}
|
|
5565
6040
|
async function applyForDiscovery(guild, options) {
|
|
5566
6041
|
const data = await guild.client.rest.post(
|
|
5567
|
-
|
|
6042
|
+
Routes27.guildDiscovery(guild.id),
|
|
5568
6043
|
{
|
|
5569
6044
|
body: toDiscoveryBody(options),
|
|
5570
6045
|
auth: true
|
|
@@ -5574,7 +6049,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
5574
6049
|
}
|
|
5575
6050
|
async function editDiscoveryApplication(guild, options) {
|
|
5576
6051
|
const data = await guild.client.rest.patch(
|
|
5577
|
-
|
|
6052
|
+
Routes27.guildDiscovery(guild.id),
|
|
5578
6053
|
{
|
|
5579
6054
|
body: toDiscoveryBody(options),
|
|
5580
6055
|
auth: true
|
|
@@ -5583,34 +6058,39 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
5583
6058
|
return toDiscoveryApplicationPayload(data);
|
|
5584
6059
|
}
|
|
5585
6060
|
async function withdrawDiscoveryApplication(guild) {
|
|
5586
|
-
await guild.client.rest.delete(
|
|
6061
|
+
await guild.client.rest.delete(Routes27.guildDiscovery(guild.id), { auth: true });
|
|
5587
6062
|
}
|
|
5588
6063
|
async function deleteGuild(guild, options) {
|
|
5589
6064
|
const body = options ? toSudoBody(options) : {};
|
|
5590
|
-
await guild.client.rest.post(
|
|
6065
|
+
await guild.client.rest.post(Routes27.guildDelete(guild.id), {
|
|
5591
6066
|
body,
|
|
5592
6067
|
auth: true
|
|
5593
6068
|
});
|
|
5594
6069
|
guild.client.guilds.delete(guild.id);
|
|
5595
6070
|
}
|
|
5596
6071
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
5597
|
-
await guild.client.rest.post(
|
|
6072
|
+
await guild.client.rest.post(Routes27.guildTransferOwnership(guild.id), {
|
|
5598
6073
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
5599
6074
|
auth: true
|
|
5600
6075
|
});
|
|
5601
6076
|
}
|
|
5602
6077
|
|
|
5603
6078
|
// src/Domain/Guild/Channels.ts
|
|
5604
|
-
import { Routes as
|
|
6079
|
+
import { Routes as Routes28 } from "@fluxerjs/types";
|
|
5605
6080
|
async function createChannel(guild, options) {
|
|
5606
|
-
const created = await guild.client.rest.post(
|
|
6081
|
+
const created = await guild.client.rest.post(Routes28.guildChannels(guild.id), {
|
|
5607
6082
|
body: toChannelCreateBody(options),
|
|
5608
6083
|
auth: true
|
|
5609
6084
|
});
|
|
5610
6085
|
return cacheChannel(guild, created);
|
|
5611
6086
|
}
|
|
5612
6087
|
async function fetchChannels(guild) {
|
|
5613
|
-
const
|
|
6088
|
+
const raw = await guild.client.rest.get(Routes28.guildChannels(guild.id));
|
|
6089
|
+
if (!Array.isArray(raw))
|
|
6090
|
+
throw new TypeError(
|
|
6091
|
+
"guild.fetchChannels() received an invalid API payload (expected an array)"
|
|
6092
|
+
);
|
|
6093
|
+
const data = raw;
|
|
5614
6094
|
const channels = [];
|
|
5615
6095
|
for (const ch of data) {
|
|
5616
6096
|
const channel = cacheChannel(guild, ch);
|
|
@@ -5619,17 +6099,17 @@ async function fetchChannels(guild) {
|
|
|
5619
6099
|
return channels;
|
|
5620
6100
|
}
|
|
5621
6101
|
async function setChannelPositions(guild, updates) {
|
|
5622
|
-
await guild.client.rest.patch(
|
|
6102
|
+
await guild.client.rest.patch(Routes28.guildChannels(guild.id), {
|
|
5623
6103
|
body: toChannelPositionBody(updates),
|
|
5624
6104
|
auth: true
|
|
5625
6105
|
});
|
|
5626
6106
|
}
|
|
5627
6107
|
async function fetchWebhooks(guild) {
|
|
5628
|
-
const data = await guild.client.rest.get(
|
|
6108
|
+
const data = await guild.client.rest.get(Routes28.guildWebhooks(guild.id));
|
|
5629
6109
|
return data.map((w) => new Webhook(guild.client, w));
|
|
5630
6110
|
}
|
|
5631
6111
|
async function fetchInvites(guild) {
|
|
5632
|
-
const data = await guild.client.rest.get(
|
|
6112
|
+
const data = await guild.client.rest.get(Routes28.guildInvites(guild.id));
|
|
5633
6113
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
5634
6114
|
}
|
|
5635
6115
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -5649,14 +6129,14 @@ function resolveGuildOnlineCount(data) {
|
|
|
5649
6129
|
}
|
|
5650
6130
|
|
|
5651
6131
|
// src/Domain/Guild/Emojis.ts
|
|
5652
|
-
import { Routes as
|
|
6132
|
+
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
5653
6133
|
async function fetchEmojis(guild) {
|
|
5654
|
-
const data = await guild.client.rest.get(
|
|
6134
|
+
const data = await guild.client.rest.get(Routes29.guildEmojis(guild.id));
|
|
5655
6135
|
return data.map((e) => cacheEmoji(guild, e));
|
|
5656
6136
|
}
|
|
5657
6137
|
async function fetchEmoji(guild, emojiId) {
|
|
5658
6138
|
try {
|
|
5659
|
-
const data = await guild.client.rest.get(
|
|
6139
|
+
const data = await guild.client.rest.get(Routes29.guildEmoji(guild.id, emojiId));
|
|
5660
6140
|
return cacheEmoji(guild, data);
|
|
5661
6141
|
} catch (err) {
|
|
5662
6142
|
rethrowMapped(err, {
|
|
@@ -5667,7 +6147,7 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
5667
6147
|
}
|
|
5668
6148
|
async function createEmoji(guild, options) {
|
|
5669
6149
|
const { reason, ...body } = options;
|
|
5670
|
-
const data = await guild.client.rest.post(
|
|
6150
|
+
const data = await guild.client.rest.post(Routes29.guildEmojis(guild.id), {
|
|
5671
6151
|
body,
|
|
5672
6152
|
auth: true,
|
|
5673
6153
|
...auditReasonHeaders(reason)
|
|
@@ -5675,7 +6155,7 @@ async function createEmoji(guild, options) {
|
|
|
5675
6155
|
return cacheEmoji(guild, data);
|
|
5676
6156
|
}
|
|
5677
6157
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
5678
|
-
const data = await guild.client.rest.post(
|
|
6158
|
+
const data = await guild.client.rest.post(Routes29.guildEmojisClone(guild.id), {
|
|
5679
6159
|
body: { source_emoji_id: sourceEmojiId },
|
|
5680
6160
|
auth: true
|
|
5681
6161
|
});
|
|
@@ -5683,7 +6163,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
5683
6163
|
}
|
|
5684
6164
|
async function createEmojisBulk(guild, emojis) {
|
|
5685
6165
|
const data = await guild.client.rest.post(
|
|
5686
|
-
|
|
6166
|
+
Routes29.guildEmojisBulk(guild.id),
|
|
5687
6167
|
{ body: { emojis }, auth: true }
|
|
5688
6168
|
);
|
|
5689
6169
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
@@ -5703,18 +6183,22 @@ var GuildRoleManager = class extends LimitedCollection3 {
|
|
|
5703
6183
|
};
|
|
5704
6184
|
|
|
5705
6185
|
// src/Domain/Guild/MemberHttp.ts
|
|
5706
|
-
import { Routes as
|
|
6186
|
+
import { Routes as Routes30 } from "@fluxerjs/types";
|
|
5707
6187
|
async function fetchMember(guild, userId) {
|
|
6188
|
+
const id = normalizeSnowflakeId(userId, "members.fetch()");
|
|
5708
6189
|
try {
|
|
5709
6190
|
const data = await guild.client.rest.get(
|
|
5710
|
-
|
|
6191
|
+
Routes30.guildMember(guild.id, id)
|
|
5711
6192
|
);
|
|
6193
|
+
if (!data?.user?.id) {
|
|
6194
|
+
throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
|
|
6195
|
+
}
|
|
5712
6196
|
return cacheMember(guild, data);
|
|
5713
6197
|
} catch (err) {
|
|
5714
6198
|
rethrowMapped(err, {
|
|
5715
6199
|
notFound: {
|
|
5716
6200
|
code: ErrorCodes.MemberNotFound,
|
|
5717
|
-
message: `Member ${
|
|
6201
|
+
message: `Member ${id} not found in guild`
|
|
5718
6202
|
},
|
|
5719
6203
|
fallback: "Failed to fetch guild member"
|
|
5720
6204
|
});
|
|
@@ -5722,17 +6206,20 @@ async function fetchMember(guild, userId) {
|
|
|
5722
6206
|
}
|
|
5723
6207
|
async function fetchMe(guild) {
|
|
5724
6208
|
const data = await guild.client.rest.get(
|
|
5725
|
-
|
|
6209
|
+
Routes30.guildMemberMe(guild.id),
|
|
5726
6210
|
{ auth: true }
|
|
5727
6211
|
);
|
|
6212
|
+
if (!data?.user?.id) {
|
|
6213
|
+
throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
|
|
6214
|
+
}
|
|
5728
6215
|
return cacheMember(guild, data);
|
|
5729
6216
|
}
|
|
5730
6217
|
|
|
5731
6218
|
// src/Domain/Guild/Moderation.ts
|
|
5732
|
-
import { Routes as
|
|
6219
|
+
import { Routes as Routes32 } from "@fluxerjs/types";
|
|
5733
6220
|
|
|
5734
6221
|
// src/Domain/Guild/GuildBan.ts
|
|
5735
|
-
import { Routes as
|
|
6222
|
+
import { Routes as Routes31 } from "@fluxerjs/types";
|
|
5736
6223
|
function parseOptionalDate2(value) {
|
|
5737
6224
|
if (value == null || value === "") return null;
|
|
5738
6225
|
const date = new Date(value);
|
|
@@ -5759,7 +6246,7 @@ var GuildBan = class extends Base {
|
|
|
5759
6246
|
* Requires Ban Members permission.
|
|
5760
6247
|
*/
|
|
5761
6248
|
async unban(reason) {
|
|
5762
|
-
await this.client.rest.delete(
|
|
6249
|
+
await this.client.rest.delete(Routes31.guildBan(this.guildId, this.user.id), {
|
|
5763
6250
|
auth: true,
|
|
5764
6251
|
...auditReasonHeaders(reason)
|
|
5765
6252
|
});
|
|
@@ -5769,35 +6256,39 @@ var GuildBan = class extends Base {
|
|
|
5769
6256
|
// src/Domain/Guild/Moderation.ts
|
|
5770
6257
|
async function ban(guild, userId, options) {
|
|
5771
6258
|
const body = options ? toGuildBanBody(options) : {};
|
|
5772
|
-
await guild.client.rest.put(
|
|
6259
|
+
await guild.client.rest.put(Routes32.guildBan(guild.id, userId), {
|
|
5773
6260
|
body: Object.keys(body).length ? body : void 0,
|
|
5774
6261
|
auth: true,
|
|
5775
6262
|
...auditReasonHeaders(options?.reason)
|
|
5776
6263
|
});
|
|
5777
6264
|
}
|
|
6265
|
+
async function fetchBan(guild, userId) {
|
|
6266
|
+
const data = await guild.client.rest.get(Routes32.guildBan(guild.id, userId));
|
|
6267
|
+
return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
|
|
6268
|
+
}
|
|
5778
6269
|
async function fetchBans(guild) {
|
|
5779
|
-
const data = await guild.client.rest.get(
|
|
6270
|
+
const data = await guild.client.rest.get(Routes32.guildBans(guild.id));
|
|
5780
6271
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
5781
6272
|
}
|
|
5782
6273
|
async function unban(guild, userId, reason) {
|
|
5783
|
-
await guild.client.rest.delete(
|
|
6274
|
+
await guild.client.rest.delete(Routes32.guildBan(guild.id, userId), {
|
|
5784
6275
|
auth: true,
|
|
5785
6276
|
...auditReasonHeaders(reason)
|
|
5786
6277
|
});
|
|
5787
6278
|
}
|
|
5788
6279
|
async function kick(guild, userId, reason) {
|
|
5789
|
-
await guild.client.rest.delete(
|
|
6280
|
+
await guild.client.rest.delete(Routes32.guildMember(guild.id, userId), {
|
|
5790
6281
|
auth: true,
|
|
5791
6282
|
...auditReasonHeaders(reason)
|
|
5792
6283
|
});
|
|
5793
6284
|
}
|
|
5794
6285
|
|
|
5795
6286
|
// src/Domain/Guild/Roles.ts
|
|
5796
|
-
import { Routes as
|
|
6287
|
+
import { Routes as Routes33 } from "@fluxerjs/types";
|
|
5797
6288
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
5798
6289
|
async function createRole(guild, options = {}) {
|
|
5799
6290
|
const body = toRoleCreateBody(options);
|
|
5800
|
-
const data = await guild.client.rest.post(
|
|
6291
|
+
const data = await guild.client.rest.post(Routes33.guildRoles(guild.id), {
|
|
5801
6292
|
body: Object.keys(body).length ? body : void 0,
|
|
5802
6293
|
auth: true,
|
|
5803
6294
|
...auditReasonHeaders(options.reason)
|
|
@@ -5805,12 +6296,14 @@ async function createRole(guild, options = {}) {
|
|
|
5805
6296
|
return cacheRole(guild, data);
|
|
5806
6297
|
}
|
|
5807
6298
|
async function fetchRoles(guild) {
|
|
5808
|
-
const data = await guild.client.rest.get(
|
|
6299
|
+
const data = await guild.client.rest.get(Routes33.guildRoles(guild.id));
|
|
6300
|
+
if (!Array.isArray(data))
|
|
6301
|
+
throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
|
|
5809
6302
|
return data.map((r) => cacheRole(guild, r));
|
|
5810
6303
|
}
|
|
5811
6304
|
async function fetchRole(guild, roleId2) {
|
|
5812
6305
|
try {
|
|
5813
|
-
const data = await guild.client.rest.get(
|
|
6306
|
+
const data = await guild.client.rest.get(Routes33.guildRole(guild.id, roleId2));
|
|
5814
6307
|
return cacheRole(guild, data);
|
|
5815
6308
|
} catch (err) {
|
|
5816
6309
|
rethrowMapped(err, {
|
|
@@ -5827,7 +6320,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
5827
6320
|
const needle = trimmed.toLowerCase();
|
|
5828
6321
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
5829
6322
|
if (cached) return cached.id;
|
|
5830
|
-
const roles = await guild.client.rest.get(
|
|
6323
|
+
const roles = await guild.client.rest.get(Routes33.guildRoles(guild.id));
|
|
5831
6324
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
5832
6325
|
if (!role) return null;
|
|
5833
6326
|
cacheRole(guild, role);
|
|
@@ -5836,7 +6329,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
5836
6329
|
async function setRolePositions(guild, updates) {
|
|
5837
6330
|
return replaceRoles(
|
|
5838
6331
|
guild,
|
|
5839
|
-
await guild.client.rest.patch(
|
|
6332
|
+
await guild.client.rest.patch(Routes33.guildRoles(guild.id), {
|
|
5840
6333
|
body: updates,
|
|
5841
6334
|
auth: true
|
|
5842
6335
|
})
|
|
@@ -5845,7 +6338,7 @@ async function setRolePositions(guild, updates) {
|
|
|
5845
6338
|
async function setRoleHoistPositions(guild, updates) {
|
|
5846
6339
|
return replaceRoles(
|
|
5847
6340
|
guild,
|
|
5848
|
-
await guild.client.rest.patch(
|
|
6341
|
+
await guild.client.rest.patch(Routes33.guildRolesHoistPositions(guild.id), {
|
|
5849
6342
|
body: updates.map((u) => ({
|
|
5850
6343
|
id: u.id,
|
|
5851
6344
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -5857,17 +6350,17 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
5857
6350
|
async function resetRoleHoistPositions(guild) {
|
|
5858
6351
|
return replaceRoles(
|
|
5859
6352
|
guild,
|
|
5860
|
-
await guild.client.rest.delete(
|
|
6353
|
+
await guild.client.rest.delete(Routes33.guildRolesHoistPositions(guild.id), {
|
|
5861
6354
|
auth: true
|
|
5862
6355
|
})
|
|
5863
6356
|
);
|
|
5864
6357
|
}
|
|
5865
6358
|
|
|
5866
6359
|
// src/Domain/Guild/Stickers.ts
|
|
5867
|
-
import { Routes as
|
|
6360
|
+
import { Routes as Routes34 } from "@fluxerjs/types";
|
|
5868
6361
|
async function createSticker(guild, options) {
|
|
5869
6362
|
const { reason, ...body } = options;
|
|
5870
|
-
const data = await guild.client.rest.post(
|
|
6363
|
+
const data = await guild.client.rest.post(Routes34.guildStickers(guild.id), {
|
|
5871
6364
|
body,
|
|
5872
6365
|
auth: true,
|
|
5873
6366
|
...auditReasonHeaders(reason)
|
|
@@ -5875,7 +6368,7 @@ async function createSticker(guild, options) {
|
|
|
5875
6368
|
return cacheSticker(guild, data);
|
|
5876
6369
|
}
|
|
5877
6370
|
async function cloneSticker(guild, sourceStickerId) {
|
|
5878
|
-
const data = await guild.client.rest.post(
|
|
6371
|
+
const data = await guild.client.rest.post(Routes34.guildStickersClone(guild.id), {
|
|
5879
6372
|
body: { source_sticker_id: sourceStickerId },
|
|
5880
6373
|
auth: true
|
|
5881
6374
|
});
|
|
@@ -5883,17 +6376,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
5883
6376
|
}
|
|
5884
6377
|
async function createStickersBulk(guild, stickers) {
|
|
5885
6378
|
const data = await guild.client.rest.post(
|
|
5886
|
-
|
|
6379
|
+
Routes34.guildStickersBulk(guild.id),
|
|
5887
6380
|
{ body: { stickers }, auth: true }
|
|
5888
6381
|
);
|
|
5889
6382
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
5890
6383
|
}
|
|
5891
6384
|
async function fetchStickers(guild) {
|
|
5892
|
-
const data = await guild.client.rest.get(
|
|
6385
|
+
const data = await guild.client.rest.get(Routes34.guildStickers(guild.id));
|
|
5893
6386
|
return data.map((s) => cacheSticker(guild, s));
|
|
5894
6387
|
}
|
|
5895
6388
|
async function fetchSticker(guild, stickerId) {
|
|
5896
|
-
const data = await guild.client.rest.get(
|
|
6389
|
+
const data = await guild.client.rest.get(Routes34.guildSticker(guild.id, stickerId));
|
|
5897
6390
|
return cacheSticker(guild, data);
|
|
5898
6391
|
}
|
|
5899
6392
|
|
|
@@ -5905,6 +6398,11 @@ var Guild = class extends Base {
|
|
|
5905
6398
|
id;
|
|
5906
6399
|
/** Whether the guild is currently available through the gateway. */
|
|
5907
6400
|
available = true;
|
|
6401
|
+
/**
|
|
6402
|
+
* True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
|
|
6403
|
+
* and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
|
|
6404
|
+
*/
|
|
6405
|
+
partial = true;
|
|
5908
6406
|
/** Guild name. */
|
|
5909
6407
|
name;
|
|
5910
6408
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -5977,6 +6475,10 @@ var Guild = class extends Base {
|
|
|
5977
6475
|
emojis;
|
|
5978
6476
|
/** Cached stickers in this guild. */
|
|
5979
6477
|
stickers;
|
|
6478
|
+
/** Live stages in this guild's stage channels, keyed by stage instance ID. */
|
|
6479
|
+
stageInstances;
|
|
6480
|
+
/** Most participants a stage can have while speakers use video, or null if unknown. */
|
|
6481
|
+
maxStageVideoChannelUsers;
|
|
5980
6482
|
/**
|
|
5981
6483
|
* Construct a guild from API data.
|
|
5982
6484
|
* @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE
|
|
@@ -5993,6 +6495,7 @@ var Guild = class extends Base {
|
|
|
5993
6495
|
this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
|
|
5994
6496
|
this.emojis = new LimitedCollection4({ maxSize: client.cache.limits.emojis });
|
|
5995
6497
|
this.stickers = new LimitedCollection4({ maxSize: client.cache.limits.stickers });
|
|
6498
|
+
this.stageInstances = new Collection9();
|
|
5996
6499
|
this.name = data.name ?? "";
|
|
5997
6500
|
this.icon = data.icon ?? null;
|
|
5998
6501
|
this.banner = data.banner ?? null;
|
|
@@ -6022,6 +6525,7 @@ var Guild = class extends Base {
|
|
|
6022
6525
|
this.bannerHeight = data.banner_height ?? null;
|
|
6023
6526
|
this.splashWidth = data.splash_width ?? null;
|
|
6024
6527
|
this.splashHeight = data.splash_height ?? null;
|
|
6528
|
+
this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
|
|
6025
6529
|
this.memberCount = resolveGuildMemberCount(data) ?? null;
|
|
6026
6530
|
this.onlineCount = resolveGuildOnlineCount(data) ?? null;
|
|
6027
6531
|
for (const r of data.roles ?? []) {
|
|
@@ -6078,6 +6582,9 @@ var Guild = class extends Base {
|
|
|
6078
6582
|
if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
|
|
6079
6583
|
if (data.splash_width !== void 0) this.splashWidth = data.splash_width ?? null;
|
|
6080
6584
|
if (data.splash_height !== void 0) this.splashHeight = data.splash_height ?? null;
|
|
6585
|
+
if (data.max_stage_video_channel_users !== void 0) {
|
|
6586
|
+
this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
|
|
6587
|
+
}
|
|
6081
6588
|
const memberCount = resolveGuildMemberCount(data);
|
|
6082
6589
|
if (memberCount !== void 0) this.memberCount = memberCount;
|
|
6083
6590
|
const onlineCount = resolveGuildOnlineCount(data);
|
|
@@ -6093,11 +6600,11 @@ var Guild = class extends Base {
|
|
|
6093
6600
|
}
|
|
6094
6601
|
/** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
|
|
6095
6602
|
get createdTimestamp() {
|
|
6096
|
-
return
|
|
6603
|
+
return SnowflakeUtil10.timestampFromSnowflake(this.id);
|
|
6097
6604
|
}
|
|
6098
6605
|
/** Date when this guild was created, derived from its snowflake ID. */
|
|
6099
6606
|
get createdAt() {
|
|
6100
|
-
return
|
|
6607
|
+
return SnowflakeUtil10.dateFromSnowflake(this.id);
|
|
6101
6608
|
}
|
|
6102
6609
|
/** The guild's name. */
|
|
6103
6610
|
toString() {
|
|
@@ -6199,6 +6706,10 @@ var Guild = class extends Base {
|
|
|
6199
6706
|
ban(userId, options) {
|
|
6200
6707
|
return ban(this, userId, options);
|
|
6201
6708
|
}
|
|
6709
|
+
/** Fetch a single ban by user ID. Requires Ban Members. */
|
|
6710
|
+
fetchBan(userId) {
|
|
6711
|
+
return fetchBan(this, userId);
|
|
6712
|
+
}
|
|
6202
6713
|
/** Fetch all bans in this guild. Requires Ban Members. */
|
|
6203
6714
|
fetchBans() {
|
|
6204
6715
|
return fetchBans(this);
|
|
@@ -6379,6 +6890,9 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
6379
6890
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
6380
6891
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
6381
6892
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
6893
|
+
if (resources.stageInstances !== void 0) syncStageInstances(guild, resources.stageInstances);
|
|
6894
|
+
if (resources.stageCounts !== void 0) applyStageCounts(guild, resources.stageCounts);
|
|
6895
|
+
if (resources.channels !== void 0) guild.partial = false;
|
|
6382
6896
|
return { guild, created, recovered };
|
|
6383
6897
|
}
|
|
6384
6898
|
function applyGuildSnapshotFromGateway(client, raw) {
|
|
@@ -6392,7 +6906,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
6392
6906
|
emojis: g.emojis,
|
|
6393
6907
|
stickers: g.stickers,
|
|
6394
6908
|
// A channel list without `threads` means this session has no viewable threads.
|
|
6395
|
-
threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
|
|
6909
|
+
threads: g.channels !== void 0 ? g.threads ?? [] : g.threads,
|
|
6910
|
+
stageInstances: g.stage_instances,
|
|
6911
|
+
stageCounts: g.stage_counts
|
|
6396
6912
|
});
|
|
6397
6913
|
if (g.voice_states?.length) {
|
|
6398
6914
|
client.emit(Events.VoiceStatesSync, {
|
|
@@ -6404,7 +6920,7 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
6404
6920
|
}
|
|
6405
6921
|
|
|
6406
6922
|
// src/ClientCore/ClientUser.ts
|
|
6407
|
-
import { GatewayOpcodes, Routes as
|
|
6923
|
+
import { GatewayOpcodes, Routes as Routes35 } from "@fluxerjs/types";
|
|
6408
6924
|
var ClientUser = class extends User {
|
|
6409
6925
|
/** Broadcast presence (gateway opcode 3) on all shards. */
|
|
6410
6926
|
setPresence(presence) {
|
|
@@ -6414,13 +6930,13 @@ var ClientUser = class extends User {
|
|
|
6414
6930
|
}
|
|
6415
6931
|
/** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
|
|
6416
6932
|
async fetch() {
|
|
6417
|
-
const data = await this.client.rest.get(
|
|
6933
|
+
const data = await this.client.rest.get(Routes35.currentUser(), { auth: true });
|
|
6418
6934
|
this._patch(data);
|
|
6419
6935
|
return this;
|
|
6420
6936
|
}
|
|
6421
6937
|
/** GET /users/@me/guilds — returns camelCase partial guilds. */
|
|
6422
6938
|
async fetchGuilds(options) {
|
|
6423
|
-
const path =
|
|
6939
|
+
const path = Routes35.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
|
|
6424
6940
|
const data = await this.client.rest.get(path, { auth: true });
|
|
6425
6941
|
return data.map((g) => ({
|
|
6426
6942
|
id: g.id,
|
|
@@ -6444,7 +6960,7 @@ var ClientUser = class extends User {
|
|
|
6444
6960
|
*/
|
|
6445
6961
|
async leaveGuild(guildId, options) {
|
|
6446
6962
|
const body = options ? toSudoBody(options) : void 0;
|
|
6447
|
-
await this.client.rest.delete(
|
|
6963
|
+
await this.client.rest.delete(Routes35.leaveGuild(guildId), {
|
|
6448
6964
|
body: body && Object.keys(body).length ? body : void 0,
|
|
6449
6965
|
auth: true
|
|
6450
6966
|
});
|
|
@@ -6452,7 +6968,7 @@ var ClientUser = class extends User {
|
|
|
6452
6968
|
/** Delete every message authored by the caller across a guild (sudo). */
|
|
6453
6969
|
async bulkDeleteMyMessagesInGuild(guildId, options) {
|
|
6454
6970
|
const body = options ? toSudoBody(options) : void 0;
|
|
6455
|
-
await this.client.rest.post(
|
|
6971
|
+
await this.client.rest.post(Routes35.guildBulkDeleteMine(guildId), {
|
|
6456
6972
|
body: body && Object.keys(body).length ? body : void 0,
|
|
6457
6973
|
auth: true
|
|
6458
6974
|
});
|
|
@@ -6462,15 +6978,7 @@ var ClientUser = class extends User {
|
|
|
6462
6978
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
6463
6979
|
import { asRecord, num, str } from "@fluxerjs/util";
|
|
6464
6980
|
function unknownUser(id) {
|
|
6465
|
-
return {
|
|
6466
|
-
id,
|
|
6467
|
-
username: "Unknown",
|
|
6468
|
-
discriminator: "0",
|
|
6469
|
-
global_name: null,
|
|
6470
|
-
avatar: null,
|
|
6471
|
-
avatar_color: null,
|
|
6472
|
-
flags: 0
|
|
6473
|
-
};
|
|
6981
|
+
return { id };
|
|
6474
6982
|
}
|
|
6475
6983
|
function indexMember(_client, guild, data) {
|
|
6476
6984
|
if (!data.user?.id) return null;
|
|
@@ -6932,7 +7440,7 @@ var memberHandlers = {
|
|
|
6932
7440
|
};
|
|
6933
7441
|
|
|
6934
7442
|
// src/ClientCore/EventHandlers/Messages.ts
|
|
6935
|
-
import { SnowflakeUtil as
|
|
7443
|
+
import { SnowflakeUtil as SnowflakeUtil11 } from "@fluxerjs/util";
|
|
6936
7444
|
function cachedTextChannel(client, channelId) {
|
|
6937
7445
|
const channel = client.channels.get(channelId);
|
|
6938
7446
|
return channel?.isTextBased() ? channel : null;
|
|
@@ -6948,7 +7456,7 @@ function toPartialMessage(client, args) {
|
|
|
6948
7456
|
const cached = args.cached;
|
|
6949
7457
|
const authorId = args.authorId ?? cached?.author?.id ?? null;
|
|
6950
7458
|
const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
|
|
6951
|
-
const createdAt = cached?.timestamp ? new Date(cached.timestamp) :
|
|
7459
|
+
const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil11.isValid(args.id) ? SnowflakeUtil11.dateFromSnowflake(args.id) : null;
|
|
6952
7460
|
return new PartialMessage(client, {
|
|
6953
7461
|
id: args.id,
|
|
6954
7462
|
channelId: args.channelId,
|
|
@@ -7154,6 +7662,9 @@ var passthroughHandlers = {
|
|
|
7154
7662
|
VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
|
|
7155
7663
|
VOICE_STATE_ACK: pass(Events.VoiceStateAck),
|
|
7156
7664
|
ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
|
|
7665
|
+
VOICE_SIGNAL: pass(Events.VoiceSignal),
|
|
7666
|
+
GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
|
|
7667
|
+
OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
|
|
7157
7668
|
TYPING_START(client, d) {
|
|
7158
7669
|
const data = d;
|
|
7159
7670
|
const payload = {
|
|
@@ -7209,6 +7720,46 @@ var passthroughHandlers = {
|
|
|
7209
7720
|
WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
|
|
7210
7721
|
};
|
|
7211
7722
|
|
|
7723
|
+
// src/ClientCore/EventHandlers/Stages.ts
|
|
7724
|
+
var stageHandlers = {
|
|
7725
|
+
STAGE_INSTANCE_CREATE(client, d) {
|
|
7726
|
+
const instance = cacheStageInstance(client, d);
|
|
7727
|
+
client.emit(Events.StageInstanceCreate, instance);
|
|
7728
|
+
},
|
|
7729
|
+
STAGE_INSTANCE_UPDATE(client, d) {
|
|
7730
|
+
const data = d;
|
|
7731
|
+
const cached = client.guilds.get(data.guild_id)?.stageInstances.get(data.id);
|
|
7732
|
+
const old = cached ? new StageInstance(client, cached.toJSON()) : null;
|
|
7733
|
+
const instance = cacheStageInstance(client, data);
|
|
7734
|
+
client.emit(Events.StageInstanceUpdate, old, instance);
|
|
7735
|
+
},
|
|
7736
|
+
STAGE_INSTANCE_DELETE(client, d) {
|
|
7737
|
+
const data = d;
|
|
7738
|
+
const guild = client.guilds.get(data.guild_id);
|
|
7739
|
+
const instance = guild?.stageInstances.get(data.id) ?? new StageInstance(client, data);
|
|
7740
|
+
instance._patch(data);
|
|
7741
|
+
guild?.stageInstances.delete(data.id);
|
|
7742
|
+
client.emit(Events.StageInstanceDelete, instance);
|
|
7743
|
+
},
|
|
7744
|
+
STAGE_COUNTS_UPDATE(client, d) {
|
|
7745
|
+
const data = d;
|
|
7746
|
+
const channel = client.channels.get(data.channel_id);
|
|
7747
|
+
if (channel?.isStage()) channel._patchCounts(data);
|
|
7748
|
+
const payload = {
|
|
7749
|
+
guildId: data.guild_id,
|
|
7750
|
+
channelId: data.channel_id,
|
|
7751
|
+
listenerCount: data.listener_count,
|
|
7752
|
+
speakerCount: data.speaker_count,
|
|
7753
|
+
requestCount: data.request_count,
|
|
7754
|
+
videoEnabled: data.video_enabled ?? null
|
|
7755
|
+
};
|
|
7756
|
+
client.emit(Events.StageCountsUpdate, payload);
|
|
7757
|
+
},
|
|
7758
|
+
STAGE_VOICE_STATES_SYNC: pass(Events.StageVoiceStatesSync),
|
|
7759
|
+
STAGE_AUDIENCE_LIST_UPDATE: pass(Events.StageAudienceListUpdate),
|
|
7760
|
+
VOICE_JOIN_QUEUED: pass(Events.VoiceJoinQueued)
|
|
7761
|
+
};
|
|
7762
|
+
|
|
7212
7763
|
// src/ClientCore/EventHandlers/Threads.ts
|
|
7213
7764
|
function cachedChannel(client, id) {
|
|
7214
7765
|
const direct = client.channels.get(id);
|
|
@@ -7319,7 +7870,8 @@ var eventHandlers = buildRegistry(
|
|
|
7319
7870
|
inviteHandlers,
|
|
7320
7871
|
guildResourceHandlers,
|
|
7321
7872
|
passthroughHandlers,
|
|
7322
|
-
threadHandlers
|
|
7873
|
+
threadHandlers,
|
|
7874
|
+
stageHandlers
|
|
7323
7875
|
);
|
|
7324
7876
|
|
|
7325
7877
|
// src/ClientCore/GatewayDispatch.ts
|
|
@@ -7344,29 +7896,63 @@ function handleGatewayDispatch(client, payload, deferred) {
|
|
|
7344
7896
|
}
|
|
7345
7897
|
return dispatchGatewayPayload(client, payload);
|
|
7346
7898
|
}
|
|
7347
|
-
|
|
7899
|
+
var dispatchQueues = /* @__PURE__ */ new WeakMap();
|
|
7900
|
+
function queueFor(client) {
|
|
7901
|
+
let queue = dispatchQueues.get(client);
|
|
7902
|
+
if (!queue) {
|
|
7903
|
+
queue = { tail: Promise.resolve(), pending: 0 };
|
|
7904
|
+
dispatchQueues.set(client, queue);
|
|
7905
|
+
}
|
|
7906
|
+
return queue;
|
|
7907
|
+
}
|
|
7908
|
+
async function runGatewayHandler(client, payload) {
|
|
7348
7909
|
const event = payload.t;
|
|
7349
|
-
if (!event) return
|
|
7910
|
+
if (!event) return;
|
|
7350
7911
|
const handler = eventHandlers.get(event);
|
|
7351
7912
|
if (!handler) {
|
|
7352
7913
|
client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
|
|
7353
|
-
return
|
|
7914
|
+
return;
|
|
7354
7915
|
}
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
}
|
|
7362
|
-
if (client.options.gatewayDeferHandlers
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
};
|
|
7367
|
-
|
|
7368
|
-
|
|
7916
|
+
if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
|
|
7917
|
+
client.emit(
|
|
7918
|
+
Events.Debug,
|
|
7919
|
+
`[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
|
|
7920
|
+
);
|
|
7921
|
+
return;
|
|
7922
|
+
}
|
|
7923
|
+
if (client.options.gatewayDeferHandlers !== false) {
|
|
7924
|
+
await new Promise((resolve) => {
|
|
7925
|
+
if (typeof setImmediate === "function") setImmediate(resolve);
|
|
7926
|
+
else setTimeout(resolve, 0);
|
|
7927
|
+
});
|
|
7928
|
+
}
|
|
7929
|
+
try {
|
|
7930
|
+
await handler(client, payload.d);
|
|
7931
|
+
} catch (err) {
|
|
7932
|
+
emitClientError(client, err);
|
|
7933
|
+
}
|
|
7934
|
+
}
|
|
7935
|
+
function dispatchGatewayPayload(client, payload) {
|
|
7936
|
+
const queue = queueFor(client);
|
|
7937
|
+
if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
|
|
7938
|
+
queue.pending++;
|
|
7939
|
+
const run = runGatewayHandler(client, payload).finally(() => {
|
|
7940
|
+
queue.pending--;
|
|
7941
|
+
});
|
|
7942
|
+
queue.tail = run.catch(() => {
|
|
7943
|
+
});
|
|
7944
|
+
return run;
|
|
7945
|
+
}
|
|
7946
|
+
queue.pending++;
|
|
7947
|
+
const next = queue.tail.then(
|
|
7948
|
+
() => runGatewayHandler(client, payload),
|
|
7949
|
+
() => runGatewayHandler(client, payload)
|
|
7950
|
+
).finally(() => {
|
|
7951
|
+
queue.pending--;
|
|
7952
|
+
});
|
|
7953
|
+
queue.tail = next.catch(() => {
|
|
7369
7954
|
});
|
|
7955
|
+
return next;
|
|
7370
7956
|
}
|
|
7371
7957
|
async function flushDeferredGatewayDispatches(client, deferred) {
|
|
7372
7958
|
while (deferred.length > 0) {
|
|
@@ -7545,7 +8131,7 @@ async function connectClientGateway(client, token, signal) {
|
|
|
7545
8131
|
|
|
7546
8132
|
// src/ClientCore/GuildManager.ts
|
|
7547
8133
|
import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
|
|
7548
|
-
import { Routes as
|
|
8134
|
+
import { Routes as Routes36 } from "@fluxerjs/types";
|
|
7549
8135
|
var GuildManager = class extends LimitedCollection5 {
|
|
7550
8136
|
constructor(client) {
|
|
7551
8137
|
super({
|
|
@@ -7554,6 +8140,7 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7554
8140
|
});
|
|
7555
8141
|
this.client = client;
|
|
7556
8142
|
}
|
|
8143
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7557
8144
|
/**
|
|
7558
8145
|
* Remove a guild from cache and cascade its channels / message caches.
|
|
7559
8146
|
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
@@ -7568,35 +8155,73 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
7568
8155
|
}
|
|
7569
8156
|
/**
|
|
7570
8157
|
* Get a guild from cache or fetch from the API if not present.
|
|
8158
|
+
* Partial (metadata-only) cached guilds are hydrated first.
|
|
7571
8159
|
* @param guildId - Snowflake of the guild
|
|
7572
8160
|
* @returns The guild
|
|
7573
8161
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7574
8162
|
*/
|
|
7575
8163
|
async resolve(guildId) {
|
|
7576
|
-
|
|
8164
|
+
const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
|
|
8165
|
+
const cached = this.get(id);
|
|
8166
|
+
if (cached && !cached.partial) return cached;
|
|
8167
|
+
if (cached) {
|
|
8168
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
8169
|
+
await this.hydrate(cached);
|
|
8170
|
+
return cached;
|
|
8171
|
+
});
|
|
8172
|
+
return cached;
|
|
8173
|
+
}
|
|
8174
|
+
const guild = await this.fetch(id);
|
|
8175
|
+
await dedupeFetch(this.pendingFetches, id, async () => {
|
|
8176
|
+
await this.hydrate(guild);
|
|
8177
|
+
return guild;
|
|
8178
|
+
});
|
|
8179
|
+
return guild;
|
|
7577
8180
|
}
|
|
7578
8181
|
/**
|
|
7579
8182
|
* Fetch a guild by ID.
|
|
7580
|
-
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
8183
|
+
* Returns the cached guild unless `force` is set, in which case REST metadata
|
|
8184
|
+
* is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
|
|
7581
8185
|
* @throws FluxerError with GUILD_NOT_FOUND if missing
|
|
7582
8186
|
*/
|
|
7583
8187
|
async fetch(guildId, options) {
|
|
7584
|
-
const
|
|
8188
|
+
const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
|
|
8189
|
+
const cached = this.get(id);
|
|
7585
8190
|
if (cached && !options?.force) return cached;
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
8191
|
+
return dedupeFetch(this.pendingFetches, id, async () => {
|
|
8192
|
+
try {
|
|
8193
|
+
const data = assertApiObjectWithId(
|
|
8194
|
+
await this.client.rest.get(Routes36.guild(id)),
|
|
8195
|
+
"guilds.fetch()"
|
|
8196
|
+
);
|
|
8197
|
+
let guild;
|
|
8198
|
+
const existing = this.get(id);
|
|
8199
|
+
if (existing) {
|
|
8200
|
+
existing._patch(data);
|
|
8201
|
+
guild = existing;
|
|
8202
|
+
} else {
|
|
8203
|
+
guild = new Guild(this.client, data);
|
|
8204
|
+
this.set(guild.id, guild);
|
|
8205
|
+
}
|
|
8206
|
+
return guild;
|
|
8207
|
+
} catch (err) {
|
|
8208
|
+
rethrowMapped(err, {
|
|
8209
|
+
notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
|
|
8210
|
+
fallback: `Failed to fetch guild ${id}`
|
|
8211
|
+
});
|
|
7591
8212
|
}
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
8213
|
+
});
|
|
8214
|
+
}
|
|
8215
|
+
/** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
|
|
8216
|
+
async hydrate(guild) {
|
|
8217
|
+
try {
|
|
8218
|
+
await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
|
|
8219
|
+
guild.partial = false;
|
|
7595
8220
|
} catch (err) {
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
8221
|
+
this.client.emit(
|
|
8222
|
+
Events.Debug,
|
|
8223
|
+
`[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
|
|
8224
|
+
);
|
|
7600
8225
|
}
|
|
7601
8226
|
}
|
|
7602
8227
|
};
|
|
@@ -7621,6 +8246,10 @@ var MessageCache = class {
|
|
|
7621
8246
|
if (limit === false) return;
|
|
7622
8247
|
if (!this.caches) this.caches = /* @__PURE__ */ new Map();
|
|
7623
8248
|
let cache = this.caches.get(channelId);
|
|
8249
|
+
if (cache) {
|
|
8250
|
+
this.caches.delete(channelId);
|
|
8251
|
+
this.caches.set(channelId, cache);
|
|
8252
|
+
}
|
|
7624
8253
|
if (!cache) {
|
|
7625
8254
|
const channelLimit = this.getChannelLimit();
|
|
7626
8255
|
if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
|
|
@@ -7672,7 +8301,7 @@ var MessageCache = class {
|
|
|
7672
8301
|
// src/ClientCore/UserManager.ts
|
|
7673
8302
|
import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
|
|
7674
8303
|
import {
|
|
7675
|
-
Routes as
|
|
8304
|
+
Routes as Routes37
|
|
7676
8305
|
} from "@fluxerjs/types";
|
|
7677
8306
|
var soft = (p) => p.catch(() => null);
|
|
7678
8307
|
var UserManager = class extends LimitedCollection6 {
|
|
@@ -7680,6 +8309,7 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7680
8309
|
super({ maxSize: client.cache.limits.users });
|
|
7681
8310
|
this.client = client;
|
|
7682
8311
|
}
|
|
8312
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
7683
8313
|
/** Remove matching users (skips `client.user`). Returns count removed. */
|
|
7684
8314
|
sweep(filter) {
|
|
7685
8315
|
let removed = 0;
|
|
@@ -7693,16 +8323,30 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7693
8323
|
}
|
|
7694
8324
|
return removed;
|
|
7695
8325
|
}
|
|
7696
|
-
/**
|
|
8326
|
+
/**
|
|
8327
|
+
* Fetch a user by ID and update cache. Returns the cached user unless `force` is set
|
|
8328
|
+
* or the cached entry is only a partial stub (e.g. from a reaction event).
|
|
8329
|
+
*/
|
|
7697
8330
|
async fetch(userId, options) {
|
|
7698
|
-
const
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
return
|
|
8331
|
+
const id = normalizeSnowflakeId(userId, "users.fetch()");
|
|
8332
|
+
const cached = this.get(id);
|
|
8333
|
+
if (cached && !cached.partial && !options?.force) return cached;
|
|
8334
|
+
return dedupeFetch(
|
|
8335
|
+
this.pendingFetches,
|
|
8336
|
+
id,
|
|
8337
|
+
async () => this.client.getOrCreateUser(
|
|
8338
|
+
assertApiObjectWithId(
|
|
8339
|
+
await this.client.rest.get(Routes37.user(id)),
|
|
8340
|
+
"users.fetch()"
|
|
8341
|
+
)
|
|
8342
|
+
)
|
|
8343
|
+
);
|
|
7702
8344
|
}
|
|
7703
|
-
/** Return a cached user, otherwise {@link fetch}. */
|
|
8345
|
+
/** Return a cached (non-partial) user, otherwise {@link fetch}. */
|
|
7704
8346
|
async resolve(userId) {
|
|
7705
|
-
|
|
8347
|
+
const id = normalizeSnowflakeId(userId, "users.resolve()");
|
|
8348
|
+
const cached = this.get(id);
|
|
8349
|
+
return cached && !cached.partial ? cached : this.fetch(id);
|
|
7706
8350
|
}
|
|
7707
8351
|
/**
|
|
7708
8352
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
@@ -7715,10 +8359,10 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
7715
8359
|
async fetchWithProfile(userId, options) {
|
|
7716
8360
|
const guildId = options?.guildId ?? void 0;
|
|
7717
8361
|
const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
|
|
7718
|
-
this.client.rest.get(
|
|
7719
|
-
soft(this.client.rest.get(
|
|
7720
|
-
guildId ? soft(this.client.rest.get(
|
|
7721
|
-
guildId ? soft(this.client.rest.get(
|
|
8362
|
+
this.client.rest.get(Routes37.user(userId)),
|
|
8363
|
+
soft(this.client.rest.get(Routes37.userProfile(userId))),
|
|
8364
|
+
guildId ? soft(this.client.rest.get(Routes37.userProfile(userId, guildId))) : null,
|
|
8365
|
+
guildId ? soft(this.client.rest.get(Routes37.guildMember(guildId, userId))) : null
|
|
7722
8366
|
]);
|
|
7723
8367
|
const user = this.client.getOrCreateUser(userData);
|
|
7724
8368
|
let member = null;
|
|
@@ -7843,7 +8487,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7843
8487
|
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
7844
8488
|
* Does not log in. Call {@link login} with a token afterward.
|
|
7845
8489
|
*
|
|
7846
|
-
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.
|
|
8490
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
|
|
7847
8491
|
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
7848
8492
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
7849
8493
|
*/
|
|
@@ -7920,6 +8564,38 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7920
8564
|
fetchStickerMetadata(stickerId) {
|
|
7921
8565
|
return fetchStickerMetadata(this, stickerId);
|
|
7922
8566
|
}
|
|
8567
|
+
/** Fetch the source guild of a custom emoji. */
|
|
8568
|
+
fetchEmojiSource(emojiId) {
|
|
8569
|
+
return fetchEmojiSource(this, emojiId);
|
|
8570
|
+
}
|
|
8571
|
+
/** Fetch the source guild of a custom sticker. */
|
|
8572
|
+
fetchStickerSource(stickerId) {
|
|
8573
|
+
return fetchStickerSource(this, stickerId);
|
|
8574
|
+
}
|
|
8575
|
+
/** List discovery categories. */
|
|
8576
|
+
fetchDiscoveryCategories() {
|
|
8577
|
+
return fetchDiscoveryCategories(this);
|
|
8578
|
+
}
|
|
8579
|
+
/** Search discoverable guilds. */
|
|
8580
|
+
searchDiscoveryGuilds(options) {
|
|
8581
|
+
return searchDiscoveryGuilds(this, options);
|
|
8582
|
+
}
|
|
8583
|
+
/** Fetch experiment assignments for this account. */
|
|
8584
|
+
fetchExperiments() {
|
|
8585
|
+
return fetchExperiments(this);
|
|
8586
|
+
}
|
|
8587
|
+
/** Refresh expiring attachment CDN URLs. */
|
|
8588
|
+
refreshAttachmentUrls(attachmentUrls) {
|
|
8589
|
+
return refreshAttachmentUrls(this, attachmentUrls);
|
|
8590
|
+
}
|
|
8591
|
+
/** List instance custom guild badges (`GET /instance/badges`). */
|
|
8592
|
+
fetchInstanceBadges(options) {
|
|
8593
|
+
return fetchInstanceBadges(this, options);
|
|
8594
|
+
}
|
|
8595
|
+
/** Fetch forum/media thread post data for a channel. */
|
|
8596
|
+
fetchChannelPostData(channelId, threadIds) {
|
|
8597
|
+
return fetchChannelPostData(this, channelId, threadIds);
|
|
8598
|
+
}
|
|
7923
8599
|
/**
|
|
7924
8600
|
* Fetch the current application (`/applications/@me`).
|
|
7925
8601
|
* @returns Application metadata (owner, flags, RPC origins, etc.)
|
|
@@ -8014,6 +8690,9 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
8014
8690
|
* @internal
|
|
8015
8691
|
*/
|
|
8016
8692
|
getOrCreateUser(data) {
|
|
8693
|
+
if (!data || typeof data.id !== "string" || data.id.length === 0) {
|
|
8694
|
+
throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
|
|
8695
|
+
}
|
|
8017
8696
|
const existing = this.users.get(data.id);
|
|
8018
8697
|
if (existing) {
|
|
8019
8698
|
existing._patch(data);
|
|
@@ -8266,7 +8945,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
8266
8945
|
* @see {@link Routes}
|
|
8267
8946
|
*/
|
|
8268
8947
|
static get Routes() {
|
|
8269
|
-
return
|
|
8948
|
+
return Routes38;
|
|
8270
8949
|
}
|
|
8271
8950
|
};
|
|
8272
8951
|
|
|
@@ -8679,9 +9358,11 @@ export {
|
|
|
8679
9358
|
ReactionCollector,
|
|
8680
9359
|
RelationshipType,
|
|
8681
9360
|
Role,
|
|
8682
|
-
|
|
9361
|
+
Routes39 as Routes,
|
|
8683
9362
|
STATIC_CDN_URL,
|
|
8684
9363
|
SplashCardAlignment,
|
|
9364
|
+
StageChannel,
|
|
9365
|
+
StageInstance,
|
|
8685
9366
|
SystemChannelFlags,
|
|
8686
9367
|
TextChannel,
|
|
8687
9368
|
ThreadAutoArchiveDuration,
|