@fluxerjs/core 2.2.0 → 3.1.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/README.md +21 -9
- package/dist/Expressions-Bdgo72qI.d.mts +34 -0
- package/dist/Expressions-Bdgo72qI.d.ts +34 -0
- package/dist/{SubpathMessage-D70lAT7N.d.mts → SubpathMessage-Cj_U0V19.d.mts} +1446 -1117
- package/dist/{SubpathMessage-D70lAT7N.d.ts → SubpathMessage-DaimQAd9.d.ts} +1446 -1117
- package/dist/Sudo-fOKSPbxN.d.mts +461 -0
- package/dist/Sudo-fOKSPbxN.d.ts +461 -0
- package/dist/client.d.mts +4 -3
- package/dist/client.d.ts +4 -3
- package/dist/client.js +2219 -1051
- package/dist/client.mjs +2103 -938
- package/dist/cluster.d.mts +5 -4
- package/dist/cluster.d.ts +5 -4
- package/dist/cluster.js +2134 -966
- package/dist/cluster.mjs +2097 -932
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2199 -1053
- package/dist/index.mjs +2035 -877
- package/dist/internal.d.mts +12 -0
- package/dist/internal.d.ts +12 -0
- package/dist/internal.js +449 -0
- package/dist/internal.mjs +398 -0
- package/dist/message.d.mts +4 -3
- package/dist/message.d.ts +4 -3
- package/dist/message.js +528 -95
- package/dist/message.mjs +528 -96
- package/package.json +13 -9
package/dist/cluster.js
CHANGED
|
@@ -83,7 +83,13 @@ var Events = {
|
|
|
83
83
|
WebhooksUpdate: "webhooksUpdate",
|
|
84
84
|
Resumed: "resumed",
|
|
85
85
|
Error: "error",
|
|
86
|
-
Debug: "debug"
|
|
86
|
+
Debug: "debug",
|
|
87
|
+
ShardReady: "shardReady",
|
|
88
|
+
ShardResumed: "shardResumed",
|
|
89
|
+
ShardDisconnect: "shardDisconnect",
|
|
90
|
+
ShardReconnecting: "shardReconnecting",
|
|
91
|
+
ShardError: "shardError",
|
|
92
|
+
ShardingRequired: "shardingRequired"
|
|
87
93
|
};
|
|
88
94
|
|
|
89
95
|
// src/LibErrors/ErrorCodes.ts
|
|
@@ -96,90 +102,13 @@ var import_util2 = require("@fluxerjs/util");
|
|
|
96
102
|
var import_node_events3 = require("events");
|
|
97
103
|
var import_rest3 = require("@fluxerjs/rest");
|
|
98
104
|
var import_types39 = require("@fluxerjs/types");
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
// src/Domain/User.ts
|
|
102
|
-
var import_types15 = require("@fluxerjs/types");
|
|
103
|
-
var import_util9 = require("@fluxerjs/util");
|
|
104
|
-
|
|
105
|
-
// src/Helpers/Constants.ts
|
|
106
|
-
var import_rest = require("@fluxerjs/rest");
|
|
107
|
-
var CDN_URL = "https://fluxerusercontent.com";
|
|
108
|
-
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
109
|
-
|
|
110
|
-
// src/Helpers/Cdn.ts
|
|
111
|
-
function mediaBase(options) {
|
|
112
|
-
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
113
|
-
}
|
|
114
|
-
function staticBase(options) {
|
|
115
|
-
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
116
|
-
}
|
|
117
|
-
function getExtension(hash, options) {
|
|
118
|
-
const ext = options?.extension ?? "png";
|
|
119
|
-
if (hash?.startsWith("a_")) return "gif";
|
|
120
|
-
return ext;
|
|
121
|
-
}
|
|
122
|
-
function appendSize(options) {
|
|
123
|
-
return options?.size ? `?size=${options.size}` : "";
|
|
124
|
-
}
|
|
125
|
-
function cdnAvatarURL(userId, avatarHash, options) {
|
|
126
|
-
if (!avatarHash) return null;
|
|
127
|
-
const ext = getExtension(avatarHash, options);
|
|
128
|
-
const size = appendSize(options);
|
|
129
|
-
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
130
|
-
}
|
|
131
|
-
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
132
|
-
if (!bannerHash) return null;
|
|
133
|
-
const ext = getExtension(bannerHash, options);
|
|
134
|
-
const size = appendSize(options);
|
|
135
|
-
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
136
|
-
}
|
|
137
|
-
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
138
|
-
if (!avatarHash) return null;
|
|
139
|
-
const ext = getExtension(avatarHash, options);
|
|
140
|
-
const size = appendSize(options);
|
|
141
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
142
|
-
}
|
|
143
|
-
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
144
|
-
if (!bannerHash) return null;
|
|
145
|
-
const ext = getExtension(bannerHash, options);
|
|
146
|
-
const size = appendSize(options);
|
|
147
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
148
|
-
}
|
|
149
|
-
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
150
|
-
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
151
|
-
return `${staticBase(options)}/avatars/${index}.png`;
|
|
152
|
-
}
|
|
153
|
-
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
154
|
-
if (!hash) return null;
|
|
155
|
-
const size = options?.size ? `?size=${options.size}` : "";
|
|
156
|
-
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
157
|
-
}
|
|
158
|
-
function cdnEmojiURL(emojiId, animated, options) {
|
|
159
|
-
const ext = animated ? "gif" : "png";
|
|
160
|
-
return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
|
|
161
|
-
}
|
|
162
|
-
function cdnStickerURL(stickerId, animated, options) {
|
|
163
|
-
const ext = animated ? "gif" : "png";
|
|
164
|
-
return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// src/Domain/Base.ts
|
|
168
|
-
var Base = class {
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// src/Domain/Channel/Base.ts
|
|
172
|
-
var import_types8 = require("@fluxerjs/types");
|
|
173
|
-
var import_util5 = require("@fluxerjs/util");
|
|
174
|
-
|
|
175
|
-
// src/ClientCore/MessageManager.ts
|
|
176
|
-
var import_collection3 = require("@fluxerjs/collection");
|
|
177
|
-
var import_types6 = require("@fluxerjs/types");
|
|
105
|
+
var import_util26 = require("@fluxerjs/util");
|
|
178
106
|
|
|
179
107
|
// src/Domain/Message/Message.ts
|
|
180
108
|
var import_builders3 = require("@fluxerjs/builders");
|
|
181
|
-
var
|
|
109
|
+
var import_collection3 = require("@fluxerjs/collection");
|
|
182
110
|
var import_types5 = require("@fluxerjs/types");
|
|
111
|
+
var import_util6 = require("@fluxerjs/util");
|
|
183
112
|
|
|
184
113
|
// src/ClientCore/SdkOptions/Attachments.ts
|
|
185
114
|
function toMessageAttachmentEditWire(attachments) {
|
|
@@ -246,21 +175,66 @@ function toAttachmentUploadPlanResponse(data) {
|
|
|
246
175
|
}
|
|
247
176
|
|
|
248
177
|
// src/ClientCore/SdkOptions/Channels.ts
|
|
178
|
+
var import_util3 = require("@fluxerjs/util");
|
|
179
|
+
function toOverwriteWire(overwrite) {
|
|
180
|
+
return {
|
|
181
|
+
id: overwrite.id,
|
|
182
|
+
type: overwrite.type,
|
|
183
|
+
allow: overwrite.allow !== void 0 ? (0, import_util3.resolvePermissionsToBitfield)(overwrite.allow) : "0",
|
|
184
|
+
deny: overwrite.deny !== void 0 ? (0, import_util3.resolvePermissionsToBitfield)(overwrite.deny) : "0"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
249
187
|
function toChannelEditBody(options) {
|
|
250
188
|
const body = {};
|
|
251
189
|
if (options.name !== void 0) body.name = options.name;
|
|
252
190
|
if (options.topic !== void 0) body.topic = options.topic;
|
|
191
|
+
if (options.url !== void 0) body.url = options.url;
|
|
253
192
|
if (options.parentId !== void 0) body.parent_id = options.parentId;
|
|
254
193
|
if (options.bitrate !== void 0) body.bitrate = options.bitrate;
|
|
255
194
|
if (options.userLimit !== void 0) body.user_limit = options.userLimit;
|
|
195
|
+
if (options.voiceConnectionLimit !== void 0) {
|
|
196
|
+
body.voice_connection_limit = options.voiceConnectionLimit;
|
|
197
|
+
}
|
|
256
198
|
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
199
|
+
if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
|
|
200
|
+
if (options.contentWarningLevel !== void 0) {
|
|
201
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
202
|
+
}
|
|
203
|
+
if (options.contentWarningText !== void 0) {
|
|
204
|
+
body.content_warning_text = options.contentWarningText;
|
|
205
|
+
}
|
|
257
206
|
if (options.rateLimitPerUser !== void 0) {
|
|
258
207
|
body.rate_limit_per_user = options.rateLimitPerUser;
|
|
259
208
|
}
|
|
260
209
|
if (options.rtcRegion !== void 0) body.rtc_region = options.rtcRegion;
|
|
210
|
+
if (options.icon !== void 0) body.icon = options.icon;
|
|
211
|
+
if (options.permissionOverwrites !== void 0) {
|
|
212
|
+
body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
|
|
213
|
+
}
|
|
214
|
+
return body;
|
|
215
|
+
}
|
|
216
|
+
function toChannelCreateBody(options) {
|
|
217
|
+
const body = { name: options.name, type: options.type };
|
|
218
|
+
if (options.topic !== void 0) body.topic = options.topic;
|
|
219
|
+
if (options.url !== void 0) body.url = options.url;
|
|
220
|
+
if (options.parentId !== void 0) body.parent_id = options.parentId;
|
|
221
|
+
if (options.bitrate !== void 0) body.bitrate = options.bitrate;
|
|
222
|
+
if (options.userLimit !== void 0) body.user_limit = options.userLimit;
|
|
223
|
+
if (options.voiceConnectionLimit !== void 0) {
|
|
224
|
+
body.voice_connection_limit = options.voiceConnectionLimit;
|
|
225
|
+
}
|
|
261
226
|
if (options.permissionOverwrites !== void 0) {
|
|
262
|
-
body.permission_overwrites = options.permissionOverwrites;
|
|
227
|
+
body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
|
|
228
|
+
}
|
|
229
|
+
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
230
|
+
if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
|
|
231
|
+
if (options.contentWarningLevel !== void 0) {
|
|
232
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
263
233
|
}
|
|
234
|
+
if (options.contentWarningText !== void 0) {
|
|
235
|
+
body.content_warning_text = options.contentWarningText;
|
|
236
|
+
}
|
|
237
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
264
238
|
return body;
|
|
265
239
|
}
|
|
266
240
|
function toChannelInviteBody(options) {
|
|
@@ -271,6 +245,13 @@ function toChannelInviteBody(options) {
|
|
|
271
245
|
if (options.temporary !== void 0) body.temporary = options.temporary;
|
|
272
246
|
return body;
|
|
273
247
|
}
|
|
248
|
+
function toGroupDmEditBody(options) {
|
|
249
|
+
const body = { type: 3 };
|
|
250
|
+
if (options.name !== void 0) body.name = options.name;
|
|
251
|
+
if (options.icon !== void 0) body.icon = options.icon;
|
|
252
|
+
if (options.nicks !== void 0) body.nicks = options.nicks;
|
|
253
|
+
return body;
|
|
254
|
+
}
|
|
274
255
|
|
|
275
256
|
// src/ClientCore/SdkOptions/Discovery.ts
|
|
276
257
|
function toDiscoveryBody(options) {
|
|
@@ -306,32 +287,8 @@ function toDiscoveryStatusPayload(data) {
|
|
|
306
287
|
};
|
|
307
288
|
}
|
|
308
289
|
|
|
309
|
-
// src/ClientCore/SdkOptions/Expressions.ts
|
|
310
|
-
function toEmojiCreateBody(options) {
|
|
311
|
-
return { name: options.name, image: options.image };
|
|
312
|
-
}
|
|
313
|
-
function toEmojiEditBody(options) {
|
|
314
|
-
return { name: options.name };
|
|
315
|
-
}
|
|
316
|
-
function toStickerCreateBody(options) {
|
|
317
|
-
const body = {
|
|
318
|
-
name: options.name,
|
|
319
|
-
image: options.file
|
|
320
|
-
};
|
|
321
|
-
if (options.description !== void 0) body.description = options.description;
|
|
322
|
-
if (options.tags !== void 0) body.tags = options.tags;
|
|
323
|
-
return body;
|
|
324
|
-
}
|
|
325
|
-
function toStickerEditBody(options) {
|
|
326
|
-
const body = {};
|
|
327
|
-
if (options.name !== void 0) body.name = options.name;
|
|
328
|
-
if (options.description !== void 0) body.description = options.description;
|
|
329
|
-
if (options.tags !== void 0) body.tags = options.tags;
|
|
330
|
-
return body;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
290
|
// src/ClientCore/SdkOptions/Guild.ts
|
|
334
|
-
var
|
|
291
|
+
var import_util4 = require("@fluxerjs/util");
|
|
335
292
|
function toGuildEditBody(options) {
|
|
336
293
|
const body = {};
|
|
337
294
|
if (options.name !== void 0) body.name = options.name;
|
|
@@ -359,6 +316,16 @@ function toGuildEditBody(options) {
|
|
|
359
316
|
body.splash_card_alignment = options.splashCardAlignment;
|
|
360
317
|
}
|
|
361
318
|
if (options.nsfwLevel !== void 0) body.nsfw_level = options.nsfwLevel;
|
|
319
|
+
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
320
|
+
if (options.contentWarningLevel !== void 0) {
|
|
321
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
322
|
+
}
|
|
323
|
+
if (options.contentWarningText !== void 0) {
|
|
324
|
+
body.content_warning_text = options.contentWarningText;
|
|
325
|
+
}
|
|
326
|
+
if (options.messageHistoryCutoff !== void 0) {
|
|
327
|
+
body.message_history_cutoff = options.messageHistoryCutoff;
|
|
328
|
+
}
|
|
362
329
|
if (options.features !== void 0) body.features = options.features;
|
|
363
330
|
return body;
|
|
364
331
|
}
|
|
@@ -368,6 +335,9 @@ function toGuildBanBody(options) {
|
|
|
368
335
|
if (options.deleteMessageDays !== void 0) {
|
|
369
336
|
body.delete_message_days = options.deleteMessageDays;
|
|
370
337
|
}
|
|
338
|
+
if (options.deleteMessageSeconds !== void 0) {
|
|
339
|
+
body.delete_message_seconds = options.deleteMessageSeconds;
|
|
340
|
+
}
|
|
371
341
|
if (options.banDurationSeconds !== void 0) {
|
|
372
342
|
body.ban_duration_seconds = options.banDurationSeconds;
|
|
373
343
|
}
|
|
@@ -382,18 +352,26 @@ function toChannelPositionBody(updates) {
|
|
|
382
352
|
return row;
|
|
383
353
|
});
|
|
384
354
|
}
|
|
385
|
-
function
|
|
355
|
+
function toRolePermissionsBody(options) {
|
|
386
356
|
const body = {};
|
|
357
|
+
if (options.permissions !== void 0) {
|
|
358
|
+
body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util4.resolvePermissionsToBitfield)(options.permissions);
|
|
359
|
+
}
|
|
360
|
+
return body;
|
|
361
|
+
}
|
|
362
|
+
function toRoleCreateBody(options) {
|
|
363
|
+
const body = { ...toRolePermissionsBody(options) };
|
|
364
|
+
if (options.name !== void 0) body.name = options.name;
|
|
365
|
+
if (options.color !== void 0) body.color = options.color;
|
|
366
|
+
return body;
|
|
367
|
+
}
|
|
368
|
+
function toRoleEditBody(options) {
|
|
369
|
+
const body = { ...toRolePermissionsBody(options) };
|
|
387
370
|
if (options.name !== void 0) body.name = options.name;
|
|
388
371
|
if (options.color !== void 0) body.color = options.color;
|
|
389
372
|
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
390
373
|
if (options.mentionable !== void 0) body.mentionable = options.mentionable;
|
|
391
|
-
if (options.unicodeEmoji !== void 0) body.unicode_emoji = options.unicodeEmoji;
|
|
392
|
-
if (options.position !== void 0) body.position = options.position;
|
|
393
374
|
if (options.hoistPosition !== void 0) body.hoist_position = options.hoistPosition;
|
|
394
|
-
if (options.permissions !== void 0) {
|
|
395
|
-
body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util3.resolvePermissionsToBitfield)(options.permissions);
|
|
396
|
-
}
|
|
397
375
|
return body;
|
|
398
376
|
}
|
|
399
377
|
|
|
@@ -411,6 +389,8 @@ function toMemberSearchBody(options) {
|
|
|
411
389
|
if (options.userCreatedAtLte !== void 0) body.user_created_at_lte = options.userCreatedAtLte;
|
|
412
390
|
if (options.sortBy !== void 0) body.sort_by = options.sortBy;
|
|
413
391
|
if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
|
|
392
|
+
if (options.joinSourceType !== void 0) body.join_source_type = options.joinSourceType;
|
|
393
|
+
if (options.sourceInviteCode !== void 0) body.source_invite_code = options.sourceInviteCode;
|
|
414
394
|
return body;
|
|
415
395
|
}
|
|
416
396
|
function toMemberEditBody(options) {
|
|
@@ -423,6 +403,7 @@ function toMemberEditBody(options) {
|
|
|
423
403
|
if (options.pronouns !== void 0) body.pronouns = options.pronouns;
|
|
424
404
|
if (options.accentColor !== void 0) body.accent_color = options.accentColor;
|
|
425
405
|
if (options.profileFlags !== void 0) body.profile_flags = options.profileFlags;
|
|
406
|
+
if (options.mentionFlags !== void 0) body.mention_flags = options.mentionFlags;
|
|
426
407
|
if (options.mute !== void 0) body.mute = options.mute;
|
|
427
408
|
if (options.deaf !== void 0) body.deaf = options.deaf;
|
|
428
409
|
if (options.communicationDisabledUntil !== void 0) {
|
|
@@ -444,15 +425,54 @@ function toBulkFetchWire(requests) {
|
|
|
444
425
|
...r.around !== void 0 ? { around: r.around } : {}
|
|
445
426
|
}));
|
|
446
427
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (options.
|
|
452
|
-
if (options.
|
|
453
|
-
|
|
428
|
+
function toMessageSearchBody(options = {}) {
|
|
429
|
+
const body = { scope: "current" };
|
|
430
|
+
if (options.content !== void 0) body.content = options.content;
|
|
431
|
+
if (options.contents !== void 0) body.contents = options.contents;
|
|
432
|
+
if (options.exactPhrases !== void 0) body.exact_phrases = options.exactPhrases;
|
|
433
|
+
if (options.channelIds !== void 0) {
|
|
434
|
+
body.channel_id = options.channelIds;
|
|
435
|
+
body.channel_ids = options.channelIds;
|
|
436
|
+
}
|
|
437
|
+
if (options.excludeChannelIds !== void 0) body.exclude_channel_id = options.excludeChannelIds;
|
|
438
|
+
if (options.contextGuildId !== void 0) body.context_guild_id = options.contextGuildId;
|
|
439
|
+
if (options.contextChannelId !== void 0) body.context_channel_id = options.contextChannelId;
|
|
440
|
+
if (options.hitsPerPage !== void 0) body.hits_per_page = options.hitsPerPage;
|
|
441
|
+
if (options.page !== void 0) body.page = options.page;
|
|
442
|
+
if (options.cursor !== void 0) body.cursor = options.cursor;
|
|
443
|
+
if (options.minId !== void 0) body.min_id = options.minId;
|
|
444
|
+
if (options.maxId !== void 0) body.max_id = options.maxId;
|
|
445
|
+
if (options.authorIds !== void 0) body.author_id = options.authorIds;
|
|
446
|
+
if (options.excludeAuthorIds !== void 0) body.exclude_author_id = options.excludeAuthorIds;
|
|
447
|
+
if (options.authorType !== void 0) body.author_type = options.authorType;
|
|
448
|
+
if (options.excludeAuthorType !== void 0) body.exclude_author_type = options.excludeAuthorType;
|
|
449
|
+
if (options.mentions !== void 0) body.mentions = options.mentions;
|
|
450
|
+
if (options.excludeMentions !== void 0) body.exclude_mentions = options.excludeMentions;
|
|
451
|
+
if (options.mentionEveryone !== void 0) body.mention_everyone = options.mentionEveryone;
|
|
452
|
+
if (options.pinned !== void 0) body.pinned = options.pinned;
|
|
453
|
+
if (options.includeNsfw !== void 0) body.include_nsfw = options.includeNsfw;
|
|
454
|
+
if (options.has !== void 0) body.has = options.has;
|
|
455
|
+
if (options.excludeHas !== void 0) body.exclude_has = options.excludeHas;
|
|
456
|
+
if (options.sortBy !== void 0) body.sort_by = options.sortBy;
|
|
457
|
+
if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
|
|
454
458
|
return body;
|
|
455
459
|
}
|
|
460
|
+
function isMessageSearchIndexing(data) {
|
|
461
|
+
return "indexing" in data && data.indexing === true;
|
|
462
|
+
}
|
|
463
|
+
function toMessageSearchResponse(data) {
|
|
464
|
+
if (isMessageSearchIndexing(data)) {
|
|
465
|
+
return { indexing: true };
|
|
466
|
+
}
|
|
467
|
+
return {
|
|
468
|
+
messages: data.messages,
|
|
469
|
+
channels: data.channels,
|
|
470
|
+
total: data.total,
|
|
471
|
+
hitsPerPage: data.hits_per_page,
|
|
472
|
+
page: data.page,
|
|
473
|
+
...data.cursor !== void 0 ? { cursor: data.cursor } : {}
|
|
474
|
+
};
|
|
475
|
+
}
|
|
456
476
|
|
|
457
477
|
// src/ClientCore/SdkOptions/Presence.ts
|
|
458
478
|
function toPresenceWire(options) {
|
|
@@ -501,6 +521,13 @@ function toSudoBody(options) {
|
|
|
501
521
|
return body;
|
|
502
522
|
}
|
|
503
523
|
|
|
524
|
+
// src/Helpers/AuditReason.ts
|
|
525
|
+
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
526
|
+
function auditReasonHeaders(reason) {
|
|
527
|
+
if (reason == null || reason === "") return {};
|
|
528
|
+
return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
|
|
529
|
+
}
|
|
530
|
+
|
|
504
531
|
// src/Helpers/MessageUtils/Body.ts
|
|
505
532
|
var import_builders = require("@fluxerjs/builders");
|
|
506
533
|
var import_types = require("@fluxerjs/types");
|
|
@@ -566,6 +593,37 @@ function applyReplyPingSuppression(body) {
|
|
|
566
593
|
function assignIfDefined(target, key, value) {
|
|
567
594
|
if (value !== void 0) target[key] = value;
|
|
568
595
|
}
|
|
596
|
+
function normalizeSendFiles(files) {
|
|
597
|
+
if (!files?.length) return void 0;
|
|
598
|
+
const normalized = [];
|
|
599
|
+
const metaFromBuilders = [];
|
|
600
|
+
let anyBuilderMeta = false;
|
|
601
|
+
for (let i = 0; i < files.length; i++) {
|
|
602
|
+
const file = files[i];
|
|
603
|
+
if (!file) continue;
|
|
604
|
+
if (file instanceof import_builders.AttachmentBuilder) {
|
|
605
|
+
normalized.push(file.toFileData());
|
|
606
|
+
const meta = {
|
|
607
|
+
id: i,
|
|
608
|
+
filename: file.filename,
|
|
609
|
+
...file.description != null ? { description: file.description } : {},
|
|
610
|
+
...file.spoiler ? { flags: import_types.MessageAttachmentFlags.IS_SPOILER } : {}
|
|
611
|
+
};
|
|
612
|
+
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
613
|
+
metaFromBuilders.push(meta);
|
|
614
|
+
} else {
|
|
615
|
+
normalized.push(file);
|
|
616
|
+
metaFromBuilders.push({
|
|
617
|
+
id: i,
|
|
618
|
+
filename: file.filename ?? file.name
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
files: normalized,
|
|
624
|
+
metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
|
|
625
|
+
};
|
|
626
|
+
}
|
|
569
627
|
function buildSendBody(options) {
|
|
570
628
|
const body = typeof options === "string" ? { content: options } : options;
|
|
571
629
|
const result = {};
|
|
@@ -573,16 +631,17 @@ function buildSendBody(options) {
|
|
|
573
631
|
if (body.embeds?.length) {
|
|
574
632
|
result.embeds = body.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
|
|
575
633
|
}
|
|
634
|
+
const normalizedFiles = normalizeSendFiles(body.files);
|
|
576
635
|
if (body.uploadedAttachments?.length) {
|
|
577
636
|
result.attachments = body.uploadedAttachments;
|
|
578
|
-
} else if (
|
|
637
|
+
} else if (normalizedFiles?.files.length) {
|
|
579
638
|
result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
|
|
580
639
|
id: a.id,
|
|
581
640
|
filename: a.filename,
|
|
582
641
|
...a.title != null && { title: a.title },
|
|
583
642
|
...a.description != null && { description: a.description },
|
|
584
643
|
...a.flags != null && { flags: a.flags }
|
|
585
|
-
})) :
|
|
644
|
+
})) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
|
|
586
645
|
}
|
|
587
646
|
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
588
647
|
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
@@ -676,9 +735,10 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
676
735
|
} else if (allowedMentions?.repliedUser === false) {
|
|
677
736
|
applyReplyPingSuppression(body);
|
|
678
737
|
}
|
|
738
|
+
const resolvedFiles = normalizeSendFiles(files);
|
|
679
739
|
return {
|
|
680
740
|
body,
|
|
681
|
-
files: !uploadedAttachments?.length && files
|
|
741
|
+
files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
|
|
682
742
|
};
|
|
683
743
|
}
|
|
684
744
|
|
|
@@ -690,9 +750,9 @@ var import_collection = require("@fluxerjs/collection");
|
|
|
690
750
|
var import_types2 = require("@fluxerjs/types");
|
|
691
751
|
|
|
692
752
|
// src/Helpers/HttpErrors.ts
|
|
693
|
-
var
|
|
753
|
+
var import_rest = require("@fluxerjs/rest");
|
|
694
754
|
function httpStatus(err) {
|
|
695
|
-
if (err instanceof
|
|
755
|
+
if (err instanceof import_rest.FluxerAPIError) return err.statusCode;
|
|
696
756
|
if (typeof err === "object" && err !== null && "statusCode" in err) {
|
|
697
757
|
const code = err.statusCode;
|
|
698
758
|
return typeof code === "number" ? code : void 0;
|
|
@@ -705,7 +765,7 @@ function errorMessage(err, fallback) {
|
|
|
705
765
|
return fallback;
|
|
706
766
|
}
|
|
707
767
|
function rethrowMapped(err, options) {
|
|
708
|
-
if (err instanceof
|
|
768
|
+
if (err instanceof import_rest.RateLimitError) throw err;
|
|
709
769
|
if (err instanceof import_util2.FluxerError) throw err;
|
|
710
770
|
if (options.notFound && httpStatus(err) === 404) {
|
|
711
771
|
throw new import_util2.FluxerError(options.notFound.message, {
|
|
@@ -727,14 +787,22 @@ function qs(params) {
|
|
|
727
787
|
return out ? `?${out}` : "";
|
|
728
788
|
}
|
|
729
789
|
|
|
790
|
+
// src/Domain/Base.ts
|
|
791
|
+
var Base = class {
|
|
792
|
+
};
|
|
793
|
+
|
|
730
794
|
// src/Domain/Message/MessageReaction.ts
|
|
731
|
-
var MessageReaction = class extends Base {
|
|
795
|
+
var MessageReaction = class _MessageReaction extends Base {
|
|
732
796
|
client;
|
|
733
797
|
messageId;
|
|
734
798
|
channelId;
|
|
735
799
|
guildId;
|
|
736
800
|
emoji;
|
|
737
|
-
/**
|
|
801
|
+
/** Total count when hydrated from a message payload; `1` for gateway add events. */
|
|
802
|
+
count;
|
|
803
|
+
/** Whether the current user reacted (message payload); false for gateway remove. */
|
|
804
|
+
me;
|
|
805
|
+
/** Raw gateway payload for low-level access (null when built from a message aggregate). */
|
|
738
806
|
_data;
|
|
739
807
|
constructor(client, data) {
|
|
740
808
|
super();
|
|
@@ -748,6 +816,26 @@ var MessageReaction = class extends Base {
|
|
|
748
816
|
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
749
817
|
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
750
818
|
};
|
|
819
|
+
this.count = 1;
|
|
820
|
+
this.me = false;
|
|
821
|
+
}
|
|
822
|
+
/** Build a reaction aggregate from a message's `reactions` array entry. */
|
|
823
|
+
static fromMessage(message, data) {
|
|
824
|
+
const reaction = new _MessageReaction(message.client, {
|
|
825
|
+
user_id: message.client.user?.id ?? "0",
|
|
826
|
+
message_id: message.id,
|
|
827
|
+
channel_id: message.channelId,
|
|
828
|
+
guild_id: message.guildId ?? void 0,
|
|
829
|
+
emoji: {
|
|
830
|
+
name: data.emoji.name,
|
|
831
|
+
id: data.emoji.id ?? void 0,
|
|
832
|
+
animated: data.emoji.animated ?? void 0
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
Object.defineProperty(reaction, "_data", { value: null });
|
|
836
|
+
reaction.count = data.count;
|
|
837
|
+
reaction.me = data.me ?? false;
|
|
838
|
+
return reaction;
|
|
751
839
|
}
|
|
752
840
|
/** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
|
|
753
841
|
get emojiIdentifier() {
|
|
@@ -757,12 +845,23 @@ var MessageReaction = class extends Base {
|
|
|
757
845
|
get guild() {
|
|
758
846
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
759
847
|
}
|
|
848
|
+
/** Cached message this reaction belongs to, or null if the message was not cached. */
|
|
849
|
+
get message() {
|
|
850
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
|
|
851
|
+
return cached ? new Message(this.client, cached) : null;
|
|
852
|
+
}
|
|
853
|
+
/** Cached text-capable channel, or null if uncached / not text-based. */
|
|
854
|
+
get channel() {
|
|
855
|
+
const channel = this.client.channels.get(this.channelId);
|
|
856
|
+
return channel?.isTextBased() ? channel : null;
|
|
857
|
+
}
|
|
760
858
|
/**
|
|
761
|
-
* Fetch the message this reaction belongs to.
|
|
762
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
859
|
+
* Fetch the message this reaction belongs to (cache first, then REST).
|
|
763
860
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
764
861
|
*/
|
|
765
862
|
async fetchMessage() {
|
|
863
|
+
const cached = this.message;
|
|
864
|
+
if (cached) return cached;
|
|
766
865
|
try {
|
|
767
866
|
const data = await this.client.rest.get(
|
|
768
867
|
import_types2.Routes.channelMessage(this.channelId, this.messageId)
|
|
@@ -781,7 +880,7 @@ var MessageReaction = class extends Base {
|
|
|
781
880
|
};
|
|
782
881
|
|
|
783
882
|
// src/Helpers/ReactionCollector.ts
|
|
784
|
-
var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
883
|
+
var ReactionCollector = class _ReactionCollector extends import_node_events.EventEmitter {
|
|
785
884
|
client;
|
|
786
885
|
messageId;
|
|
787
886
|
channelId;
|
|
@@ -824,15 +923,17 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
824
923
|
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
825
924
|
}
|
|
826
925
|
});
|
|
827
|
-
const
|
|
926
|
+
const cached = this.client.users.get(entry.userId);
|
|
927
|
+
const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
|
|
928
|
+
{
|
|
828
929
|
id: entry.userId,
|
|
829
930
|
username: "Unknown",
|
|
830
931
|
discriminator: "0",
|
|
831
|
-
|
|
932
|
+
globalName: null,
|
|
832
933
|
avatar: null,
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
}
|
|
934
|
+
bot: false,
|
|
935
|
+
system: false
|
|
936
|
+
};
|
|
836
937
|
this._collect(reaction, user, entry.userId);
|
|
837
938
|
}
|
|
838
939
|
};
|
|
@@ -864,6 +965,21 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
864
965
|
}
|
|
865
966
|
this.emit("end", this.collected, reason);
|
|
866
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* One-shot helper used by {@link Message.awaitReactions}.
|
|
970
|
+
* Resolves with the collected reactions when the collector ends.
|
|
971
|
+
* Rejects if `options.errors` includes the end reason.
|
|
972
|
+
*/
|
|
973
|
+
static awaitReactions(client, messageId, channelId, options) {
|
|
974
|
+
const errors = options?.errors ?? [];
|
|
975
|
+
return new Promise((resolve, reject) => {
|
|
976
|
+
const collector = new _ReactionCollector(client, messageId, channelId, options);
|
|
977
|
+
collector.on("end", (collected, reason) => {
|
|
978
|
+
if (errors.includes(reason)) reject(collected);
|
|
979
|
+
else resolve(collected);
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
}
|
|
867
983
|
on(event, listener) {
|
|
868
984
|
return super.on(event, listener);
|
|
869
985
|
}
|
|
@@ -872,135 +988,355 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
|
|
|
872
988
|
}
|
|
873
989
|
};
|
|
874
990
|
|
|
875
|
-
// src/Domain/Message/
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
name: parsed.name,
|
|
897
|
-
id: parsed.id,
|
|
898
|
-
...parsed.animated ? { animated: true } : {}
|
|
899
|
-
};
|
|
900
|
-
}
|
|
901
|
-
let name = emoji;
|
|
902
|
-
try {
|
|
903
|
-
name = decodeURIComponent(emoji);
|
|
904
|
-
} catch {
|
|
905
|
-
}
|
|
906
|
-
return { name: parsed?.name ?? name };
|
|
907
|
-
}
|
|
908
|
-
function emitOwnReactionAdd(message, wireOrInput) {
|
|
909
|
-
const user = message.client.user;
|
|
910
|
-
if (!user) return;
|
|
911
|
-
const emojiPayload = toReactionEmoji(wireOrInput);
|
|
912
|
-
const reaction = new MessageReaction(message.client, {
|
|
913
|
-
user_id: user.id,
|
|
914
|
-
channel_id: message.channelId,
|
|
915
|
-
message_id: message.id,
|
|
916
|
-
guild_id: message.guildId ?? void 0,
|
|
917
|
-
emoji: {
|
|
918
|
-
name: emojiPayload.name,
|
|
919
|
-
...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
|
|
920
|
-
...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
const payload = {
|
|
924
|
-
reaction,
|
|
925
|
-
user,
|
|
926
|
-
messageId: message.id,
|
|
927
|
-
channelId: message.channelId,
|
|
928
|
-
emoji: emojiPayload,
|
|
929
|
-
userId: user.id
|
|
991
|
+
// src/Domain/Message/Attachment.ts
|
|
992
|
+
function toMessageAttachment(data) {
|
|
993
|
+
return {
|
|
994
|
+
id: data.id,
|
|
995
|
+
filename: data.filename,
|
|
996
|
+
title: data.title ?? null,
|
|
997
|
+
description: data.description ?? null,
|
|
998
|
+
contentType: data.content_type ?? null,
|
|
999
|
+
contentHash: data.content_hash ?? null,
|
|
1000
|
+
size: data.size,
|
|
1001
|
+
url: data.url ?? null,
|
|
1002
|
+
proxyUrl: data.proxy_url ?? null,
|
|
1003
|
+
width: data.width ?? null,
|
|
1004
|
+
height: data.height ?? null,
|
|
1005
|
+
placeholder: data.placeholder ?? null,
|
|
1006
|
+
flags: data.flags ?? 0,
|
|
1007
|
+
nsfw: data.nsfw ?? false,
|
|
1008
|
+
duration: data.duration ?? null,
|
|
1009
|
+
waveform: data.waveform ?? null,
|
|
1010
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
1011
|
+
expired: data.expired ?? false
|
|
930
1012
|
};
|
|
931
|
-
message.client.emit(Events.MessageReactionAdd, payload);
|
|
932
|
-
}
|
|
933
|
-
async function reactToMessage(message, emoji) {
|
|
934
|
-
const wire = await emojiPath(message, emoji);
|
|
935
|
-
await message.client.rest.put(
|
|
936
|
-
import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
937
|
-
);
|
|
938
|
-
emitOwnReactionAdd(message, wire);
|
|
939
|
-
}
|
|
940
|
-
async function removeMessageReaction(message, emoji, userId) {
|
|
941
|
-
const e = await emojiPath(message, emoji);
|
|
942
|
-
const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
|
|
943
|
-
await message.client.rest.delete(route);
|
|
944
|
-
}
|
|
945
|
-
async function removeAllMessageReactions(message) {
|
|
946
|
-
await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
|
|
947
|
-
}
|
|
948
|
-
async function removeMessageReactionEmoji(message, emoji) {
|
|
949
|
-
const e = await emojiPath(message, emoji);
|
|
950
|
-
await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
|
|
951
1013
|
}
|
|
952
|
-
|
|
953
|
-
|
|
1014
|
+
|
|
1015
|
+
// src/Domain/Message/Embed.ts
|
|
1016
|
+
function toMessageEmbedAuthor(data) {
|
|
1017
|
+
return {
|
|
1018
|
+
name: data.name ?? null,
|
|
1019
|
+
url: data.url ?? null,
|
|
1020
|
+
iconUrl: data.icon_url ?? null,
|
|
1021
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
1022
|
+
};
|
|
954
1023
|
}
|
|
955
|
-
|
|
956
|
-
const e = await emojiPath(message, emoji);
|
|
957
|
-
const params = new URLSearchParams();
|
|
958
|
-
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
959
|
-
if (options?.after) params.set("after", options.after);
|
|
960
|
-
const qs2 = params.toString();
|
|
961
|
-
const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
|
|
962
|
-
const data = await message.client.rest.get(route);
|
|
963
|
-
if (Array.isArray(data)) {
|
|
964
|
-
return {
|
|
965
|
-
users: data.map((u) => message.client.getOrCreateUser(u)),
|
|
966
|
-
hasMore: false,
|
|
967
|
-
nextAfter: null
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
const list = data.items ?? data.users ?? [];
|
|
1024
|
+
function toMessageEmbedFooter(data) {
|
|
971
1025
|
return {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1026
|
+
text: data.text,
|
|
1027
|
+
iconUrl: data.icon_url ?? null,
|
|
1028
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
975
1029
|
};
|
|
976
1030
|
}
|
|
977
|
-
|
|
978
|
-
// src/Domain/Message/Send.ts
|
|
979
|
-
var import_builders2 = require("@fluxerjs/builders");
|
|
980
|
-
var import_types4 = require("@fluxerjs/types");
|
|
981
|
-
function toReplyTarget(ref) {
|
|
1031
|
+
function toMessageEmbedMedia(data) {
|
|
982
1032
|
return {
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1033
|
+
url: data.url,
|
|
1034
|
+
proxyUrl: data.proxy_url ?? null,
|
|
1035
|
+
contentType: data.content_type ?? null,
|
|
1036
|
+
contentHash: data.content_hash ?? null,
|
|
1037
|
+
width: data.width ?? null,
|
|
1038
|
+
height: data.height ?? null,
|
|
1039
|
+
description: data.description ?? null,
|
|
1040
|
+
placeholder: data.placeholder ?? null,
|
|
1041
|
+
duration: data.duration ?? null,
|
|
1042
|
+
flags: data.flags ?? null
|
|
986
1043
|
};
|
|
987
1044
|
}
|
|
988
|
-
function
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1045
|
+
function toMessageEmbed(data) {
|
|
1046
|
+
const full = data;
|
|
1047
|
+
return {
|
|
1048
|
+
type: data.type ?? "rich",
|
|
1049
|
+
url: data.url ?? null,
|
|
1050
|
+
title: data.title ?? null,
|
|
1051
|
+
color: data.color ?? null,
|
|
1052
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
1053
|
+
description: data.description ?? null,
|
|
1054
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
1055
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
1056
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
1057
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
1058
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
1059
|
+
name: f.name,
|
|
1060
|
+
value: f.value,
|
|
1061
|
+
inline: f.inline ?? false
|
|
1062
|
+
})),
|
|
1063
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
1064
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
1065
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
1066
|
+
nsfw: data.nsfw ?? false,
|
|
1067
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
1068
|
+
html: full.html ?? null,
|
|
1069
|
+
htmlWidth: full.html_width ?? null,
|
|
1070
|
+
htmlHeight: full.html_height ?? null
|
|
1071
|
+
};
|
|
992
1072
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1073
|
+
|
|
1074
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
1075
|
+
var import_collection2 = require("@fluxerjs/collection");
|
|
1076
|
+
var MessageReactionManager = class {
|
|
1077
|
+
constructor(message) {
|
|
1078
|
+
this.message = message;
|
|
996
1079
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1080
|
+
_cache = new import_collection2.Collection();
|
|
1081
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
1082
|
+
get cache() {
|
|
1083
|
+
return this._cache;
|
|
1001
1084
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1085
|
+
get size() {
|
|
1086
|
+
return this._cache.size;
|
|
1087
|
+
}
|
|
1088
|
+
[Symbol.iterator]() {
|
|
1089
|
+
return this._cache.values();
|
|
1090
|
+
}
|
|
1091
|
+
/** @internal Sync from an API message payload. */
|
|
1092
|
+
_patch(reactions) {
|
|
1093
|
+
this._cache.clear();
|
|
1094
|
+
for (const data of reactions ?? []) {
|
|
1095
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
1096
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1102
|
+
var import_util5 = require("@fluxerjs/util");
|
|
1103
|
+
|
|
1104
|
+
// src/Helpers/Constants.ts
|
|
1105
|
+
var import_rest2 = require("@fluxerjs/rest");
|
|
1106
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
1107
|
+
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1108
|
+
|
|
1109
|
+
// src/Helpers/Cdn.ts
|
|
1110
|
+
var CDN_SIZE_LADDER = [
|
|
1111
|
+
16,
|
|
1112
|
+
20,
|
|
1113
|
+
22,
|
|
1114
|
+
24,
|
|
1115
|
+
28,
|
|
1116
|
+
32,
|
|
1117
|
+
40,
|
|
1118
|
+
44,
|
|
1119
|
+
48,
|
|
1120
|
+
56,
|
|
1121
|
+
60,
|
|
1122
|
+
64,
|
|
1123
|
+
80,
|
|
1124
|
+
96,
|
|
1125
|
+
100,
|
|
1126
|
+
128,
|
|
1127
|
+
160,
|
|
1128
|
+
240,
|
|
1129
|
+
256,
|
|
1130
|
+
300,
|
|
1131
|
+
320,
|
|
1132
|
+
480,
|
|
1133
|
+
512,
|
|
1134
|
+
600,
|
|
1135
|
+
640,
|
|
1136
|
+
1024,
|
|
1137
|
+
1280,
|
|
1138
|
+
1536,
|
|
1139
|
+
2048,
|
|
1140
|
+
3072,
|
|
1141
|
+
4096,
|
|
1142
|
+
8192,
|
|
1143
|
+
16384
|
|
1144
|
+
];
|
|
1145
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
1146
|
+
icon: { min: 128, max: 1024 },
|
|
1147
|
+
banner: { min: 480, max: 2400 },
|
|
1148
|
+
emoji: { min: 32, max: 512 },
|
|
1149
|
+
sticker: { min: 128, max: 512 }
|
|
1150
|
+
};
|
|
1151
|
+
function nearestSize(requested, candidates) {
|
|
1152
|
+
let best = candidates[0];
|
|
1153
|
+
let bestDist = Math.abs(requested - best);
|
|
1154
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
1155
|
+
const step = candidates[i];
|
|
1156
|
+
const dist = Math.abs(requested - step);
|
|
1157
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1158
|
+
best = step;
|
|
1159
|
+
bestDist = dist;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return best;
|
|
1163
|
+
}
|
|
1164
|
+
function snapCdnSize(requested, assetClass) {
|
|
1165
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1166
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1167
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1168
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1169
|
+
return nearestSize(clamped, allowed);
|
|
1170
|
+
}
|
|
1171
|
+
function mediaBase(options) {
|
|
1172
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1173
|
+
}
|
|
1174
|
+
function staticBase(options) {
|
|
1175
|
+
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
1176
|
+
}
|
|
1177
|
+
function getExtension(hash, options) {
|
|
1178
|
+
const ext = options?.extension ?? "png";
|
|
1179
|
+
if (hash?.startsWith("a_")) return "gif";
|
|
1180
|
+
return ext;
|
|
1181
|
+
}
|
|
1182
|
+
function appendSize(options, assetClass) {
|
|
1183
|
+
const size = options?.size;
|
|
1184
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1185
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1186
|
+
}
|
|
1187
|
+
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1188
|
+
if (!avatarHash) return null;
|
|
1189
|
+
const ext = getExtension(avatarHash, options);
|
|
1190
|
+
const size = appendSize(options, "icon");
|
|
1191
|
+
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1192
|
+
}
|
|
1193
|
+
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1194
|
+
if (!bannerHash) return null;
|
|
1195
|
+
const ext = getExtension(bannerHash, options);
|
|
1196
|
+
const size = appendSize(options, "banner");
|
|
1197
|
+
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1198
|
+
}
|
|
1199
|
+
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1200
|
+
if (!avatarHash) return null;
|
|
1201
|
+
const ext = getExtension(avatarHash, options);
|
|
1202
|
+
const size = appendSize(options, "icon");
|
|
1203
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1204
|
+
}
|
|
1205
|
+
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1206
|
+
if (!bannerHash) return null;
|
|
1207
|
+
const ext = getExtension(bannerHash, options);
|
|
1208
|
+
const size = appendSize(options, "banner");
|
|
1209
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1210
|
+
}
|
|
1211
|
+
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
1212
|
+
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
1213
|
+
return `${staticBase(options)}/avatars/${index}.png`;
|
|
1214
|
+
}
|
|
1215
|
+
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1216
|
+
if (!hash) return null;
|
|
1217
|
+
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1218
|
+
const size = appendSize(options, assetClass);
|
|
1219
|
+
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1220
|
+
}
|
|
1221
|
+
function cdnEmojiURL(emojiId, animated, options) {
|
|
1222
|
+
const ext = animated ? "gif" : "png";
|
|
1223
|
+
const size = appendSize(options, "emoji");
|
|
1224
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1225
|
+
}
|
|
1226
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
1227
|
+
const ext = animated ? "gif" : "png";
|
|
1228
|
+
const size = appendSize(options, "sticker");
|
|
1229
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1233
|
+
var MessageSticker = class extends Base {
|
|
1234
|
+
client;
|
|
1235
|
+
id;
|
|
1236
|
+
name;
|
|
1237
|
+
description;
|
|
1238
|
+
tags;
|
|
1239
|
+
animated;
|
|
1240
|
+
constructor(client, data) {
|
|
1241
|
+
super();
|
|
1242
|
+
this.client = client;
|
|
1243
|
+
this.id = data.id;
|
|
1244
|
+
this.name = data.name;
|
|
1245
|
+
this.description = data.description ?? "";
|
|
1246
|
+
this.tags = data.tags ?? [];
|
|
1247
|
+
this.animated = data.animated ?? false;
|
|
1248
|
+
}
|
|
1249
|
+
/** CDN URL for this sticker image. */
|
|
1250
|
+
get url() {
|
|
1251
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
1252
|
+
mediaBase: this.client.instance.endpoints.media
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
1256
|
+
get createdTimestamp() {
|
|
1257
|
+
return import_util5.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1258
|
+
}
|
|
1259
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
1260
|
+
get createdAt() {
|
|
1261
|
+
return import_util5.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
// src/Domain/Message/Reactions.ts
|
|
1266
|
+
var import_types3 = require("@fluxerjs/types");
|
|
1267
|
+
async function emojiPath(message, emoji) {
|
|
1268
|
+
return message.client.resolveEmoji(emoji, message.guildId);
|
|
1269
|
+
}
|
|
1270
|
+
async function reactToMessage(message, emoji) {
|
|
1271
|
+
const wire = await emojiPath(message, emoji);
|
|
1272
|
+
await message.client.rest.put(
|
|
1273
|
+
import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
async function removeMessageReaction(message, emoji, userId) {
|
|
1277
|
+
const e = await emojiPath(message, emoji);
|
|
1278
|
+
const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
|
|
1279
|
+
await message.client.rest.delete(route);
|
|
1280
|
+
}
|
|
1281
|
+
async function removeAllMessageReactions(message) {
|
|
1282
|
+
await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
|
|
1283
|
+
}
|
|
1284
|
+
async function removeMessageReactionEmoji(message, emoji) {
|
|
1285
|
+
const e = await emojiPath(message, emoji);
|
|
1286
|
+
await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
|
|
1287
|
+
}
|
|
1288
|
+
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
1289
|
+
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
1290
|
+
}
|
|
1291
|
+
async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
1292
|
+
const e = await emojiPath(message, emoji);
|
|
1293
|
+
const params = new URLSearchParams();
|
|
1294
|
+
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
1295
|
+
if (options?.after) params.set("after", options.after);
|
|
1296
|
+
const qs2 = params.toString();
|
|
1297
|
+
const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
|
|
1298
|
+
const data = await message.client.rest.get(route);
|
|
1299
|
+
if (Array.isArray(data)) {
|
|
1300
|
+
return {
|
|
1301
|
+
users: data.map((u) => message.client.getOrCreateUser(u)),
|
|
1302
|
+
hasMore: false,
|
|
1303
|
+
nextAfter: null
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
const list = data.items ?? data.users ?? [];
|
|
1307
|
+
return {
|
|
1308
|
+
users: list.map((u) => message.client.getOrCreateUser(u)),
|
|
1309
|
+
hasMore: data.has_more ?? false,
|
|
1310
|
+
nextAfter: data.next_after ?? null
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// src/Domain/Message/Send.ts
|
|
1315
|
+
var import_builders2 = require("@fluxerjs/builders");
|
|
1316
|
+
var import_types4 = require("@fluxerjs/types");
|
|
1317
|
+
function toReplyTarget(ref) {
|
|
1318
|
+
return {
|
|
1319
|
+
channelId: ref.channel_id,
|
|
1320
|
+
messageId: ref.message_id,
|
|
1321
|
+
...ref.guild_id != null ? { guildId: ref.guild_id } : {}
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
function toSendOptions(content) {
|
|
1325
|
+
if (typeof content === "string") return { content };
|
|
1326
|
+
if (content instanceof import_builders2.MessagePayload) return messagePayloadToSendOptions(content);
|
|
1327
|
+
return { ...content };
|
|
1328
|
+
}
|
|
1329
|
+
async function createMessageBody(content, referenced_message, ping) {
|
|
1330
|
+
if (typeof content === "string" && content.length === 0) {
|
|
1331
|
+
throw new import_util2.FluxerError("Cannot send an empty message", { code: import_util.ErrorCodes.EmptyMessage });
|
|
1332
|
+
}
|
|
1333
|
+
const opts = toSendOptions(content);
|
|
1334
|
+
if (referenced_message) {
|
|
1335
|
+
opts.replyTo = toReplyTarget(referenced_message);
|
|
1336
|
+
if (ping !== void 0) opts.ping = ping;
|
|
1337
|
+
}
|
|
1338
|
+
return prepareMessagePostPayload(opts);
|
|
1339
|
+
}
|
|
1004
1340
|
function asReplyTarget(value) {
|
|
1005
1341
|
if ("messageId" in value) return value;
|
|
1006
1342
|
return {
|
|
@@ -1041,7 +1377,33 @@ async function replyToMessage(message, options, replyOptions) {
|
|
|
1041
1377
|
}
|
|
1042
1378
|
|
|
1043
1379
|
// src/Domain/Message/Message.ts
|
|
1380
|
+
function toMessageCall(data) {
|
|
1381
|
+
return {
|
|
1382
|
+
participants: data.participants,
|
|
1383
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
function toMessageSnapshot(client, data) {
|
|
1387
|
+
return {
|
|
1388
|
+
content: data.content ?? null,
|
|
1389
|
+
createdAt: new Date(data.timestamp),
|
|
1390
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
1391
|
+
mentionUserIds: data.mentions ?? [],
|
|
1392
|
+
mentionRoles: data.mention_roles ?? [],
|
|
1393
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
1394
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
1395
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
1396
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
function resolveMessageFlags(flags) {
|
|
1400
|
+
if (flags === void 0) return void 0;
|
|
1401
|
+
if (typeof flags === "number") return flags;
|
|
1402
|
+
return Number(import_util6.MessageFlagsBitField.resolve(flags));
|
|
1403
|
+
}
|
|
1044
1404
|
var Message = class _Message extends Base {
|
|
1405
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
1406
|
+
partial = false;
|
|
1045
1407
|
/** The {@link Client} that instantiated this message. */
|
|
1046
1408
|
client;
|
|
1047
1409
|
/** Snowflake ID of this message. */
|
|
@@ -1070,7 +1432,7 @@ var Message = class _Message extends Base {
|
|
|
1070
1432
|
mentionEveryone;
|
|
1071
1433
|
/** Whether this is a text-to-speech message. */
|
|
1072
1434
|
tts;
|
|
1073
|
-
/** Embedded content (
|
|
1435
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
1074
1436
|
embeds;
|
|
1075
1437
|
/** Stickers sent with the message. */
|
|
1076
1438
|
stickers;
|
|
@@ -1092,26 +1454,43 @@ var Message = class _Message extends Base {
|
|
|
1092
1454
|
mentionRoles;
|
|
1093
1455
|
/** Client-side nonce for deduplication. */
|
|
1094
1456
|
nonce;
|
|
1095
|
-
/**
|
|
1457
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
1458
|
+
nsfwEmojis;
|
|
1459
|
+
/**
|
|
1460
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1461
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
1462
|
+
*/
|
|
1096
1463
|
get channel() {
|
|
1097
|
-
|
|
1464
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1465
|
+
return channel?.isTextBased() ? channel : null;
|
|
1098
1466
|
}
|
|
1099
1467
|
/** Cached guild, or null for DMs / uncached. */
|
|
1100
1468
|
get guild() {
|
|
1101
1469
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
1102
1470
|
}
|
|
1103
|
-
/**
|
|
1471
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
1472
|
+
get member() {
|
|
1473
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1477
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1478
|
+
* @example
|
|
1479
|
+
* const channel = await message.resolveChannel();
|
|
1480
|
+
* await channel.delete();
|
|
1481
|
+
*/
|
|
1104
1482
|
async resolveChannel() {
|
|
1105
1483
|
return this.client.channels.resolve(this.channelId);
|
|
1106
1484
|
}
|
|
1107
|
-
/**
|
|
1485
|
+
/**
|
|
1486
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
1487
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
1488
|
+
* @example
|
|
1489
|
+
* const guild = await message.resolveGuild();
|
|
1490
|
+
*/
|
|
1108
1491
|
async resolveGuild() {
|
|
1109
1492
|
if (!this.guildId) return null;
|
|
1110
|
-
|
|
1111
|
-
return await this.client.guilds.resolve(this.guildId);
|
|
1112
|
-
} catch {
|
|
1113
|
-
return null;
|
|
1114
|
-
}
|
|
1493
|
+
return this.client.guilds.resolve(this.guildId);
|
|
1115
1494
|
}
|
|
1116
1495
|
/**
|
|
1117
1496
|
* Construct a message from API data.
|
|
@@ -1128,29 +1507,75 @@ var Message = class _Message extends Base {
|
|
|
1128
1507
|
this.createdAt = new Date(data.timestamp);
|
|
1129
1508
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1130
1509
|
this.pinned = data.pinned;
|
|
1131
|
-
this.attachments = new
|
|
1132
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
1510
|
+
this.attachments = new import_collection3.Collection();
|
|
1511
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1133
1512
|
this.type = data.type ?? import_types5.MessageType.Default;
|
|
1134
|
-
this.flags = data.flags ?? 0;
|
|
1513
|
+
this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1135
1514
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1136
1515
|
this.tts = data.tts ?? false;
|
|
1137
|
-
this.embeds = data.embeds ?? [];
|
|
1138
|
-
this.stickers = data.stickers ?? [];
|
|
1139
|
-
this.reactions =
|
|
1140
|
-
this.
|
|
1141
|
-
this.
|
|
1142
|
-
|
|
1516
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1517
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
1518
|
+
this.reactions = new MessageReactionManager(this);
|
|
1519
|
+
this.reactions._patch(data.reactions);
|
|
1520
|
+
this.messageReference = data.message_reference ? {
|
|
1521
|
+
channelId: data.message_reference.channel_id,
|
|
1522
|
+
messageId: data.message_reference.message_id,
|
|
1523
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1524
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1525
|
+
} : null;
|
|
1526
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
1527
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1143
1528
|
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
1144
1529
|
this.webhookId = data.webhook_id ?? null;
|
|
1145
1530
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1146
1531
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1147
1532
|
this.nonce = data.nonce ?? null;
|
|
1533
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1148
1534
|
}
|
|
1149
|
-
/**
|
|
1535
|
+
/**
|
|
1536
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
1537
|
+
* @internal
|
|
1538
|
+
*/
|
|
1539
|
+
_patch(data) {
|
|
1540
|
+
this.content = data.content;
|
|
1541
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1542
|
+
this.pinned = data.pinned;
|
|
1543
|
+
this.attachments.clear();
|
|
1544
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1545
|
+
this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1546
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1547
|
+
this.tts = data.tts ?? false;
|
|
1548
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1549
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1550
|
+
this.reactions._patch(data.reactions);
|
|
1551
|
+
this.messageReference = data.message_reference ? {
|
|
1552
|
+
channelId: data.message_reference.channel_id,
|
|
1553
|
+
messageId: data.message_reference.message_id,
|
|
1554
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1555
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1556
|
+
} : null;
|
|
1557
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1558
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1559
|
+
);
|
|
1560
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1561
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1562
|
+
this.webhookId = data.webhook_id ?? null;
|
|
1563
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1564
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
1565
|
+
this.nonce = data.nonce ?? null;
|
|
1566
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Send a standalone message in this channel (not a reply).
|
|
1570
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
1571
|
+
*/
|
|
1150
1572
|
async send(options) {
|
|
1151
1573
|
return sendMessage(this, options);
|
|
1152
1574
|
}
|
|
1153
|
-
/**
|
|
1575
|
+
/**
|
|
1576
|
+
* Send a message to another channel by ID.
|
|
1577
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
1578
|
+
*/
|
|
1154
1579
|
async sendTo(channelId, options) {
|
|
1155
1580
|
return sendMessageTo(this, channelId, options);
|
|
1156
1581
|
}
|
|
@@ -1164,6 +1589,16 @@ var Message = class _Message extends Base {
|
|
|
1164
1589
|
async reply(options, replyOptions) {
|
|
1165
1590
|
return replyToMessage(this, options, replyOptions);
|
|
1166
1591
|
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Hydrate a partial message, or return the message as-is.
|
|
1594
|
+
* @example
|
|
1595
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
1596
|
+
* const message = await Message.resolve(msg);
|
|
1597
|
+
* });
|
|
1598
|
+
*/
|
|
1599
|
+
static async resolve(message) {
|
|
1600
|
+
return message.partial ? message.fetch() : message;
|
|
1601
|
+
}
|
|
1167
1602
|
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
1168
1603
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
1169
1604
|
return createMessageBody(content, referenced_message, ping);
|
|
@@ -1176,7 +1611,7 @@ var Message = class _Message extends Base {
|
|
|
1176
1611
|
async edit(options) {
|
|
1177
1612
|
const body = {};
|
|
1178
1613
|
if (options.content !== void 0) body.content = options.content;
|
|
1179
|
-
if (options.embeds
|
|
1614
|
+
if (options.embeds !== void 0) {
|
|
1180
1615
|
body.embeds = options.embeds.map(
|
|
1181
1616
|
(e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e
|
|
1182
1617
|
);
|
|
@@ -1184,7 +1619,8 @@ var Message = class _Message extends Base {
|
|
|
1184
1619
|
if (options.allowedMentions) {
|
|
1185
1620
|
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
1186
1621
|
}
|
|
1187
|
-
|
|
1622
|
+
const flags = resolveMessageFlags(options.flags);
|
|
1623
|
+
if (flags !== void 0) body.flags = flags;
|
|
1188
1624
|
if (options.attachments !== void 0) {
|
|
1189
1625
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
1190
1626
|
}
|
|
@@ -1199,13 +1635,22 @@ var Message = class _Message extends Base {
|
|
|
1199
1635
|
createReactionCollector(options) {
|
|
1200
1636
|
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
1201
1637
|
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
1640
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1641
|
+
*/
|
|
1642
|
+
awaitReactions(options) {
|
|
1643
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1644
|
+
}
|
|
1202
1645
|
/** Fetch the latest version of this message from the API. */
|
|
1203
1646
|
async fetch() {
|
|
1204
1647
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1205
1648
|
}
|
|
1206
1649
|
/** Delete this message. */
|
|
1207
|
-
async delete() {
|
|
1208
|
-
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id)
|
|
1650
|
+
async delete(reason) {
|
|
1651
|
+
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id), {
|
|
1652
|
+
...auditReasonHeaders(reason)
|
|
1653
|
+
});
|
|
1209
1654
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
1210
1655
|
}
|
|
1211
1656
|
/** Delete a specific attachment from this message. */
|
|
@@ -1252,7 +1697,68 @@ var Message = class _Message extends Base {
|
|
|
1252
1697
|
}
|
|
1253
1698
|
};
|
|
1254
1699
|
|
|
1700
|
+
// src/Domain/Message/PartialMessage.ts
|
|
1701
|
+
var import_util7 = require("@fluxerjs/util");
|
|
1702
|
+
var PartialMessage = class {
|
|
1703
|
+
partial = true;
|
|
1704
|
+
client;
|
|
1705
|
+
id;
|
|
1706
|
+
channelId;
|
|
1707
|
+
guildId;
|
|
1708
|
+
content;
|
|
1709
|
+
authorId;
|
|
1710
|
+
author;
|
|
1711
|
+
createdAt;
|
|
1712
|
+
constructor(client, data) {
|
|
1713
|
+
this.client = client;
|
|
1714
|
+
this.id = data.id;
|
|
1715
|
+
this.channelId = data.channelId;
|
|
1716
|
+
this.guildId = data.guildId ?? null;
|
|
1717
|
+
this.content = data.content ?? null;
|
|
1718
|
+
this.authorId = data.authorId ?? null;
|
|
1719
|
+
this.author = data.author ?? null;
|
|
1720
|
+
this.createdAt = data.createdAt ?? (import_util7.SnowflakeUtil.isValid(data.id) ? import_util7.SnowflakeUtil.dateFromSnowflake(data.id) : null);
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
1724
|
+
* Same contract as {@link Message.channel}.
|
|
1725
|
+
*/
|
|
1726
|
+
get channel() {
|
|
1727
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1728
|
+
return channel?.isTextBased() ? channel : null;
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1732
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1733
|
+
* @example
|
|
1734
|
+
* const channel = await message.resolveChannel();
|
|
1735
|
+
* await channel.delete();
|
|
1736
|
+
*/
|
|
1737
|
+
async resolveChannel() {
|
|
1738
|
+
return this.client.channels.resolve(this.channelId);
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Fetch the full message from the API.
|
|
1742
|
+
* @example
|
|
1743
|
+
* const message = await partial.fetch();
|
|
1744
|
+
* await message.reply('Pong!');
|
|
1745
|
+
*/
|
|
1746
|
+
async fetch() {
|
|
1747
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1748
|
+
}
|
|
1749
|
+
};
|
|
1750
|
+
|
|
1751
|
+
// src/Domain/User.ts
|
|
1752
|
+
var import_types16 = require("@fluxerjs/types");
|
|
1753
|
+
var import_util14 = require("@fluxerjs/util");
|
|
1754
|
+
|
|
1755
|
+
// src/Domain/Channel/Base.ts
|
|
1756
|
+
var import_types8 = require("@fluxerjs/types");
|
|
1757
|
+
var import_util8 = require("@fluxerjs/util");
|
|
1758
|
+
|
|
1255
1759
|
// src/ClientCore/MessageManager.ts
|
|
1760
|
+
var import_collection4 = require("@fluxerjs/collection");
|
|
1761
|
+
var import_types6 = require("@fluxerjs/types");
|
|
1256
1762
|
var BULK = {
|
|
1257
1763
|
requests: { min: 1, max: 25 },
|
|
1258
1764
|
limit: { min: 1, max: 25 },
|
|
@@ -1286,19 +1792,40 @@ var MessageManager = class {
|
|
|
1286
1792
|
this.client = client;
|
|
1287
1793
|
this.channelId = channelId;
|
|
1288
1794
|
}
|
|
1795
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1796
|
+
_structures = new import_collection4.Collection();
|
|
1289
1797
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1290
1798
|
get(messageId) {
|
|
1291
1799
|
const data = this.client._getMessageCache(this.channelId)?.get(messageId);
|
|
1292
|
-
|
|
1800
|
+
if (!data) {
|
|
1801
|
+
this._structures.delete(messageId);
|
|
1802
|
+
return void 0;
|
|
1803
|
+
}
|
|
1804
|
+
const existing = this._structures.get(messageId);
|
|
1805
|
+
if (existing) return existing;
|
|
1806
|
+
const message = new Message(this.client, data);
|
|
1807
|
+
this._structures.set(messageId, message);
|
|
1808
|
+
return message;
|
|
1809
|
+
}
|
|
1810
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1811
|
+
async resolve(messageId) {
|
|
1812
|
+
return this.get(messageId) ?? this.fetch(messageId);
|
|
1293
1813
|
}
|
|
1294
1814
|
async fetch(idOrOptions) {
|
|
1295
1815
|
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1296
1816
|
}
|
|
1297
|
-
/** Cache API data and return a {@link Message}
|
|
1817
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1298
1818
|
wrap(data) {
|
|
1299
1819
|
this.client._addMessageToCache(this.channelId, data);
|
|
1300
1820
|
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
1301
|
-
|
|
1821
|
+
const existing = this._structures.get(data.id);
|
|
1822
|
+
if (existing) {
|
|
1823
|
+
existing._patch(cached);
|
|
1824
|
+
return existing;
|
|
1825
|
+
}
|
|
1826
|
+
const message = new Message(this.client, cached);
|
|
1827
|
+
this._structures.set(data.id, message);
|
|
1828
|
+
return message;
|
|
1302
1829
|
}
|
|
1303
1830
|
/** Fetch a single message from the API. */
|
|
1304
1831
|
async fetchOne(messageId) {
|
|
@@ -1331,14 +1858,135 @@ var MessageManager = class {
|
|
|
1331
1858
|
}
|
|
1332
1859
|
const base = import_types6.Routes.channelMessages(this.channelId);
|
|
1333
1860
|
const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
|
|
1334
|
-
const collection = new
|
|
1861
|
+
const collection = new import_collection4.Collection();
|
|
1335
1862
|
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
1336
1863
|
return collection;
|
|
1337
1864
|
}
|
|
1338
1865
|
};
|
|
1339
1866
|
|
|
1867
|
+
// src/Helpers/MessageCollector.ts
|
|
1868
|
+
var import_node_events2 = require("events");
|
|
1869
|
+
var import_collection5 = require("@fluxerjs/collection");
|
|
1870
|
+
function requireCollectorBounds(options) {
|
|
1871
|
+
const time = options.time ?? 0;
|
|
1872
|
+
const max = options.max ?? 0;
|
|
1873
|
+
if (time <= 0 && max <= 0) {
|
|
1874
|
+
throw new import_util2.FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
1875
|
+
code: import_util.ErrorCodes.CollectorOptionsRequired
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
var MessageCollector = class _MessageCollector extends import_node_events2.EventEmitter {
|
|
1880
|
+
client;
|
|
1881
|
+
channelId;
|
|
1882
|
+
options;
|
|
1883
|
+
collected = new import_collection5.Collection();
|
|
1884
|
+
_timeout = null;
|
|
1885
|
+
_ended = false;
|
|
1886
|
+
_listener;
|
|
1887
|
+
constructor(client, channelId, options = {}) {
|
|
1888
|
+
super();
|
|
1889
|
+
requireCollectorBounds(options);
|
|
1890
|
+
this.client = client;
|
|
1891
|
+
this.channelId = channelId;
|
|
1892
|
+
this.options = {
|
|
1893
|
+
filter: options.filter ?? (() => true),
|
|
1894
|
+
time: options.time ?? 0,
|
|
1895
|
+
max: options.max ?? 0
|
|
1896
|
+
};
|
|
1897
|
+
this._listener = (message) => {
|
|
1898
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
1899
|
+
if (!this.options.filter(message)) return;
|
|
1900
|
+
this.collected.set(message.id, message);
|
|
1901
|
+
this.emit("collect", message);
|
|
1902
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
1903
|
+
this.stop("limit");
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
1907
|
+
if (this.options.time > 0) {
|
|
1908
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
stop(reason = "user") {
|
|
1912
|
+
if (this._ended) return;
|
|
1913
|
+
this._ended = true;
|
|
1914
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
1915
|
+
if (this._timeout) {
|
|
1916
|
+
clearTimeout(this._timeout);
|
|
1917
|
+
this._timeout = null;
|
|
1918
|
+
}
|
|
1919
|
+
this.emit("end", this.collected, reason);
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
1923
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
1924
|
+
* the end reason is not listed in `errors`).
|
|
1925
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
1926
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
1927
|
+
*/
|
|
1928
|
+
static awaitMessages(client, channelId, options) {
|
|
1929
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
1930
|
+
return new Promise((resolve, reject) => {
|
|
1931
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
1932
|
+
collector.on("end", (collected, reason) => {
|
|
1933
|
+
if (!errors.includes(reason)) {
|
|
1934
|
+
resolve(collected);
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
if (reason === "time") {
|
|
1938
|
+
reject(
|
|
1939
|
+
new import_util2.FluxerError("Message collector timed out", {
|
|
1940
|
+
code: import_util.ErrorCodes.CollectorIdle
|
|
1941
|
+
})
|
|
1942
|
+
);
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
if (reason === "limit") {
|
|
1946
|
+
reject(
|
|
1947
|
+
new import_util2.FluxerError("Message collector reached max", {
|
|
1948
|
+
code: import_util.ErrorCodes.CollectorMax
|
|
1949
|
+
})
|
|
1950
|
+
);
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1953
|
+
reject(collected);
|
|
1954
|
+
});
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
on(event, listener) {
|
|
1958
|
+
return super.on(event, listener);
|
|
1959
|
+
}
|
|
1960
|
+
emit(event, ...args) {
|
|
1961
|
+
return super.emit(event, ...args);
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
|
|
1340
1965
|
// src/Domain/Channel/Attachments.ts
|
|
1341
1966
|
var import_types7 = require("@fluxerjs/types");
|
|
1967
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
1968
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
1969
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
1970
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
1971
|
+
if (!rules?.length) return null;
|
|
1972
|
+
const snapshot = {};
|
|
1973
|
+
for (const rule of rules) {
|
|
1974
|
+
Object.assign(snapshot, rule.overrides);
|
|
1975
|
+
}
|
|
1976
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
1977
|
+
}
|
|
1978
|
+
function assertBotAttachmentLimits(client, files) {
|
|
1979
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
1980
|
+
for (const file of files) {
|
|
1981
|
+
const size = file.data.byteLength;
|
|
1982
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
1983
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
1984
|
+
throw new import_util2.FluxerError(
|
|
1985
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
1986
|
+
{ code: import_util.ErrorCodes.AttachmentTooLarge }
|
|
1987
|
+
);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1342
1990
|
function asBytes(data) {
|
|
1343
1991
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
1344
1992
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -1358,6 +2006,7 @@ async function putBlob(url, body, contentType) {
|
|
|
1358
2006
|
}
|
|
1359
2007
|
}
|
|
1360
2008
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
2009
|
+
assertBotAttachmentLimits(client, files);
|
|
1361
2010
|
const plan = await client.rest.post(
|
|
1362
2011
|
import_types7.Routes.channelAttachments(channelId),
|
|
1363
2012
|
{
|
|
@@ -1415,6 +2064,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1415
2064
|
|
|
1416
2065
|
// src/Domain/Channel/Base.ts
|
|
1417
2066
|
var Channel = class extends Base {
|
|
2067
|
+
#messages;
|
|
1418
2068
|
/** The {@link Client} that instantiated this channel. */
|
|
1419
2069
|
client;
|
|
1420
2070
|
/** Snowflake ID of this channel. */
|
|
@@ -1438,11 +2088,11 @@ var Channel = class extends Base {
|
|
|
1438
2088
|
}
|
|
1439
2089
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1440
2090
|
get createdTimestamp() {
|
|
1441
|
-
return
|
|
2091
|
+
return import_util8.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1442
2092
|
}
|
|
1443
2093
|
/** Date when this channel was created, derived from its snowflake ID. */
|
|
1444
2094
|
get createdAt() {
|
|
1445
|
-
return
|
|
2095
|
+
return import_util8.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1446
2096
|
}
|
|
1447
2097
|
/**
|
|
1448
2098
|
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
@@ -1456,19 +2106,36 @@ var Channel = class extends Base {
|
|
|
1456
2106
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1457
2107
|
}
|
|
1458
2108
|
}
|
|
1459
|
-
/**
|
|
2109
|
+
/** @internal Factory wired after subclasses load. */
|
|
1460
2110
|
static from(_c, _d) {
|
|
1461
2111
|
throw new Error("Channel.from not initialized");
|
|
1462
2112
|
}
|
|
2113
|
+
/** @internal Factory wired after subclasses load. */
|
|
1463
2114
|
static fromOrCreate(_c, _d) {
|
|
1464
2115
|
throw new Error("Channel.fromOrCreate not initialized");
|
|
1465
2116
|
}
|
|
2117
|
+
/** @internal Factory wired after subclasses load. */
|
|
1466
2118
|
static createDM(_c, _d) {
|
|
1467
2119
|
throw new Error("Channel.createDM not initialized");
|
|
1468
2120
|
}
|
|
1469
|
-
/**
|
|
2121
|
+
/**
|
|
2122
|
+
* Whether this channel type can carry messages (text, voice, DM, group DM, notes).
|
|
2123
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
2124
|
+
*/
|
|
1470
2125
|
isTextBased() {
|
|
1471
|
-
return
|
|
2126
|
+
return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
|
|
2127
|
+
}
|
|
2128
|
+
/** Check if this is a guild channel (text, voice, category, or link). */
|
|
2129
|
+
isGuild() {
|
|
2130
|
+
return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.GuildCategory || this.type === import_types8.ChannelType.GuildLink;
|
|
2131
|
+
}
|
|
2132
|
+
/** Check if this is a guild text channel. */
|
|
2133
|
+
isText() {
|
|
2134
|
+
return this.type === import_types8.ChannelType.GuildText;
|
|
2135
|
+
}
|
|
2136
|
+
/** Check if this is a category channel. */
|
|
2137
|
+
isCategory() {
|
|
2138
|
+
return this.type === import_types8.ChannelType.GuildCategory;
|
|
1472
2139
|
}
|
|
1473
2140
|
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1474
2141
|
isDM() {
|
|
@@ -1480,11 +2147,11 @@ var Channel = class extends Base {
|
|
|
1480
2147
|
}
|
|
1481
2148
|
/** Check if this is a voice channel. */
|
|
1482
2149
|
isVoice() {
|
|
1483
|
-
return
|
|
2150
|
+
return this.type === import_types8.ChannelType.GuildVoice;
|
|
1484
2151
|
}
|
|
1485
2152
|
/** Check if this is a link channel. */
|
|
1486
2153
|
isLink() {
|
|
1487
|
-
return
|
|
2154
|
+
return this.type === import_types8.ChannelType.GuildLink;
|
|
1488
2155
|
}
|
|
1489
2156
|
/**
|
|
1490
2157
|
* Delete recent messages or an explicit ID list.
|
|
@@ -1523,7 +2190,7 @@ var Channel = class extends Base {
|
|
|
1523
2190
|
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1524
2191
|
return ids;
|
|
1525
2192
|
}
|
|
1526
|
-
/** Delete all messages sent by the bot in this channel
|
|
2193
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1527
2194
|
async bulkDeleteMyMessages(options) {
|
|
1528
2195
|
const body = options ? toSudoBody(options) : void 0;
|
|
1529
2196
|
await this.client.rest.post(import_types8.Routes.channelBulkDeleteMine(this.id), {
|
|
@@ -1531,11 +2198,17 @@ var Channel = class extends Base {
|
|
|
1531
2198
|
auth: true
|
|
1532
2199
|
});
|
|
1533
2200
|
}
|
|
1534
|
-
/**
|
|
2201
|
+
/**
|
|
2202
|
+
* Mark all pinned messages as read in this channel.
|
|
2203
|
+
* Session-token helper; bots usually skip this.
|
|
2204
|
+
*/
|
|
1535
2205
|
async acknowledgePins() {
|
|
1536
2206
|
await this.client.rest.post(import_types8.Routes.channelPinsAck(this.id), { auth: true });
|
|
1537
2207
|
}
|
|
1538
|
-
/**
|
|
2208
|
+
/**
|
|
2209
|
+
* Clear the read state for this channel.
|
|
2210
|
+
* Session-token helper; bots usually skip this.
|
|
2211
|
+
*/
|
|
1539
2212
|
async clearReadState() {
|
|
1540
2213
|
await this.client.rest.delete(import_types8.Routes.channelMessagesAck(this.id), { auth: true });
|
|
1541
2214
|
}
|
|
@@ -1571,7 +2244,11 @@ var Channel = class extends Base {
|
|
|
1571
2244
|
async sendTyping() {
|
|
1572
2245
|
await this.client.rest.post(import_types8.Routes.channelTyping(this.id), { auth: true });
|
|
1573
2246
|
}
|
|
1574
|
-
/**
|
|
2247
|
+
/**
|
|
2248
|
+
* Fetch available RTC regions for voice channels.
|
|
2249
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
2250
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
2251
|
+
*/
|
|
1575
2252
|
async fetchRtcRegions() {
|
|
1576
2253
|
const data = await this.client.rest.get(import_types8.Routes.channelRtcRegions(this.id), {
|
|
1577
2254
|
auth: true
|
|
@@ -1590,71 +2267,66 @@ var Channel = class extends Base {
|
|
|
1590
2267
|
nextSendAllowedAt: data.next_send_allowed_at
|
|
1591
2268
|
};
|
|
1592
2269
|
}
|
|
1593
|
-
/**
|
|
2270
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1594
2271
|
canSendMessage() {
|
|
1595
|
-
return this.
|
|
2272
|
+
return this.isTextBased();
|
|
1596
2273
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
// src/Domain/Channel/TextCapable.ts
|
|
1603
|
-
var import_types9 = require("@fluxerjs/types");
|
|
1604
|
-
|
|
1605
|
-
// src/Helpers/MessageCollector.ts
|
|
1606
|
-
var import_node_events2 = require("events");
|
|
1607
|
-
var import_collection4 = require("@fluxerjs/collection");
|
|
1608
|
-
var MessageCollector = class extends import_node_events2.EventEmitter {
|
|
1609
|
-
client;
|
|
1610
|
-
channelId;
|
|
1611
|
-
options;
|
|
1612
|
-
collected = new import_collection4.Collection();
|
|
1613
|
-
_timeout = null;
|
|
1614
|
-
_ended = false;
|
|
1615
|
-
_listener;
|
|
1616
|
-
constructor(client, channelId, options = {}) {
|
|
1617
|
-
super();
|
|
1618
|
-
this.client = client;
|
|
1619
|
-
this.channelId = channelId;
|
|
1620
|
-
this.options = {
|
|
1621
|
-
filter: options.filter ?? (() => true),
|
|
1622
|
-
time: options.time ?? 0,
|
|
1623
|
-
max: options.max ?? 0
|
|
1624
|
-
};
|
|
1625
|
-
this._listener = (message) => {
|
|
1626
|
-
if (this._ended || message.channelId !== this.channelId) return;
|
|
1627
|
-
if (!this.options.filter(message)) return;
|
|
1628
|
-
this.collected.set(message.id, message);
|
|
1629
|
-
this.emit("collect", message);
|
|
1630
|
-
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
1631
|
-
this.stop("limit");
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
this.client.on(Events.MessageCreate, this._listener);
|
|
1635
|
-
if (this.options.time > 0) {
|
|
1636
|
-
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
stop(reason = "user") {
|
|
1640
|
-
if (this._ended) return;
|
|
1641
|
-
this._ended = true;
|
|
1642
|
-
this.client.off(Events.MessageCreate, this._listener);
|
|
1643
|
-
if (this._timeout) {
|
|
1644
|
-
clearTimeout(this._timeout);
|
|
1645
|
-
this._timeout = null;
|
|
2274
|
+
/** Per-channel message cache + fetch. */
|
|
2275
|
+
get messages() {
|
|
2276
|
+
if (!this.#messages) {
|
|
2277
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1646
2278
|
}
|
|
1647
|
-
|
|
2279
|
+
return this.#messages;
|
|
1648
2280
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
2281
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
2282
|
+
createMessageCollector(options) {
|
|
2283
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1651
2284
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
2285
|
+
/**
|
|
2286
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
2287
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
2288
|
+
* @example
|
|
2289
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
2290
|
+
*/
|
|
2291
|
+
awaitMessages(options) {
|
|
2292
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* Delete this channel (or close it if it is a DM).
|
|
2296
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
2297
|
+
* @example
|
|
2298
|
+
* const channel = await client.channels.fetch(channelId);
|
|
2299
|
+
* await channel.delete();
|
|
2300
|
+
*/
|
|
2301
|
+
async delete(options) {
|
|
2302
|
+
const params = new URLSearchParams();
|
|
2303
|
+
if (options?.silent) params.set("silent", "true");
|
|
2304
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2305
|
+
const qs2 = params.toString();
|
|
2306
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
2307
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2308
|
+
await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2309
|
+
body,
|
|
2310
|
+
auth: true,
|
|
2311
|
+
...auditReasonHeaders(_reason)
|
|
2312
|
+
});
|
|
2313
|
+
this.client.channels.delete(this.id);
|
|
2314
|
+
this.client._clearMessageCache(this.id);
|
|
2315
|
+
if (this.isGuild() && this.guildId) {
|
|
2316
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
/** Channel mention (`<#id>`). */
|
|
2320
|
+
toString() {
|
|
2321
|
+
return `<#${this.id}>`;
|
|
1654
2322
|
}
|
|
1655
2323
|
};
|
|
1656
2324
|
|
|
2325
|
+
// src/Domain/Channel/Dm.ts
|
|
2326
|
+
var import_types10 = require("@fluxerjs/types");
|
|
2327
|
+
|
|
1657
2328
|
// src/Domain/Channel/TextCapable.ts
|
|
2329
|
+
var import_types9 = require("@fluxerjs/types");
|
|
1658
2330
|
async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
1659
2331
|
const params = new URLSearchParams();
|
|
1660
2332
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
@@ -1672,27 +2344,19 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
|
1672
2344
|
}
|
|
1673
2345
|
function TextCapable(Base2) {
|
|
1674
2346
|
class TextCapableChannel extends Base2 {
|
|
1675
|
-
|
|
2347
|
+
/**
|
|
2348
|
+
* Send a message in this channel.
|
|
2349
|
+
* @example
|
|
2350
|
+
* await channel.send('hi');
|
|
2351
|
+
*/
|
|
1676
2352
|
async send(options) {
|
|
1677
|
-
|
|
1678
|
-
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
1679
|
-
});
|
|
1680
|
-
const data = await this.client.rest.post(import_types9.Routes.channelMessages(this.id), payload);
|
|
1681
|
-
this.client._addMessageToCache(this.id, data);
|
|
1682
|
-
return new Message(this.client, data);
|
|
1683
|
-
}
|
|
1684
|
-
get messages() {
|
|
1685
|
-
if (!this.#messages) {
|
|
1686
|
-
this.#messages = new MessageManager(this.client, this.id);
|
|
1687
|
-
}
|
|
1688
|
-
return this.#messages;
|
|
1689
|
-
}
|
|
1690
|
-
createMessageCollector(options) {
|
|
1691
|
-
return new MessageCollector(this.client, this.id, options);
|
|
2353
|
+
return this.client.channels.send(this.id, options);
|
|
1692
2354
|
}
|
|
2355
|
+
/** Fetch pinned messages in this channel. */
|
|
1693
2356
|
async fetchPinnedMessages(options) {
|
|
1694
2357
|
return (await this.fetchPinnedMessagesPage(options)).messages;
|
|
1695
2358
|
}
|
|
2359
|
+
/** Fetch a page of pinned messages plus pagination metadata. */
|
|
1696
2360
|
async fetchPinnedMessagesPage(options) {
|
|
1697
2361
|
return fetchPinnedMessagesPageFor(this.client, this.id, options);
|
|
1698
2362
|
}
|
|
@@ -1718,7 +2382,38 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1718
2382
|
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
1719
2383
|
this.nicks = full.nicks ?? {};
|
|
1720
2384
|
}
|
|
1721
|
-
/**
|
|
2385
|
+
/**
|
|
2386
|
+
* Apply DM/group-DM fields in place.
|
|
2387
|
+
* @internal
|
|
2388
|
+
*/
|
|
2389
|
+
_patch(data) {
|
|
2390
|
+
super._patch(data);
|
|
2391
|
+
const full = data;
|
|
2392
|
+
if ("last_message_id" in full && full.last_message_id !== void 0) {
|
|
2393
|
+
this.lastMessageId = full.last_message_id ?? null;
|
|
2394
|
+
}
|
|
2395
|
+
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2396
|
+
if ("recipients" in full && full.recipients !== void 0) {
|
|
2397
|
+
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2398
|
+
}
|
|
2399
|
+
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Edit this group DM (name, icon, nicks).
|
|
2403
|
+
* Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
|
|
2404
|
+
*/
|
|
2405
|
+
async edit(options) {
|
|
2406
|
+
const data = await this.client.rest.patch(import_types10.Routes.channel(this.id), {
|
|
2407
|
+
body: toGroupDmEditBody(options),
|
|
2408
|
+
auth: true
|
|
2409
|
+
});
|
|
2410
|
+
this._patch(data);
|
|
2411
|
+
return this;
|
|
2412
|
+
}
|
|
2413
|
+
/**
|
|
2414
|
+
* Purge all messages from personal notes. Only works on personal notes channels.
|
|
2415
|
+
* Notes-only; bots usually skip this.
|
|
2416
|
+
*/
|
|
1722
2417
|
async purgeMessages() {
|
|
1723
2418
|
if (this.type !== import_types10.ChannelType.DMPersonalNotes) {
|
|
1724
2419
|
throw new import_util2.FluxerError("purgeMessages is only available on personal notes channels", {
|
|
@@ -1731,15 +2426,24 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1731
2426
|
);
|
|
1732
2427
|
return data.deleted_count;
|
|
1733
2428
|
}
|
|
1734
|
-
/**
|
|
2429
|
+
/**
|
|
2430
|
+
* Pin this DM channel to the top of the DM list.
|
|
2431
|
+
* Session-token helper; bots usually skip this.
|
|
2432
|
+
*/
|
|
1735
2433
|
async pinInList() {
|
|
1736
2434
|
await this.client.rest.put(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
|
|
1737
2435
|
}
|
|
1738
|
-
/**
|
|
2436
|
+
/**
|
|
2437
|
+
* Unpin this DM channel from the DM list.
|
|
2438
|
+
* Session-token helper; bots usually skip this.
|
|
2439
|
+
*/
|
|
1739
2440
|
async unpinFromList() {
|
|
1740
2441
|
await this.client.rest.delete(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
|
|
1741
2442
|
}
|
|
1742
|
-
/**
|
|
2443
|
+
/**
|
|
2444
|
+
* Add a user to this group DM.
|
|
2445
|
+
* Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
|
|
2446
|
+
*/
|
|
1743
2447
|
async addRecipient(userId) {
|
|
1744
2448
|
await this.client.rest.put(import_types10.Routes.channelRecipient(this.id, userId), { auth: true });
|
|
1745
2449
|
const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
|
|
@@ -1755,16 +2459,16 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1755
2459
|
};
|
|
1756
2460
|
|
|
1757
2461
|
// src/Domain/Channel/Guild.ts
|
|
1758
|
-
var
|
|
1759
|
-
var
|
|
2462
|
+
var import_types14 = require("@fluxerjs/types");
|
|
2463
|
+
var import_util13 = require("@fluxerjs/util");
|
|
1760
2464
|
|
|
1761
2465
|
// src/Domain/Invite.ts
|
|
1762
2466
|
var import_types11 = require("@fluxerjs/types");
|
|
1763
2467
|
|
|
1764
2468
|
// src/Helpers/Instance.ts
|
|
1765
|
-
var
|
|
2469
|
+
var import_util9 = require("@fluxerjs/util");
|
|
1766
2470
|
var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
|
|
1767
|
-
api: "https://
|
|
2471
|
+
api: "https://web.fluxer.app/api",
|
|
1768
2472
|
api_client: "https://web.fluxer.app/api",
|
|
1769
2473
|
api_public: "https://api.fluxer.app",
|
|
1770
2474
|
gateway: "wss://gateway.fluxer.app",
|
|
@@ -1798,6 +2502,10 @@ function requireString(obj, key, path) {
|
|
|
1798
2502
|
}
|
|
1799
2503
|
return value;
|
|
1800
2504
|
}
|
|
2505
|
+
var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
|
|
2506
|
+
function instanceDiscoveryUrl(origin) {
|
|
2507
|
+
return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
|
|
2508
|
+
}
|
|
1801
2509
|
function normalizeApiOrigin(api) {
|
|
1802
2510
|
const trimmed = api.trim().replace(/\/+$/, "");
|
|
1803
2511
|
return trimmed.replace(/\/v\d+$/i, "");
|
|
@@ -1806,7 +2514,7 @@ function normalizeInviteBase(invite) {
|
|
|
1806
2514
|
return invite.trim().replace(/\/+$/, "");
|
|
1807
2515
|
}
|
|
1808
2516
|
function parseInstanceDiscovery(raw) {
|
|
1809
|
-
if (!(0,
|
|
2517
|
+
if (!(0, import_util9.isRecord)(raw)) {
|
|
1810
2518
|
throw new import_util2.FluxerError("Invalid instance discovery: expected an object", {
|
|
1811
2519
|
code: import_util.ErrorCodes.InvalidInstanceDiscovery
|
|
1812
2520
|
});
|
|
@@ -1816,7 +2524,7 @@ function parseInstanceDiscovery(raw) {
|
|
|
1816
2524
|
code: import_util.ErrorCodes.InvalidInstanceDiscovery
|
|
1817
2525
|
});
|
|
1818
2526
|
}
|
|
1819
|
-
if (!(0,
|
|
2527
|
+
if (!(0, import_util9.isRecord)(raw.endpoints)) {
|
|
1820
2528
|
throw new import_util2.FluxerError("Invalid instance discovery: endpoints must be an object", {
|
|
1821
2529
|
code: import_util.ErrorCodes.InvalidInstanceDiscovery
|
|
1822
2530
|
});
|
|
@@ -1826,6 +2534,8 @@ function parseInstanceDiscovery(raw) {
|
|
|
1826
2534
|
endpoints[key] = requireString(raw.endpoints, key, "endpoints");
|
|
1827
2535
|
}
|
|
1828
2536
|
endpoints.api = normalizeApiOrigin(endpoints.api);
|
|
2537
|
+
endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
|
|
2538
|
+
endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
|
|
1829
2539
|
endpoints.invite = normalizeInviteBase(endpoints.invite);
|
|
1830
2540
|
endpoints.media = endpoints.media.replace(/\/+$/, "");
|
|
1831
2541
|
endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
|
|
@@ -1886,7 +2596,7 @@ function resolveInstanceEndpoints(input) {
|
|
|
1886
2596
|
discovery: null
|
|
1887
2597
|
});
|
|
1888
2598
|
}
|
|
1889
|
-
const isFull = "endpoints" in input && (0,
|
|
2599
|
+
const isFull = "endpoints" in input && (0, import_util9.isRecord)(input.endpoints) && typeof input.api_code_version === "number";
|
|
1890
2600
|
if (isFull) {
|
|
1891
2601
|
const discovery = parseInstanceDiscovery(input);
|
|
1892
2602
|
return Object.freeze({
|
|
@@ -1903,6 +2613,11 @@ function resolveInstanceEndpoints(input) {
|
|
|
1903
2613
|
}
|
|
1904
2614
|
}
|
|
1905
2615
|
merged.api = normalizeApiOrigin(merged.api);
|
|
2616
|
+
merged.api_client = normalizeApiOrigin(merged.api_client);
|
|
2617
|
+
merged.api_public = normalizeApiOrigin(merged.api_public);
|
|
2618
|
+
if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
|
|
2619
|
+
merged.api_public = merged.api;
|
|
2620
|
+
}
|
|
1906
2621
|
merged.invite = normalizeInviteBase(merged.invite);
|
|
1907
2622
|
merged.media = merged.media.replace(/\/+$/, "");
|
|
1908
2623
|
merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
|
|
@@ -1911,13 +2626,13 @@ function resolveInstanceEndpoints(input) {
|
|
|
1911
2626
|
discovery: null
|
|
1912
2627
|
});
|
|
1913
2628
|
}
|
|
1914
|
-
function resolveRestApi(
|
|
1915
|
-
const fromInstance = normalizeApiOrigin(
|
|
2629
|
+
function resolveRestApi(instanceApiPublic, restApi) {
|
|
2630
|
+
const fromInstance = normalizeApiOrigin(instanceApiPublic);
|
|
1916
2631
|
if (restApi === void 0) return fromInstance;
|
|
1917
2632
|
const fromRest = normalizeApiOrigin(restApi);
|
|
1918
2633
|
if (fromRest !== fromInstance) {
|
|
1919
2634
|
throw new import_util2.FluxerError(
|
|
1920
|
-
`Conflicting API hosts: instance.
|
|
2635
|
+
`Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
|
|
1921
2636
|
{ code: import_util.ErrorCodes.ConflictingInstanceConfig }
|
|
1922
2637
|
);
|
|
1923
2638
|
}
|
|
@@ -1953,13 +2668,36 @@ function parseInviteCode(codeOrUrl) {
|
|
|
1953
2668
|
}
|
|
1954
2669
|
return code;
|
|
1955
2670
|
}
|
|
2671
|
+
function parseOptionalDate(value) {
|
|
2672
|
+
if (value == null || value === "") return null;
|
|
2673
|
+
const date = new Date(value);
|
|
2674
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
2675
|
+
}
|
|
2676
|
+
function toInviteGuild(data) {
|
|
2677
|
+
return {
|
|
2678
|
+
id: data.id,
|
|
2679
|
+
name: data.name,
|
|
2680
|
+
icon: data.icon ?? null,
|
|
2681
|
+
banner: data.banner ?? null,
|
|
2682
|
+
splash: data.splash ?? null,
|
|
2683
|
+
features: data.features ?? []
|
|
2684
|
+
};
|
|
2685
|
+
}
|
|
2686
|
+
function toInviteChannel(data) {
|
|
2687
|
+
return {
|
|
2688
|
+
id: data.id,
|
|
2689
|
+
name: data.name ?? null,
|
|
2690
|
+
type: data.type,
|
|
2691
|
+
icon: data.icon ?? null,
|
|
2692
|
+
parentId: data.parent_id ?? null
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
1956
2695
|
var Invite = class _Invite extends Base {
|
|
1957
2696
|
client;
|
|
1958
2697
|
code;
|
|
1959
2698
|
type;
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
pack;
|
|
2699
|
+
guildSnapshot;
|
|
2700
|
+
channelSnapshot;
|
|
1963
2701
|
inviter;
|
|
1964
2702
|
memberCount;
|
|
1965
2703
|
presenceCount;
|
|
@@ -1974,15 +2712,14 @@ var Invite = class _Invite extends Base {
|
|
|
1974
2712
|
this.client = client;
|
|
1975
2713
|
this.code = data.code;
|
|
1976
2714
|
this.type = data.type;
|
|
1977
|
-
this.
|
|
1978
|
-
this.
|
|
1979
|
-
this.pack = (0, import_types11.isPackInvite)(data) ? data.pack : null;
|
|
2715
|
+
this.guildSnapshot = (0, import_types11.isGuildInvite)(data) ? toInviteGuild(data.guild) : null;
|
|
2716
|
+
this.channelSnapshot = (0, import_types11.isGuildInvite)(data) || (0, import_types11.isGroupDmInvite)(data) ? toInviteChannel(data.channel) : null;
|
|
1980
2717
|
this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
|
|
1981
|
-
this.memberCount =
|
|
2718
|
+
this.memberCount = data.member_count ?? null;
|
|
1982
2719
|
this.presenceCount = (0, import_types11.isGuildInvite)(data) ? data.presence_count ?? null : null;
|
|
1983
|
-
this.expiresAt = data.expires_at
|
|
2720
|
+
this.expiresAt = parseOptionalDate(data.expires_at);
|
|
1984
2721
|
this.temporary = data.temporary ?? null;
|
|
1985
|
-
this.createdAt = data.created_at
|
|
2722
|
+
this.createdAt = parseOptionalDate(data.created_at);
|
|
1986
2723
|
this.uses = data.uses ?? null;
|
|
1987
2724
|
this.maxUses = data.max_uses ?? null;
|
|
1988
2725
|
this.maxAge = data.max_age ?? null;
|
|
@@ -1993,16 +2730,25 @@ var Invite = class _Invite extends Base {
|
|
|
1993
2730
|
isGroupDM() {
|
|
1994
2731
|
return this.type === import_types11.InviteType.GroupDM;
|
|
1995
2732
|
}
|
|
1996
|
-
isPack() {
|
|
1997
|
-
return this.type === import_types11.InviteType.EmojiPack || this.type === import_types11.InviteType.StickerPack;
|
|
1998
|
-
}
|
|
1999
2733
|
/** Full invite URL (uses this client's instance invite base). */
|
|
2000
2734
|
get url() {
|
|
2001
2735
|
return inviteUrl(this.client.instance.endpoints.invite, this.code);
|
|
2002
2736
|
}
|
|
2003
|
-
/**
|
|
2004
|
-
|
|
2005
|
-
|
|
2737
|
+
/**
|
|
2738
|
+
* Resolve the cached/fetched {@link Guild} for this invite, or null.
|
|
2739
|
+
* `guildSnapshot` is metadata only.
|
|
2740
|
+
*/
|
|
2741
|
+
async resolveGuild() {
|
|
2742
|
+
if (!this.guildSnapshot?.id) return null;
|
|
2743
|
+
return this.client.guilds.resolve(this.guildSnapshot.id);
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* Resolve the cached/fetched {@link Channel} for this invite, or null.
|
|
2747
|
+
* `channelSnapshot` is metadata only.
|
|
2748
|
+
*/
|
|
2749
|
+
async resolveChannel() {
|
|
2750
|
+
if (!this.channelSnapshot?.id) return null;
|
|
2751
|
+
return this.client.channels.resolve(this.channelSnapshot.id);
|
|
2006
2752
|
}
|
|
2007
2753
|
/** Fetch invite metadata by code or URL (does not join). */
|
|
2008
2754
|
static async fetch(client, codeOrUrl) {
|
|
@@ -2018,7 +2764,7 @@ var Invite = class _Invite extends Base {
|
|
|
2018
2764
|
// src/Domain/Webhook.ts
|
|
2019
2765
|
var import_builders4 = require("@fluxerjs/builders");
|
|
2020
2766
|
var import_types12 = require("@fluxerjs/types");
|
|
2021
|
-
var
|
|
2767
|
+
var import_util10 = require("@fluxerjs/util");
|
|
2022
2768
|
var Webhook = class _Webhook extends Base {
|
|
2023
2769
|
/** Parent client instance. */
|
|
2024
2770
|
client;
|
|
@@ -2055,11 +2801,11 @@ var Webhook = class _Webhook extends Base {
|
|
|
2055
2801
|
}
|
|
2056
2802
|
/** Unix timestamp (ms) when this webhook was created, derived from its snowflake ID. */
|
|
2057
2803
|
get createdTimestamp() {
|
|
2058
|
-
return
|
|
2804
|
+
return import_util10.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
2059
2805
|
}
|
|
2060
2806
|
/** Date when this webhook was created, derived from its snowflake ID. */
|
|
2061
2807
|
get createdAt() {
|
|
2062
|
-
return
|
|
2808
|
+
return import_util10.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
2063
2809
|
}
|
|
2064
2810
|
/** Delete this webhook (token auth when available, otherwise bot auth). */
|
|
2065
2811
|
async delete() {
|
|
@@ -2181,9 +2927,103 @@ var Webhook = class _Webhook extends Base {
|
|
|
2181
2927
|
}
|
|
2182
2928
|
};
|
|
2183
2929
|
|
|
2930
|
+
// src/Domain/Channel/PermissionOverwriteManager.ts
|
|
2931
|
+
var import_collection6 = require("@fluxerjs/collection");
|
|
2932
|
+
var import_types13 = require("@fluxerjs/types");
|
|
2933
|
+
var import_util12 = require("@fluxerjs/util");
|
|
2934
|
+
|
|
2935
|
+
// src/Domain/Channel/PermissionOverwrite.ts
|
|
2936
|
+
var import_util11 = require("@fluxerjs/util");
|
|
2937
|
+
var PermissionOverwrite = class {
|
|
2938
|
+
id;
|
|
2939
|
+
type;
|
|
2940
|
+
/** @internal Raw allow bitfield string. */
|
|
2941
|
+
_allow;
|
|
2942
|
+
/** @internal Raw deny bitfield string. */
|
|
2943
|
+
_deny;
|
|
2944
|
+
constructor(data) {
|
|
2945
|
+
this.id = data.id;
|
|
2946
|
+
this.type = data.type;
|
|
2947
|
+
this._allow = data.allow ?? "0";
|
|
2948
|
+
this._deny = data.deny ?? "0";
|
|
2949
|
+
}
|
|
2950
|
+
/** Allowed permissions for this overwrite. */
|
|
2951
|
+
get allow() {
|
|
2952
|
+
return new import_util11.PermissionsBitField(BigInt(this._allow || "0"));
|
|
2953
|
+
}
|
|
2954
|
+
/** Denied permissions for this overwrite. */
|
|
2955
|
+
get deny() {
|
|
2956
|
+
return new import_util11.PermissionsBitField(BigInt(this._deny || "0"));
|
|
2957
|
+
}
|
|
2958
|
+
/** Wire shape for permission computation / REST. */
|
|
2959
|
+
toJSON() {
|
|
2960
|
+
return {
|
|
2961
|
+
id: this.id,
|
|
2962
|
+
type: this.type,
|
|
2963
|
+
allow: this._allow,
|
|
2964
|
+
deny: this._deny
|
|
2965
|
+
};
|
|
2966
|
+
}
|
|
2967
|
+
};
|
|
2968
|
+
|
|
2969
|
+
// src/Domain/Channel/PermissionOverwriteManager.ts
|
|
2970
|
+
var PermissionOverwriteManager = class {
|
|
2971
|
+
constructor(channel, initial = []) {
|
|
2972
|
+
this.channel = channel;
|
|
2973
|
+
this._patch(initial);
|
|
2974
|
+
}
|
|
2975
|
+
_cache = new import_collection6.Collection();
|
|
2976
|
+
/** Cached overwrites keyed by role/member ID. */
|
|
2977
|
+
get cache() {
|
|
2978
|
+
return this._cache;
|
|
2979
|
+
}
|
|
2980
|
+
get size() {
|
|
2981
|
+
return this._cache.size;
|
|
2982
|
+
}
|
|
2983
|
+
[Symbol.iterator]() {
|
|
2984
|
+
return this._cache.values();
|
|
2985
|
+
}
|
|
2986
|
+
/** Wire-shaped overwrites for permission computation. */
|
|
2987
|
+
toJSON() {
|
|
2988
|
+
return [...this._cache.values()].map((o) => o.toJSON());
|
|
2989
|
+
}
|
|
2990
|
+
/** Edit or create a permission overwrite. */
|
|
2991
|
+
async edit(overwriteId, options) {
|
|
2992
|
+
const allow = options.allow !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.allow) : "0";
|
|
2993
|
+
const deny = options.deny !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.deny) : "0";
|
|
2994
|
+
await this.channel.client.rest.put(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
|
|
2995
|
+
body: { type: options.type, allow, deny },
|
|
2996
|
+
auth: true
|
|
2997
|
+
});
|
|
2998
|
+
this._cache.set(
|
|
2999
|
+
overwriteId,
|
|
3000
|
+
new PermissionOverwrite({
|
|
3001
|
+
id: overwriteId,
|
|
3002
|
+
type: options.type,
|
|
3003
|
+
allow,
|
|
3004
|
+
deny
|
|
3005
|
+
})
|
|
3006
|
+
);
|
|
3007
|
+
}
|
|
3008
|
+
/** Delete a permission overwrite. */
|
|
3009
|
+
async delete(overwriteId) {
|
|
3010
|
+
await this.channel.client.rest.delete(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
|
|
3011
|
+
auth: true
|
|
3012
|
+
});
|
|
3013
|
+
this._cache.delete(overwriteId);
|
|
3014
|
+
}
|
|
3015
|
+
/** @internal Sync from an API channel payload. */
|
|
3016
|
+
_patch(overwrites) {
|
|
3017
|
+
this._cache.clear();
|
|
3018
|
+
for (const entry of overwrites ?? []) {
|
|
3019
|
+
this._cache.set(entry.id, new PermissionOverwrite(entry));
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
};
|
|
3023
|
+
|
|
2184
3024
|
// src/Domain/Channel/Guild.ts
|
|
2185
3025
|
var GuildChannel = class extends Channel {
|
|
2186
|
-
/** Guild ID this channel belongs to. */
|
|
3026
|
+
/** Guild ID this channel belongs to, or null if missing from the payload. */
|
|
2187
3027
|
guildId;
|
|
2188
3028
|
/** Position in the channel list. */
|
|
2189
3029
|
position;
|
|
@@ -2193,11 +3033,14 @@ var GuildChannel = class extends Channel {
|
|
|
2193
3033
|
permissionOverwrites;
|
|
2194
3034
|
constructor(client, data) {
|
|
2195
3035
|
super(client, data);
|
|
2196
|
-
this.guildId = data.guild_id ??
|
|
3036
|
+
this.guildId = data.guild_id ?? null;
|
|
2197
3037
|
this.name = data.name ?? null;
|
|
2198
3038
|
this.position = data.position;
|
|
2199
3039
|
this.parentId = data.parent_id ?? null;
|
|
2200
|
-
this.permissionOverwrites =
|
|
3040
|
+
this.permissionOverwrites = new PermissionOverwriteManager(
|
|
3041
|
+
this,
|
|
3042
|
+
data.permission_overwrites ?? []
|
|
3043
|
+
);
|
|
2201
3044
|
}
|
|
2202
3045
|
/**
|
|
2203
3046
|
* Apply guild-channel fields in place.
|
|
@@ -2209,13 +3052,13 @@ var GuildChannel = class extends Channel {
|
|
|
2209
3052
|
if (data.position !== void 0) this.position = data.position;
|
|
2210
3053
|
if (data.parent_id !== void 0) this.parentId = data.parent_id ?? null;
|
|
2211
3054
|
if (data.permission_overwrites !== void 0) {
|
|
2212
|
-
this.permissionOverwrites
|
|
3055
|
+
this.permissionOverwrites._patch(data.permission_overwrites ?? []);
|
|
2213
3056
|
}
|
|
2214
3057
|
this.applyEditPatch(data);
|
|
2215
3058
|
}
|
|
2216
3059
|
/** Create a webhook for this channel. Requires Manage Webhooks. */
|
|
2217
3060
|
async createWebhook(options) {
|
|
2218
|
-
const data = await this.client.rest.post(
|
|
3061
|
+
const data = await this.client.rest.post(import_types14.Routes.channelWebhooks(this.id), {
|
|
2219
3062
|
body: options,
|
|
2220
3063
|
auth: true
|
|
2221
3064
|
});
|
|
@@ -2223,13 +3066,13 @@ var GuildChannel = class extends Channel {
|
|
|
2223
3066
|
}
|
|
2224
3067
|
/** Fetch all webhooks in this channel. Requires Manage Webhooks. */
|
|
2225
3068
|
async fetchWebhooks() {
|
|
2226
|
-
const data = await this.client.rest.get(
|
|
3069
|
+
const data = await this.client.rest.get(import_types14.Routes.channelWebhooks(this.id));
|
|
2227
3070
|
return data.map((w) => new Webhook(this.client, w));
|
|
2228
3071
|
}
|
|
2229
3072
|
/** Create an invite for this channel. Requires Create Instant Invite. */
|
|
2230
3073
|
async createInvite(options) {
|
|
2231
3074
|
const body = options ? toChannelInviteBody(options) : {};
|
|
2232
|
-
const data = await this.client.rest.post(
|
|
3075
|
+
const data = await this.client.rest.post(import_types14.Routes.channelInvites(this.id), {
|
|
2233
3076
|
body: Object.keys(body).length ? body : void 0,
|
|
2234
3077
|
auth: true
|
|
2235
3078
|
});
|
|
@@ -2237,109 +3080,161 @@ var GuildChannel = class extends Channel {
|
|
|
2237
3080
|
}
|
|
2238
3081
|
/** Fetch all invites for this channel. Requires Manage Channels. */
|
|
2239
3082
|
async fetchInvites() {
|
|
2240
|
-
const data = await this.client.rest.get(
|
|
3083
|
+
const data = await this.client.rest.get(import_types14.Routes.channelInvites(this.id));
|
|
2241
3084
|
return data.map((i) => new Invite(this.client, i));
|
|
2242
3085
|
}
|
|
2243
|
-
/**
|
|
2244
|
-
async editPermission(overwriteId, options) {
|
|
2245
|
-
await this.client.rest.put(import_types13.Routes.channelPermission(this.id, overwriteId), {
|
|
2246
|
-
body: options,
|
|
2247
|
-
auth: true
|
|
2248
|
-
});
|
|
2249
|
-
const entry = {
|
|
2250
|
-
id: overwriteId,
|
|
2251
|
-
type: options.type,
|
|
2252
|
-
allow: options.allow ?? "0",
|
|
2253
|
-
deny: options.deny ?? "0"
|
|
2254
|
-
};
|
|
2255
|
-
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
2256
|
-
if (idx >= 0) this.permissionOverwrites[idx] = entry;
|
|
2257
|
-
else this.permissionOverwrites.push(entry);
|
|
2258
|
-
}
|
|
2259
|
-
/** Delete a permission overwrite. Requires Manage Roles. */
|
|
2260
|
-
async deletePermission(overwriteId) {
|
|
2261
|
-
await this.client.rest.delete(import_types13.Routes.channelPermission(this.id, overwriteId), { auth: true });
|
|
2262
|
-
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
2263
|
-
if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
|
|
2264
|
-
}
|
|
2265
|
-
/** Check if the bot can send messages in this channel (with permissions). */
|
|
3086
|
+
/** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
|
|
2266
3087
|
canSendMessage() {
|
|
3088
|
+
if (!this.guildId) return false;
|
|
2267
3089
|
const me = this.client.guilds.get(this.guildId)?.members.me;
|
|
2268
3090
|
if (!me) return false;
|
|
2269
3091
|
const perms = me.permissionsIn(this);
|
|
2270
|
-
return perms.has(
|
|
3092
|
+
return perms.has(import_util13.PermissionFlags.ViewChannel) && perms.has(import_util13.PermissionFlags.SendMessages);
|
|
3093
|
+
}
|
|
3094
|
+
/**
|
|
3095
|
+
* Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
|
|
3096
|
+
* Returns false when the channel has no guildId.
|
|
3097
|
+
*/
|
|
3098
|
+
async canSend() {
|
|
3099
|
+
if (!this.guildId) return false;
|
|
3100
|
+
const guild = this.client.guilds.get(this.guildId);
|
|
3101
|
+
if (!guild) return false;
|
|
3102
|
+
if (!guild.members.me) {
|
|
3103
|
+
try {
|
|
3104
|
+
await guild.members.fetchMe();
|
|
3105
|
+
} catch {
|
|
3106
|
+
return false;
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
return this.canSendMessage();
|
|
2271
3110
|
}
|
|
2272
3111
|
/** Edit this channel's settings. Requires Manage Channels. */
|
|
2273
3112
|
async edit(options) {
|
|
2274
|
-
const data = await this.client.rest.patch(
|
|
3113
|
+
const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
|
|
2275
3114
|
body: toChannelEditBody(options),
|
|
2276
|
-
auth: true
|
|
3115
|
+
auth: true,
|
|
3116
|
+
...auditReasonHeaders(options.reason)
|
|
2277
3117
|
});
|
|
2278
3118
|
this.name = data.name ?? this.name;
|
|
2279
3119
|
this.parentId = data.parent_id ?? this.parentId;
|
|
2280
|
-
|
|
3120
|
+
if (data.permission_overwrites !== void 0) {
|
|
3121
|
+
this.permissionOverwrites._patch(data.permission_overwrites);
|
|
3122
|
+
}
|
|
2281
3123
|
this.applyEditPatch(data);
|
|
2282
3124
|
return this;
|
|
2283
3125
|
}
|
|
2284
3126
|
applyEditPatch(_data) {
|
|
2285
3127
|
}
|
|
2286
|
-
/** Delete this channel. Requires Manage Channels or channel ownership. */
|
|
2287
|
-
async delete(options) {
|
|
2288
|
-
const params = new URLSearchParams();
|
|
2289
|
-
if (options?.silent) params.set("silent", "true");
|
|
2290
|
-
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2291
|
-
const qs2 = params.toString();
|
|
2292
|
-
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2293
|
-
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2294
|
-
await this.client.rest.delete(import_types13.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2295
|
-
body,
|
|
2296
|
-
auth: true
|
|
2297
|
-
});
|
|
2298
|
-
this.client.channels.delete(this.id);
|
|
2299
|
-
this.client._clearMessageCache(this.id);
|
|
2300
|
-
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
2301
|
-
}
|
|
2302
3128
|
};
|
|
2303
3129
|
var TextChannel = class extends TextCapable(GuildChannel) {
|
|
2304
3130
|
/** Channel topic. */
|
|
2305
3131
|
topic;
|
|
2306
3132
|
/** Whether this channel is marked as NSFW. */
|
|
2307
3133
|
nsfw;
|
|
3134
|
+
/** Per-channel NSFW override (`null` inherits). */
|
|
3135
|
+
nsfwOverride;
|
|
2308
3136
|
/** Slowmode rate limit in seconds. */
|
|
2309
3137
|
rateLimitPerUser;
|
|
2310
3138
|
/** ID of the last message sent in this channel. */
|
|
2311
3139
|
lastMessageId;
|
|
3140
|
+
/** Content warning level. */
|
|
3141
|
+
contentWarningLevel;
|
|
3142
|
+
/** Custom content warning text. */
|
|
3143
|
+
contentWarningText;
|
|
2312
3144
|
constructor(client, data) {
|
|
2313
3145
|
super(client, data);
|
|
2314
3146
|
this.topic = data.topic ?? null;
|
|
2315
3147
|
this.nsfw = data.nsfw ?? false;
|
|
3148
|
+
this.nsfwOverride = data.nsfw_override ?? null;
|
|
2316
3149
|
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
2317
3150
|
this.lastMessageId = data.last_message_id ?? null;
|
|
3151
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3152
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3153
|
+
}
|
|
3154
|
+
/**
|
|
3155
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3156
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3157
|
+
*/
|
|
3158
|
+
async setSlowmode(seconds) {
|
|
3159
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
2318
3160
|
}
|
|
2319
3161
|
applyEditPatch(data) {
|
|
2320
3162
|
if ("topic" in data) this.topic = data.topic ?? null;
|
|
2321
3163
|
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3164
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
2322
3165
|
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3166
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3167
|
+
if ("content_warning_level" in data) {
|
|
3168
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3169
|
+
}
|
|
3170
|
+
if ("content_warning_text" in data) {
|
|
3171
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3172
|
+
}
|
|
2323
3173
|
}
|
|
2324
3174
|
};
|
|
2325
3175
|
var CategoryChannel = class extends GuildChannel {
|
|
2326
3176
|
};
|
|
2327
|
-
var VoiceChannel = class extends GuildChannel {
|
|
3177
|
+
var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
3178
|
+
/** Channel topic. */
|
|
3179
|
+
topic;
|
|
3180
|
+
/** Whether this channel is marked as NSFW. */
|
|
3181
|
+
nsfw;
|
|
3182
|
+
/** Per-channel NSFW override (`null` inherits). */
|
|
3183
|
+
nsfwOverride;
|
|
3184
|
+
/** Slowmode rate limit in seconds. */
|
|
3185
|
+
rateLimitPerUser;
|
|
3186
|
+
/** ID of the last message sent in this channel. */
|
|
3187
|
+
lastMessageId;
|
|
3188
|
+
/** Content warning level. */
|
|
3189
|
+
contentWarningLevel;
|
|
3190
|
+
/** Custom content warning text. */
|
|
3191
|
+
contentWarningText;
|
|
2328
3192
|
/** Voice bitrate. */
|
|
2329
3193
|
bitrate;
|
|
2330
3194
|
/** Maximum number of users allowed. */
|
|
2331
3195
|
userLimit;
|
|
3196
|
+
/** Max active voice connections per user. */
|
|
3197
|
+
voiceConnectionLimit;
|
|
2332
3198
|
/** RTC region override for this channel. */
|
|
2333
3199
|
rtcRegion;
|
|
2334
3200
|
constructor(client, data) {
|
|
2335
3201
|
super(client, data);
|
|
3202
|
+
this.topic = data.topic ?? null;
|
|
3203
|
+
this.nsfw = data.nsfw ?? false;
|
|
3204
|
+
this.nsfwOverride = data.nsfw_override ?? null;
|
|
3205
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3206
|
+
this.lastMessageId = data.last_message_id ?? null;
|
|
3207
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3208
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
2336
3209
|
this.bitrate = data.bitrate ?? null;
|
|
2337
3210
|
this.userLimit = data.user_limit ?? null;
|
|
3211
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
2338
3212
|
this.rtcRegion = data.rtc_region ?? null;
|
|
2339
3213
|
}
|
|
3214
|
+
/**
|
|
3215
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3216
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3217
|
+
*/
|
|
3218
|
+
async setSlowmode(seconds) {
|
|
3219
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
3220
|
+
}
|
|
2340
3221
|
applyEditPatch(data) {
|
|
3222
|
+
if ("topic" in data) this.topic = data.topic ?? null;
|
|
3223
|
+
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3224
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
3225
|
+
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3226
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3227
|
+
if ("content_warning_level" in data) {
|
|
3228
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3229
|
+
}
|
|
3230
|
+
if ("content_warning_text" in data) {
|
|
3231
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3232
|
+
}
|
|
2341
3233
|
if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
|
|
2342
3234
|
if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
|
|
3235
|
+
if ("voice_connection_limit" in data) {
|
|
3236
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3237
|
+
}
|
|
2343
3238
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
2344
3239
|
}
|
|
2345
3240
|
};
|
|
@@ -2350,20 +3245,23 @@ var LinkChannel = class extends GuildChannel {
|
|
|
2350
3245
|
super(client, data);
|
|
2351
3246
|
this.url = data.url ?? null;
|
|
2352
3247
|
}
|
|
3248
|
+
applyEditPatch(data) {
|
|
3249
|
+
if ("url" in data) this.url = data.url ?? null;
|
|
3250
|
+
}
|
|
2353
3251
|
};
|
|
2354
3252
|
|
|
2355
3253
|
// src/Domain/Channel/Factory.ts
|
|
2356
|
-
var
|
|
3254
|
+
var import_types15 = require("@fluxerjs/types");
|
|
2357
3255
|
var GUILD_FACTORIES = {
|
|
2358
|
-
[
|
|
2359
|
-
[
|
|
2360
|
-
[
|
|
2361
|
-
[
|
|
3256
|
+
[import_types15.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
|
|
3257
|
+
[import_types15.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
3258
|
+
[import_types15.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
3259
|
+
[import_types15.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
|
|
2362
3260
|
};
|
|
2363
3261
|
var DM_TYPES = /* @__PURE__ */ new Set([
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
3262
|
+
import_types15.ChannelType.DM,
|
|
3263
|
+
import_types15.ChannelType.GroupDM,
|
|
3264
|
+
import_types15.ChannelType.DMPersonalNotes
|
|
2367
3265
|
]);
|
|
2368
3266
|
function createDM(client, data) {
|
|
2369
3267
|
return new DMChannel(client, data);
|
|
@@ -2465,11 +3363,11 @@ var User = class extends Base {
|
|
|
2465
3363
|
*/
|
|
2466
3364
|
/** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
|
|
2467
3365
|
get createdTimestamp() {
|
|
2468
|
-
return
|
|
3366
|
+
return import_util14.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
2469
3367
|
}
|
|
2470
3368
|
/** Date when this account was created, derived from its snowflake ID. */
|
|
2471
3369
|
get createdAt() {
|
|
2472
|
-
return
|
|
3370
|
+
return import_util14.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
2473
3371
|
}
|
|
2474
3372
|
toString() {
|
|
2475
3373
|
return `<@${this.id}>`;
|
|
@@ -2479,7 +3377,7 @@ var User = class extends Base {
|
|
|
2479
3377
|
* @returns DM channel instance (cached if already open)
|
|
2480
3378
|
*/
|
|
2481
3379
|
async createDM() {
|
|
2482
|
-
const data = await this.client.rest.post(
|
|
3380
|
+
const data = await this.client.rest.post(import_types16.Routes.userMeChannels(), {
|
|
2483
3381
|
body: { recipient_id: this.id },
|
|
2484
3382
|
auth: true
|
|
2485
3383
|
});
|
|
@@ -2594,6 +3492,9 @@ var CacheController = class {
|
|
|
2594
3492
|
stickers
|
|
2595
3493
|
};
|
|
2596
3494
|
}
|
|
3495
|
+
/**
|
|
3496
|
+
* Sweep cached messages. Filter receives a hydrated {@link Message} (`createdAt`).
|
|
3497
|
+
*/
|
|
2597
3498
|
sweepMessages(filter, channelId) {
|
|
2598
3499
|
return this.client.sweepMessages(filter, channelId);
|
|
2599
3500
|
}
|
|
@@ -2662,7 +3563,7 @@ var CacheController = class {
|
|
|
2662
3563
|
* @internal
|
|
2663
3564
|
*/
|
|
2664
3565
|
cascadeChannel(channel, from = "both") {
|
|
2665
|
-
const guildId =
|
|
3566
|
+
const guildId = typeof channel.isGuild === "function" && channel.isGuild() ? channel.guildId : void 0;
|
|
2666
3567
|
const dropFromGuild = () => {
|
|
2667
3568
|
if (!guildId) return;
|
|
2668
3569
|
const guildChannels = this.client.guilds.get(guildId)?.channels;
|
|
@@ -2692,12 +3593,12 @@ var CacheController = class {
|
|
|
2692
3593
|
};
|
|
2693
3594
|
|
|
2694
3595
|
// src/ClientCore/ChannelManager.ts
|
|
2695
|
-
var
|
|
2696
|
-
var
|
|
3596
|
+
var import_collection8 = require("@fluxerjs/collection");
|
|
3597
|
+
var import_types23 = require("@fluxerjs/types");
|
|
2697
3598
|
|
|
2698
3599
|
// src/Domain/Guild/GuildEmoji.ts
|
|
2699
|
-
var
|
|
2700
|
-
var
|
|
3600
|
+
var import_types17 = require("@fluxerjs/types");
|
|
3601
|
+
var import_util15 = require("@fluxerjs/util");
|
|
2701
3602
|
var GuildEmoji = class extends Base {
|
|
2702
3603
|
client;
|
|
2703
3604
|
id;
|
|
@@ -2733,20 +3634,21 @@ var GuildEmoji = class extends Base {
|
|
|
2733
3634
|
}
|
|
2734
3635
|
/** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
|
|
2735
3636
|
get createdTimestamp() {
|
|
2736
|
-
return
|
|
3637
|
+
return import_util15.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
2737
3638
|
}
|
|
2738
3639
|
/** Date when this emoji was created, derived from its snowflake ID. */
|
|
2739
3640
|
get createdAt() {
|
|
2740
|
-
return
|
|
3641
|
+
return import_util15.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
2741
3642
|
}
|
|
2742
3643
|
/** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
|
|
2743
3644
|
toString() {
|
|
2744
3645
|
return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
|
|
2745
3646
|
}
|
|
2746
3647
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
2747
|
-
async delete() {
|
|
2748
|
-
await this.client.rest.delete(
|
|
2749
|
-
auth: true
|
|
3648
|
+
async delete(reason) {
|
|
3649
|
+
await this.client.rest.delete(import_types17.Routes.guildEmoji(this.guildId, this.id), {
|
|
3650
|
+
auth: true,
|
|
3651
|
+
...auditReasonHeaders(reason)
|
|
2750
3652
|
});
|
|
2751
3653
|
const guild = this.client.guilds.get(this.guildId);
|
|
2752
3654
|
if (guild) guild.emojis.delete(this.id);
|
|
@@ -2756,9 +3658,11 @@ var GuildEmoji = class extends Base {
|
|
|
2756
3658
|
* Requires Manage Emojis and Stickers permission.
|
|
2757
3659
|
*/
|
|
2758
3660
|
async edit(options) {
|
|
2759
|
-
const
|
|
2760
|
-
|
|
2761
|
-
|
|
3661
|
+
const { reason, name } = options;
|
|
3662
|
+
const data = await this.client.rest.patch(import_types17.Routes.guildEmoji(this.guildId, this.id), {
|
|
3663
|
+
body: { name },
|
|
3664
|
+
auth: true,
|
|
3665
|
+
...auditReasonHeaders(reason)
|
|
2762
3666
|
});
|
|
2763
3667
|
this.name = data.name;
|
|
2764
3668
|
return this;
|
|
@@ -2766,28 +3670,31 @@ var GuildEmoji = class extends Base {
|
|
|
2766
3670
|
};
|
|
2767
3671
|
|
|
2768
3672
|
// src/Domain/Guild/GuildMember.ts
|
|
2769
|
-
var
|
|
2770
|
-
var
|
|
3673
|
+
var import_types20 = require("@fluxerjs/types");
|
|
3674
|
+
var import_util17 = require("@fluxerjs/util");
|
|
2771
3675
|
|
|
2772
3676
|
// src/Helpers/Permissions.ts
|
|
2773
|
-
var
|
|
2774
|
-
var
|
|
3677
|
+
var import_types18 = require("@fluxerjs/types");
|
|
3678
|
+
var import_util16 = require("@fluxerjs/util");
|
|
2775
3679
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
2776
|
-
if (isOwner) return
|
|
3680
|
+
if (isOwner) return import_util16.ALL_PERMISSIONS_BIGINT;
|
|
3681
|
+
if ((basePermissions & import_util16.PermissionFlags.Administrator) !== 0n) {
|
|
3682
|
+
return import_util16.ALL_PERMISSIONS_BIGINT;
|
|
3683
|
+
}
|
|
2777
3684
|
let perms = basePermissions;
|
|
2778
3685
|
for (const overwrite of overwrites ?? []) {
|
|
2779
|
-
const applies = overwrite.type ===
|
|
3686
|
+
const applies = overwrite.type === import_types18.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types18.OverwriteType.Member && overwrite.id === memberId;
|
|
2780
3687
|
if (!applies) continue;
|
|
2781
3688
|
const allow = BigInt(overwrite.allow || "0");
|
|
2782
3689
|
const deny = BigInt(overwrite.deny || "0");
|
|
2783
3690
|
perms = perms & ~deny | allow;
|
|
2784
3691
|
}
|
|
2785
|
-
return
|
|
3692
|
+
return perms;
|
|
2786
3693
|
}
|
|
2787
3694
|
|
|
2788
3695
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
2789
|
-
var
|
|
2790
|
-
var
|
|
3696
|
+
var import_collection7 = require("@fluxerjs/collection");
|
|
3697
|
+
var import_types19 = require("@fluxerjs/types");
|
|
2791
3698
|
function roleId(roleOrId) {
|
|
2792
3699
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
2793
3700
|
}
|
|
@@ -2805,7 +3712,7 @@ var GuildMemberRoleManager = class {
|
|
|
2805
3712
|
}
|
|
2806
3713
|
/** Live Role objects from `guild.roles` for this member's role IDs. */
|
|
2807
3714
|
get cache() {
|
|
2808
|
-
const out = new
|
|
3715
|
+
const out = new import_collection7.Collection();
|
|
2809
3716
|
for (const id of this.ids) {
|
|
2810
3717
|
const role = this.member.guild.roles.get(id);
|
|
2811
3718
|
if (role) out.set(id, role);
|
|
@@ -2816,7 +3723,7 @@ var GuildMemberRoleManager = class {
|
|
|
2816
3723
|
const id = roleId(roleOrId);
|
|
2817
3724
|
if (this.ids.includes(id)) return;
|
|
2818
3725
|
await this.member.client.rest.put(
|
|
2819
|
-
|
|
3726
|
+
import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2820
3727
|
);
|
|
2821
3728
|
this.ids.push(id);
|
|
2822
3729
|
}
|
|
@@ -2825,13 +3732,13 @@ var GuildMemberRoleManager = class {
|
|
|
2825
3732
|
const idx = this.ids.indexOf(id);
|
|
2826
3733
|
if (idx === -1) return;
|
|
2827
3734
|
await this.member.client.rest.delete(
|
|
2828
|
-
|
|
3735
|
+
import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2829
3736
|
);
|
|
2830
3737
|
this.ids.splice(idx, 1);
|
|
2831
3738
|
}
|
|
2832
3739
|
async set(roleIds) {
|
|
2833
3740
|
const data = await this.member.client.rest.patch(
|
|
2834
|
-
|
|
3741
|
+
import_types19.Routes.guildMember(this.member.guild.id, this.member.id),
|
|
2835
3742
|
{ body: { roles: roleIds }, auth: true }
|
|
2836
3743
|
);
|
|
2837
3744
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -2844,6 +3751,8 @@ var GuildMemberRoleManager = class {
|
|
|
2844
3751
|
|
|
2845
3752
|
// src/Domain/Guild/GuildMember.ts
|
|
2846
3753
|
var GuildMember = class _GuildMember extends Base {
|
|
3754
|
+
/** Discriminant vs {@link PartialGuildMember}: always `false` on a hydrated member. */
|
|
3755
|
+
partial = false;
|
|
2847
3756
|
/** Parent client instance. */
|
|
2848
3757
|
client;
|
|
2849
3758
|
/** User ID (same as `user.id`). */
|
|
@@ -2872,6 +3781,12 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2872
3781
|
accentColor;
|
|
2873
3782
|
/** Guild-specific profile flags. */
|
|
2874
3783
|
profileFlags;
|
|
3784
|
+
/** Per-guild reply mention preference override. */
|
|
3785
|
+
mentionFlags;
|
|
3786
|
+
/** Guild-specific bio (set from member edit; not always on GET member). */
|
|
3787
|
+
bio;
|
|
3788
|
+
/** Guild-specific pronouns (set from member edit; not always on GET member). */
|
|
3789
|
+
pronouns;
|
|
2875
3790
|
constructor(client, data, guild) {
|
|
2876
3791
|
super();
|
|
2877
3792
|
this.client = client;
|
|
@@ -2888,6 +3803,9 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2888
3803
|
this.banner = data.banner ?? null;
|
|
2889
3804
|
this.accentColor = data.accent_color ?? null;
|
|
2890
3805
|
this.profileFlags = data.profile_flags ?? null;
|
|
3806
|
+
this.mentionFlags = data.mention_flags ?? null;
|
|
3807
|
+
this.bio = data.bio ?? null;
|
|
3808
|
+
this.pronouns = data.pronouns ?? null;
|
|
2891
3809
|
}
|
|
2892
3810
|
/**
|
|
2893
3811
|
* Apply an API member payload in place (gateway GUILD_MEMBER_UPDATE / REST edit).
|
|
@@ -2906,6 +3824,9 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2906
3824
|
if (data.banner !== void 0) this.banner = data.banner ?? null;
|
|
2907
3825
|
if (data.accent_color !== void 0) this.accentColor = data.accent_color ?? null;
|
|
2908
3826
|
if (data.profile_flags !== void 0) this.profileFlags = data.profile_flags ?? null;
|
|
3827
|
+
if (data.mention_flags !== void 0) this.mentionFlags = data.mention_flags ?? null;
|
|
3828
|
+
if (data.bio !== void 0) this.bio = data.bio ?? null;
|
|
3829
|
+
if (data.pronouns !== void 0) this.pronouns = data.pronouns ?? null;
|
|
2909
3830
|
}
|
|
2910
3831
|
/**
|
|
2911
3832
|
* Snapshot for `guildMemberUpdate` old-member arg (before in-place patch).
|
|
@@ -2934,7 +3855,10 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2934
3855
|
avatar: this.avatar,
|
|
2935
3856
|
banner: this.banner,
|
|
2936
3857
|
accent_color: this.accentColor,
|
|
2937
|
-
profile_flags: this.profileFlags ?? void 0
|
|
3858
|
+
profile_flags: this.profileFlags ?? void 0,
|
|
3859
|
+
mention_flags: this.mentionFlags,
|
|
3860
|
+
bio: this.bio,
|
|
3861
|
+
pronouns: this.pronouns
|
|
2938
3862
|
},
|
|
2939
3863
|
this.guild
|
|
2940
3864
|
);
|
|
@@ -2961,15 +3885,23 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2961
3885
|
mediaBase: this.client.instance.endpoints.media
|
|
2962
3886
|
});
|
|
2963
3887
|
}
|
|
2964
|
-
/**
|
|
3888
|
+
/**
|
|
3889
|
+
* PATCH member (`/members/@me` when editing the bot).
|
|
3890
|
+
* @example
|
|
3891
|
+
* await member.edit({ nick: 'Ada' });
|
|
3892
|
+
*/
|
|
2965
3893
|
async edit(options) {
|
|
2966
3894
|
const isMe = this.client.user?.id === this.id;
|
|
2967
|
-
const route = isMe ?
|
|
3895
|
+
const route = isMe ? import_types20.Routes.guildMemberMe(this.guild.id) : import_types20.Routes.guildMember(this.guild.id, this.id);
|
|
2968
3896
|
const data = await this.client.rest.patch(route, {
|
|
2969
3897
|
body: toMemberEditBody(options),
|
|
2970
|
-
auth: true
|
|
3898
|
+
auth: true,
|
|
3899
|
+
...auditReasonHeaders(options.reason ?? options.timeoutReason)
|
|
2971
3900
|
});
|
|
2972
3901
|
this._patch(data);
|
|
3902
|
+
if (options.bio !== void 0) this.bio = options.bio;
|
|
3903
|
+
if (options.pronouns !== void 0) this.pronouns = options.pronouns;
|
|
3904
|
+
if (options.mentionFlags !== void 0) this.mentionFlags = options.mentionFlags;
|
|
2973
3905
|
return this;
|
|
2974
3906
|
}
|
|
2975
3907
|
/**
|
|
@@ -2977,7 +3909,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2977
3909
|
* @see {@link permissionsIn} for channel-specific permissions
|
|
2978
3910
|
*/
|
|
2979
3911
|
get permissions() {
|
|
2980
|
-
return new
|
|
3912
|
+
return new import_util17.PermissionsBitField(this._effectivePermissions([], []));
|
|
2981
3913
|
}
|
|
2982
3914
|
/**
|
|
2983
3915
|
* Effective permissions in a channel (roles + overwrites).
|
|
@@ -2985,8 +3917,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2985
3917
|
* @returns Computed permissions bitfield
|
|
2986
3918
|
*/
|
|
2987
3919
|
permissionsIn(channel) {
|
|
2988
|
-
return new
|
|
2989
|
-
this._effectivePermissions(channel.permissionOverwrites, [...this.roles.roleIds])
|
|
3920
|
+
return new import_util17.PermissionsBitField(
|
|
3921
|
+
this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
|
|
2990
3922
|
);
|
|
2991
3923
|
}
|
|
2992
3924
|
/**
|
|
@@ -2997,6 +3929,63 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2997
3929
|
async move(channelId, connectionId) {
|
|
2998
3930
|
await this.edit({ channelId, connectionId });
|
|
2999
3931
|
}
|
|
3932
|
+
/** Kick this member. Requires Kick Members. */
|
|
3933
|
+
async kick(reason) {
|
|
3934
|
+
await this.guild.kick(this.id, reason);
|
|
3935
|
+
}
|
|
3936
|
+
/** Ban this member. Requires Ban Members. */
|
|
3937
|
+
async ban(options) {
|
|
3938
|
+
await this.guild.ban(this.id, options);
|
|
3939
|
+
}
|
|
3940
|
+
/**
|
|
3941
|
+
* Whether the bot can kick this member (cache-only; needs `members.me`).
|
|
3942
|
+
* False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
|
|
3943
|
+
*/
|
|
3944
|
+
get kickable() {
|
|
3945
|
+
return this._moderatableWith(import_util17.PermissionFlags.KickMembers);
|
|
3946
|
+
}
|
|
3947
|
+
/**
|
|
3948
|
+
* Whether the bot can ban this member (cache-only; needs `members.me`).
|
|
3949
|
+
*/
|
|
3950
|
+
get bannable() {
|
|
3951
|
+
return this._moderatableWith(import_util17.PermissionFlags.BanMembers);
|
|
3952
|
+
}
|
|
3953
|
+
/**
|
|
3954
|
+
* Whether the bot can timeout this member (cache-only; needs `members.me`).
|
|
3955
|
+
*/
|
|
3956
|
+
get moderatable() {
|
|
3957
|
+
return this._moderatableWith(import_util17.PermissionFlags.ModerateMembers);
|
|
3958
|
+
}
|
|
3959
|
+
_moderatableWith(flag) {
|
|
3960
|
+
const me = this.guild.members.me;
|
|
3961
|
+
if (!me) return false;
|
|
3962
|
+
if (this.id === me.id) return false;
|
|
3963
|
+
if (this.guild.ownerId != null && String(this.guild.ownerId) === String(this.id)) return false;
|
|
3964
|
+
if (!me.permissions.has(flag)) return false;
|
|
3965
|
+
return this._compareRolePosition(me) < 0;
|
|
3966
|
+
}
|
|
3967
|
+
/** Negative when this member's highest role is below `other`'s. */
|
|
3968
|
+
_compareRolePosition(other) {
|
|
3969
|
+
const highest = (m) => {
|
|
3970
|
+
let pos = -1;
|
|
3971
|
+
for (const role of m.roles.cache.values()) {
|
|
3972
|
+
if (role.position > pos) pos = role.position;
|
|
3973
|
+
}
|
|
3974
|
+
return pos;
|
|
3975
|
+
};
|
|
3976
|
+
return highest(this) - highest(other);
|
|
3977
|
+
}
|
|
3978
|
+
/**
|
|
3979
|
+
* Timeout this member for `durationMs` milliseconds, or pass `null` to clear.
|
|
3980
|
+
* Requires Moderate Members.
|
|
3981
|
+
*/
|
|
3982
|
+
async timeout(durationMs, reason) {
|
|
3983
|
+
const communicationDisabledUntil = durationMs == null || durationMs <= 0 ? null : new Date(Date.now() + durationMs).toISOString();
|
|
3984
|
+
return this.edit({
|
|
3985
|
+
communicationDisabledUntil,
|
|
3986
|
+
...reason !== void 0 ? { timeoutReason: reason } : {}
|
|
3987
|
+
});
|
|
3988
|
+
}
|
|
3000
3989
|
_effectivePermissions(overwrites, roleIds) {
|
|
3001
3990
|
const ownerId = this.guild.ownerId;
|
|
3002
3991
|
const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
|
|
@@ -3016,8 +4005,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3016
4005
|
};
|
|
3017
4006
|
|
|
3018
4007
|
// src/Domain/Guild/GuildSticker.ts
|
|
3019
|
-
var
|
|
3020
|
-
var
|
|
4008
|
+
var import_types21 = require("@fluxerjs/types");
|
|
4009
|
+
var import_util18 = require("@fluxerjs/util");
|
|
3021
4010
|
var GuildSticker = class extends Base {
|
|
3022
4011
|
client;
|
|
3023
4012
|
id;
|
|
@@ -3059,16 +4048,17 @@ var GuildSticker = class extends Base {
|
|
|
3059
4048
|
}
|
|
3060
4049
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
3061
4050
|
get createdTimestamp() {
|
|
3062
|
-
return
|
|
4051
|
+
return import_util18.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
3063
4052
|
}
|
|
3064
4053
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
3065
4054
|
get createdAt() {
|
|
3066
|
-
return
|
|
4055
|
+
return import_util18.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
3067
4056
|
}
|
|
3068
4057
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3069
|
-
async delete() {
|
|
3070
|
-
await this.client.rest.delete(
|
|
3071
|
-
auth: true
|
|
4058
|
+
async delete(reason) {
|
|
4059
|
+
await this.client.rest.delete(import_types21.Routes.guildSticker(this.guildId, this.id), {
|
|
4060
|
+
auth: true,
|
|
4061
|
+
...auditReasonHeaders(reason)
|
|
3072
4062
|
});
|
|
3073
4063
|
const guild = this.client.guilds.get(this.guildId);
|
|
3074
4064
|
if (guild) guild.stickers.delete(this.id);
|
|
@@ -3078,9 +4068,11 @@ var GuildSticker = class extends Base {
|
|
|
3078
4068
|
* Requires Manage Emojis and Stickers permission.
|
|
3079
4069
|
*/
|
|
3080
4070
|
async edit(options) {
|
|
3081
|
-
const
|
|
3082
|
-
|
|
3083
|
-
|
|
4071
|
+
const { reason, ...body } = options;
|
|
4072
|
+
const data = await this.client.rest.patch(import_types21.Routes.guildSticker(this.guildId, this.id), {
|
|
4073
|
+
body,
|
|
4074
|
+
auth: true,
|
|
4075
|
+
...auditReasonHeaders(reason)
|
|
3084
4076
|
});
|
|
3085
4077
|
const s = data;
|
|
3086
4078
|
this.name = s.name;
|
|
@@ -3090,8 +4082,8 @@ var GuildSticker = class extends Base {
|
|
|
3090
4082
|
};
|
|
3091
4083
|
|
|
3092
4084
|
// src/Domain/Guild/Role.ts
|
|
3093
|
-
var
|
|
3094
|
-
var
|
|
4085
|
+
var import_types22 = require("@fluxerjs/types");
|
|
4086
|
+
var import_util19 = require("@fluxerjs/util");
|
|
3095
4087
|
var Role = class _Role extends Base {
|
|
3096
4088
|
/** Parent client instance. */
|
|
3097
4089
|
client;
|
|
@@ -3134,21 +4126,29 @@ var Role = class _Role extends Base {
|
|
|
3134
4126
|
*/
|
|
3135
4127
|
get permissions() {
|
|
3136
4128
|
const bits = BigInt(this._permissions);
|
|
3137
|
-
return new
|
|
3138
|
-
(bits &
|
|
4129
|
+
return new import_util19.PermissionsBitField(
|
|
4130
|
+
(bits & import_util19.PermissionFlags.Administrator) !== 0n ? import_util19.ALL_PERMISSIONS_BIGINT : bits
|
|
3139
4131
|
);
|
|
3140
4132
|
}
|
|
4133
|
+
/**
|
|
4134
|
+
* Alias of {@link permissions}.has for discord.js-style checks.
|
|
4135
|
+
* @example
|
|
4136
|
+
* if (role.has(PermissionFlags.BanMembers)) { ... }
|
|
4137
|
+
*/
|
|
4138
|
+
has(permission) {
|
|
4139
|
+
return this.permissions.has(permission);
|
|
4140
|
+
}
|
|
3141
4141
|
/**
|
|
3142
4142
|
* Format as a mention string (`<@&id>`).
|
|
3143
4143
|
* @returns Mention syntax
|
|
3144
4144
|
*/
|
|
3145
4145
|
/** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
|
|
3146
4146
|
get createdTimestamp() {
|
|
3147
|
-
return
|
|
4147
|
+
return import_util19.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
3148
4148
|
}
|
|
3149
4149
|
/** Date when this role was created, derived from its snowflake ID. */
|
|
3150
4150
|
get createdAt() {
|
|
3151
|
-
return
|
|
4151
|
+
return import_util19.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
3152
4152
|
}
|
|
3153
4153
|
toString() {
|
|
3154
4154
|
return `<@&${this.id}>`;
|
|
@@ -3191,19 +4191,24 @@ var Role = class _Role extends Base {
|
|
|
3191
4191
|
* @returns This role instance (updated in-place)
|
|
3192
4192
|
*/
|
|
3193
4193
|
async edit(options) {
|
|
3194
|
-
const body =
|
|
3195
|
-
const data = await this.client.rest.patch(
|
|
4194
|
+
const body = toRoleEditBody(options);
|
|
4195
|
+
const data = await this.client.rest.patch(import_types22.Routes.guildRole(this.guildId, this.id), {
|
|
3196
4196
|
body: Object.keys(body).length ? body : void 0,
|
|
3197
|
-
auth: true
|
|
4197
|
+
auth: true,
|
|
4198
|
+
...auditReasonHeaders(options.reason)
|
|
3198
4199
|
});
|
|
3199
4200
|
this._patch(data);
|
|
3200
4201
|
return this;
|
|
3201
4202
|
}
|
|
3202
4203
|
/**
|
|
3203
4204
|
* DELETE role. Requires Manage Roles.
|
|
4205
|
+
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
3204
4206
|
*/
|
|
3205
|
-
async delete() {
|
|
3206
|
-
await this.client.rest.delete(
|
|
4207
|
+
async delete(reason) {
|
|
4208
|
+
await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), {
|
|
4209
|
+
auth: true,
|
|
4210
|
+
...auditReasonHeaders(reason)
|
|
4211
|
+
});
|
|
3207
4212
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
3208
4213
|
}
|
|
3209
4214
|
};
|
|
@@ -3211,17 +4216,15 @@ var Role = class _Role extends Base {
|
|
|
3211
4216
|
// src/Domain/Guild/Cache.ts
|
|
3212
4217
|
function putChannel(client, channel, guild) {
|
|
3213
4218
|
client.channels.set(channel.id, channel);
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
return guildId ? client.guilds.get(guildId) : void 0;
|
|
3217
|
-
})();
|
|
4219
|
+
if (!channel.isGuild()) return;
|
|
4220
|
+
const resolvedGuild = guild ?? (channel.guildId ? client.guilds.get(channel.guildId) : void 0);
|
|
3218
4221
|
if (resolvedGuild) {
|
|
3219
4222
|
resolvedGuild.channels.set(channel.id, channel);
|
|
3220
4223
|
}
|
|
3221
4224
|
}
|
|
3222
4225
|
function cacheChannel(guild, data) {
|
|
3223
4226
|
const existing = guild.channels.get(data.id) ?? guild.client.channels.get(data.id);
|
|
3224
|
-
if (existing &&
|
|
4227
|
+
if (existing?.isGuild() && existing.type === data.type) {
|
|
3225
4228
|
existing._patch(data);
|
|
3226
4229
|
putChannel(guild.client, existing, guild);
|
|
3227
4230
|
return existing;
|
|
@@ -3327,7 +4330,7 @@ function syncStickers(guild, stickers) {
|
|
|
3327
4330
|
}
|
|
3328
4331
|
|
|
3329
4332
|
// src/ClientCore/ChannelManager.ts
|
|
3330
|
-
var ChannelManager = class extends
|
|
4333
|
+
var ChannelManager = class extends import_collection8.LimitedCollection {
|
|
3331
4334
|
constructor(client) {
|
|
3332
4335
|
super({
|
|
3333
4336
|
maxSize: client.cache.limits.channels,
|
|
@@ -3335,6 +4338,10 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
|
|
|
3335
4338
|
});
|
|
3336
4339
|
this.client = client;
|
|
3337
4340
|
}
|
|
4341
|
+
/**
|
|
4342
|
+
* Remove a channel from cache. Does not delete it on the API.
|
|
4343
|
+
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
4344
|
+
*/
|
|
3338
4345
|
delete(key) {
|
|
3339
4346
|
const channel = this.get(key);
|
|
3340
4347
|
const deleted = super.delete(key);
|
|
@@ -3348,15 +4355,20 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
|
|
|
3348
4355
|
return this.get(channelId) ?? this.fetch(channelId);
|
|
3349
4356
|
}
|
|
3350
4357
|
/**
|
|
3351
|
-
* Fetch a channel by ID.
|
|
3352
|
-
*
|
|
4358
|
+
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
4359
|
+
* and {@link Channel.send} (send throws if the type is not text-based).
|
|
4360
|
+
* Returns the cached channel unless `force` is set.
|
|
4361
|
+
* @example
|
|
4362
|
+
* const channel = await client.channels.fetch(channelId);
|
|
4363
|
+
* await channel.delete();
|
|
4364
|
+
* await channel.send('hi');
|
|
3353
4365
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
3354
4366
|
*/
|
|
3355
4367
|
async fetch(channelId, options) {
|
|
3356
4368
|
const cached = this.get(channelId);
|
|
3357
4369
|
if (cached && !options?.force) return cached;
|
|
3358
4370
|
try {
|
|
3359
|
-
const data = await this.client.rest.get(
|
|
4371
|
+
const data = await this.client.rest.get(import_types23.Routes.channel(channelId));
|
|
3360
4372
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
3361
4373
|
if (guildId) {
|
|
3362
4374
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -3392,6 +4404,7 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
|
|
|
3392
4404
|
}
|
|
3393
4405
|
/**
|
|
3394
4406
|
* Send to a channel by ID without resolving it first.
|
|
4407
|
+
* Prefer {@link Channel.send} after {@link fetch} when you want the channel object.
|
|
3395
4408
|
* @example
|
|
3396
4409
|
* await client.channels.send(logChannelId, 'User joined!');
|
|
3397
4410
|
*/
|
|
@@ -3400,7 +4413,7 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
|
|
|
3400
4413
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
3401
4414
|
});
|
|
3402
4415
|
const data = await this.client.rest.post(
|
|
3403
|
-
|
|
4416
|
+
import_types23.Routes.channelMessages(channelId),
|
|
3404
4417
|
postPayload
|
|
3405
4418
|
);
|
|
3406
4419
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -3409,29 +4422,29 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
|
|
|
3409
4422
|
};
|
|
3410
4423
|
|
|
3411
4424
|
// src/ClientCore/ClientEmoji.ts
|
|
3412
|
-
var
|
|
3413
|
-
var
|
|
3414
|
-
var
|
|
4425
|
+
var import_collection9 = require("@fluxerjs/collection");
|
|
4426
|
+
var import_types24 = require("@fluxerjs/types");
|
|
4427
|
+
var import_util20 = require("@fluxerjs/util");
|
|
3415
4428
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
3416
4429
|
if (typeof emoji === "object" && emoji.id) {
|
|
3417
|
-
return (0,
|
|
4430
|
+
return (0, import_util20.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
|
|
3418
4431
|
}
|
|
3419
|
-
const parsed = (0,
|
|
4432
|
+
const parsed = (0, import_util20.parseEmoji)(
|
|
3420
4433
|
typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
|
|
3421
4434
|
);
|
|
3422
4435
|
if (!parsed) {
|
|
3423
4436
|
throw new import_util2.FluxerError("Invalid emoji", { code: import_util.ErrorCodes.InvalidEmoji });
|
|
3424
4437
|
}
|
|
3425
4438
|
if (parsed.id) {
|
|
3426
|
-
return (0,
|
|
4439
|
+
return (0, import_util20.formatEmoji)(parsed);
|
|
3427
4440
|
}
|
|
3428
4441
|
if (!/^\w+$/.test(parsed.name)) return parsed.name;
|
|
3429
|
-
const unicodeFromShortcode = (0,
|
|
4442
|
+
const unicodeFromShortcode = (0, import_util20.getUnicodeFromShortcode)(parsed.name);
|
|
3430
4443
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
3431
4444
|
if (guildId) {
|
|
3432
|
-
const emojis = await client.rest.get(
|
|
4445
|
+
const emojis = await client.rest.get(import_types24.Routes.guildEmojis(guildId));
|
|
3433
4446
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
3434
|
-
if (found) return (0,
|
|
4447
|
+
if (found) return (0, import_util20.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
|
|
3435
4448
|
throw new import_util2.FluxerError(
|
|
3436
4449
|
`Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format.`,
|
|
3437
4450
|
{ code: import_util.ErrorCodes.EmojiNotFound }
|
|
@@ -3446,28 +4459,34 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
3446
4459
|
return parsed.name;
|
|
3447
4460
|
}
|
|
3448
4461
|
async function fetchInstance(client) {
|
|
3449
|
-
const raw = await client.rest.get(
|
|
4462
|
+
const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
|
|
4463
|
+
auth: false,
|
|
4464
|
+
unversioned: true
|
|
4465
|
+
});
|
|
3450
4466
|
return parseInstanceDiscovery(raw);
|
|
3451
4467
|
}
|
|
3452
4468
|
function fetchGatewayInfo(client) {
|
|
3453
|
-
return client.rest.get(
|
|
4469
|
+
return client.rest.get(import_types24.Routes.gatewayBot());
|
|
3454
4470
|
}
|
|
3455
4471
|
function fetchEmojiMetadata(client, emojiId) {
|
|
3456
|
-
return client.rest.get(
|
|
4472
|
+
return client.rest.get(import_types24.Routes.emojiMetadata(emojiId), { auth: true });
|
|
3457
4473
|
}
|
|
3458
4474
|
function fetchStickerMetadata(client, stickerId) {
|
|
3459
|
-
return client.rest.get(
|
|
4475
|
+
return client.rest.get(import_types24.Routes.stickerMetadata(stickerId), { auth: true });
|
|
3460
4476
|
}
|
|
3461
4477
|
function fetchApplication(client) {
|
|
3462
|
-
return client.rest.get(
|
|
4478
|
+
return client.rest.get(import_types24.Routes.applicationsMe(), { auth: true });
|
|
3463
4479
|
}
|
|
3464
4480
|
async function fetchOAuthApplications(client) {
|
|
3465
|
-
const data = await client.rest.get(
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
4481
|
+
const data = await client.rest.get(import_types24.Routes.oauth2ApplicationsMe(), { auth: true });
|
|
4482
|
+
if (Array.isArray(data)) return data;
|
|
4483
|
+
if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
|
|
4484
|
+
return data.applications;
|
|
4485
|
+
}
|
|
4486
|
+
if (data && typeof data === "object" && "id" in data && typeof data.id === "string") {
|
|
4487
|
+
return [data];
|
|
4488
|
+
}
|
|
4489
|
+
return [];
|
|
3471
4490
|
}
|
|
3472
4491
|
function assertChannelIdBatch(name, channelIds) {
|
|
3473
4492
|
if (channelIds.length < 1 || channelIds.length > 100) {
|
|
@@ -3478,14 +4497,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
3478
4497
|
}
|
|
3479
4498
|
function preloadMessages(client, channelIds) {
|
|
3480
4499
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
3481
|
-
return client.rest.post(
|
|
4500
|
+
return client.rest.post(import_types24.Routes.preloadMessages(), {
|
|
3482
4501
|
body: { channels: channelIds },
|
|
3483
4502
|
auth: true
|
|
3484
4503
|
});
|
|
3485
4504
|
}
|
|
3486
4505
|
function preloadMessagesAlt(client, channelIds) {
|
|
3487
4506
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
3488
|
-
return client.rest.post(
|
|
4507
|
+
return client.rest.post(import_types24.Routes.preloadMessagesAlt(), {
|
|
3489
4508
|
body: { channels: channelIds },
|
|
3490
4509
|
auth: true
|
|
3491
4510
|
});
|
|
@@ -3493,14 +4512,14 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
3493
4512
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
3494
4513
|
validateBulkMessageFetchRequests(requests);
|
|
3495
4514
|
const wire = toBulkFetchWire(requests);
|
|
3496
|
-
const data = await client.rest.post(
|
|
4515
|
+
const data = await client.rest.post(import_types24.Routes.channelsMessagesBulk(), {
|
|
3497
4516
|
body: { requests: wire },
|
|
3498
4517
|
auth: true
|
|
3499
4518
|
});
|
|
3500
4519
|
if (options.hydrate === false) return data;
|
|
3501
4520
|
return {
|
|
3502
4521
|
channels: data.channels.map((entry) => {
|
|
3503
|
-
const collection = new
|
|
4522
|
+
const collection = new import_collection9.Collection();
|
|
3504
4523
|
for (const msg of entry.messages) {
|
|
3505
4524
|
client._addMessageToCache(entry.channel_id, msg);
|
|
3506
4525
|
collection.set(msg.id, new Message(client, msg));
|
|
@@ -3509,6 +4528,13 @@ async function bulkFetchMessages(client, requests, options = {}) {
|
|
|
3509
4528
|
})
|
|
3510
4529
|
};
|
|
3511
4530
|
}
|
|
4531
|
+
async function searchMessages(client, options = {}) {
|
|
4532
|
+
const data = await client.rest.post(import_types24.Routes.searchMessages(), {
|
|
4533
|
+
body: toMessageSearchBody(options),
|
|
4534
|
+
auth: true
|
|
4535
|
+
});
|
|
4536
|
+
return toMessageSearchResponse(data);
|
|
4537
|
+
}
|
|
3512
4538
|
|
|
3513
4539
|
// src/ClientCore/ClientEvents.ts
|
|
3514
4540
|
function createEventMethods(client) {
|
|
@@ -3527,14 +4553,14 @@ function createEventMethods(client) {
|
|
|
3527
4553
|
var import_ws = require("@fluxerjs/ws");
|
|
3528
4554
|
|
|
3529
4555
|
// src/Domain/Guild/Guild.ts
|
|
3530
|
-
var
|
|
3531
|
-
var
|
|
3532
|
-
var
|
|
4556
|
+
var import_collection12 = require("@fluxerjs/collection");
|
|
4557
|
+
var import_types34 = require("@fluxerjs/types");
|
|
4558
|
+
var import_util22 = require("@fluxerjs/util");
|
|
3533
4559
|
|
|
3534
4560
|
// src/ClientCore/GuildMemberManager.ts
|
|
3535
|
-
var
|
|
3536
|
-
var
|
|
3537
|
-
var GuildMemberManager = class extends
|
|
4561
|
+
var import_collection10 = require("@fluxerjs/collection");
|
|
4562
|
+
var import_types25 = require("@fluxerjs/types");
|
|
4563
|
+
var GuildMemberManager = class extends import_collection10.LimitedCollection {
|
|
3538
4564
|
constructor(guild) {
|
|
3539
4565
|
super({ maxSize: guild.client.cache.limits.members });
|
|
3540
4566
|
this.guild = guild;
|
|
@@ -3550,7 +4576,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
|
|
|
3550
4576
|
* console.log(member.displayName);
|
|
3551
4577
|
*/
|
|
3552
4578
|
async resolve(userId) {
|
|
3553
|
-
return this.get(userId) ?? this.
|
|
4579
|
+
return this.get(userId) ?? this.fetch(userId);
|
|
3554
4580
|
}
|
|
3555
4581
|
/**
|
|
3556
4582
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -3577,17 +4603,20 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
|
|
|
3577
4603
|
async fetchMe() {
|
|
3578
4604
|
return this.guild.fetchMe();
|
|
3579
4605
|
}
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
4606
|
+
async fetch(userIdOrOptions, options) {
|
|
4607
|
+
if (typeof userIdOrOptions === "string") {
|
|
4608
|
+
const cached = this.get(userIdOrOptions);
|
|
4609
|
+
if (cached && !options?.force) return cached;
|
|
4610
|
+
return this.guild.fetchMember(userIdOrOptions);
|
|
4611
|
+
}
|
|
4612
|
+
return this.fetchMany(userIdOrOptions);
|
|
4613
|
+
}
|
|
4614
|
+
async fetchMany(options) {
|
|
3586
4615
|
const params = new URLSearchParams();
|
|
3587
4616
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
3588
4617
|
if (options?.after) params.set("after", options.after);
|
|
3589
4618
|
const qs2 = params.toString();
|
|
3590
|
-
const url =
|
|
4619
|
+
const url = import_types25.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
3591
4620
|
const data = await this.guild.client.rest.get(url, { auth: true });
|
|
3592
4621
|
const members = [];
|
|
3593
4622
|
for (const m of data) {
|
|
@@ -3610,7 +4639,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
|
|
|
3610
4639
|
*/
|
|
3611
4640
|
async search(options = {}) {
|
|
3612
4641
|
const data = await this.guild.client.rest.post(
|
|
3613
|
-
|
|
4642
|
+
import_types25.Routes.guildMembersSearch(this.guild.id),
|
|
3614
4643
|
{ body: toMemberSearchBody(options), auth: true }
|
|
3615
4644
|
);
|
|
3616
4645
|
const offset = options.offset ?? 0;
|
|
@@ -3636,7 +4665,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
|
|
|
3636
4665
|
};
|
|
3637
4666
|
|
|
3638
4667
|
// src/Domain/Guild/Admin.ts
|
|
3639
|
-
var
|
|
4668
|
+
var import_types26 = require("@fluxerjs/types");
|
|
3640
4669
|
function toAuditLogEntryPayload(entry, guildId) {
|
|
3641
4670
|
return {
|
|
3642
4671
|
id: entry.id,
|
|
@@ -3657,7 +4686,7 @@ function toVanityPayload(data) {
|
|
|
3657
4686
|
return { code: data.code ?? null, uses: data.uses };
|
|
3658
4687
|
}
|
|
3659
4688
|
async function fetchAuditLogs(guild, options) {
|
|
3660
|
-
const url =
|
|
4689
|
+
const url = import_types26.Routes.guildAuditLogs(guild.id) + qs({
|
|
3661
4690
|
limit: options?.limit,
|
|
3662
4691
|
before: options?.before,
|
|
3663
4692
|
after: options?.after,
|
|
@@ -3681,7 +4710,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
3681
4710
|
};
|
|
3682
4711
|
}
|
|
3683
4712
|
async function editGuild(guild, options) {
|
|
3684
|
-
const data = await guild.client.rest.patch(
|
|
4713
|
+
const data = await guild.client.rest.patch(import_types26.Routes.guild(guild.id), {
|
|
3685
4714
|
body: toGuildEditBody(options),
|
|
3686
4715
|
auth: true
|
|
3687
4716
|
});
|
|
@@ -3689,13 +4718,13 @@ async function editGuild(guild, options) {
|
|
|
3689
4718
|
return guild;
|
|
3690
4719
|
}
|
|
3691
4720
|
async function fetchVanityURL(guild) {
|
|
3692
|
-
const data = await guild.client.rest.get(
|
|
4721
|
+
const data = await guild.client.rest.get(import_types26.Routes.guildVanityUrl(guild.id), {
|
|
3693
4722
|
auth: true
|
|
3694
4723
|
});
|
|
3695
4724
|
return toVanityPayload(data);
|
|
3696
4725
|
}
|
|
3697
4726
|
async function editVanityURL(guild, code) {
|
|
3698
|
-
const data = await guild.client.rest.patch(
|
|
4727
|
+
const data = await guild.client.rest.patch(import_types26.Routes.guildVanityUrl(guild.id), {
|
|
3699
4728
|
body: { code },
|
|
3700
4729
|
auth: true
|
|
3701
4730
|
});
|
|
@@ -3703,14 +4732,14 @@ async function editVanityURL(guild, code) {
|
|
|
3703
4732
|
return toVanityPayload(data);
|
|
3704
4733
|
}
|
|
3705
4734
|
async function fetchDiscoveryStatus(guild) {
|
|
3706
|
-
const data = await guild.client.rest.get(
|
|
4735
|
+
const data = await guild.client.rest.get(import_types26.Routes.guildDiscovery(guild.id), {
|
|
3707
4736
|
auth: true
|
|
3708
4737
|
});
|
|
3709
4738
|
return toDiscoveryStatusPayload(data);
|
|
3710
4739
|
}
|
|
3711
4740
|
async function applyForDiscovery(guild, options) {
|
|
3712
4741
|
const data = await guild.client.rest.post(
|
|
3713
|
-
|
|
4742
|
+
import_types26.Routes.guildDiscovery(guild.id),
|
|
3714
4743
|
{
|
|
3715
4744
|
body: toDiscoveryBody(options),
|
|
3716
4745
|
auth: true
|
|
@@ -3720,7 +4749,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
3720
4749
|
}
|
|
3721
4750
|
async function editDiscoveryApplication(guild, options) {
|
|
3722
4751
|
const data = await guild.client.rest.patch(
|
|
3723
|
-
|
|
4752
|
+
import_types26.Routes.guildDiscovery(guild.id),
|
|
3724
4753
|
{
|
|
3725
4754
|
body: toDiscoveryBody(options),
|
|
3726
4755
|
auth: true
|
|
@@ -3729,34 +4758,34 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
3729
4758
|
return toDiscoveryApplicationPayload(data);
|
|
3730
4759
|
}
|
|
3731
4760
|
async function withdrawDiscoveryApplication(guild) {
|
|
3732
|
-
await guild.client.rest.delete(
|
|
4761
|
+
await guild.client.rest.delete(import_types26.Routes.guildDiscovery(guild.id), { auth: true });
|
|
3733
4762
|
}
|
|
3734
4763
|
async function deleteGuild(guild, options) {
|
|
3735
4764
|
const body = options ? toSudoBody(options) : {};
|
|
3736
|
-
await guild.client.rest.post(
|
|
4765
|
+
await guild.client.rest.post(import_types26.Routes.guildDelete(guild.id), {
|
|
3737
4766
|
body,
|
|
3738
4767
|
auth: true
|
|
3739
4768
|
});
|
|
3740
4769
|
guild.client.guilds.delete(guild.id);
|
|
3741
4770
|
}
|
|
3742
4771
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
3743
|
-
await guild.client.rest.post(
|
|
4772
|
+
await guild.client.rest.post(import_types26.Routes.guildTransferOwnership(guild.id), {
|
|
3744
4773
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
3745
4774
|
auth: true
|
|
3746
4775
|
});
|
|
3747
4776
|
}
|
|
3748
4777
|
|
|
3749
4778
|
// src/Domain/Guild/Channels.ts
|
|
3750
|
-
var
|
|
3751
|
-
async function createChannel(guild,
|
|
3752
|
-
const created = await guild.client.rest.post(
|
|
3753
|
-
body:
|
|
4779
|
+
var import_types27 = require("@fluxerjs/types");
|
|
4780
|
+
async function createChannel(guild, options) {
|
|
4781
|
+
const created = await guild.client.rest.post(import_types27.Routes.guildChannels(guild.id), {
|
|
4782
|
+
body: toChannelCreateBody(options),
|
|
3754
4783
|
auth: true
|
|
3755
4784
|
});
|
|
3756
4785
|
return cacheChannel(guild, created);
|
|
3757
4786
|
}
|
|
3758
4787
|
async function fetchChannels(guild) {
|
|
3759
|
-
const data = await guild.client.rest.get(
|
|
4788
|
+
const data = await guild.client.rest.get(import_types27.Routes.guildChannels(guild.id));
|
|
3760
4789
|
const channels = [];
|
|
3761
4790
|
for (const ch of data) {
|
|
3762
4791
|
const channel = cacheChannel(guild, ch);
|
|
@@ -3765,17 +4794,17 @@ async function fetchChannels(guild) {
|
|
|
3765
4794
|
return channels;
|
|
3766
4795
|
}
|
|
3767
4796
|
async function setChannelPositions(guild, updates) {
|
|
3768
|
-
await guild.client.rest.patch(
|
|
4797
|
+
await guild.client.rest.patch(import_types27.Routes.guildChannels(guild.id), {
|
|
3769
4798
|
body: toChannelPositionBody(updates),
|
|
3770
4799
|
auth: true
|
|
3771
4800
|
});
|
|
3772
4801
|
}
|
|
3773
4802
|
async function fetchWebhooks(guild) {
|
|
3774
|
-
const data = await guild.client.rest.get(
|
|
4803
|
+
const data = await guild.client.rest.get(import_types27.Routes.guildWebhooks(guild.id));
|
|
3775
4804
|
return data.map((w) => new Webhook(guild.client, w));
|
|
3776
4805
|
}
|
|
3777
4806
|
async function fetchInvites(guild) {
|
|
3778
|
-
const data = await guild.client.rest.get(
|
|
4807
|
+
const data = await guild.client.rest.get(import_types27.Routes.guildInvites(guild.id));
|
|
3779
4808
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
3780
4809
|
}
|
|
3781
4810
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -3795,14 +4824,14 @@ function resolveGuildOnlineCount(data) {
|
|
|
3795
4824
|
}
|
|
3796
4825
|
|
|
3797
4826
|
// src/Domain/Guild/Emojis.ts
|
|
3798
|
-
var
|
|
4827
|
+
var import_types28 = require("@fluxerjs/types");
|
|
3799
4828
|
async function fetchEmojis(guild) {
|
|
3800
|
-
const data = await guild.client.rest.get(
|
|
4829
|
+
const data = await guild.client.rest.get(import_types28.Routes.guildEmojis(guild.id));
|
|
3801
4830
|
return data.map((e) => cacheEmoji(guild, e));
|
|
3802
4831
|
}
|
|
3803
4832
|
async function fetchEmoji(guild, emojiId) {
|
|
3804
4833
|
try {
|
|
3805
|
-
const data = await guild.client.rest.get(
|
|
4834
|
+
const data = await guild.client.rest.get(import_types28.Routes.guildEmoji(guild.id, emojiId));
|
|
3806
4835
|
return cacheEmoji(guild, data);
|
|
3807
4836
|
} catch (err) {
|
|
3808
4837
|
rethrowMapped(err, {
|
|
@@ -3812,14 +4841,16 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
3812
4841
|
}
|
|
3813
4842
|
}
|
|
3814
4843
|
async function createEmoji(guild, options) {
|
|
3815
|
-
const
|
|
3816
|
-
|
|
3817
|
-
|
|
4844
|
+
const { reason, ...body } = options;
|
|
4845
|
+
const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
|
|
4846
|
+
body,
|
|
4847
|
+
auth: true,
|
|
4848
|
+
...auditReasonHeaders(reason)
|
|
3818
4849
|
});
|
|
3819
4850
|
return cacheEmoji(guild, data);
|
|
3820
4851
|
}
|
|
3821
4852
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
3822
|
-
const data = await guild.client.rest.post(
|
|
4853
|
+
const data = await guild.client.rest.post(import_types28.Routes.guildEmojisClone(guild.id), {
|
|
3823
4854
|
body: { source_emoji_id: sourceEmojiId },
|
|
3824
4855
|
auth: true
|
|
3825
4856
|
});
|
|
@@ -3827,18 +4858,31 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
3827
4858
|
}
|
|
3828
4859
|
async function createEmojisBulk(guild, emojis) {
|
|
3829
4860
|
const data = await guild.client.rest.post(
|
|
3830
|
-
|
|
4861
|
+
import_types28.Routes.guildEmojisBulk(guild.id),
|
|
3831
4862
|
{ body: { emojis }, auth: true }
|
|
3832
4863
|
);
|
|
3833
4864
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
3834
4865
|
}
|
|
3835
4866
|
|
|
4867
|
+
// src/Domain/Guild/GuildRoleManager.ts
|
|
4868
|
+
var import_collection11 = require("@fluxerjs/collection");
|
|
4869
|
+
var GuildRoleManager = class extends import_collection11.LimitedCollection {
|
|
4870
|
+
constructor(guildId, options) {
|
|
4871
|
+
super(options);
|
|
4872
|
+
this.guildId = guildId;
|
|
4873
|
+
}
|
|
4874
|
+
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4875
|
+
get everyone() {
|
|
4876
|
+
return this.get(this.guildId);
|
|
4877
|
+
}
|
|
4878
|
+
};
|
|
4879
|
+
|
|
3836
4880
|
// src/Domain/Guild/MemberHttp.ts
|
|
3837
|
-
var
|
|
4881
|
+
var import_types29 = require("@fluxerjs/types");
|
|
3838
4882
|
async function fetchMember(guild, userId) {
|
|
3839
4883
|
try {
|
|
3840
4884
|
const data = await guild.client.rest.get(
|
|
3841
|
-
|
|
4885
|
+
import_types29.Routes.guildMember(guild.id, userId)
|
|
3842
4886
|
);
|
|
3843
4887
|
return cacheMember(guild, data);
|
|
3844
4888
|
} catch (err) {
|
|
@@ -3853,23 +4897,28 @@ async function fetchMember(guild, userId) {
|
|
|
3853
4897
|
}
|
|
3854
4898
|
async function fetchMe(guild) {
|
|
3855
4899
|
const data = await guild.client.rest.get(
|
|
3856
|
-
|
|
4900
|
+
import_types29.Routes.guildMemberMe(guild.id),
|
|
3857
4901
|
{ auth: true }
|
|
3858
4902
|
);
|
|
3859
4903
|
return cacheMember(guild, data);
|
|
3860
4904
|
}
|
|
3861
4905
|
|
|
3862
4906
|
// src/Domain/Guild/Moderation.ts
|
|
3863
|
-
var
|
|
4907
|
+
var import_types31 = require("@fluxerjs/types");
|
|
3864
4908
|
|
|
3865
4909
|
// src/Domain/Guild/GuildBan.ts
|
|
3866
|
-
var
|
|
4910
|
+
var import_types30 = require("@fluxerjs/types");
|
|
4911
|
+
function parseOptionalDate2(value) {
|
|
4912
|
+
if (value == null || value === "") return null;
|
|
4913
|
+
const date = new Date(value);
|
|
4914
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
4915
|
+
}
|
|
3867
4916
|
var GuildBan = class extends Base {
|
|
3868
4917
|
client;
|
|
3869
4918
|
guildId;
|
|
3870
4919
|
user;
|
|
3871
4920
|
reason;
|
|
3872
|
-
/**
|
|
4921
|
+
/** When a temporary ban expires. Null for permanent bans. */
|
|
3873
4922
|
expiresAt;
|
|
3874
4923
|
/** @param data - API ban from GET /guilds/{id}/bans or gateway GUILD_BAN_ADD */
|
|
3875
4924
|
constructor(client, data, guildId) {
|
|
@@ -3878,15 +4927,16 @@ var GuildBan = class extends Base {
|
|
|
3878
4927
|
this.guildId = data.guild_id ?? guildId;
|
|
3879
4928
|
this.user = client.getOrCreateUser(data.user);
|
|
3880
4929
|
this.reason = data.reason ?? null;
|
|
3881
|
-
this.expiresAt = data.expires_at
|
|
4930
|
+
this.expiresAt = parseOptionalDate2(data.expires_at);
|
|
3882
4931
|
}
|
|
3883
4932
|
/**
|
|
3884
4933
|
* Remove this ban (unban the user).
|
|
3885
4934
|
* Requires Ban Members permission.
|
|
3886
4935
|
*/
|
|
3887
|
-
async unban() {
|
|
3888
|
-
await this.client.rest.delete(
|
|
3889
|
-
auth: true
|
|
4936
|
+
async unban(reason) {
|
|
4937
|
+
await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
|
|
4938
|
+
auth: true,
|
|
4939
|
+
...auditReasonHeaders(reason)
|
|
3890
4940
|
});
|
|
3891
4941
|
}
|
|
3892
4942
|
};
|
|
@@ -3894,40 +4944,48 @@ var GuildBan = class extends Base {
|
|
|
3894
4944
|
// src/Domain/Guild/Moderation.ts
|
|
3895
4945
|
async function ban(guild, userId, options) {
|
|
3896
4946
|
const body = options ? toGuildBanBody(options) : {};
|
|
3897
|
-
await guild.client.rest.put(
|
|
4947
|
+
await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
|
|
3898
4948
|
body: Object.keys(body).length ? body : void 0,
|
|
3899
|
-
auth: true
|
|
4949
|
+
auth: true,
|
|
4950
|
+
...auditReasonHeaders(options?.reason)
|
|
3900
4951
|
});
|
|
3901
4952
|
}
|
|
3902
4953
|
async function fetchBans(guild) {
|
|
3903
|
-
const data = await guild.client.rest.get(
|
|
4954
|
+
const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
|
|
3904
4955
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
3905
4956
|
}
|
|
3906
|
-
async function unban(guild, userId) {
|
|
3907
|
-
await guild.client.rest.delete(
|
|
4957
|
+
async function unban(guild, userId, reason) {
|
|
4958
|
+
await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
|
|
4959
|
+
auth: true,
|
|
4960
|
+
...auditReasonHeaders(reason)
|
|
4961
|
+
});
|
|
3908
4962
|
}
|
|
3909
|
-
async function kick(guild, userId) {
|
|
3910
|
-
await guild.client.rest.delete(
|
|
4963
|
+
async function kick(guild, userId, reason) {
|
|
4964
|
+
await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
|
|
4965
|
+
auth: true,
|
|
4966
|
+
...auditReasonHeaders(reason)
|
|
4967
|
+
});
|
|
3911
4968
|
}
|
|
3912
4969
|
|
|
3913
4970
|
// src/Domain/Guild/Roles.ts
|
|
3914
|
-
var
|
|
3915
|
-
var
|
|
4971
|
+
var import_types32 = require("@fluxerjs/types");
|
|
4972
|
+
var import_util21 = require("@fluxerjs/util");
|
|
3916
4973
|
async function createRole(guild, options = {}) {
|
|
3917
|
-
const body =
|
|
3918
|
-
const data = await guild.client.rest.post(
|
|
4974
|
+
const body = toRoleCreateBody(options);
|
|
4975
|
+
const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
|
|
3919
4976
|
body: Object.keys(body).length ? body : void 0,
|
|
3920
|
-
auth: true
|
|
4977
|
+
auth: true,
|
|
4978
|
+
...auditReasonHeaders(options.reason)
|
|
3921
4979
|
});
|
|
3922
4980
|
return cacheRole(guild, data);
|
|
3923
4981
|
}
|
|
3924
4982
|
async function fetchRoles(guild) {
|
|
3925
|
-
const data = await guild.client.rest.get(
|
|
4983
|
+
const data = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
|
|
3926
4984
|
return data.map((r) => cacheRole(guild, r));
|
|
3927
4985
|
}
|
|
3928
4986
|
async function fetchRole(guild, roleId2) {
|
|
3929
4987
|
try {
|
|
3930
|
-
const data = await guild.client.rest.get(
|
|
4988
|
+
const data = await guild.client.rest.get(import_types32.Routes.guildRole(guild.id, roleId2));
|
|
3931
4989
|
return cacheRole(guild, data);
|
|
3932
4990
|
} catch (err) {
|
|
3933
4991
|
rethrowMapped(err, {
|
|
@@ -3937,14 +4995,14 @@ async function fetchRole(guild, roleId2) {
|
|
|
3937
4995
|
}
|
|
3938
4996
|
}
|
|
3939
4997
|
async function resolveRoleId(guild, arg) {
|
|
3940
|
-
const parsed = (0,
|
|
4998
|
+
const parsed = (0, import_util21.parseRoleMention)(arg);
|
|
3941
4999
|
if (parsed) return parsed;
|
|
3942
5000
|
const trimmed = arg.trim();
|
|
3943
5001
|
if (/^\d{17,19}$/.test(trimmed)) return trimmed;
|
|
3944
5002
|
const needle = trimmed.toLowerCase();
|
|
3945
5003
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3946
5004
|
if (cached) return cached.id;
|
|
3947
|
-
const roles = await guild.client.rest.get(
|
|
5005
|
+
const roles = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
|
|
3948
5006
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3949
5007
|
if (!role) return null;
|
|
3950
5008
|
cacheRole(guild, role);
|
|
@@ -3953,7 +5011,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3953
5011
|
async function setRolePositions(guild, updates) {
|
|
3954
5012
|
return replaceRoles(
|
|
3955
5013
|
guild,
|
|
3956
|
-
await guild.client.rest.patch(
|
|
5014
|
+
await guild.client.rest.patch(import_types32.Routes.guildRoles(guild.id), {
|
|
3957
5015
|
body: updates,
|
|
3958
5016
|
auth: true
|
|
3959
5017
|
})
|
|
@@ -3962,7 +5020,7 @@ async function setRolePositions(guild, updates) {
|
|
|
3962
5020
|
async function setRoleHoistPositions(guild, updates) {
|
|
3963
5021
|
return replaceRoles(
|
|
3964
5022
|
guild,
|
|
3965
|
-
await guild.client.rest.patch(
|
|
5023
|
+
await guild.client.rest.patch(import_types32.Routes.guildRolesHoistPositions(guild.id), {
|
|
3966
5024
|
body: updates.map((u) => ({
|
|
3967
5025
|
id: u.id,
|
|
3968
5026
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -3974,23 +5032,25 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
3974
5032
|
async function resetRoleHoistPositions(guild) {
|
|
3975
5033
|
return replaceRoles(
|
|
3976
5034
|
guild,
|
|
3977
|
-
await guild.client.rest.delete(
|
|
5035
|
+
await guild.client.rest.delete(import_types32.Routes.guildRolesHoistPositions(guild.id), {
|
|
3978
5036
|
auth: true
|
|
3979
5037
|
})
|
|
3980
5038
|
);
|
|
3981
5039
|
}
|
|
3982
5040
|
|
|
3983
5041
|
// src/Domain/Guild/Stickers.ts
|
|
3984
|
-
var
|
|
5042
|
+
var import_types33 = require("@fluxerjs/types");
|
|
3985
5043
|
async function createSticker(guild, options) {
|
|
3986
|
-
const
|
|
3987
|
-
|
|
3988
|
-
|
|
5044
|
+
const { reason, ...body } = options;
|
|
5045
|
+
const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
|
|
5046
|
+
body,
|
|
5047
|
+
auth: true,
|
|
5048
|
+
...auditReasonHeaders(reason)
|
|
3989
5049
|
});
|
|
3990
5050
|
return cacheSticker(guild, data);
|
|
3991
5051
|
}
|
|
3992
5052
|
async function cloneSticker(guild, sourceStickerId) {
|
|
3993
|
-
const data = await guild.client.rest.post(
|
|
5053
|
+
const data = await guild.client.rest.post(import_types33.Routes.guildStickersClone(guild.id), {
|
|
3994
5054
|
body: { source_sticker_id: sourceStickerId },
|
|
3995
5055
|
auth: true
|
|
3996
5056
|
});
|
|
@@ -3998,17 +5058,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
3998
5058
|
}
|
|
3999
5059
|
async function createStickersBulk(guild, stickers) {
|
|
4000
5060
|
const data = await guild.client.rest.post(
|
|
4001
|
-
|
|
5061
|
+
import_types33.Routes.guildStickersBulk(guild.id),
|
|
4002
5062
|
{ body: { stickers }, auth: true }
|
|
4003
5063
|
);
|
|
4004
5064
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
4005
5065
|
}
|
|
4006
5066
|
async function fetchStickers(guild) {
|
|
4007
|
-
const data = await guild.client.rest.get(
|
|
5067
|
+
const data = await guild.client.rest.get(import_types33.Routes.guildStickers(guild.id));
|
|
4008
5068
|
return data.map((s) => cacheSticker(guild, s));
|
|
4009
5069
|
}
|
|
4010
5070
|
async function fetchSticker(guild, stickerId) {
|
|
4011
|
-
const data = await guild.client.rest.get(
|
|
5071
|
+
const data = await guild.client.rest.get(import_types33.Routes.guildSticker(guild.id, stickerId));
|
|
4012
5072
|
return cacheSticker(guild, data);
|
|
4013
5073
|
}
|
|
4014
5074
|
|
|
@@ -4048,8 +5108,26 @@ var Guild = class extends Base {
|
|
|
4048
5108
|
systemChannelId;
|
|
4049
5109
|
/** Rules channel ID (for Community guilds), or null if none. */
|
|
4050
5110
|
rulesChannelId;
|
|
5111
|
+
/** {@link SystemChannelFlags} bitfield. */
|
|
5112
|
+
systemChannelFlags;
|
|
5113
|
+
/** Splash card alignment. */
|
|
5114
|
+
splashCardAlignment;
|
|
5115
|
+
/** Embed splash hash. */
|
|
5116
|
+
embedSplash;
|
|
4051
5117
|
/** NSFW level for this guild. */
|
|
4052
5118
|
nsfwLevel;
|
|
5119
|
+
/** Whether the guild is marked as adult (18+) content. */
|
|
5120
|
+
nsfw;
|
|
5121
|
+
/** Content warning level. */
|
|
5122
|
+
contentWarningLevel;
|
|
5123
|
+
/** Custom guild-wide content warning text. */
|
|
5124
|
+
contentWarningText;
|
|
5125
|
+
/** {@link GuildOperations} bitfield of disabled operations. */
|
|
5126
|
+
disabledOperations;
|
|
5127
|
+
/** ISO-8601 timestamp before which message history is not available. */
|
|
5128
|
+
messageHistoryCutoff;
|
|
5129
|
+
/** Permissions for the current member in this guild (bitfield string). */
|
|
5130
|
+
permissions;
|
|
4053
5131
|
/** MFA level required for moderation actions. */
|
|
4054
5132
|
mfaLevel;
|
|
4055
5133
|
/** Banner width in pixels. */
|
|
@@ -4083,13 +5161,13 @@ var Guild = class extends Base {
|
|
|
4083
5161
|
this.client = client;
|
|
4084
5162
|
this.id = data.id;
|
|
4085
5163
|
this.members = new GuildMemberManager(this);
|
|
4086
|
-
this.channels = new
|
|
5164
|
+
this.channels = new import_collection12.LimitedCollection({
|
|
4087
5165
|
maxSize: Number.POSITIVE_INFINITY,
|
|
4088
5166
|
onEvict: (_id, channel) => client.cache.cascadeChannel(channel, "guild")
|
|
4089
5167
|
});
|
|
4090
|
-
this.roles = new
|
|
4091
|
-
this.emojis = new
|
|
4092
|
-
this.stickers = new
|
|
5168
|
+
this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
|
|
5169
|
+
this.emojis = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.emojis });
|
|
5170
|
+
this.stickers = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.stickers });
|
|
4093
5171
|
this.name = data.name ?? "";
|
|
4094
5172
|
this.icon = data.icon ?? null;
|
|
4095
5173
|
this.banner = data.banner ?? null;
|
|
@@ -4104,7 +5182,16 @@ var Guild = class extends Base {
|
|
|
4104
5182
|
this.afkTimeout = data.afk_timeout ?? 0;
|
|
4105
5183
|
this.systemChannelId = data.system_channel_id ?? null;
|
|
4106
5184
|
this.rulesChannelId = data.rules_channel_id ?? null;
|
|
4107
|
-
this.
|
|
5185
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
5186
|
+
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
5187
|
+
this.embedSplash = data.embed_splash ?? null;
|
|
5188
|
+
this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
|
|
5189
|
+
this.nsfw = data.nsfw ?? false;
|
|
5190
|
+
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
5191
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
5192
|
+
this.disabledOperations = data.disabled_operations ?? 0;
|
|
5193
|
+
this.messageHistoryCutoff = data.message_history_cutoff ?? null;
|
|
5194
|
+
this.permissions = data.permissions ?? null;
|
|
4108
5195
|
this.mfaLevel = data.mfa_level ?? 0;
|
|
4109
5196
|
this.bannerWidth = data.banner_width ?? null;
|
|
4110
5197
|
this.bannerHeight = data.banner_height ?? null;
|
|
@@ -4139,7 +5226,28 @@ var Guild = class extends Base {
|
|
|
4139
5226
|
if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
|
|
4140
5227
|
if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
|
|
4141
5228
|
if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
|
|
4142
|
-
if (data.
|
|
5229
|
+
if (data.system_channel_flags !== void 0) {
|
|
5230
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
5231
|
+
}
|
|
5232
|
+
if (data.splash_card_alignment !== void 0) {
|
|
5233
|
+
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
5234
|
+
}
|
|
5235
|
+
if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
|
|
5236
|
+
if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
|
|
5237
|
+
if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
|
|
5238
|
+
if (data.content_warning_level !== void 0) {
|
|
5239
|
+
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
5240
|
+
}
|
|
5241
|
+
if (data.content_warning_text !== void 0) {
|
|
5242
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
5243
|
+
}
|
|
5244
|
+
if (data.disabled_operations !== void 0) {
|
|
5245
|
+
this.disabledOperations = data.disabled_operations ?? 0;
|
|
5246
|
+
}
|
|
5247
|
+
if (data.message_history_cutoff !== void 0) {
|
|
5248
|
+
this.messageHistoryCutoff = data.message_history_cutoff ?? null;
|
|
5249
|
+
}
|
|
5250
|
+
if (data.permissions !== void 0) this.permissions = data.permissions ?? null;
|
|
4143
5251
|
if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
|
|
4144
5252
|
if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
|
|
4145
5253
|
if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
|
|
@@ -4160,11 +5268,11 @@ var Guild = class extends Base {
|
|
|
4160
5268
|
}
|
|
4161
5269
|
/** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
|
|
4162
5270
|
get createdTimestamp() {
|
|
4163
|
-
return
|
|
5271
|
+
return import_util22.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
4164
5272
|
}
|
|
4165
5273
|
/** Date when this guild was created, derived from its snowflake ID. */
|
|
4166
5274
|
get createdAt() {
|
|
4167
|
-
return
|
|
5275
|
+
return import_util22.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
4168
5276
|
}
|
|
4169
5277
|
/** The guild's name. */
|
|
4170
5278
|
toString() {
|
|
@@ -4192,11 +5300,11 @@ var Guild = class extends Base {
|
|
|
4192
5300
|
});
|
|
4193
5301
|
}
|
|
4194
5302
|
/**
|
|
4195
|
-
* Create a channel. `
|
|
5303
|
+
* Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
|
|
4196
5304
|
* Requires Manage Channels.
|
|
4197
5305
|
*/
|
|
4198
|
-
createChannel(
|
|
4199
|
-
return createChannel(this,
|
|
5306
|
+
createChannel(options) {
|
|
5307
|
+
return createChannel(this, options);
|
|
4200
5308
|
}
|
|
4201
5309
|
/** Fetch all channels in this guild from the API. */
|
|
4202
5310
|
fetchChannels() {
|
|
@@ -4258,7 +5366,7 @@ var Guild = class extends Base {
|
|
|
4258
5366
|
resetRoleHoistPositions() {
|
|
4259
5367
|
return resetRoleHoistPositions(this);
|
|
4260
5368
|
}
|
|
4261
|
-
/** Ban a user from the guild. Requires Ban Members. `
|
|
5369
|
+
/** Ban a user from the guild. Requires Ban Members. `banDurationSeconds`: 0 = permanent. */
|
|
4262
5370
|
ban(userId, options) {
|
|
4263
5371
|
return ban(this, userId, options);
|
|
4264
5372
|
}
|
|
@@ -4267,12 +5375,12 @@ var Guild = class extends Base {
|
|
|
4267
5375
|
return fetchBans(this);
|
|
4268
5376
|
}
|
|
4269
5377
|
/** Unban a user from the guild. Requires Ban Members. */
|
|
4270
|
-
unban(userId) {
|
|
4271
|
-
return unban(this, userId);
|
|
5378
|
+
unban(userId, reason) {
|
|
5379
|
+
return unban(this, userId, reason);
|
|
4272
5380
|
}
|
|
4273
5381
|
/** Kick a user from the guild. Requires Kick Members. */
|
|
4274
|
-
kick(userId) {
|
|
4275
|
-
return kick(this, userId);
|
|
5382
|
+
kick(userId, reason) {
|
|
5383
|
+
return kick(this, userId, reason);
|
|
4276
5384
|
}
|
|
4277
5385
|
/** Fetch all emojis in this guild from the API. */
|
|
4278
5386
|
fetchEmojis() {
|
|
@@ -4357,7 +5465,7 @@ var Guild = class extends Base {
|
|
|
4357
5465
|
};
|
|
4358
5466
|
|
|
4359
5467
|
// src/Domain/Guild/Payload.ts
|
|
4360
|
-
var
|
|
5468
|
+
var import_util23 = require("@fluxerjs/util");
|
|
4361
5469
|
var TOP_LEVEL_COUNT_KEYS = [
|
|
4362
5470
|
"member_count",
|
|
4363
5471
|
"online_count",
|
|
@@ -4397,10 +5505,10 @@ function mergeTopLevelSnapshotFields(properties, raw) {
|
|
|
4397
5505
|
return out;
|
|
4398
5506
|
}
|
|
4399
5507
|
function normalizeGuildSnapshotPayload(raw) {
|
|
4400
|
-
if (!(0,
|
|
5508
|
+
if (!(0, import_util23.isRecord)(raw)) return null;
|
|
4401
5509
|
const flatPayload = isHydratableGuildPayload(raw) && (raw.roles === void 0 || Array.isArray(raw.roles)) ? raw : null;
|
|
4402
5510
|
let nestedPayload = null;
|
|
4403
|
-
if (Object.hasOwn(raw, "properties") && (0,
|
|
5511
|
+
if (Object.hasOwn(raw, "properties") && (0, import_util23.isRecord)(raw.properties)) {
|
|
4404
5512
|
const properties = raw.properties;
|
|
4405
5513
|
const rolesValid = raw.roles === void 0 || Array.isArray(raw.roles);
|
|
4406
5514
|
if (rolesValid && isHydratableGuildPayload(properties) && raw.id === properties.id) {
|
|
@@ -4412,7 +5520,7 @@ function normalizeGuildSnapshotPayload(raw) {
|
|
|
4412
5520
|
return flatPayload ?? nestedPayload;
|
|
4413
5521
|
}
|
|
4414
5522
|
function normalizeGuildUpdatePayload(raw) {
|
|
4415
|
-
if (!(0,
|
|
5523
|
+
if (!(0, import_util23.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
|
|
4416
5524
|
return raw;
|
|
4417
5525
|
}
|
|
4418
5526
|
|
|
@@ -4458,23 +5566,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
4458
5566
|
}
|
|
4459
5567
|
|
|
4460
5568
|
// src/ClientCore/ClientUser.ts
|
|
4461
|
-
var
|
|
5569
|
+
var import_types35 = require("@fluxerjs/types");
|
|
4462
5570
|
var ClientUser = class extends User {
|
|
4463
5571
|
/** Broadcast presence (gateway opcode 3) on all shards. */
|
|
4464
5572
|
setPresence(presence) {
|
|
5573
|
+
this.client.options.presence = presence;
|
|
4465
5574
|
const wire = toPresenceWire(presence);
|
|
4466
|
-
this.client.
|
|
4467
|
-
this.client._sendToAllShards({ op: import_types34.GatewayOpcodes.PresenceUpdate, d: wire });
|
|
5575
|
+
this.client._sendToAllShards({ op: import_types35.GatewayOpcodes.PresenceUpdate, d: wire });
|
|
4468
5576
|
}
|
|
4469
5577
|
/** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
|
|
4470
5578
|
async fetch() {
|
|
4471
|
-
const data = await this.client.rest.get(
|
|
5579
|
+
const data = await this.client.rest.get(import_types35.Routes.currentUser(), { auth: true });
|
|
4472
5580
|
this._patch(data);
|
|
4473
5581
|
return this;
|
|
4474
5582
|
}
|
|
4475
5583
|
/** GET /users/@me/guilds — returns camelCase partial guilds. */
|
|
4476
5584
|
async fetchGuilds(options) {
|
|
4477
|
-
const path =
|
|
5585
|
+
const path = import_types35.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
|
|
4478
5586
|
const data = await this.client.rest.get(path, { auth: true });
|
|
4479
5587
|
return data.map((g) => ({
|
|
4480
5588
|
id: g.id,
|
|
@@ -4487,10 +5595,18 @@ var ClientUser = class extends User {
|
|
|
4487
5595
|
...g.approximate_presence_count !== void 0 ? { approximatePresenceCount: g.approximate_presence_count } : {}
|
|
4488
5596
|
}));
|
|
4489
5597
|
}
|
|
4490
|
-
/**
|
|
5598
|
+
/**
|
|
5599
|
+
* Leave a guild (`client.user.leaveGuild`).
|
|
5600
|
+
* DELETE /users/@me/guilds/{guild_id}.
|
|
5601
|
+
*
|
|
5602
|
+
* @param guildId - Guild to leave
|
|
5603
|
+
* @param options - Optional sudo / MFA body for user accounts
|
|
5604
|
+
* @example
|
|
5605
|
+
* await client.user.leaveGuild(guildId);
|
|
5606
|
+
*/
|
|
4491
5607
|
async leaveGuild(guildId, options) {
|
|
4492
5608
|
const body = options ? toSudoBody(options) : void 0;
|
|
4493
|
-
await this.client.rest.delete(
|
|
5609
|
+
await this.client.rest.delete(import_types35.Routes.leaveGuild(guildId), {
|
|
4494
5610
|
body: body && Object.keys(body).length ? body : void 0,
|
|
4495
5611
|
auth: true
|
|
4496
5612
|
});
|
|
@@ -4498,7 +5614,7 @@ var ClientUser = class extends User {
|
|
|
4498
5614
|
/** Delete every message authored by the caller across a guild (sudo). */
|
|
4499
5615
|
async bulkDeleteMyMessagesInGuild(guildId, options) {
|
|
4500
5616
|
const body = options ? toSudoBody(options) : void 0;
|
|
4501
|
-
await this.client.rest.post(
|
|
5617
|
+
await this.client.rest.post(import_types35.Routes.guildBulkDeleteMine(guildId), {
|
|
4502
5618
|
body: body && Object.keys(body).length ? body : void 0,
|
|
4503
5619
|
auth: true
|
|
4504
5620
|
});
|
|
@@ -4506,7 +5622,7 @@ var ClientUser = class extends User {
|
|
|
4506
5622
|
};
|
|
4507
5623
|
|
|
4508
5624
|
// src/ClientCore/EventHandlers/Helpers.ts
|
|
4509
|
-
var
|
|
5625
|
+
var import_util24 = require("@fluxerjs/util");
|
|
4510
5626
|
function unknownUser(id) {
|
|
4511
5627
|
return {
|
|
4512
5628
|
id,
|
|
@@ -4665,7 +5781,7 @@ var guildResourceHandlers = {
|
|
|
4665
5781
|
role = new Role(client, data.role, data.guild_id);
|
|
4666
5782
|
guild?.roles.set(role.id, role);
|
|
4667
5783
|
}
|
|
4668
|
-
client.emit(Events.GuildRoleUpdate,
|
|
5784
|
+
client.emit(Events.GuildRoleUpdate, oldRole, role);
|
|
4669
5785
|
},
|
|
4670
5786
|
GUILD_ROLE_UPDATE_BULK(client, d) {
|
|
4671
5787
|
const data = d;
|
|
@@ -4681,11 +5797,7 @@ var guildResourceHandlers = {
|
|
|
4681
5797
|
const guild = client.guilds.get(data.guild_id);
|
|
4682
5798
|
const role = guild?.roles.get(data.role_id) ?? null;
|
|
4683
5799
|
guild?.roles.delete(data.role_id);
|
|
4684
|
-
client.emit(Events.GuildRoleDelete,
|
|
4685
|
-
roleId: data.role_id,
|
|
4686
|
-
guildId: data.guild_id,
|
|
4687
|
-
role
|
|
4688
|
-
});
|
|
5800
|
+
client.emit(Events.GuildRoleDelete, role, data.guild_id, data.role_id);
|
|
4689
5801
|
},
|
|
4690
5802
|
GUILD_BAN_ADD(client, d) {
|
|
4691
5803
|
const data = d;
|
|
@@ -4718,7 +5830,14 @@ function markGuildUnavailable(client, id) {
|
|
|
4718
5830
|
guild.available = false;
|
|
4719
5831
|
client.emit(Events.GuildUnavailable, guild);
|
|
4720
5832
|
}
|
|
5833
|
+
function isStartupGuildHydration(client) {
|
|
5834
|
+
return client._guildStreamSettleTimeout !== null;
|
|
5835
|
+
}
|
|
4721
5836
|
var guildHandlers = {
|
|
5837
|
+
/**
|
|
5838
|
+
* Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
|
|
5839
|
+
* {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
|
|
5840
|
+
*/
|
|
4722
5841
|
GUILD_CREATE(client, d) {
|
|
4723
5842
|
const raw = d;
|
|
4724
5843
|
if (raw.unavailable === true) {
|
|
@@ -4731,11 +5850,32 @@ var guildHandlers = {
|
|
|
4731
5850
|
}
|
|
4732
5851
|
return;
|
|
4733
5852
|
}
|
|
5853
|
+
const startupHydration = isStartupGuildHydration(client);
|
|
5854
|
+
if (startupHydration) {
|
|
5855
|
+
resetGuildStreamSettle(client);
|
|
5856
|
+
}
|
|
4734
5857
|
const result = applyGuildSnapshotFromGateway(client, d);
|
|
4735
5858
|
if (!result) return;
|
|
4736
5859
|
const { guild, recovered } = result;
|
|
4737
|
-
|
|
4738
|
-
|
|
5860
|
+
const legacyStartup = client.options.emitGuildCreateOnStartup === true;
|
|
5861
|
+
const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
|
|
5862
|
+
const isStartupBackfill = wasReadyStub || startupHydration;
|
|
5863
|
+
if (recovered) {
|
|
5864
|
+
guild.available = true;
|
|
5865
|
+
if (legacyStartup && isStartupBackfill) {
|
|
5866
|
+
client.emit(Events.GuildCreate, guild);
|
|
5867
|
+
} else {
|
|
5868
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5869
|
+
}
|
|
5870
|
+
} else if (startupHydration) {
|
|
5871
|
+
if (legacyStartup) {
|
|
5872
|
+
client.emit(Events.GuildCreate, guild);
|
|
5873
|
+
} else {
|
|
5874
|
+
client.emit(Events.GuildAvailable, guild);
|
|
5875
|
+
}
|
|
5876
|
+
} else {
|
|
5877
|
+
client.emit(Events.GuildCreate, guild);
|
|
5878
|
+
}
|
|
4739
5879
|
client._onGuildReceived(guild.id);
|
|
4740
5880
|
},
|
|
4741
5881
|
GUILD_UPDATE(client, d) {
|
|
@@ -4774,6 +5914,7 @@ var guildHandlers = {
|
|
|
4774
5914
|
markGuildUnavailable(client, id);
|
|
4775
5915
|
return;
|
|
4776
5916
|
}
|
|
5917
|
+
client._readyStubGuildIds.delete(id);
|
|
4777
5918
|
const guild = client.guilds.get(id);
|
|
4778
5919
|
if (!guild) return;
|
|
4779
5920
|
client.guilds.delete(id);
|
|
@@ -4785,55 +5926,50 @@ var guildHandlers = {
|
|
|
4785
5926
|
};
|
|
4786
5927
|
|
|
4787
5928
|
// src/ClientCore/EventHandlers/Invites.ts
|
|
4788
|
-
var
|
|
5929
|
+
var import_types36 = require("@fluxerjs/types");
|
|
4789
5930
|
function normalizeInviteCreate(client, payload) {
|
|
4790
|
-
const raw = (0,
|
|
4791
|
-
const code = (0,
|
|
5931
|
+
const raw = (0, import_util24.asRecord)(payload);
|
|
5932
|
+
const code = (0, import_util24.str)(raw?.code);
|
|
4792
5933
|
if (!raw || !code) return null;
|
|
4793
|
-
const typeNum = (0,
|
|
4794
|
-
const type = typeNum ===
|
|
5934
|
+
const typeNum = (0, import_util24.num)(raw.type);
|
|
5935
|
+
const type = typeNum === import_types36.InviteType.GroupDM ? import_types36.InviteType.GroupDM : import_types36.InviteType.Guild;
|
|
4795
5936
|
const shared = {
|
|
4796
5937
|
code,
|
|
4797
5938
|
inviter: raw.inviter ?? null,
|
|
4798
|
-
member_count: (0,
|
|
5939
|
+
member_count: (0, import_util24.num)(raw.member_count),
|
|
4799
5940
|
expires_at: raw.expires_at ?? void 0,
|
|
4800
5941
|
temporary: typeof raw.temporary === "boolean" ? raw.temporary : void 0,
|
|
4801
|
-
created_at: (0,
|
|
4802
|
-
uses: (0,
|
|
4803
|
-
max_uses: (0,
|
|
4804
|
-
max_age: (0,
|
|
5942
|
+
created_at: (0, import_util24.str)(raw.created_at),
|
|
5943
|
+
uses: (0, import_util24.num)(raw.uses),
|
|
5944
|
+
max_uses: (0, import_util24.num)(raw.max_uses),
|
|
5945
|
+
max_age: (0, import_util24.num)(raw.max_age)
|
|
4805
5946
|
};
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
}
|
|
4811
|
-
const guildObj = (0, import_util19.asRecord)(raw.guild);
|
|
4812
|
-
const channelObj = (0, import_util19.asRecord)(raw.channel);
|
|
4813
|
-
const guildId = (0, import_util19.str)(guildObj?.id) ?? (0, import_util19.str)(raw.guild_id) ?? "0";
|
|
4814
|
-
const channelId = (0, import_util19.str)(channelObj?.id) ?? (0, import_util19.str)(raw.channel_id) ?? "0";
|
|
5947
|
+
const guildObj = (0, import_util24.asRecord)(raw.guild);
|
|
5948
|
+
const channelObj = (0, import_util24.asRecord)(raw.channel);
|
|
5949
|
+
const guildId = (0, import_util24.str)(guildObj?.id) ?? (0, import_util24.str)(raw.guild_id) ?? "0";
|
|
5950
|
+
const channelId = (0, import_util24.str)(channelObj?.id) ?? (0, import_util24.str)(raw.channel_id) ?? "0";
|
|
4815
5951
|
const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
|
|
4816
5952
|
const cachedChannel = channelId !== "0" ? client.channels.get(channelId) : null;
|
|
4817
5953
|
const channel = {
|
|
4818
5954
|
id: channelId,
|
|
4819
|
-
type: (0,
|
|
4820
|
-
name: (0,
|
|
5955
|
+
type: (0, import_util24.num)(channelObj?.type) ?? cachedChannel?.type ?? import_types36.ChannelType.GuildText,
|
|
5956
|
+
name: (0, import_util24.str)(channelObj?.name) ?? cachedChannel?.name ?? null,
|
|
4821
5957
|
icon: channelObj?.icon ?? null
|
|
4822
5958
|
};
|
|
4823
|
-
if (type ===
|
|
5959
|
+
if (type === import_types36.InviteType.GroupDM) return { ...shared, type, channel };
|
|
4824
5960
|
return {
|
|
4825
5961
|
...shared,
|
|
4826
|
-
type:
|
|
5962
|
+
type: import_types36.InviteType.Guild,
|
|
4827
5963
|
guild: {
|
|
4828
5964
|
id: guildId,
|
|
4829
|
-
name: (0,
|
|
5965
|
+
name: (0, import_util24.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
|
|
4830
5966
|
icon: guildObj?.icon ?? null,
|
|
4831
5967
|
banner: guildObj?.banner ?? null,
|
|
4832
5968
|
splash: guildObj?.splash ?? null,
|
|
4833
5969
|
features: Array.isArray(guildObj?.features) ? guildObj.features : void 0
|
|
4834
5970
|
},
|
|
4835
5971
|
channel,
|
|
4836
|
-
presence_count: (0,
|
|
5972
|
+
presence_count: (0, import_util24.num)(raw.presence_count)
|
|
4837
5973
|
};
|
|
4838
5974
|
}
|
|
4839
5975
|
var inviteHandlers = {
|
|
@@ -4859,6 +5995,30 @@ var inviteHandlers = {
|
|
|
4859
5995
|
}
|
|
4860
5996
|
};
|
|
4861
5997
|
|
|
5998
|
+
// src/Domain/Guild/PartialGuildMember.ts
|
|
5999
|
+
var PartialGuildMember = class {
|
|
6000
|
+
partial = true;
|
|
6001
|
+
client;
|
|
6002
|
+
id;
|
|
6003
|
+
user;
|
|
6004
|
+
guildId;
|
|
6005
|
+
guild;
|
|
6006
|
+
constructor(data) {
|
|
6007
|
+
this.client = data.client;
|
|
6008
|
+
this.id = data.id;
|
|
6009
|
+
this.user = data.user;
|
|
6010
|
+
this.guild = data.guild;
|
|
6011
|
+
this.guildId = data.guild.id;
|
|
6012
|
+
}
|
|
6013
|
+
/**
|
|
6014
|
+
* Fetch the full {@link GuildMember} from the API (cache-aware via `guild.members.fetch`).
|
|
6015
|
+
* @throws FluxerError with MEMBER_NOT_FOUND if the user is not in the guild
|
|
6016
|
+
*/
|
|
6017
|
+
async fetch() {
|
|
6018
|
+
return this.guild.members.fetch(this.id);
|
|
6019
|
+
}
|
|
6020
|
+
};
|
|
6021
|
+
|
|
4862
6022
|
// src/ClientCore/EventHandlers/Members.ts
|
|
4863
6023
|
var memberHandlers = {
|
|
4864
6024
|
GUILD_MEMBER_ADD(client, d) {
|
|
@@ -4885,28 +6045,15 @@ var memberHandlers = {
|
|
|
4885
6045
|
const data = d;
|
|
4886
6046
|
const guild = client.guilds.get(data.guild_id);
|
|
4887
6047
|
if (!guild || !data.user?.id) return;
|
|
4888
|
-
|
|
4889
|
-
if (
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
...data.user,
|
|
4898
|
-
username: data.user.username ?? "Unknown",
|
|
4899
|
-
discriminator: data.user.discriminator ?? "0"
|
|
4900
|
-
},
|
|
4901
|
-
roles: [],
|
|
4902
|
-
joined_at: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
4903
|
-
nick: null,
|
|
4904
|
-
mute: false,
|
|
4905
|
-
deaf: false
|
|
4906
|
-
},
|
|
4907
|
-
guild
|
|
4908
|
-
);
|
|
4909
|
-
}
|
|
6048
|
+
const cached = guild.members.get(data.user.id);
|
|
6049
|
+
if (cached) guild.members.delete(data.user.id);
|
|
6050
|
+
const user = client.getOrCreateUser(data.user);
|
|
6051
|
+
const member = cached ?? new PartialGuildMember({
|
|
6052
|
+
client,
|
|
6053
|
+
id: data.user.id,
|
|
6054
|
+
user,
|
|
6055
|
+
guild
|
|
6056
|
+
});
|
|
4910
6057
|
guild.adjustMemberCount(-1);
|
|
4911
6058
|
client.emit(Events.GuildMemberRemove, member);
|
|
4912
6059
|
},
|
|
@@ -4925,7 +6072,7 @@ var memberHandlers = {
|
|
|
4925
6072
|
members,
|
|
4926
6073
|
chunkIndex: data.chunk_index,
|
|
4927
6074
|
chunkCount: data.chunk_count,
|
|
4928
|
-
notFound: [],
|
|
6075
|
+
notFound: data.not_found ?? [],
|
|
4929
6076
|
nonce: data.nonce ?? null
|
|
4930
6077
|
};
|
|
4931
6078
|
client.emit(Events.GuildMembersChunk, payload);
|
|
@@ -4933,7 +6080,35 @@ var memberHandlers = {
|
|
|
4933
6080
|
};
|
|
4934
6081
|
|
|
4935
6082
|
// src/ClientCore/EventHandlers/Messages.ts
|
|
4936
|
-
|
|
6083
|
+
var import_util25 = require("@fluxerjs/util");
|
|
6084
|
+
function cachedTextChannel(client, channelId) {
|
|
6085
|
+
const channel = client.channels.get(channelId);
|
|
6086
|
+
return channel?.isTextBased() ? channel : null;
|
|
6087
|
+
}
|
|
6088
|
+
function cachedMessage(client, channelId, messageId) {
|
|
6089
|
+
const data = client._getMessageCache(channelId)?.get(messageId);
|
|
6090
|
+
return data ? new Message(client, data) : null;
|
|
6091
|
+
}
|
|
6092
|
+
function isHydratableMessage(data) {
|
|
6093
|
+
return Boolean(data.author?.id && data.timestamp);
|
|
6094
|
+
}
|
|
6095
|
+
function toPartialMessage(client, args) {
|
|
6096
|
+
const cached = args.cached;
|
|
6097
|
+
const authorId = args.authorId ?? cached?.author?.id ?? null;
|
|
6098
|
+
const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
|
|
6099
|
+
const createdAt = cached?.timestamp ? new Date(cached.timestamp) : import_util25.SnowflakeUtil.isValid(args.id) ? import_util25.SnowflakeUtil.dateFromSnowflake(args.id) : null;
|
|
6100
|
+
return new PartialMessage(client, {
|
|
6101
|
+
id: args.id,
|
|
6102
|
+
channelId: args.channelId,
|
|
6103
|
+
guildId: args.guildId ?? cached?.guild_id ?? null,
|
|
6104
|
+
channel: cachedTextChannel(client, args.channelId),
|
|
6105
|
+
content: args.content ?? cached?.content ?? null,
|
|
6106
|
+
authorId,
|
|
6107
|
+
author,
|
|
6108
|
+
createdAt
|
|
6109
|
+
});
|
|
6110
|
+
}
|
|
6111
|
+
function toReactionEmoji(emoji) {
|
|
4937
6112
|
return {
|
|
4938
6113
|
name: emoji.name,
|
|
4939
6114
|
...emoji.id !== void 0 ? { id: emoji.id } : {},
|
|
@@ -4950,9 +6125,12 @@ function emitReaction(event) {
|
|
|
4950
6125
|
const payload = {
|
|
4951
6126
|
reaction,
|
|
4952
6127
|
user,
|
|
6128
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6129
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
6130
|
+
member,
|
|
4953
6131
|
messageId: data.message_id,
|
|
4954
6132
|
channelId: data.channel_id,
|
|
4955
|
-
emoji:
|
|
6133
|
+
emoji: toReactionEmoji(data.emoji),
|
|
4956
6134
|
userId: data.user_id
|
|
4957
6135
|
};
|
|
4958
6136
|
client.emit(event, payload);
|
|
@@ -4972,37 +6150,60 @@ var messageHandlers = {
|
|
|
4972
6150
|
},
|
|
4973
6151
|
MESSAGE_UPDATE(client, d) {
|
|
4974
6152
|
const partial = d;
|
|
4975
|
-
const
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
if (
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
mergedData = { ...oldData, ...partial };
|
|
4983
|
-
}
|
|
6153
|
+
const oldData = client._getMessageCache(partial.channel_id)?.get(partial.id);
|
|
6154
|
+
const oldMessage = oldData ? new Message(client, oldData) : null;
|
|
6155
|
+
const mergedData = oldData ? { ...oldData, ...partial } : partial;
|
|
6156
|
+
if (isHydratableMessage(mergedData)) {
|
|
6157
|
+
client._addMessageToCache(partial.channel_id, mergedData);
|
|
6158
|
+
client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
|
|
6159
|
+
return;
|
|
4984
6160
|
}
|
|
4985
|
-
client.
|
|
4986
|
-
|
|
6161
|
+
client.emit(
|
|
6162
|
+
Events.MessageUpdate,
|
|
6163
|
+
oldMessage,
|
|
6164
|
+
toPartialMessage(client, {
|
|
6165
|
+
id: partial.id,
|
|
6166
|
+
channelId: partial.channel_id,
|
|
6167
|
+
guildId: partial.guild_id ?? oldData?.guild_id ?? null,
|
|
6168
|
+
content: partial.content ?? oldData?.content ?? null,
|
|
6169
|
+
authorId: partial.author?.id ?? oldData?.author?.id ?? null,
|
|
6170
|
+
cached: oldData
|
|
6171
|
+
})
|
|
6172
|
+
);
|
|
4987
6173
|
},
|
|
4988
6174
|
MESSAGE_DELETE(client, d) {
|
|
4989
6175
|
const data = d;
|
|
4990
|
-
client.
|
|
4991
|
-
client
|
|
6176
|
+
const cached = client._getMessageCache(data.channel_id)?.get(data.id);
|
|
6177
|
+
const payload = toPartialMessage(client, {
|
|
4992
6178
|
id: data.id,
|
|
4993
6179
|
channelId: data.channel_id,
|
|
4994
|
-
|
|
4995
|
-
content: data.content ?? null,
|
|
4996
|
-
authorId: data.author_id ?? null
|
|
6180
|
+
guildId: data.guild_id ?? cached?.guild_id ?? null,
|
|
6181
|
+
content: data.content ?? cached?.content ?? null,
|
|
6182
|
+
authorId: data.author_id ?? cached?.author?.id ?? null,
|
|
6183
|
+
cached
|
|
4997
6184
|
});
|
|
6185
|
+
client._removeMessageFromCache(data.channel_id, data.id);
|
|
6186
|
+
client.emit(Events.MessageDelete, payload);
|
|
4998
6187
|
},
|
|
4999
6188
|
MESSAGE_DELETE_BULK(client, d) {
|
|
5000
6189
|
const data = d;
|
|
5001
|
-
|
|
6190
|
+
const ids = data.ids ?? [];
|
|
6191
|
+
const cache = client._getMessageCache(data.channel_id);
|
|
6192
|
+
const messages = ids.map(
|
|
6193
|
+
(id) => toPartialMessage(client, {
|
|
6194
|
+
id,
|
|
6195
|
+
channelId: data.channel_id,
|
|
6196
|
+
guildId: data.guild_id ?? cache?.get(id)?.guild_id ?? null,
|
|
6197
|
+
cached: cache?.get(id)
|
|
6198
|
+
})
|
|
6199
|
+
);
|
|
6200
|
+
for (const id of ids) client._removeMessageFromCache(data.channel_id, id);
|
|
5002
6201
|
client.emit(Events.MessageDeleteBulk, {
|
|
5003
|
-
ids
|
|
6202
|
+
ids,
|
|
5004
6203
|
channelId: data.channel_id,
|
|
5005
|
-
guildId: data.guild_id ?? null
|
|
6204
|
+
guildId: data.guild_id ?? null,
|
|
6205
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
6206
|
+
messages
|
|
5006
6207
|
});
|
|
5007
6208
|
},
|
|
5008
6209
|
MESSAGE_REACTION_ADD: emitReaction(Events.MessageReactionAdd),
|
|
@@ -5012,7 +6213,9 @@ var messageHandlers = {
|
|
|
5012
6213
|
const payload = {
|
|
5013
6214
|
messageId: data.message_id,
|
|
5014
6215
|
channelId: data.channel_id,
|
|
5015
|
-
guildId: data.guild_id ?? null
|
|
6216
|
+
guildId: data.guild_id ?? null,
|
|
6217
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6218
|
+
channel: cachedTextChannel(client, data.channel_id)
|
|
5016
6219
|
};
|
|
5017
6220
|
client.emit(Events.MessageReactionRemoveAll, payload);
|
|
5018
6221
|
},
|
|
@@ -5022,7 +6225,9 @@ var messageHandlers = {
|
|
|
5022
6225
|
messageId: data.message_id,
|
|
5023
6226
|
channelId: data.channel_id,
|
|
5024
6227
|
guildId: data.guild_id ?? null,
|
|
5025
|
-
emoji:
|
|
6228
|
+
emoji: toReactionEmoji(data.emoji),
|
|
6229
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6230
|
+
channel: cachedTextChannel(client, data.channel_id)
|
|
5026
6231
|
};
|
|
5027
6232
|
client.emit(Events.MessageReactionRemoveEmoji, payload);
|
|
5028
6233
|
},
|
|
@@ -5041,7 +6246,7 @@ var messageHandlers = {
|
|
|
5041
6246
|
}
|
|
5042
6247
|
reactions.push({
|
|
5043
6248
|
userId: entry.user_id,
|
|
5044
|
-
emoji:
|
|
6249
|
+
emoji: toReactionEmoji(entry.emoji),
|
|
5045
6250
|
member
|
|
5046
6251
|
});
|
|
5047
6252
|
}
|
|
@@ -5049,6 +6254,8 @@ var messageHandlers = {
|
|
|
5049
6254
|
channelId: data.channel_id,
|
|
5050
6255
|
messageId: data.message_id,
|
|
5051
6256
|
guildId: data.guild_id ?? null,
|
|
6257
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6258
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
5052
6259
|
reactions
|
|
5053
6260
|
};
|
|
5054
6261
|
client.emit(Events.MessageReactionAddMany, payload);
|
|
@@ -5223,10 +6430,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
|
|
|
5223
6430
|
for (const g of guilds ?? []) {
|
|
5224
6431
|
if (g.unavailable === true) {
|
|
5225
6432
|
if (typeof g.id === "string") {
|
|
5226
|
-
|
|
5227
|
-
if (
|
|
5228
|
-
|
|
6433
|
+
let guild = client.guilds.get(g.id);
|
|
6434
|
+
if (!guild) {
|
|
6435
|
+
guild = new Guild(client, { id: g.id });
|
|
6436
|
+
guild.available = false;
|
|
6437
|
+
client.guilds.set(g.id, guild);
|
|
6438
|
+
} else if (guild.available !== false) {
|
|
6439
|
+
guild.available = false;
|
|
5229
6440
|
}
|
|
6441
|
+
client._readyStubGuildIds.add(g.id);
|
|
5230
6442
|
if (pending !== null) pending.add(g.id);
|
|
5231
6443
|
}
|
|
5232
6444
|
continue;
|
|
@@ -5254,22 +6466,36 @@ function clearGuildStreamSettle(client) {
|
|
|
5254
6466
|
clearTimeout(client._guildStreamSettleTimeout);
|
|
5255
6467
|
client._guildStreamSettleTimeout = null;
|
|
5256
6468
|
}
|
|
6469
|
+
function resetGuildStreamSettle(client) {
|
|
6470
|
+
clearGuildStreamSettle(client);
|
|
6471
|
+
client._guildStreamSettleTimeout = setTimeout(() => {
|
|
6472
|
+
client._guildStreamSettleTimeout = null;
|
|
6473
|
+
if (client.readyAt === null) finalizeClientReady(client);
|
|
6474
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
6475
|
+
}
|
|
5257
6476
|
function handleReadyPayload(client, data) {
|
|
5258
6477
|
client.user = new ClientUser(client, data.user);
|
|
5259
6478
|
const waitForGuilds = client.options.waitForGuilds === true;
|
|
5260
6479
|
const guilds = data.guilds ?? [];
|
|
5261
6480
|
const pending = hydrateReadyGuilds(client, guilds, waitForGuilds);
|
|
5262
|
-
if (
|
|
5263
|
-
|
|
6481
|
+
if (client.readyAt !== null) {
|
|
6482
|
+
if (pending !== null && pending.size > 0) {
|
|
6483
|
+
const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
|
|
6484
|
+
for (const id of pending) existing.add(id);
|
|
6485
|
+
client._pendingGuildIds = existing;
|
|
6486
|
+
}
|
|
5264
6487
|
return;
|
|
5265
6488
|
}
|
|
5266
|
-
if (
|
|
5267
|
-
client.
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
}, GUILD_STREAM_SETTLE_MS);
|
|
6489
|
+
if (pending !== null && pending.size > 0) {
|
|
6490
|
+
const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
|
|
6491
|
+
for (const id of pending) existing.add(id);
|
|
6492
|
+
client._pendingGuildIds = existing;
|
|
5271
6493
|
return;
|
|
5272
6494
|
}
|
|
6495
|
+
if (guilds.length === 0) {
|
|
6496
|
+
resetGuildStreamSettle(client);
|
|
6497
|
+
if (waitForGuilds) return;
|
|
6498
|
+
}
|
|
5273
6499
|
finalizeClientReady(client);
|
|
5274
6500
|
}
|
|
5275
6501
|
async function connectClientGateway(client, token, signal) {
|
|
@@ -5279,7 +6505,7 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5279
6505
|
const ws = new import_ws.WebSocketManager({
|
|
5280
6506
|
token,
|
|
5281
6507
|
intents: client.options.intents ?? 0,
|
|
5282
|
-
presence: client.options.presence,
|
|
6508
|
+
presence: client.options.presence ? toPresenceWire(client.options.presence) : void 0,
|
|
5283
6509
|
flags: client.options.identifyFlags,
|
|
5284
6510
|
ignoredEvents: client.options.ignoredEvents,
|
|
5285
6511
|
initialGuildId: client.options.initialGuildId,
|
|
@@ -5288,24 +6514,57 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5288
6514
|
},
|
|
5289
6515
|
version: client.options.rest?.version ?? "1",
|
|
5290
6516
|
debug: client.options.gatewayDebug !== false,
|
|
5291
|
-
WebSocket: client.options.WebSocket
|
|
6517
|
+
WebSocket: client.options.WebSocket,
|
|
6518
|
+
shardCount: client.options.shardCount ?? client.options.totalShards,
|
|
6519
|
+
shardIds: client.options.shardIds ?? client.options.shardList,
|
|
6520
|
+
guildsPerShard: client.options.guildsPerShard,
|
|
6521
|
+
buildStrategy: client.options.buildStrategy,
|
|
6522
|
+
sessionStore: client.options.sessionStore,
|
|
6523
|
+
identifyThrottler: client.options.identifyThrottler
|
|
5292
6524
|
});
|
|
5293
6525
|
ws.on("dispatch", ({ payload }) => {
|
|
5294
6526
|
handleGatewayDispatch(client, payload, client._deferredGatewayDispatches).catch(
|
|
5295
6527
|
(err) => emitClientError(client, err)
|
|
5296
6528
|
);
|
|
5297
6529
|
});
|
|
5298
|
-
ws.on("ready", ({ data }) => {
|
|
5299
|
-
|
|
6530
|
+
ws.on("ready", ({ shardId, data }) => {
|
|
6531
|
+
client.emit(Events.ShardReady, shardId);
|
|
6532
|
+
try {
|
|
6533
|
+
handleReadyPayload(client, data);
|
|
6534
|
+
} catch (err) {
|
|
6535
|
+
emitClientError(client, err);
|
|
6536
|
+
}
|
|
6537
|
+
});
|
|
6538
|
+
ws.on("resumed", (shardId) => {
|
|
6539
|
+
client.emit(Events.ShardResumed, shardId);
|
|
6540
|
+
});
|
|
6541
|
+
ws.on("close", ({ shardId, code }) => {
|
|
6542
|
+
client.emit(Events.ShardDisconnect, shardId, code);
|
|
6543
|
+
if (code === import_ws.GatewayCloseCodes.AuthenticationFailed) {
|
|
6544
|
+
emitClientError(
|
|
6545
|
+
client,
|
|
6546
|
+
new import_util2.FluxerError("Gateway authentication failed (4004). Check the bot token.", {
|
|
6547
|
+
code: import_util.ErrorCodes.InvalidToken
|
|
6548
|
+
})
|
|
6549
|
+
);
|
|
6550
|
+
}
|
|
5300
6551
|
});
|
|
5301
|
-
ws.on("error", ({ error }) => {
|
|
5302
|
-
|
|
6552
|
+
ws.on("error", ({ shardId, error }) => {
|
|
6553
|
+
if (shardId >= 0) client.emit(Events.ShardError, shardId, error);
|
|
6554
|
+
client.logger.error("gateway error", {
|
|
6555
|
+
error: error.message,
|
|
6556
|
+
name: error.name,
|
|
6557
|
+
shardId
|
|
6558
|
+
});
|
|
5303
6559
|
client.emit(Events.Error, error);
|
|
5304
6560
|
});
|
|
5305
6561
|
ws.on("debug", (msg) => {
|
|
5306
6562
|
client.logger.debug(msg);
|
|
5307
6563
|
client.emit(Events.Debug, msg);
|
|
5308
6564
|
});
|
|
6565
|
+
ws.on("shardingRequired", (payload) => {
|
|
6566
|
+
client.emit(Events.ShardingRequired, payload);
|
|
6567
|
+
});
|
|
5309
6568
|
client._ws = ws;
|
|
5310
6569
|
const onAbort = () => {
|
|
5311
6570
|
ws.destroy();
|
|
@@ -5331,9 +6590,9 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5331
6590
|
}
|
|
5332
6591
|
|
|
5333
6592
|
// src/ClientCore/GuildManager.ts
|
|
5334
|
-
var
|
|
5335
|
-
var
|
|
5336
|
-
var GuildManager = class extends
|
|
6593
|
+
var import_collection13 = require("@fluxerjs/collection");
|
|
6594
|
+
var import_types37 = require("@fluxerjs/types");
|
|
6595
|
+
var GuildManager = class extends import_collection13.LimitedCollection {
|
|
5337
6596
|
constructor(client) {
|
|
5338
6597
|
super({
|
|
5339
6598
|
maxSize: client.cache.limits.guilds,
|
|
@@ -5342,8 +6601,8 @@ var GuildManager = class extends import_collection10.LimitedCollection {
|
|
|
5342
6601
|
this.client = client;
|
|
5343
6602
|
}
|
|
5344
6603
|
/**
|
|
5345
|
-
* Remove a guild and cascade its channels / message caches.
|
|
5346
|
-
*
|
|
6604
|
+
* Remove a guild from cache and cascade its channels / message caches.
|
|
6605
|
+
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
5347
6606
|
*/
|
|
5348
6607
|
delete(key) {
|
|
5349
6608
|
const guild = this.get(key);
|
|
@@ -5371,7 +6630,7 @@ var GuildManager = class extends import_collection10.LimitedCollection {
|
|
|
5371
6630
|
const cached = this.get(guildId);
|
|
5372
6631
|
if (cached && !options?.force) return cached;
|
|
5373
6632
|
try {
|
|
5374
|
-
const data = await this.client.rest.get(
|
|
6633
|
+
const data = await this.client.rest.get(import_types37.Routes.guild(guildId));
|
|
5375
6634
|
if (cached) {
|
|
5376
6635
|
cached._patch(data);
|
|
5377
6636
|
return cached;
|
|
@@ -5456,180 +6715,11 @@ var MessageCache = class {
|
|
|
5456
6715
|
}
|
|
5457
6716
|
};
|
|
5458
6717
|
|
|
5459
|
-
// src/ClientCore/PackManager.ts
|
|
5460
|
-
var import_types37 = require("@fluxerjs/types");
|
|
5461
|
-
function toPackSummaryPayload(data) {
|
|
5462
|
-
return {
|
|
5463
|
-
id: data.id,
|
|
5464
|
-
name: data.name,
|
|
5465
|
-
description: data.description,
|
|
5466
|
-
type: data.type,
|
|
5467
|
-
creatorId: data.creator_id,
|
|
5468
|
-
createdAt: data.created_at,
|
|
5469
|
-
updatedAt: data.updated_at,
|
|
5470
|
-
...data.installed_at !== void 0 ? { installedAt: data.installed_at } : {}
|
|
5471
|
-
};
|
|
5472
|
-
}
|
|
5473
|
-
function toEmojiPayload(data) {
|
|
5474
|
-
return {
|
|
5475
|
-
id: data.id,
|
|
5476
|
-
name: data.name,
|
|
5477
|
-
animated: data.animated
|
|
5478
|
-
};
|
|
5479
|
-
}
|
|
5480
|
-
function toStickerPayload(data) {
|
|
5481
|
-
return {
|
|
5482
|
-
id: data.id,
|
|
5483
|
-
name: data.name,
|
|
5484
|
-
description: data.description,
|
|
5485
|
-
tags: data.tags,
|
|
5486
|
-
animated: data.animated,
|
|
5487
|
-
nsfw: data.nsfw
|
|
5488
|
-
};
|
|
5489
|
-
}
|
|
5490
|
-
function toInvitePayload(data) {
|
|
5491
|
-
return {
|
|
5492
|
-
code: data.code,
|
|
5493
|
-
...data.max_uses !== void 0 ? { maxUses: data.max_uses } : {},
|
|
5494
|
-
...data.max_age !== void 0 ? { maxAge: data.max_age } : {},
|
|
5495
|
-
...data.uses !== void 0 ? { uses: data.uses } : {},
|
|
5496
|
-
...data.temporary !== void 0 ? { temporary: data.temporary } : {},
|
|
5497
|
-
...data.created_at !== void 0 ? { createdAt: data.created_at } : {},
|
|
5498
|
-
...data.expires_at !== void 0 ? { expiresAt: data.expires_at } : {}
|
|
5499
|
-
};
|
|
5500
|
-
}
|
|
5501
|
-
function mapDashboardSection(section) {
|
|
5502
|
-
return {
|
|
5503
|
-
installedLimit: section.installed_limit,
|
|
5504
|
-
createdLimit: section.created_limit,
|
|
5505
|
-
installed: section.installed.map(toPackSummaryPayload),
|
|
5506
|
-
created: section.created.map(toPackSummaryPayload)
|
|
5507
|
-
};
|
|
5508
|
-
}
|
|
5509
|
-
var PackManager = class {
|
|
5510
|
-
constructor(client) {
|
|
5511
|
-
this.client = client;
|
|
5512
|
-
}
|
|
5513
|
-
/** Fetch the current user's pack dashboard (camelCase summaries). */
|
|
5514
|
-
async fetchDashboard() {
|
|
5515
|
-
const data = await this.client.rest.get(import_types37.Routes.packs());
|
|
5516
|
-
return {
|
|
5517
|
-
emoji: mapDashboardSection(data.emoji),
|
|
5518
|
-
sticker: mapDashboardSection(data.sticker)
|
|
5519
|
-
};
|
|
5520
|
-
}
|
|
5521
|
-
/** Create a pack. */
|
|
5522
|
-
async create(packType, body) {
|
|
5523
|
-
const data = await this.client.rest.post(import_types37.Routes.packsByType(packType), {
|
|
5524
|
-
body
|
|
5525
|
-
});
|
|
5526
|
-
return toPackSummaryPayload(data);
|
|
5527
|
-
}
|
|
5528
|
-
/** Edit a pack. */
|
|
5529
|
-
async edit(packId, body) {
|
|
5530
|
-
const data = await this.client.rest.patch(import_types37.Routes.pack(packId), { body });
|
|
5531
|
-
return toPackSummaryPayload(data);
|
|
5532
|
-
}
|
|
5533
|
-
/** Delete a pack. */
|
|
5534
|
-
async delete(packId) {
|
|
5535
|
-
await this.client.rest.delete(import_types37.Routes.pack(packId));
|
|
5536
|
-
}
|
|
5537
|
-
/** Install a pack for the current user. */
|
|
5538
|
-
async install(packId) {
|
|
5539
|
-
await this.client.rest.post(import_types37.Routes.packInstall(packId));
|
|
5540
|
-
}
|
|
5541
|
-
/** Uninstall a pack for the current user. */
|
|
5542
|
-
async uninstall(packId) {
|
|
5543
|
-
await this.client.rest.delete(import_types37.Routes.packInstall(packId));
|
|
5544
|
-
}
|
|
5545
|
-
/** List invites for a pack. */
|
|
5546
|
-
async listInvites(packId) {
|
|
5547
|
-
const data = await this.client.rest.get(import_types37.Routes.packInvites(packId));
|
|
5548
|
-
return data.map(toInvitePayload);
|
|
5549
|
-
}
|
|
5550
|
-
/** Create an invite for a pack. */
|
|
5551
|
-
async createInvite(packId, options = {}) {
|
|
5552
|
-
const body = toPackInviteBody(options);
|
|
5553
|
-
const data = await this.client.rest.post(import_types37.Routes.packInvites(packId), {
|
|
5554
|
-
body: Object.keys(body).length ? body : void 0
|
|
5555
|
-
});
|
|
5556
|
-
return toInvitePayload(data);
|
|
5557
|
-
}
|
|
5558
|
-
/** List emojis in a pack. */
|
|
5559
|
-
async listEmojis(packId) {
|
|
5560
|
-
const data = await this.client.rest.get(import_types37.Routes.packEmojis(packId));
|
|
5561
|
-
return data.map(toEmojiPayload);
|
|
5562
|
-
}
|
|
5563
|
-
/** Create an emoji in a pack. */
|
|
5564
|
-
async createEmoji(packId, options) {
|
|
5565
|
-
const data = await this.client.rest.post(import_types37.Routes.packEmojis(packId), {
|
|
5566
|
-
body: toEmojiCreateBody(options)
|
|
5567
|
-
});
|
|
5568
|
-
return toEmojiPayload(data);
|
|
5569
|
-
}
|
|
5570
|
-
/** Bulk-create emojis in a pack. */
|
|
5571
|
-
async createEmojisBulk(packId, emojis) {
|
|
5572
|
-
const data = await this.client.rest.post(
|
|
5573
|
-
import_types37.Routes.packEmojisBulk(packId),
|
|
5574
|
-
{ body: { emojis: emojis.map(toEmojiCreateBody) } }
|
|
5575
|
-
);
|
|
5576
|
-
return {
|
|
5577
|
-
success: data.success.map(toEmojiPayload),
|
|
5578
|
-
failed: data.failed
|
|
5579
|
-
};
|
|
5580
|
-
}
|
|
5581
|
-
/** Edit an emoji in a pack. */
|
|
5582
|
-
async editEmoji(packId, emojiId, options) {
|
|
5583
|
-
const data = await this.client.rest.patch(import_types37.Routes.packEmoji(packId, emojiId), {
|
|
5584
|
-
body: toEmojiEditBody(options)
|
|
5585
|
-
});
|
|
5586
|
-
return toEmojiPayload(data);
|
|
5587
|
-
}
|
|
5588
|
-
/** Delete an emoji from a pack. */
|
|
5589
|
-
async deleteEmoji(packId, emojiId) {
|
|
5590
|
-
await this.client.rest.delete(import_types37.Routes.packEmoji(packId, emojiId));
|
|
5591
|
-
}
|
|
5592
|
-
/** List stickers in a pack. */
|
|
5593
|
-
async listStickers(packId) {
|
|
5594
|
-
const data = await this.client.rest.get(import_types37.Routes.packStickers(packId));
|
|
5595
|
-
return data.map(toStickerPayload);
|
|
5596
|
-
}
|
|
5597
|
-
/** Create a sticker in a pack. */
|
|
5598
|
-
async createSticker(packId, options) {
|
|
5599
|
-
const data = await this.client.rest.post(import_types37.Routes.packStickers(packId), {
|
|
5600
|
-
body: toStickerCreateBody(options)
|
|
5601
|
-
});
|
|
5602
|
-
return toStickerPayload(data);
|
|
5603
|
-
}
|
|
5604
|
-
/** Bulk-create stickers in a pack. */
|
|
5605
|
-
async createStickersBulk(packId, stickers) {
|
|
5606
|
-
const data = await this.client.rest.post(
|
|
5607
|
-
import_types37.Routes.packStickersBulk(packId),
|
|
5608
|
-
{ body: { stickers: stickers.map(toStickerCreateBody) } }
|
|
5609
|
-
);
|
|
5610
|
-
return {
|
|
5611
|
-
success: data.success.map(toStickerPayload),
|
|
5612
|
-
failed: data.failed
|
|
5613
|
-
};
|
|
5614
|
-
}
|
|
5615
|
-
/** Edit a sticker in a pack. */
|
|
5616
|
-
async editSticker(packId, stickerId, options) {
|
|
5617
|
-
const data = await this.client.rest.patch(import_types37.Routes.packSticker(packId, stickerId), {
|
|
5618
|
-
body: toStickerEditBody(options)
|
|
5619
|
-
});
|
|
5620
|
-
return toStickerPayload(data);
|
|
5621
|
-
}
|
|
5622
|
-
/** Delete a sticker from a pack. */
|
|
5623
|
-
async deleteSticker(packId, stickerId) {
|
|
5624
|
-
await this.client.rest.delete(import_types37.Routes.packSticker(packId, stickerId));
|
|
5625
|
-
}
|
|
5626
|
-
};
|
|
5627
|
-
|
|
5628
6718
|
// src/ClientCore/UserManager.ts
|
|
5629
|
-
var
|
|
6719
|
+
var import_collection14 = require("@fluxerjs/collection");
|
|
5630
6720
|
var import_types38 = require("@fluxerjs/types");
|
|
5631
6721
|
var soft = (p) => p.catch(() => null);
|
|
5632
|
-
var UserManager = class extends
|
|
6722
|
+
var UserManager = class extends import_collection14.LimitedCollection {
|
|
5633
6723
|
constructor(client) {
|
|
5634
6724
|
super({ maxSize: client.cache.limits.users });
|
|
5635
6725
|
this.client = client;
|
|
@@ -5647,11 +6737,17 @@ var UserManager = class extends import_collection11.LimitedCollection {
|
|
|
5647
6737
|
}
|
|
5648
6738
|
return removed;
|
|
5649
6739
|
}
|
|
5650
|
-
/** Fetch a user by ID and update cache. */
|
|
5651
|
-
async fetch(userId) {
|
|
6740
|
+
/** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
|
|
6741
|
+
async fetch(userId, options) {
|
|
6742
|
+
const cached = this.get(userId);
|
|
6743
|
+
if (cached && !options?.force) return cached;
|
|
5652
6744
|
const data = await this.client.rest.get(import_types38.Routes.user(userId));
|
|
5653
6745
|
return this.client.getOrCreateUser(data);
|
|
5654
6746
|
}
|
|
6747
|
+
/** Return a cached user, otherwise {@link fetch}. */
|
|
6748
|
+
async resolve(userId) {
|
|
6749
|
+
return this.get(userId) ?? this.fetch(userId);
|
|
6750
|
+
}
|
|
5655
6751
|
/**
|
|
5656
6752
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
5657
6753
|
* @example
|
|
@@ -5711,19 +6807,32 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5711
6807
|
users;
|
|
5712
6808
|
/** Cache limits, stats, sweeps, and cascade entry points. */
|
|
5713
6809
|
cache;
|
|
5714
|
-
/**
|
|
5715
|
-
packs = new PackManager(this);
|
|
5716
|
-
/** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
|
|
6810
|
+
/** Typed event handlers. Prefer `client.on(Events.*, ...)`. */
|
|
5717
6811
|
events;
|
|
5718
6812
|
/** The authenticated bot user. Null until READY is received. */
|
|
5719
6813
|
user = null;
|
|
5720
6814
|
/** Timestamp when the client became ready. Null until READY is received. */
|
|
5721
6815
|
readyAt = null;
|
|
6816
|
+
/**
|
|
6817
|
+
* Milliseconds since {@link readyAt}, or `null` if the client is not ready.
|
|
6818
|
+
* @example
|
|
6819
|
+
* client.on(Events.Ready, () => {
|
|
6820
|
+
* console.log(client.uptime);
|
|
6821
|
+
* });
|
|
6822
|
+
*/
|
|
6823
|
+
get uptime() {
|
|
6824
|
+
return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
|
|
6825
|
+
}
|
|
5722
6826
|
/** @internal WebSocket manager. */
|
|
5723
6827
|
_ws = null;
|
|
5724
6828
|
/** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
|
|
5725
6829
|
_pendingGuildIds = null;
|
|
5726
|
-
/**
|
|
6830
|
+
/** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
|
|
6831
|
+
_readyStubGuildIds = /* @__PURE__ */ new Set();
|
|
6832
|
+
/**
|
|
6833
|
+
* @internal Empty-READY guild stream window.
|
|
6834
|
+
* Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
|
|
6835
|
+
*/
|
|
5727
6836
|
_guildStreamSettleTimeout = null;
|
|
5728
6837
|
/** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
|
|
5729
6838
|
_deferredGatewayDispatches = [];
|
|
@@ -5740,7 +6849,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5740
6849
|
cache: resolved.cache,
|
|
5741
6850
|
defaultReplyPing: options.defaultReplyPing ?? true
|
|
5742
6851
|
};
|
|
5743
|
-
this.logger = options.logger ?? (0,
|
|
6852
|
+
this.logger = options.logger ?? (0, import_util26.createLogger)({
|
|
5744
6853
|
level: options.logLevel ?? "warn"
|
|
5745
6854
|
});
|
|
5746
6855
|
this.cache = new CacheController(this, resolved.limits);
|
|
@@ -5754,7 +6863,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5754
6863
|
const restApi = options.rest?.api;
|
|
5755
6864
|
if (options.instance !== void 0) {
|
|
5756
6865
|
this.instance = resolveInstanceEndpoints(options.instance);
|
|
5757
|
-
resolveRestApi(this.instance.endpoints.
|
|
6866
|
+
resolveRestApi(this.instance.endpoints.api_public, restApi);
|
|
5758
6867
|
} else {
|
|
5759
6868
|
this.instance = resolveInstanceEndpoints(
|
|
5760
6869
|
restApi !== void 0 ? { api: restApi } : void 0
|
|
@@ -5767,27 +6876,31 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5767
6876
|
}
|
|
5768
6877
|
this.rest = new import_rest3.REST({
|
|
5769
6878
|
...this.options.rest,
|
|
5770
|
-
api: this.instance.endpoints.
|
|
5771
|
-
version: this.options.rest?.version ?? "1"
|
|
6879
|
+
api: this.instance.endpoints.api_public,
|
|
6880
|
+
version: this.options.rest?.version ?? "1",
|
|
6881
|
+
locale: this.options.locale ?? this.options.rest?.locale
|
|
5772
6882
|
});
|
|
5773
6883
|
}
|
|
5774
6884
|
/**
|
|
5775
6885
|
* Create a client from instance discovery (`GET /.well-known/fluxer`).
|
|
5776
|
-
*
|
|
6886
|
+
* Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
|
|
6887
|
+
* Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
|
|
6888
|
+
* Does not log in. Call {@link login} with a token afterward.
|
|
5777
6889
|
*
|
|
5778
|
-
* @param origin -
|
|
5779
|
-
* @param options - Client options (must not conflict with discovered `endpoints.
|
|
6890
|
+
* @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
|
|
6891
|
+
* @param options - Client options (must not conflict with discovered `endpoints.api_public`)
|
|
5780
6892
|
* @param connectOptions - Optional abort signal for the discovery request
|
|
5781
6893
|
*/
|
|
5782
6894
|
static async fromDiscovery(origin, options = {}, connectOptions) {
|
|
5783
|
-
const
|
|
6895
|
+
const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
|
|
5784
6896
|
const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
|
|
5785
6897
|
const bootstrap = new import_rest3.REST({
|
|
5786
6898
|
...options.rest ?? {},
|
|
5787
|
-
api:
|
|
5788
|
-
version
|
|
6899
|
+
api: bootstrapOrigin,
|
|
6900
|
+
version,
|
|
6901
|
+
locale: options.locale ?? options.rest?.locale
|
|
5789
6902
|
});
|
|
5790
|
-
const raw = await bootstrap.get(
|
|
6903
|
+
const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
|
|
5791
6904
|
auth: false,
|
|
5792
6905
|
...connectOptions?.signal ? { signal: connectOptions.signal } : {}
|
|
5793
6906
|
});
|
|
@@ -5795,7 +6908,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5795
6908
|
const { rest, ...restOptions } = options;
|
|
5796
6909
|
return new _Client({
|
|
5797
6910
|
...restOptions,
|
|
5798
|
-
// Drop rest.api so discovered endpoints.
|
|
6911
|
+
// Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
|
|
5799
6912
|
...rest ? { rest: { ...rest, api: void 0 } } : {},
|
|
5800
6913
|
instance: discovery
|
|
5801
6914
|
});
|
|
@@ -5822,7 +6935,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5822
6935
|
return resolveClientEmoji(this, emoji, guildId);
|
|
5823
6936
|
}
|
|
5824
6937
|
/**
|
|
5825
|
-
* Fetch instance discovery document (
|
|
6938
|
+
* Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
|
|
5826
6939
|
* @returns Instance configuration (endpoints, features, metadata)
|
|
5827
6940
|
*/
|
|
5828
6941
|
fetchInstance() {
|
|
@@ -5859,33 +6972,23 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5859
6972
|
return fetchApplication(this);
|
|
5860
6973
|
}
|
|
5861
6974
|
/**
|
|
5862
|
-
* Fetch OAuth2 applications
|
|
5863
|
-
*
|
|
6975
|
+
* Fetch OAuth2 applications (`GET /oauth2/applications/@me`).
|
|
6976
|
+
* A bot token returns the bot application object (normalized to a one-element array).
|
|
6977
|
+
* A user token returns the owner's application list.
|
|
5864
6978
|
*/
|
|
5865
6979
|
fetchOAuthApplications() {
|
|
5866
6980
|
return fetchOAuthApplications(this);
|
|
5867
6981
|
}
|
|
5868
|
-
/**
|
|
5869
|
-
* Check username#discriminator availability.
|
|
5870
|
-
* @param username - Username to check
|
|
5871
|
-
* @param discriminator - Discriminator to check
|
|
5872
|
-
* @returns Availability result
|
|
5873
|
-
*/
|
|
5874
|
-
checkUsernameTag(username, discriminator) {
|
|
5875
|
-
return checkUsernameTag(this, username, discriminator);
|
|
5876
|
-
}
|
|
5877
6982
|
/**
|
|
5878
6983
|
* Preload recent messages for multiple channels (batch endpoint).
|
|
5879
|
-
* @
|
|
5880
|
-
* @returns Preload response with message counts/timestamps
|
|
6984
|
+
* Prefer this over {@link bulkFetchMessages} for bots (`bulkFetchMessages` is user-account only).
|
|
5881
6985
|
*/
|
|
5882
6986
|
preloadMessages(channelIds) {
|
|
5883
6987
|
return preloadMessages(this, channelIds);
|
|
5884
6988
|
}
|
|
5885
6989
|
/**
|
|
5886
6990
|
* Preload recent messages (alternate endpoint).
|
|
5887
|
-
*
|
|
5888
|
-
* @returns Preload response with message counts/timestamps
|
|
6991
|
+
* Prefer this over {@link bulkFetchMessages} for bots.
|
|
5889
6992
|
*/
|
|
5890
6993
|
preloadMessagesAlt(channelIds) {
|
|
5891
6994
|
return preloadMessagesAlt(this, channelIds);
|
|
@@ -5893,6 +6996,14 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5893
6996
|
bulkFetchMessages(requests, options = {}) {
|
|
5894
6997
|
return bulkFetchMessages(this, requests, options);
|
|
5895
6998
|
}
|
|
6999
|
+
/**
|
|
7000
|
+
* Search messages in the current bot scope (`POST /search/messages`, `scope: current`).
|
|
7001
|
+
* Other scopes are denied for bots (`BOT_SEARCH_SCOPE_UNAVAILABLE`).
|
|
7002
|
+
* Returns camelCase results (`hitsPerPage`) or `{ indexing: true }` while channels are indexed.
|
|
7003
|
+
*/
|
|
7004
|
+
searchMessages(options) {
|
|
7005
|
+
return searchMessages(this, options);
|
|
7006
|
+
}
|
|
5896
7007
|
/** @internal */
|
|
5897
7008
|
_getMessageCache(channelId) {
|
|
5898
7009
|
return this._messageCache.get(channelId);
|
|
@@ -5916,12 +7027,16 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5916
7027
|
/**
|
|
5917
7028
|
* Sweep cached messages (remove entries matching filter).
|
|
5918
7029
|
* Prefer {@link CacheController.sweepMessages} (`client.cache.sweepMessages`).
|
|
7030
|
+
* The filter receives a hydrated {@link Message} (`createdAt`), not the stored wire payload.
|
|
5919
7031
|
* @param filter - Predicate to test each message (return true to remove)
|
|
5920
7032
|
* @param channelId - Optional channel ID to scope sweep
|
|
5921
7033
|
* @returns Count of messages removed
|
|
5922
7034
|
*/
|
|
5923
7035
|
sweepMessages(filter, channelId) {
|
|
5924
|
-
return this._messageCache.sweep(
|
|
7036
|
+
return this._messageCache.sweep(
|
|
7037
|
+
filter ? (data, chId) => filter(new Message(this, data), chId) : void 0,
|
|
7038
|
+
channelId
|
|
7039
|
+
);
|
|
5925
7040
|
}
|
|
5926
7041
|
/**
|
|
5927
7042
|
* Sweep cached members across all guilds (remove entries matching filter).
|
|
@@ -5954,6 +7069,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5954
7069
|
}
|
|
5955
7070
|
/**
|
|
5956
7071
|
* The underlying {@link WebSocketManager} (throws if not logged in).
|
|
7072
|
+
* Gateway heartbeat ACK latency: `client.ws.ping` (ms, or `-1` before the first ACK).
|
|
7073
|
+
* @example
|
|
7074
|
+
* console.log(client.ws.ping);
|
|
5957
7075
|
* @throws {@link FluxerError} with {@link ErrorCodes.NotLoggedIn}
|
|
5958
7076
|
*/
|
|
5959
7077
|
get ws() {
|
|
@@ -5992,6 +7110,37 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
5992
7110
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
5993
7111
|
this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildMembers, d: data });
|
|
5994
7112
|
}
|
|
7113
|
+
/**
|
|
7114
|
+
* Request guild member/online counts via gateway opcode 15.
|
|
7115
|
+
* Listen for `guildCountsUpdate`. Cached `guild.memberCount` / `guild.onlineCount` update when that event arrives.
|
|
7116
|
+
*/
|
|
7117
|
+
requestGuildCounts(options) {
|
|
7118
|
+
const guildIds = [...new Set(options.guildIds.filter(Boolean))];
|
|
7119
|
+
if (!guildIds.length) {
|
|
7120
|
+
throw new import_util2.FluxerError("requestGuildCounts requires at least one guildId", {
|
|
7121
|
+
code: import_util.ErrorCodes.InvalidGatewayRequest
|
|
7122
|
+
});
|
|
7123
|
+
}
|
|
7124
|
+
const data = { guild_ids: guildIds };
|
|
7125
|
+
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
7126
|
+
this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildCounts, d: data });
|
|
7127
|
+
}
|
|
7128
|
+
/**
|
|
7129
|
+
* Request per-channel member counts via gateway opcode 16.
|
|
7130
|
+
* Event-only: listen for `channelMemberCountsUpdate`. There is no `channel.memberCount` field.
|
|
7131
|
+
*/
|
|
7132
|
+
requestChannelMemberCounts(options) {
|
|
7133
|
+
if (!options.guildId) {
|
|
7134
|
+
throw new import_util2.FluxerError("requestChannelMemberCounts requires guildId", {
|
|
7135
|
+
code: import_util.ErrorCodes.InvalidGatewayRequest
|
|
7136
|
+
});
|
|
7137
|
+
}
|
|
7138
|
+
const data = { guild_id: options.guildId };
|
|
7139
|
+
if (options.channelId !== void 0) data.channel_id = options.channelId;
|
|
7140
|
+
if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
|
|
7141
|
+
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
7142
|
+
this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestChannelMemberCounts, d: data });
|
|
7143
|
+
}
|
|
5995
7144
|
/**
|
|
5996
7145
|
* Broadcast a gateway payload to all shards.
|
|
5997
7146
|
* @param payload - Gateway send payload
|
|
@@ -6005,9 +7154,13 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6005
7154
|
}
|
|
6006
7155
|
/**
|
|
6007
7156
|
* Connect to the gateway with a bot token.
|
|
7157
|
+
* @example
|
|
7158
|
+
* const client = new Client();
|
|
7159
|
+
* client.on(Events.Ready, () => console.log('Ready!'));
|
|
7160
|
+
* await client.login(process.env.FLUXER_BOT_TOKEN);
|
|
6008
7161
|
* @param token - Bot token from the developer portal
|
|
6009
7162
|
* @param options - Optional abort signal for cancellation
|
|
6010
|
-
* @returns
|
|
7163
|
+
* @returns This client (for chaining)
|
|
6011
7164
|
* @throws {@link FluxerError} if already logged in or token is invalid
|
|
6012
7165
|
*/
|
|
6013
7166
|
async login(token, options) {
|
|
@@ -6022,7 +7175,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6022
7175
|
this.rest.setToken(token);
|
|
6023
7176
|
try {
|
|
6024
7177
|
this._ws = await connectClientGateway(this, token, options?.signal);
|
|
6025
|
-
return
|
|
7178
|
+
return this;
|
|
6026
7179
|
} catch (err) {
|
|
6027
7180
|
this._ws?.destroy();
|
|
6028
7181
|
this._ws = null;
|
|
@@ -6051,6 +7204,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6051
7204
|
this.user = null;
|
|
6052
7205
|
this.readyAt = null;
|
|
6053
7206
|
this._pendingGuildIds = null;
|
|
7207
|
+
this._readyStubGuildIds.clear();
|
|
6054
7208
|
this.guilds.clear();
|
|
6055
7209
|
this.channels.clear();
|
|
6056
7210
|
this.users.clear();
|
|
@@ -6075,6 +7229,20 @@ var Client = class _Client extends import_node_events3.EventEmitter {
|
|
|
6075
7229
|
);
|
|
6076
7230
|
}
|
|
6077
7231
|
}
|
|
7232
|
+
/**
|
|
7233
|
+
* REST path helpers ({@link Routes}). Pass the path to {@link REST client.rest}.
|
|
7234
|
+
* Prefer high-level helpers (`channel.send()`, `guild.members.fetch()`) when they exist.
|
|
7235
|
+
*
|
|
7236
|
+
* @example
|
|
7237
|
+
* const channel = await client.rest.get(Client.Routes.channel(channelId));
|
|
7238
|
+
*
|
|
7239
|
+
* @example
|
|
7240
|
+
* await client.rest.post(Client.Routes.channelMessages(channelId), {
|
|
7241
|
+
* body: { content: 'hello' },
|
|
7242
|
+
* });
|
|
7243
|
+
*
|
|
7244
|
+
* @see {@link Routes}
|
|
7245
|
+
*/
|
|
6078
7246
|
static get Routes() {
|
|
6079
7247
|
return import_types39.Routes;
|
|
6080
7248
|
}
|