@fluxerjs/core 2.2.0 → 3.0.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-CjQBbVmb.d.mts} +1390 -1104
- package/dist/{SubpathMessage-D70lAT7N.d.ts → SubpathMessage-DNlKq2Nj.d.ts} +1390 -1104
- package/dist/Sudo-CFfbmis3.d.mts +453 -0
- package/dist/Sudo-CFfbmis3.d.ts +453 -0
- package/dist/client.d.mts +4 -3
- package/dist/client.d.ts +4 -3
- package/dist/client.js +1976 -1001
- package/dist/client.mjs +1768 -796
- package/dist/cluster.d.mts +4 -3
- package/dist/cluster.d.ts +4 -3
- package/dist/cluster.js +1898 -923
- package/dist/cluster.mjs +1770 -798
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1957 -1008
- package/dist/index.mjs +1797 -834
- 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 +446 -93
- package/dist/message.mjs +446 -94
- package/package.json +13 -9
package/dist/client.mjs
CHANGED
|
@@ -4,91 +4,14 @@ import { REST } from "@fluxerjs/rest";
|
|
|
4
4
|
import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes34 } from "@fluxerjs/types";
|
|
5
5
|
import { createLogger } from "@fluxerjs/util";
|
|
6
6
|
|
|
7
|
-
// src/Domain/User.ts
|
|
8
|
-
import { Routes as Routes13 } from "@fluxerjs/types";
|
|
9
|
-
import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
|
|
10
|
-
|
|
11
|
-
// src/Helpers/Constants.ts
|
|
12
|
-
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
13
|
-
var CDN_URL = "https://fluxerusercontent.com";
|
|
14
|
-
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
15
|
-
|
|
16
|
-
// src/Helpers/Cdn.ts
|
|
17
|
-
function mediaBase(options) {
|
|
18
|
-
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
19
|
-
}
|
|
20
|
-
function staticBase(options) {
|
|
21
|
-
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
22
|
-
}
|
|
23
|
-
function getExtension(hash, options) {
|
|
24
|
-
const ext = options?.extension ?? "png";
|
|
25
|
-
if (hash?.startsWith("a_")) return "gif";
|
|
26
|
-
return ext;
|
|
27
|
-
}
|
|
28
|
-
function appendSize(options) {
|
|
29
|
-
return options?.size ? `?size=${options.size}` : "";
|
|
30
|
-
}
|
|
31
|
-
function cdnAvatarURL(userId, avatarHash, options) {
|
|
32
|
-
if (!avatarHash) return null;
|
|
33
|
-
const ext = getExtension(avatarHash, options);
|
|
34
|
-
const size = appendSize(options);
|
|
35
|
-
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
36
|
-
}
|
|
37
|
-
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
38
|
-
if (!bannerHash) return null;
|
|
39
|
-
const ext = getExtension(bannerHash, options);
|
|
40
|
-
const size = appendSize(options);
|
|
41
|
-
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
42
|
-
}
|
|
43
|
-
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
44
|
-
if (!avatarHash) return null;
|
|
45
|
-
const ext = getExtension(avatarHash, options);
|
|
46
|
-
const size = appendSize(options);
|
|
47
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
48
|
-
}
|
|
49
|
-
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
50
|
-
if (!bannerHash) return null;
|
|
51
|
-
const ext = getExtension(bannerHash, options);
|
|
52
|
-
const size = appendSize(options);
|
|
53
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
54
|
-
}
|
|
55
|
-
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
56
|
-
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
57
|
-
return `${staticBase(options)}/avatars/${index}.png`;
|
|
58
|
-
}
|
|
59
|
-
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
60
|
-
if (!hash) return null;
|
|
61
|
-
const size = options?.size ? `?size=${options.size}` : "";
|
|
62
|
-
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
63
|
-
}
|
|
64
|
-
function cdnEmojiURL(emojiId, animated, options) {
|
|
65
|
-
const ext = animated ? "gif" : "png";
|
|
66
|
-
return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
|
|
67
|
-
}
|
|
68
|
-
function cdnStickerURL(stickerId, animated, options) {
|
|
69
|
-
const ext = animated ? "gif" : "png";
|
|
70
|
-
return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// src/Domain/Base.ts
|
|
74
|
-
var Base = class {
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/Domain/Channel/Base.ts
|
|
78
|
-
import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
|
|
79
|
-
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
80
|
-
|
|
81
|
-
// src/ClientCore/MessageManager.ts
|
|
82
|
-
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
83
|
-
import { Routes as Routes5 } from "@fluxerjs/types";
|
|
84
|
-
|
|
85
7
|
// src/Domain/Message/Message.ts
|
|
86
8
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
87
|
-
import { Collection as
|
|
9
|
+
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
88
10
|
import {
|
|
89
11
|
MessageType,
|
|
90
12
|
Routes as Routes4
|
|
91
13
|
} from "@fluxerjs/types";
|
|
14
|
+
import { MessageFlagsBitField } from "@fluxerjs/util";
|
|
92
15
|
|
|
93
16
|
// src/ClientCore/SdkOptions/Attachments.ts
|
|
94
17
|
function toMessageAttachmentEditWire(attachments) {
|
|
@@ -155,23 +78,68 @@ function toAttachmentUploadPlanResponse(data) {
|
|
|
155
78
|
}
|
|
156
79
|
|
|
157
80
|
// src/ClientCore/SdkOptions/Channels.ts
|
|
81
|
+
import { resolvePermissionsToBitfield } from "@fluxerjs/util";
|
|
82
|
+
function toOverwriteWire(overwrite) {
|
|
83
|
+
return {
|
|
84
|
+
id: overwrite.id,
|
|
85
|
+
type: overwrite.type,
|
|
86
|
+
allow: overwrite.allow !== void 0 ? resolvePermissionsToBitfield(overwrite.allow) : "0",
|
|
87
|
+
deny: overwrite.deny !== void 0 ? resolvePermissionsToBitfield(overwrite.deny) : "0"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
158
90
|
function toChannelEditBody(options) {
|
|
159
91
|
const body = {};
|
|
160
92
|
if (options.name !== void 0) body.name = options.name;
|
|
161
93
|
if (options.topic !== void 0) body.topic = options.topic;
|
|
94
|
+
if (options.url !== void 0) body.url = options.url;
|
|
162
95
|
if (options.parentId !== void 0) body.parent_id = options.parentId;
|
|
163
96
|
if (options.bitrate !== void 0) body.bitrate = options.bitrate;
|
|
164
97
|
if (options.userLimit !== void 0) body.user_limit = options.userLimit;
|
|
98
|
+
if (options.voiceConnectionLimit !== void 0) {
|
|
99
|
+
body.voice_connection_limit = options.voiceConnectionLimit;
|
|
100
|
+
}
|
|
165
101
|
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
102
|
+
if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
|
|
103
|
+
if (options.contentWarningLevel !== void 0) {
|
|
104
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
105
|
+
}
|
|
106
|
+
if (options.contentWarningText !== void 0) {
|
|
107
|
+
body.content_warning_text = options.contentWarningText;
|
|
108
|
+
}
|
|
166
109
|
if (options.rateLimitPerUser !== void 0) {
|
|
167
110
|
body.rate_limit_per_user = options.rateLimitPerUser;
|
|
168
111
|
}
|
|
169
112
|
if (options.rtcRegion !== void 0) body.rtc_region = options.rtcRegion;
|
|
113
|
+
if (options.icon !== void 0) body.icon = options.icon;
|
|
170
114
|
if (options.permissionOverwrites !== void 0) {
|
|
171
|
-
body.permission_overwrites = options.permissionOverwrites;
|
|
115
|
+
body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
|
|
172
116
|
}
|
|
173
117
|
return body;
|
|
174
118
|
}
|
|
119
|
+
function toChannelCreateBody(options) {
|
|
120
|
+
const body = { name: options.name, type: options.type };
|
|
121
|
+
if (options.topic !== void 0) body.topic = options.topic;
|
|
122
|
+
if (options.url !== void 0) body.url = options.url;
|
|
123
|
+
if (options.parentId !== void 0) body.parent_id = options.parentId;
|
|
124
|
+
if (options.bitrate !== void 0) body.bitrate = options.bitrate;
|
|
125
|
+
if (options.userLimit !== void 0) body.user_limit = options.userLimit;
|
|
126
|
+
if (options.voiceConnectionLimit !== void 0) {
|
|
127
|
+
body.voice_connection_limit = options.voiceConnectionLimit;
|
|
128
|
+
}
|
|
129
|
+
if (options.permissionOverwrites !== void 0) {
|
|
130
|
+
body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
|
|
131
|
+
}
|
|
132
|
+
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
133
|
+
if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
|
|
134
|
+
if (options.contentWarningLevel !== void 0) {
|
|
135
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
136
|
+
}
|
|
137
|
+
if (options.contentWarningText !== void 0) {
|
|
138
|
+
body.content_warning_text = options.contentWarningText;
|
|
139
|
+
}
|
|
140
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
141
|
+
return body;
|
|
142
|
+
}
|
|
175
143
|
function toChannelInviteBody(options) {
|
|
176
144
|
const body = {};
|
|
177
145
|
if (options.maxUses !== void 0) body.max_uses = options.maxUses;
|
|
@@ -180,6 +148,13 @@ function toChannelInviteBody(options) {
|
|
|
180
148
|
if (options.temporary !== void 0) body.temporary = options.temporary;
|
|
181
149
|
return body;
|
|
182
150
|
}
|
|
151
|
+
function toGroupDmEditBody(options) {
|
|
152
|
+
const body = { type: 3 };
|
|
153
|
+
if (options.name !== void 0) body.name = options.name;
|
|
154
|
+
if (options.icon !== void 0) body.icon = options.icon;
|
|
155
|
+
if (options.nicks !== void 0) body.nicks = options.nicks;
|
|
156
|
+
return body;
|
|
157
|
+
}
|
|
183
158
|
|
|
184
159
|
// src/ClientCore/SdkOptions/Discovery.ts
|
|
185
160
|
function toDiscoveryBody(options) {
|
|
@@ -215,32 +190,8 @@ function toDiscoveryStatusPayload(data) {
|
|
|
215
190
|
};
|
|
216
191
|
}
|
|
217
192
|
|
|
218
|
-
// src/ClientCore/SdkOptions/Expressions.ts
|
|
219
|
-
function toEmojiCreateBody(options) {
|
|
220
|
-
return { name: options.name, image: options.image };
|
|
221
|
-
}
|
|
222
|
-
function toEmojiEditBody(options) {
|
|
223
|
-
return { name: options.name };
|
|
224
|
-
}
|
|
225
|
-
function toStickerCreateBody(options) {
|
|
226
|
-
const body = {
|
|
227
|
-
name: options.name,
|
|
228
|
-
image: options.file
|
|
229
|
-
};
|
|
230
|
-
if (options.description !== void 0) body.description = options.description;
|
|
231
|
-
if (options.tags !== void 0) body.tags = options.tags;
|
|
232
|
-
return body;
|
|
233
|
-
}
|
|
234
|
-
function toStickerEditBody(options) {
|
|
235
|
-
const body = {};
|
|
236
|
-
if (options.name !== void 0) body.name = options.name;
|
|
237
|
-
if (options.description !== void 0) body.description = options.description;
|
|
238
|
-
if (options.tags !== void 0) body.tags = options.tags;
|
|
239
|
-
return body;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
193
|
// src/ClientCore/SdkOptions/Guild.ts
|
|
243
|
-
import { resolvePermissionsToBitfield } from "@fluxerjs/util";
|
|
194
|
+
import { resolvePermissionsToBitfield as resolvePermissionsToBitfield2 } from "@fluxerjs/util";
|
|
244
195
|
function toGuildEditBody(options) {
|
|
245
196
|
const body = {};
|
|
246
197
|
if (options.name !== void 0) body.name = options.name;
|
|
@@ -268,6 +219,16 @@ function toGuildEditBody(options) {
|
|
|
268
219
|
body.splash_card_alignment = options.splashCardAlignment;
|
|
269
220
|
}
|
|
270
221
|
if (options.nsfwLevel !== void 0) body.nsfw_level = options.nsfwLevel;
|
|
222
|
+
if (options.nsfw !== void 0) body.nsfw = options.nsfw;
|
|
223
|
+
if (options.contentWarningLevel !== void 0) {
|
|
224
|
+
body.content_warning_level = options.contentWarningLevel;
|
|
225
|
+
}
|
|
226
|
+
if (options.contentWarningText !== void 0) {
|
|
227
|
+
body.content_warning_text = options.contentWarningText;
|
|
228
|
+
}
|
|
229
|
+
if (options.messageHistoryCutoff !== void 0) {
|
|
230
|
+
body.message_history_cutoff = options.messageHistoryCutoff;
|
|
231
|
+
}
|
|
271
232
|
if (options.features !== void 0) body.features = options.features;
|
|
272
233
|
return body;
|
|
273
234
|
}
|
|
@@ -277,6 +238,9 @@ function toGuildBanBody(options) {
|
|
|
277
238
|
if (options.deleteMessageDays !== void 0) {
|
|
278
239
|
body.delete_message_days = options.deleteMessageDays;
|
|
279
240
|
}
|
|
241
|
+
if (options.deleteMessageSeconds !== void 0) {
|
|
242
|
+
body.delete_message_seconds = options.deleteMessageSeconds;
|
|
243
|
+
}
|
|
280
244
|
if (options.banDurationSeconds !== void 0) {
|
|
281
245
|
body.ban_duration_seconds = options.banDurationSeconds;
|
|
282
246
|
}
|
|
@@ -291,18 +255,26 @@ function toChannelPositionBody(updates) {
|
|
|
291
255
|
return row;
|
|
292
256
|
});
|
|
293
257
|
}
|
|
294
|
-
function
|
|
258
|
+
function toRolePermissionsBody(options) {
|
|
295
259
|
const body = {};
|
|
260
|
+
if (options.permissions !== void 0) {
|
|
261
|
+
body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield2(options.permissions);
|
|
262
|
+
}
|
|
263
|
+
return body;
|
|
264
|
+
}
|
|
265
|
+
function toRoleCreateBody(options) {
|
|
266
|
+
const body = { ...toRolePermissionsBody(options) };
|
|
267
|
+
if (options.name !== void 0) body.name = options.name;
|
|
268
|
+
if (options.color !== void 0) body.color = options.color;
|
|
269
|
+
return body;
|
|
270
|
+
}
|
|
271
|
+
function toRoleEditBody(options) {
|
|
272
|
+
const body = { ...toRolePermissionsBody(options) };
|
|
296
273
|
if (options.name !== void 0) body.name = options.name;
|
|
297
274
|
if (options.color !== void 0) body.color = options.color;
|
|
298
275
|
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
299
276
|
if (options.mentionable !== void 0) body.mentionable = options.mentionable;
|
|
300
|
-
if (options.unicodeEmoji !== void 0) body.unicode_emoji = options.unicodeEmoji;
|
|
301
|
-
if (options.position !== void 0) body.position = options.position;
|
|
302
277
|
if (options.hoistPosition !== void 0) body.hoist_position = options.hoistPosition;
|
|
303
|
-
if (options.permissions !== void 0) {
|
|
304
|
-
body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield(options.permissions);
|
|
305
|
-
}
|
|
306
278
|
return body;
|
|
307
279
|
}
|
|
308
280
|
|
|
@@ -320,6 +292,8 @@ function toMemberSearchBody(options) {
|
|
|
320
292
|
if (options.userCreatedAtLte !== void 0) body.user_created_at_lte = options.userCreatedAtLte;
|
|
321
293
|
if (options.sortBy !== void 0) body.sort_by = options.sortBy;
|
|
322
294
|
if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
|
|
295
|
+
if (options.joinSourceType !== void 0) body.join_source_type = options.joinSourceType;
|
|
296
|
+
if (options.sourceInviteCode !== void 0) body.source_invite_code = options.sourceInviteCode;
|
|
323
297
|
return body;
|
|
324
298
|
}
|
|
325
299
|
function toMemberEditBody(options) {
|
|
@@ -332,6 +306,7 @@ function toMemberEditBody(options) {
|
|
|
332
306
|
if (options.pronouns !== void 0) body.pronouns = options.pronouns;
|
|
333
307
|
if (options.accentColor !== void 0) body.accent_color = options.accentColor;
|
|
334
308
|
if (options.profileFlags !== void 0) body.profile_flags = options.profileFlags;
|
|
309
|
+
if (options.mentionFlags !== void 0) body.mention_flags = options.mentionFlags;
|
|
335
310
|
if (options.mute !== void 0) body.mute = options.mute;
|
|
336
311
|
if (options.deaf !== void 0) body.deaf = options.deaf;
|
|
337
312
|
if (options.communicationDisabledUntil !== void 0) {
|
|
@@ -353,15 +328,54 @@ function toBulkFetchWire(requests) {
|
|
|
353
328
|
...r.around !== void 0 ? { around: r.around } : {}
|
|
354
329
|
}));
|
|
355
330
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (options.
|
|
361
|
-
if (options.
|
|
362
|
-
|
|
331
|
+
function toMessageSearchBody(options = {}) {
|
|
332
|
+
const body = { scope: "current" };
|
|
333
|
+
if (options.content !== void 0) body.content = options.content;
|
|
334
|
+
if (options.contents !== void 0) body.contents = options.contents;
|
|
335
|
+
if (options.exactPhrases !== void 0) body.exact_phrases = options.exactPhrases;
|
|
336
|
+
if (options.channelIds !== void 0) {
|
|
337
|
+
body.channel_id = options.channelIds;
|
|
338
|
+
body.channel_ids = options.channelIds;
|
|
339
|
+
}
|
|
340
|
+
if (options.excludeChannelIds !== void 0) body.exclude_channel_id = options.excludeChannelIds;
|
|
341
|
+
if (options.contextGuildId !== void 0) body.context_guild_id = options.contextGuildId;
|
|
342
|
+
if (options.contextChannelId !== void 0) body.context_channel_id = options.contextChannelId;
|
|
343
|
+
if (options.hitsPerPage !== void 0) body.hits_per_page = options.hitsPerPage;
|
|
344
|
+
if (options.page !== void 0) body.page = options.page;
|
|
345
|
+
if (options.cursor !== void 0) body.cursor = options.cursor;
|
|
346
|
+
if (options.minId !== void 0) body.min_id = options.minId;
|
|
347
|
+
if (options.maxId !== void 0) body.max_id = options.maxId;
|
|
348
|
+
if (options.authorIds !== void 0) body.author_id = options.authorIds;
|
|
349
|
+
if (options.excludeAuthorIds !== void 0) body.exclude_author_id = options.excludeAuthorIds;
|
|
350
|
+
if (options.authorType !== void 0) body.author_type = options.authorType;
|
|
351
|
+
if (options.excludeAuthorType !== void 0) body.exclude_author_type = options.excludeAuthorType;
|
|
352
|
+
if (options.mentions !== void 0) body.mentions = options.mentions;
|
|
353
|
+
if (options.excludeMentions !== void 0) body.exclude_mentions = options.excludeMentions;
|
|
354
|
+
if (options.mentionEveryone !== void 0) body.mention_everyone = options.mentionEveryone;
|
|
355
|
+
if (options.pinned !== void 0) body.pinned = options.pinned;
|
|
356
|
+
if (options.includeNsfw !== void 0) body.include_nsfw = options.includeNsfw;
|
|
357
|
+
if (options.has !== void 0) body.has = options.has;
|
|
358
|
+
if (options.excludeHas !== void 0) body.exclude_has = options.excludeHas;
|
|
359
|
+
if (options.sortBy !== void 0) body.sort_by = options.sortBy;
|
|
360
|
+
if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
|
|
363
361
|
return body;
|
|
364
362
|
}
|
|
363
|
+
function isMessageSearchIndexing(data) {
|
|
364
|
+
return "indexing" in data && data.indexing === true;
|
|
365
|
+
}
|
|
366
|
+
function toMessageSearchResponse(data) {
|
|
367
|
+
if (isMessageSearchIndexing(data)) {
|
|
368
|
+
return { indexing: true };
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
messages: data.messages,
|
|
372
|
+
channels: data.channels,
|
|
373
|
+
total: data.total,
|
|
374
|
+
hitsPerPage: data.hits_per_page,
|
|
375
|
+
page: data.page,
|
|
376
|
+
...data.cursor !== void 0 ? { cursor: data.cursor } : {}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
365
379
|
|
|
366
380
|
// src/ClientCore/SdkOptions/Presence.ts
|
|
367
381
|
function toPresenceWire(options) {
|
|
@@ -411,8 +425,8 @@ function toSudoBody(options) {
|
|
|
411
425
|
}
|
|
412
426
|
|
|
413
427
|
// src/Helpers/MessageUtils/Body.ts
|
|
414
|
-
import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
415
|
-
import { MessageReferenceType } from "@fluxerjs/types";
|
|
428
|
+
import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
|
|
429
|
+
import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
|
|
416
430
|
|
|
417
431
|
// src/LibErrors/ErrorCodes.ts
|
|
418
432
|
import { ErrorCodes } from "@fluxerjs/util";
|
|
@@ -481,6 +495,37 @@ function applyReplyPingSuppression(body) {
|
|
|
481
495
|
function assignIfDefined(target, key, value) {
|
|
482
496
|
if (value !== void 0) target[key] = value;
|
|
483
497
|
}
|
|
498
|
+
function normalizeSendFiles(files) {
|
|
499
|
+
if (!files?.length) return void 0;
|
|
500
|
+
const normalized = [];
|
|
501
|
+
const metaFromBuilders = [];
|
|
502
|
+
let anyBuilderMeta = false;
|
|
503
|
+
for (let i = 0; i < files.length; i++) {
|
|
504
|
+
const file = files[i];
|
|
505
|
+
if (!file) continue;
|
|
506
|
+
if (file instanceof AttachmentBuilder) {
|
|
507
|
+
normalized.push(file.toFileData());
|
|
508
|
+
const meta = {
|
|
509
|
+
id: i,
|
|
510
|
+
filename: file.filename,
|
|
511
|
+
...file.description != null ? { description: file.description } : {},
|
|
512
|
+
...file.spoiler ? { flags: MessageAttachmentFlags.IS_SPOILER } : {}
|
|
513
|
+
};
|
|
514
|
+
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
515
|
+
metaFromBuilders.push(meta);
|
|
516
|
+
} else {
|
|
517
|
+
normalized.push(file);
|
|
518
|
+
metaFromBuilders.push({
|
|
519
|
+
id: i,
|
|
520
|
+
filename: file.filename ?? file.name
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
files: normalized,
|
|
526
|
+
metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
|
|
527
|
+
};
|
|
528
|
+
}
|
|
484
529
|
function buildSendBody(options) {
|
|
485
530
|
const body = typeof options === "string" ? { content: options } : options;
|
|
486
531
|
const result = {};
|
|
@@ -488,16 +533,17 @@ function buildSendBody(options) {
|
|
|
488
533
|
if (body.embeds?.length) {
|
|
489
534
|
result.embeds = body.embeds.map((e) => e instanceof EmbedBuilder ? e.toJSON() : e);
|
|
490
535
|
}
|
|
536
|
+
const normalizedFiles = normalizeSendFiles(body.files);
|
|
491
537
|
if (body.uploadedAttachments?.length) {
|
|
492
538
|
result.attachments = body.uploadedAttachments;
|
|
493
|
-
} else if (
|
|
539
|
+
} else if (normalizedFiles?.files.length) {
|
|
494
540
|
result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
|
|
495
541
|
id: a.id,
|
|
496
542
|
filename: a.filename,
|
|
497
543
|
...a.title != null && { title: a.title },
|
|
498
544
|
...a.description != null && { description: a.description },
|
|
499
545
|
...a.flags != null && { flags: a.flags }
|
|
500
|
-
})) :
|
|
546
|
+
})) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
|
|
501
547
|
}
|
|
502
548
|
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
503
549
|
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
@@ -591,9 +637,10 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
591
637
|
} else if (allowedMentions?.repliedUser === false) {
|
|
592
638
|
applyReplyPingSuppression(body);
|
|
593
639
|
}
|
|
640
|
+
const resolvedFiles = normalizeSendFiles(files);
|
|
594
641
|
return {
|
|
595
642
|
body,
|
|
596
|
-
files: !uploadedAttachments?.length && files
|
|
643
|
+
files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
|
|
597
644
|
};
|
|
598
645
|
}
|
|
599
646
|
|
|
@@ -642,14 +689,22 @@ function qs(params) {
|
|
|
642
689
|
return out ? `?${out}` : "";
|
|
643
690
|
}
|
|
644
691
|
|
|
692
|
+
// src/Domain/Base.ts
|
|
693
|
+
var Base = class {
|
|
694
|
+
};
|
|
695
|
+
|
|
645
696
|
// src/Domain/Message/MessageReaction.ts
|
|
646
|
-
var MessageReaction = class extends Base {
|
|
697
|
+
var MessageReaction = class _MessageReaction extends Base {
|
|
647
698
|
client;
|
|
648
699
|
messageId;
|
|
649
700
|
channelId;
|
|
650
701
|
guildId;
|
|
651
702
|
emoji;
|
|
652
|
-
/**
|
|
703
|
+
/** Total count when hydrated from a message payload; `1` for gateway add events. */
|
|
704
|
+
count;
|
|
705
|
+
/** Whether the current user reacted (message payload); false for gateway remove. */
|
|
706
|
+
me;
|
|
707
|
+
/** Raw gateway payload for low-level access (null when built from a message aggregate). */
|
|
653
708
|
_data;
|
|
654
709
|
constructor(client, data) {
|
|
655
710
|
super();
|
|
@@ -663,6 +718,26 @@ var MessageReaction = class extends Base {
|
|
|
663
718
|
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
664
719
|
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
665
720
|
};
|
|
721
|
+
this.count = 1;
|
|
722
|
+
this.me = false;
|
|
723
|
+
}
|
|
724
|
+
/** Build a reaction aggregate from a message's `reactions` array entry. */
|
|
725
|
+
static fromMessage(message, data) {
|
|
726
|
+
const reaction = new _MessageReaction(message.client, {
|
|
727
|
+
user_id: message.client.user?.id ?? "0",
|
|
728
|
+
message_id: message.id,
|
|
729
|
+
channel_id: message.channelId,
|
|
730
|
+
guild_id: message.guildId ?? void 0,
|
|
731
|
+
emoji: {
|
|
732
|
+
name: data.emoji.name,
|
|
733
|
+
id: data.emoji.id ?? void 0,
|
|
734
|
+
animated: data.emoji.animated ?? void 0
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
Object.defineProperty(reaction, "_data", { value: null });
|
|
738
|
+
reaction.count = data.count;
|
|
739
|
+
reaction.me = data.me ?? false;
|
|
740
|
+
return reaction;
|
|
666
741
|
}
|
|
667
742
|
/** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
|
|
668
743
|
get emojiIdentifier() {
|
|
@@ -672,12 +747,23 @@ var MessageReaction = class extends Base {
|
|
|
672
747
|
get guild() {
|
|
673
748
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
674
749
|
}
|
|
750
|
+
/** Cached message this reaction belongs to, or null if the message was not cached. */
|
|
751
|
+
get message() {
|
|
752
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
|
|
753
|
+
return cached ? new Message(this.client, cached) : null;
|
|
754
|
+
}
|
|
755
|
+
/** Cached text-capable channel, or null if uncached / not text-based. */
|
|
756
|
+
get channel() {
|
|
757
|
+
const channel = this.client.channels.get(this.channelId);
|
|
758
|
+
return channel?.isTextBased() ? channel : null;
|
|
759
|
+
}
|
|
675
760
|
/**
|
|
676
|
-
* Fetch the message this reaction belongs to.
|
|
677
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
761
|
+
* Fetch the message this reaction belongs to (cache first, then REST).
|
|
678
762
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
679
763
|
*/
|
|
680
764
|
async fetchMessage() {
|
|
765
|
+
const cached = this.message;
|
|
766
|
+
if (cached) return cached;
|
|
681
767
|
try {
|
|
682
768
|
const data = await this.client.rest.get(
|
|
683
769
|
Routes.channelMessage(this.channelId, this.messageId)
|
|
@@ -748,11 +834,17 @@ var Events = {
|
|
|
748
834
|
WebhooksUpdate: "webhooksUpdate",
|
|
749
835
|
Resumed: "resumed",
|
|
750
836
|
Error: "error",
|
|
751
|
-
Debug: "debug"
|
|
837
|
+
Debug: "debug",
|
|
838
|
+
ShardReady: "shardReady",
|
|
839
|
+
ShardResumed: "shardResumed",
|
|
840
|
+
ShardDisconnect: "shardDisconnect",
|
|
841
|
+
ShardReconnecting: "shardReconnecting",
|
|
842
|
+
ShardError: "shardError",
|
|
843
|
+
ShardingRequired: "shardingRequired"
|
|
752
844
|
};
|
|
753
845
|
|
|
754
846
|
// src/Helpers/ReactionCollector.ts
|
|
755
|
-
var ReactionCollector = class extends EventEmitter {
|
|
847
|
+
var ReactionCollector = class _ReactionCollector extends EventEmitter {
|
|
756
848
|
client;
|
|
757
849
|
messageId;
|
|
758
850
|
channelId;
|
|
@@ -795,15 +887,17 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
795
887
|
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
796
888
|
}
|
|
797
889
|
});
|
|
798
|
-
const
|
|
890
|
+
const cached = this.client.users.get(entry.userId);
|
|
891
|
+
const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
|
|
892
|
+
{
|
|
799
893
|
id: entry.userId,
|
|
800
894
|
username: "Unknown",
|
|
801
895
|
discriminator: "0",
|
|
802
|
-
|
|
896
|
+
globalName: null,
|
|
803
897
|
avatar: null,
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
898
|
+
bot: false,
|
|
899
|
+
system: false
|
|
900
|
+
};
|
|
807
901
|
this._collect(reaction, user, entry.userId);
|
|
808
902
|
}
|
|
809
903
|
};
|
|
@@ -835,6 +929,21 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
835
929
|
}
|
|
836
930
|
this.emit("end", this.collected, reason);
|
|
837
931
|
}
|
|
932
|
+
/**
|
|
933
|
+
* One-shot helper used by {@link Message.awaitReactions}.
|
|
934
|
+
* Resolves with the collected reactions when the collector ends.
|
|
935
|
+
* Rejects if `options.errors` includes the end reason.
|
|
936
|
+
*/
|
|
937
|
+
static awaitReactions(client, messageId, channelId, options) {
|
|
938
|
+
const errors = options?.errors ?? [];
|
|
939
|
+
return new Promise((resolve, reject) => {
|
|
940
|
+
const collector = new _ReactionCollector(client, messageId, channelId, options);
|
|
941
|
+
collector.on("end", (collected, reason) => {
|
|
942
|
+
if (errors.includes(reason)) reject(collected);
|
|
943
|
+
else resolve(collected);
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
}
|
|
838
947
|
on(event, listener) {
|
|
839
948
|
return super.on(event, listener);
|
|
840
949
|
}
|
|
@@ -843,70 +952,224 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
843
952
|
}
|
|
844
953
|
};
|
|
845
954
|
|
|
846
|
-
// src/Domain/Message/
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
955
|
+
// src/Domain/Message/Attachment.ts
|
|
956
|
+
function toMessageAttachment(data) {
|
|
957
|
+
return {
|
|
958
|
+
id: data.id,
|
|
959
|
+
filename: data.filename,
|
|
960
|
+
title: data.title ?? null,
|
|
961
|
+
description: data.description ?? null,
|
|
962
|
+
contentType: data.content_type ?? null,
|
|
963
|
+
contentHash: data.content_hash ?? null,
|
|
964
|
+
size: data.size,
|
|
965
|
+
url: data.url ?? null,
|
|
966
|
+
proxyUrl: data.proxy_url ?? null,
|
|
967
|
+
width: data.width ?? null,
|
|
968
|
+
height: data.height ?? null,
|
|
969
|
+
placeholder: data.placeholder ?? null,
|
|
970
|
+
flags: data.flags ?? 0,
|
|
971
|
+
nsfw: data.nsfw ?? false,
|
|
972
|
+
duration: data.duration ?? null,
|
|
973
|
+
waveform: data.waveform ?? null,
|
|
974
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
975
|
+
expired: data.expired ?? false
|
|
976
|
+
};
|
|
851
977
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
978
|
+
|
|
979
|
+
// src/Domain/Message/Embed.ts
|
|
980
|
+
function toMessageEmbedAuthor(data) {
|
|
981
|
+
return {
|
|
982
|
+
name: data.name ?? null,
|
|
983
|
+
url: data.url ?? null,
|
|
984
|
+
iconUrl: data.icon_url ?? null,
|
|
985
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
function toMessageEmbedFooter(data) {
|
|
989
|
+
return {
|
|
990
|
+
text: data.text,
|
|
991
|
+
iconUrl: data.icon_url ?? null,
|
|
992
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
function toMessageEmbedMedia(data) {
|
|
996
|
+
return {
|
|
997
|
+
url: data.url,
|
|
998
|
+
proxyUrl: data.proxy_url ?? null,
|
|
999
|
+
contentType: data.content_type ?? null,
|
|
1000
|
+
contentHash: data.content_hash ?? null,
|
|
1001
|
+
width: data.width ?? null,
|
|
1002
|
+
height: data.height ?? null,
|
|
1003
|
+
description: data.description ?? null,
|
|
1004
|
+
placeholder: data.placeholder ?? null,
|
|
1005
|
+
duration: data.duration ?? null,
|
|
1006
|
+
flags: data.flags ?? null
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
function toMessageEmbed(data) {
|
|
1010
|
+
const full = data;
|
|
1011
|
+
return {
|
|
1012
|
+
type: data.type ?? "rich",
|
|
1013
|
+
url: data.url ?? null,
|
|
1014
|
+
title: data.title ?? null,
|
|
1015
|
+
color: data.color ?? null,
|
|
1016
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
1017
|
+
description: data.description ?? null,
|
|
1018
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
1019
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
1020
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
1021
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
1022
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
1023
|
+
name: f.name,
|
|
1024
|
+
value: f.value,
|
|
1025
|
+
inline: f.inline ?? false
|
|
1026
|
+
})),
|
|
1027
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
1028
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
1029
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
1030
|
+
nsfw: data.nsfw ?? false,
|
|
1031
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
1032
|
+
html: full.html ?? null,
|
|
1033
|
+
htmlWidth: full.html_width ?? null,
|
|
1034
|
+
htmlHeight: full.html_height ?? null
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
1039
|
+
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
1040
|
+
var MessageReactionManager = class {
|
|
1041
|
+
constructor(message) {
|
|
1042
|
+
this.message = message;
|
|
859
1043
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1044
|
+
_cache = new Collection2();
|
|
1045
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
1046
|
+
get cache() {
|
|
1047
|
+
return this._cache;
|
|
863
1048
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return {
|
|
867
|
-
name: parsed.name,
|
|
868
|
-
id: parsed.id,
|
|
869
|
-
...parsed.animated ? { animated: true } : {}
|
|
870
|
-
};
|
|
1049
|
+
get size() {
|
|
1050
|
+
return this._cache.size;
|
|
871
1051
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
if (!user) return;
|
|
882
|
-
const emojiPayload = toReactionEmoji(wireOrInput);
|
|
883
|
-
const reaction = new MessageReaction(message.client, {
|
|
884
|
-
user_id: user.id,
|
|
885
|
-
channel_id: message.channelId,
|
|
886
|
-
message_id: message.id,
|
|
887
|
-
guild_id: message.guildId ?? void 0,
|
|
888
|
-
emoji: {
|
|
889
|
-
name: emojiPayload.name,
|
|
890
|
-
...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
|
|
891
|
-
...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
|
|
1052
|
+
[Symbol.iterator]() {
|
|
1053
|
+
return this._cache.values();
|
|
1054
|
+
}
|
|
1055
|
+
/** @internal Sync from an API message payload. */
|
|
1056
|
+
_patch(reactions) {
|
|
1057
|
+
this._cache.clear();
|
|
1058
|
+
for (const data of reactions ?? []) {
|
|
1059
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
1060
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
892
1061
|
}
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1066
|
+
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
1067
|
+
|
|
1068
|
+
// src/Helpers/Constants.ts
|
|
1069
|
+
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
1070
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
1071
|
+
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1072
|
+
|
|
1073
|
+
// src/Helpers/Cdn.ts
|
|
1074
|
+
function mediaBase(options) {
|
|
1075
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1076
|
+
}
|
|
1077
|
+
function staticBase(options) {
|
|
1078
|
+
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
1079
|
+
}
|
|
1080
|
+
function getExtension(hash, options) {
|
|
1081
|
+
const ext = options?.extension ?? "png";
|
|
1082
|
+
if (hash?.startsWith("a_")) return "gif";
|
|
1083
|
+
return ext;
|
|
1084
|
+
}
|
|
1085
|
+
function appendSize(options) {
|
|
1086
|
+
return options?.size ? `?size=${options.size}` : "";
|
|
1087
|
+
}
|
|
1088
|
+
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1089
|
+
if (!avatarHash) return null;
|
|
1090
|
+
const ext = getExtension(avatarHash, options);
|
|
1091
|
+
const size = appendSize(options);
|
|
1092
|
+
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1093
|
+
}
|
|
1094
|
+
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1095
|
+
if (!bannerHash) return null;
|
|
1096
|
+
const ext = getExtension(bannerHash, options);
|
|
1097
|
+
const size = appendSize(options);
|
|
1098
|
+
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1099
|
+
}
|
|
1100
|
+
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1101
|
+
if (!avatarHash) return null;
|
|
1102
|
+
const ext = getExtension(avatarHash, options);
|
|
1103
|
+
const size = appendSize(options);
|
|
1104
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1105
|
+
}
|
|
1106
|
+
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1107
|
+
if (!bannerHash) return null;
|
|
1108
|
+
const ext = getExtension(bannerHash, options);
|
|
1109
|
+
const size = appendSize(options);
|
|
1110
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1111
|
+
}
|
|
1112
|
+
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
1113
|
+
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
1114
|
+
return `${staticBase(options)}/avatars/${index}.png`;
|
|
1115
|
+
}
|
|
1116
|
+
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1117
|
+
if (!hash) return null;
|
|
1118
|
+
const size = options?.size ? `?size=${options.size}` : "";
|
|
1119
|
+
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1120
|
+
}
|
|
1121
|
+
function cdnEmojiURL(emojiId, animated, options) {
|
|
1122
|
+
const ext = animated ? "gif" : "png";
|
|
1123
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
|
|
1124
|
+
}
|
|
1125
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
1126
|
+
const ext = animated ? "gif" : "png";
|
|
1127
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1131
|
+
var MessageSticker = class extends Base {
|
|
1132
|
+
client;
|
|
1133
|
+
id;
|
|
1134
|
+
name;
|
|
1135
|
+
description;
|
|
1136
|
+
tags;
|
|
1137
|
+
animated;
|
|
1138
|
+
constructor(client, data) {
|
|
1139
|
+
super();
|
|
1140
|
+
this.client = client;
|
|
1141
|
+
this.id = data.id;
|
|
1142
|
+
this.name = data.name;
|
|
1143
|
+
this.description = data.description ?? "";
|
|
1144
|
+
this.tags = data.tags ?? [];
|
|
1145
|
+
this.animated = data.animated ?? false;
|
|
1146
|
+
}
|
|
1147
|
+
/** CDN URL for this sticker image. */
|
|
1148
|
+
get url() {
|
|
1149
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
1150
|
+
mediaBase: this.client.instance.endpoints.media
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
1154
|
+
get createdTimestamp() {
|
|
1155
|
+
return SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1156
|
+
}
|
|
1157
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
1158
|
+
get createdAt() {
|
|
1159
|
+
return SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
// src/Domain/Message/Reactions.ts
|
|
1164
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
1165
|
+
async function emojiPath(message, emoji) {
|
|
1166
|
+
return message.client.resolveEmoji(emoji, message.guildId);
|
|
903
1167
|
}
|
|
904
1168
|
async function reactToMessage(message, emoji) {
|
|
905
1169
|
const wire = await emojiPath(message, emoji);
|
|
906
1170
|
await message.client.rest.put(
|
|
907
1171
|
Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
908
1172
|
);
|
|
909
|
-
emitOwnReactionAdd(message, wire);
|
|
910
1173
|
}
|
|
911
1174
|
async function removeMessageReaction(message, emoji, userId) {
|
|
912
1175
|
const e = await emojiPath(message, emoji);
|
|
@@ -1012,7 +1275,33 @@ async function replyToMessage(message, options, replyOptions) {
|
|
|
1012
1275
|
}
|
|
1013
1276
|
|
|
1014
1277
|
// src/Domain/Message/Message.ts
|
|
1278
|
+
function toMessageCall(data) {
|
|
1279
|
+
return {
|
|
1280
|
+
participants: data.participants,
|
|
1281
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
function toMessageSnapshot(client, data) {
|
|
1285
|
+
return {
|
|
1286
|
+
content: data.content ?? null,
|
|
1287
|
+
createdAt: new Date(data.timestamp),
|
|
1288
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
1289
|
+
mentionUserIds: data.mentions ?? [],
|
|
1290
|
+
mentionRoles: data.mention_roles ?? [],
|
|
1291
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
1292
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
1293
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
1294
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
function resolveMessageFlags(flags) {
|
|
1298
|
+
if (flags === void 0) return void 0;
|
|
1299
|
+
if (typeof flags === "number") return flags;
|
|
1300
|
+
return Number(MessageFlagsBitField.resolve(flags));
|
|
1301
|
+
}
|
|
1015
1302
|
var Message = class _Message extends Base {
|
|
1303
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
1304
|
+
partial = false;
|
|
1016
1305
|
/** The {@link Client} that instantiated this message. */
|
|
1017
1306
|
client;
|
|
1018
1307
|
/** Snowflake ID of this message. */
|
|
@@ -1041,7 +1330,7 @@ var Message = class _Message extends Base {
|
|
|
1041
1330
|
mentionEveryone;
|
|
1042
1331
|
/** Whether this is a text-to-speech message. */
|
|
1043
1332
|
tts;
|
|
1044
|
-
/** Embedded content (
|
|
1333
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
1045
1334
|
embeds;
|
|
1046
1335
|
/** Stickers sent with the message. */
|
|
1047
1336
|
stickers;
|
|
@@ -1063,26 +1352,41 @@ var Message = class _Message extends Base {
|
|
|
1063
1352
|
mentionRoles;
|
|
1064
1353
|
/** Client-side nonce for deduplication. */
|
|
1065
1354
|
nonce;
|
|
1066
|
-
/**
|
|
1355
|
+
/**
|
|
1356
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1357
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
1358
|
+
*/
|
|
1067
1359
|
get channel() {
|
|
1068
|
-
|
|
1360
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1361
|
+
return channel?.isTextBased() ? channel : null;
|
|
1069
1362
|
}
|
|
1070
1363
|
/** Cached guild, or null for DMs / uncached. */
|
|
1071
1364
|
get guild() {
|
|
1072
1365
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
1073
1366
|
}
|
|
1074
|
-
/**
|
|
1367
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
1368
|
+
get member() {
|
|
1369
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1373
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1374
|
+
* @example
|
|
1375
|
+
* const channel = await message.resolveChannel();
|
|
1376
|
+
* await channel.delete();
|
|
1377
|
+
*/
|
|
1075
1378
|
async resolveChannel() {
|
|
1076
1379
|
return this.client.channels.resolve(this.channelId);
|
|
1077
1380
|
}
|
|
1078
|
-
/**
|
|
1381
|
+
/**
|
|
1382
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
1383
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
1384
|
+
* @example
|
|
1385
|
+
* const guild = await message.resolveGuild();
|
|
1386
|
+
*/
|
|
1079
1387
|
async resolveGuild() {
|
|
1080
1388
|
if (!this.guildId) return null;
|
|
1081
|
-
|
|
1082
|
-
return await this.client.guilds.resolve(this.guildId);
|
|
1083
|
-
} catch {
|
|
1084
|
-
return null;
|
|
1085
|
-
}
|
|
1389
|
+
return this.client.guilds.resolve(this.guildId);
|
|
1086
1390
|
}
|
|
1087
1391
|
/**
|
|
1088
1392
|
* Construct a message from API data.
|
|
@@ -1099,29 +1403,73 @@ var Message = class _Message extends Base {
|
|
|
1099
1403
|
this.createdAt = new Date(data.timestamp);
|
|
1100
1404
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1101
1405
|
this.pinned = data.pinned;
|
|
1102
|
-
this.attachments = new
|
|
1103
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
1406
|
+
this.attachments = new Collection3();
|
|
1407
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1104
1408
|
this.type = data.type ?? MessageType.Default;
|
|
1105
|
-
this.flags = data.flags ?? 0;
|
|
1409
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1106
1410
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1107
1411
|
this.tts = data.tts ?? false;
|
|
1108
|
-
this.embeds = data.embeds ?? [];
|
|
1109
|
-
this.stickers = data.stickers ?? [];
|
|
1110
|
-
this.reactions =
|
|
1111
|
-
this.
|
|
1112
|
-
this.
|
|
1113
|
-
|
|
1412
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1413
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
1414
|
+
this.reactions = new MessageReactionManager(this);
|
|
1415
|
+
this.reactions._patch(data.reactions);
|
|
1416
|
+
this.messageReference = data.message_reference ? {
|
|
1417
|
+
channelId: data.message_reference.channel_id,
|
|
1418
|
+
messageId: data.message_reference.message_id,
|
|
1419
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1420
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1421
|
+
} : null;
|
|
1422
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
1423
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1114
1424
|
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
1115
1425
|
this.webhookId = data.webhook_id ?? null;
|
|
1116
1426
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1117
1427
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1118
1428
|
this.nonce = data.nonce ?? null;
|
|
1119
1429
|
}
|
|
1120
|
-
/**
|
|
1430
|
+
/**
|
|
1431
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
1432
|
+
* @internal
|
|
1433
|
+
*/
|
|
1434
|
+
_patch(data) {
|
|
1435
|
+
this.content = data.content;
|
|
1436
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1437
|
+
this.pinned = data.pinned;
|
|
1438
|
+
this.attachments.clear();
|
|
1439
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1440
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1441
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1442
|
+
this.tts = data.tts ?? false;
|
|
1443
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1444
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1445
|
+
this.reactions._patch(data.reactions);
|
|
1446
|
+
this.messageReference = data.message_reference ? {
|
|
1447
|
+
channelId: data.message_reference.channel_id,
|
|
1448
|
+
messageId: data.message_reference.message_id,
|
|
1449
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1450
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1451
|
+
} : null;
|
|
1452
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1453
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1454
|
+
);
|
|
1455
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1456
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1457
|
+
this.webhookId = data.webhook_id ?? null;
|
|
1458
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1459
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
1460
|
+
this.nonce = data.nonce ?? null;
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Send a standalone message in this channel (not a reply).
|
|
1464
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
1465
|
+
*/
|
|
1121
1466
|
async send(options) {
|
|
1122
1467
|
return sendMessage(this, options);
|
|
1123
1468
|
}
|
|
1124
|
-
/**
|
|
1469
|
+
/**
|
|
1470
|
+
* Send a message to another channel by ID.
|
|
1471
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
1472
|
+
*/
|
|
1125
1473
|
async sendTo(channelId, options) {
|
|
1126
1474
|
return sendMessageTo(this, channelId, options);
|
|
1127
1475
|
}
|
|
@@ -1135,6 +1483,16 @@ var Message = class _Message extends Base {
|
|
|
1135
1483
|
async reply(options, replyOptions) {
|
|
1136
1484
|
return replyToMessage(this, options, replyOptions);
|
|
1137
1485
|
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Hydrate a partial message, or return the message as-is.
|
|
1488
|
+
* @example
|
|
1489
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
1490
|
+
* const message = await Message.resolve(msg);
|
|
1491
|
+
* });
|
|
1492
|
+
*/
|
|
1493
|
+
static async resolve(message) {
|
|
1494
|
+
return message.partial ? message.fetch() : message;
|
|
1495
|
+
}
|
|
1138
1496
|
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
1139
1497
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
1140
1498
|
return createMessageBody(content, referenced_message, ping);
|
|
@@ -1147,7 +1505,7 @@ var Message = class _Message extends Base {
|
|
|
1147
1505
|
async edit(options) {
|
|
1148
1506
|
const body = {};
|
|
1149
1507
|
if (options.content !== void 0) body.content = options.content;
|
|
1150
|
-
if (options.embeds
|
|
1508
|
+
if (options.embeds !== void 0) {
|
|
1151
1509
|
body.embeds = options.embeds.map(
|
|
1152
1510
|
(e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
|
|
1153
1511
|
);
|
|
@@ -1155,7 +1513,8 @@ var Message = class _Message extends Base {
|
|
|
1155
1513
|
if (options.allowedMentions) {
|
|
1156
1514
|
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
1157
1515
|
}
|
|
1158
|
-
|
|
1516
|
+
const flags = resolveMessageFlags(options.flags);
|
|
1517
|
+
if (flags !== void 0) body.flags = flags;
|
|
1159
1518
|
if (options.attachments !== void 0) {
|
|
1160
1519
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
1161
1520
|
}
|
|
@@ -1170,6 +1529,13 @@ var Message = class _Message extends Base {
|
|
|
1170
1529
|
createReactionCollector(options) {
|
|
1171
1530
|
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
1172
1531
|
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
1534
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1535
|
+
*/
|
|
1536
|
+
awaitReactions(options) {
|
|
1537
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1538
|
+
}
|
|
1173
1539
|
/** Fetch the latest version of this message from the API. */
|
|
1174
1540
|
async fetch() {
|
|
1175
1541
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
@@ -1223,7 +1589,68 @@ var Message = class _Message extends Base {
|
|
|
1223
1589
|
}
|
|
1224
1590
|
};
|
|
1225
1591
|
|
|
1592
|
+
// src/Domain/Message/PartialMessage.ts
|
|
1593
|
+
import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
|
|
1594
|
+
var PartialMessage = class {
|
|
1595
|
+
partial = true;
|
|
1596
|
+
client;
|
|
1597
|
+
id;
|
|
1598
|
+
channelId;
|
|
1599
|
+
guildId;
|
|
1600
|
+
content;
|
|
1601
|
+
authorId;
|
|
1602
|
+
author;
|
|
1603
|
+
createdAt;
|
|
1604
|
+
constructor(client, data) {
|
|
1605
|
+
this.client = client;
|
|
1606
|
+
this.id = data.id;
|
|
1607
|
+
this.channelId = data.channelId;
|
|
1608
|
+
this.guildId = data.guildId ?? null;
|
|
1609
|
+
this.content = data.content ?? null;
|
|
1610
|
+
this.authorId = data.authorId ?? null;
|
|
1611
|
+
this.author = data.author ?? null;
|
|
1612
|
+
this.createdAt = data.createdAt ?? (SnowflakeUtil2.isValid(data.id) ? SnowflakeUtil2.dateFromSnowflake(data.id) : null);
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
1616
|
+
* Same contract as {@link Message.channel}.
|
|
1617
|
+
*/
|
|
1618
|
+
get channel() {
|
|
1619
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1620
|
+
return channel?.isTextBased() ? channel : null;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1624
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1625
|
+
* @example
|
|
1626
|
+
* const channel = await message.resolveChannel();
|
|
1627
|
+
* await channel.delete();
|
|
1628
|
+
*/
|
|
1629
|
+
async resolveChannel() {
|
|
1630
|
+
return this.client.channels.resolve(this.channelId);
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Fetch the full message from the API.
|
|
1634
|
+
* @example
|
|
1635
|
+
* const message = await partial.fetch();
|
|
1636
|
+
* await message.reply('Pong!');
|
|
1637
|
+
*/
|
|
1638
|
+
async fetch() {
|
|
1639
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1643
|
+
// src/Domain/User.ts
|
|
1644
|
+
import { Routes as Routes14 } from "@fluxerjs/types";
|
|
1645
|
+
import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
|
|
1646
|
+
|
|
1647
|
+
// src/Domain/Channel/Base.ts
|
|
1648
|
+
import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
|
|
1649
|
+
import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
|
|
1650
|
+
|
|
1226
1651
|
// src/ClientCore/MessageManager.ts
|
|
1652
|
+
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
1653
|
+
import { Routes as Routes5 } from "@fluxerjs/types";
|
|
1227
1654
|
var BULK = {
|
|
1228
1655
|
requests: { min: 1, max: 25 },
|
|
1229
1656
|
limit: { min: 1, max: 25 },
|
|
@@ -1257,19 +1684,40 @@ var MessageManager = class {
|
|
|
1257
1684
|
this.client = client;
|
|
1258
1685
|
this.channelId = channelId;
|
|
1259
1686
|
}
|
|
1687
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1688
|
+
_structures = new Collection4();
|
|
1260
1689
|
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1261
1690
|
get(messageId) {
|
|
1262
1691
|
const data = this.client._getMessageCache(this.channelId)?.get(messageId);
|
|
1263
|
-
|
|
1692
|
+
if (!data) {
|
|
1693
|
+
this._structures.delete(messageId);
|
|
1694
|
+
return void 0;
|
|
1695
|
+
}
|
|
1696
|
+
const existing = this._structures.get(messageId);
|
|
1697
|
+
if (existing) return existing;
|
|
1698
|
+
const message = new Message(this.client, data);
|
|
1699
|
+
this._structures.set(messageId, message);
|
|
1700
|
+
return message;
|
|
1701
|
+
}
|
|
1702
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1703
|
+
async resolve(messageId) {
|
|
1704
|
+
return this.get(messageId) ?? this.fetch(messageId);
|
|
1264
1705
|
}
|
|
1265
1706
|
async fetch(idOrOptions) {
|
|
1266
1707
|
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1267
1708
|
}
|
|
1268
|
-
/** Cache API data and return a {@link Message}
|
|
1709
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1269
1710
|
wrap(data) {
|
|
1270
1711
|
this.client._addMessageToCache(this.channelId, data);
|
|
1271
1712
|
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
1272
|
-
|
|
1713
|
+
const existing = this._structures.get(data.id);
|
|
1714
|
+
if (existing) {
|
|
1715
|
+
existing._patch(cached);
|
|
1716
|
+
return existing;
|
|
1717
|
+
}
|
|
1718
|
+
const message = new Message(this.client, cached);
|
|
1719
|
+
this._structures.set(data.id, message);
|
|
1720
|
+
return message;
|
|
1273
1721
|
}
|
|
1274
1722
|
/** Fetch a single message from the API. */
|
|
1275
1723
|
async fetchOne(messageId) {
|
|
@@ -1302,12 +1750,110 @@ var MessageManager = class {
|
|
|
1302
1750
|
}
|
|
1303
1751
|
const base = Routes5.channelMessages(this.channelId);
|
|
1304
1752
|
const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
|
|
1305
|
-
const collection = new
|
|
1753
|
+
const collection = new Collection4();
|
|
1306
1754
|
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
1307
1755
|
return collection;
|
|
1308
1756
|
}
|
|
1309
1757
|
};
|
|
1310
1758
|
|
|
1759
|
+
// src/Helpers/MessageCollector.ts
|
|
1760
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
1761
|
+
import { Collection as Collection5 } from "@fluxerjs/collection";
|
|
1762
|
+
function requireCollectorBounds(options) {
|
|
1763
|
+
const time = options.time ?? 0;
|
|
1764
|
+
const max = options.max ?? 0;
|
|
1765
|
+
if (time <= 0 && max <= 0) {
|
|
1766
|
+
throw new FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
1767
|
+
code: ErrorCodes.CollectorOptionsRequired
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
var MessageCollector = class _MessageCollector extends EventEmitter2 {
|
|
1772
|
+
client;
|
|
1773
|
+
channelId;
|
|
1774
|
+
options;
|
|
1775
|
+
collected = new Collection5();
|
|
1776
|
+
_timeout = null;
|
|
1777
|
+
_ended = false;
|
|
1778
|
+
_listener;
|
|
1779
|
+
constructor(client, channelId, options = {}) {
|
|
1780
|
+
super();
|
|
1781
|
+
requireCollectorBounds(options);
|
|
1782
|
+
this.client = client;
|
|
1783
|
+
this.channelId = channelId;
|
|
1784
|
+
this.options = {
|
|
1785
|
+
filter: options.filter ?? (() => true),
|
|
1786
|
+
time: options.time ?? 0,
|
|
1787
|
+
max: options.max ?? 0
|
|
1788
|
+
};
|
|
1789
|
+
this._listener = (message) => {
|
|
1790
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
1791
|
+
if (!this.options.filter(message)) return;
|
|
1792
|
+
this.collected.set(message.id, message);
|
|
1793
|
+
this.emit("collect", message);
|
|
1794
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
1795
|
+
this.stop("limit");
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
1799
|
+
if (this.options.time > 0) {
|
|
1800
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
stop(reason = "user") {
|
|
1804
|
+
if (this._ended) return;
|
|
1805
|
+
this._ended = true;
|
|
1806
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
1807
|
+
if (this._timeout) {
|
|
1808
|
+
clearTimeout(this._timeout);
|
|
1809
|
+
this._timeout = null;
|
|
1810
|
+
}
|
|
1811
|
+
this.emit("end", this.collected, reason);
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
1815
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
1816
|
+
* the end reason is not listed in `errors`).
|
|
1817
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
1818
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
1819
|
+
*/
|
|
1820
|
+
static awaitMessages(client, channelId, options) {
|
|
1821
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
1822
|
+
return new Promise((resolve, reject) => {
|
|
1823
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
1824
|
+
collector.on("end", (collected, reason) => {
|
|
1825
|
+
if (!errors.includes(reason)) {
|
|
1826
|
+
resolve(collected);
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
if (reason === "time") {
|
|
1830
|
+
reject(
|
|
1831
|
+
new FluxerError("Message collector timed out", {
|
|
1832
|
+
code: ErrorCodes.CollectorIdle
|
|
1833
|
+
})
|
|
1834
|
+
);
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1837
|
+
if (reason === "limit") {
|
|
1838
|
+
reject(
|
|
1839
|
+
new FluxerError("Message collector reached max", {
|
|
1840
|
+
code: ErrorCodes.CollectorMax
|
|
1841
|
+
})
|
|
1842
|
+
);
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
reject(collected);
|
|
1846
|
+
});
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
on(event, listener) {
|
|
1850
|
+
return super.on(event, listener);
|
|
1851
|
+
}
|
|
1852
|
+
emit(event, ...args) {
|
|
1853
|
+
return super.emit(event, ...args);
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
|
|
1311
1857
|
// src/Domain/Channel/Attachments.ts
|
|
1312
1858
|
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
1313
1859
|
function asBytes(data) {
|
|
@@ -1386,6 +1932,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1386
1932
|
|
|
1387
1933
|
// src/Domain/Channel/Base.ts
|
|
1388
1934
|
var Channel = class extends Base {
|
|
1935
|
+
#messages;
|
|
1389
1936
|
/** The {@link Client} that instantiated this channel. */
|
|
1390
1937
|
client;
|
|
1391
1938
|
/** Snowflake ID of this channel. */
|
|
@@ -1409,11 +1956,11 @@ var Channel = class extends Base {
|
|
|
1409
1956
|
}
|
|
1410
1957
|
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1411
1958
|
get createdTimestamp() {
|
|
1412
|
-
return
|
|
1959
|
+
return SnowflakeUtil3.timestampFromSnowflake(this.id);
|
|
1413
1960
|
}
|
|
1414
1961
|
/** Date when this channel was created, derived from its snowflake ID. */
|
|
1415
1962
|
get createdAt() {
|
|
1416
|
-
return
|
|
1963
|
+
return SnowflakeUtil3.dateFromSnowflake(this.id);
|
|
1417
1964
|
}
|
|
1418
1965
|
/**
|
|
1419
1966
|
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
@@ -1427,19 +1974,36 @@ var Channel = class extends Base {
|
|
|
1427
1974
|
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1428
1975
|
}
|
|
1429
1976
|
}
|
|
1430
|
-
/**
|
|
1977
|
+
/** @internal Factory wired after subclasses load. */
|
|
1431
1978
|
static from(_c, _d) {
|
|
1432
1979
|
throw new Error("Channel.from not initialized");
|
|
1433
1980
|
}
|
|
1981
|
+
/** @internal Factory wired after subclasses load. */
|
|
1434
1982
|
static fromOrCreate(_c, _d) {
|
|
1435
1983
|
throw new Error("Channel.fromOrCreate not initialized");
|
|
1436
1984
|
}
|
|
1985
|
+
/** @internal Factory wired after subclasses load. */
|
|
1437
1986
|
static createDM(_c, _d) {
|
|
1438
1987
|
throw new Error("Channel.createDM not initialized");
|
|
1439
1988
|
}
|
|
1440
|
-
/**
|
|
1989
|
+
/**
|
|
1990
|
+
* Whether this channel type can carry messages (text, voice, DM, group DM, notes).
|
|
1991
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
1992
|
+
*/
|
|
1441
1993
|
isTextBased() {
|
|
1442
|
-
return
|
|
1994
|
+
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
|
|
1995
|
+
}
|
|
1996
|
+
/** Check if this is a guild channel (text, voice, category, or link). */
|
|
1997
|
+
isGuild() {
|
|
1998
|
+
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
|
|
1999
|
+
}
|
|
2000
|
+
/** Check if this is a guild text channel. */
|
|
2001
|
+
isText() {
|
|
2002
|
+
return this.type === ChannelType.GuildText;
|
|
2003
|
+
}
|
|
2004
|
+
/** Check if this is a category channel. */
|
|
2005
|
+
isCategory() {
|
|
2006
|
+
return this.type === ChannelType.GuildCategory;
|
|
1443
2007
|
}
|
|
1444
2008
|
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1445
2009
|
isDM() {
|
|
@@ -1451,11 +2015,11 @@ var Channel = class extends Base {
|
|
|
1451
2015
|
}
|
|
1452
2016
|
/** Check if this is a voice channel. */
|
|
1453
2017
|
isVoice() {
|
|
1454
|
-
return
|
|
2018
|
+
return this.type === ChannelType.GuildVoice;
|
|
1455
2019
|
}
|
|
1456
2020
|
/** Check if this is a link channel. */
|
|
1457
2021
|
isLink() {
|
|
1458
|
-
return
|
|
2022
|
+
return this.type === ChannelType.GuildLink;
|
|
1459
2023
|
}
|
|
1460
2024
|
/**
|
|
1461
2025
|
* Delete recent messages or an explicit ID list.
|
|
@@ -1494,7 +2058,7 @@ var Channel = class extends Base {
|
|
|
1494
2058
|
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1495
2059
|
return ids;
|
|
1496
2060
|
}
|
|
1497
|
-
/** Delete all messages sent by the bot in this channel
|
|
2061
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1498
2062
|
async bulkDeleteMyMessages(options) {
|
|
1499
2063
|
const body = options ? toSudoBody(options) : void 0;
|
|
1500
2064
|
await this.client.rest.post(Routes7.channelBulkDeleteMine(this.id), {
|
|
@@ -1502,11 +2066,17 @@ var Channel = class extends Base {
|
|
|
1502
2066
|
auth: true
|
|
1503
2067
|
});
|
|
1504
2068
|
}
|
|
1505
|
-
/**
|
|
2069
|
+
/**
|
|
2070
|
+
* Mark all pinned messages as read in this channel.
|
|
2071
|
+
* Session-token helper; bots usually skip this.
|
|
2072
|
+
*/
|
|
1506
2073
|
async acknowledgePins() {
|
|
1507
2074
|
await this.client.rest.post(Routes7.channelPinsAck(this.id), { auth: true });
|
|
1508
2075
|
}
|
|
1509
|
-
/**
|
|
2076
|
+
/**
|
|
2077
|
+
* Clear the read state for this channel.
|
|
2078
|
+
* Session-token helper; bots usually skip this.
|
|
2079
|
+
*/
|
|
1510
2080
|
async clearReadState() {
|
|
1511
2081
|
await this.client.rest.delete(Routes7.channelMessagesAck(this.id), { auth: true });
|
|
1512
2082
|
}
|
|
@@ -1542,7 +2112,11 @@ var Channel = class extends Base {
|
|
|
1542
2112
|
async sendTyping() {
|
|
1543
2113
|
await this.client.rest.post(Routes7.channelTyping(this.id), { auth: true });
|
|
1544
2114
|
}
|
|
1545
|
-
/**
|
|
2115
|
+
/**
|
|
2116
|
+
* Fetch available RTC regions for voice channels.
|
|
2117
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
2118
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
2119
|
+
*/
|
|
1546
2120
|
async fetchRtcRegions() {
|
|
1547
2121
|
const data = await this.client.rest.get(Routes7.channelRtcRegions(this.id), {
|
|
1548
2122
|
auth: true
|
|
@@ -1561,71 +2135,65 @@ var Channel = class extends Base {
|
|
|
1561
2135
|
nextSendAllowedAt: data.next_send_allowed_at
|
|
1562
2136
|
};
|
|
1563
2137
|
}
|
|
1564
|
-
/**
|
|
2138
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1565
2139
|
canSendMessage() {
|
|
1566
|
-
return this.
|
|
2140
|
+
return this.isTextBased();
|
|
1567
2141
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
// src/Domain/Channel/TextCapable.ts
|
|
1574
|
-
import { Routes as Routes8 } from "@fluxerjs/types";
|
|
1575
|
-
|
|
1576
|
-
// src/Helpers/MessageCollector.ts
|
|
1577
|
-
import { EventEmitter as EventEmitter2 } from "events";
|
|
1578
|
-
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
1579
|
-
var MessageCollector = class extends EventEmitter2 {
|
|
1580
|
-
client;
|
|
1581
|
-
channelId;
|
|
1582
|
-
options;
|
|
1583
|
-
collected = new Collection4();
|
|
1584
|
-
_timeout = null;
|
|
1585
|
-
_ended = false;
|
|
1586
|
-
_listener;
|
|
1587
|
-
constructor(client, channelId, options = {}) {
|
|
1588
|
-
super();
|
|
1589
|
-
this.client = client;
|
|
1590
|
-
this.channelId = channelId;
|
|
1591
|
-
this.options = {
|
|
1592
|
-
filter: options.filter ?? (() => true),
|
|
1593
|
-
time: options.time ?? 0,
|
|
1594
|
-
max: options.max ?? 0
|
|
1595
|
-
};
|
|
1596
|
-
this._listener = (message) => {
|
|
1597
|
-
if (this._ended || message.channelId !== this.channelId) return;
|
|
1598
|
-
if (!this.options.filter(message)) return;
|
|
1599
|
-
this.collected.set(message.id, message);
|
|
1600
|
-
this.emit("collect", message);
|
|
1601
|
-
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
1602
|
-
this.stop("limit");
|
|
1603
|
-
}
|
|
1604
|
-
};
|
|
1605
|
-
this.client.on(Events.MessageCreate, this._listener);
|
|
1606
|
-
if (this.options.time > 0) {
|
|
1607
|
-
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
2142
|
+
/** Per-channel message cache + fetch. */
|
|
2143
|
+
get messages() {
|
|
2144
|
+
if (!this.#messages) {
|
|
2145
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1608
2146
|
}
|
|
2147
|
+
return this.#messages;
|
|
1609
2148
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
this.
|
|
1613
|
-
this.client.off(Events.MessageCreate, this._listener);
|
|
1614
|
-
if (this._timeout) {
|
|
1615
|
-
clearTimeout(this._timeout);
|
|
1616
|
-
this._timeout = null;
|
|
1617
|
-
}
|
|
1618
|
-
this.emit("end", this.collected, reason);
|
|
2149
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
2150
|
+
createMessageCollector(options) {
|
|
2151
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1619
2152
|
}
|
|
1620
|
-
|
|
1621
|
-
|
|
2153
|
+
/**
|
|
2154
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
2155
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
2156
|
+
* @example
|
|
2157
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
2158
|
+
*/
|
|
2159
|
+
awaitMessages(options) {
|
|
2160
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
1622
2161
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
2162
|
+
/**
|
|
2163
|
+
* Delete this channel (or close it if it is a DM).
|
|
2164
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
2165
|
+
* @example
|
|
2166
|
+
* const channel = await client.channels.fetch(channelId);
|
|
2167
|
+
* await channel.delete();
|
|
2168
|
+
*/
|
|
2169
|
+
async delete(options) {
|
|
2170
|
+
const params = new URLSearchParams();
|
|
2171
|
+
if (options?.silent) params.set("silent", "true");
|
|
2172
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2173
|
+
const qs2 = params.toString();
|
|
2174
|
+
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2175
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2176
|
+
await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2177
|
+
body,
|
|
2178
|
+
auth: true
|
|
2179
|
+
});
|
|
2180
|
+
this.client.channels.delete(this.id);
|
|
2181
|
+
this.client._clearMessageCache(this.id);
|
|
2182
|
+
if (this.isGuild() && this.guildId) {
|
|
2183
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
/** Channel mention (`<#id>`). */
|
|
2187
|
+
toString() {
|
|
2188
|
+
return `<#${this.id}>`;
|
|
1625
2189
|
}
|
|
1626
2190
|
};
|
|
1627
2191
|
|
|
2192
|
+
// src/Domain/Channel/Dm.ts
|
|
2193
|
+
import { ChannelType as ChannelType2, Routes as Routes9 } from "@fluxerjs/types";
|
|
2194
|
+
|
|
1628
2195
|
// src/Domain/Channel/TextCapable.ts
|
|
2196
|
+
import { Routes as Routes8 } from "@fluxerjs/types";
|
|
1629
2197
|
async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
1630
2198
|
const params = new URLSearchParams();
|
|
1631
2199
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
@@ -1643,27 +2211,19 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
|
1643
2211
|
}
|
|
1644
2212
|
function TextCapable(Base2) {
|
|
1645
2213
|
class TextCapableChannel extends Base2 {
|
|
1646
|
-
|
|
2214
|
+
/**
|
|
2215
|
+
* Send a message in this channel.
|
|
2216
|
+
* @example
|
|
2217
|
+
* await channel.send('hi');
|
|
2218
|
+
*/
|
|
1647
2219
|
async send(options) {
|
|
1648
|
-
|
|
1649
|
-
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
1650
|
-
});
|
|
1651
|
-
const data = await this.client.rest.post(Routes8.channelMessages(this.id), payload);
|
|
1652
|
-
this.client._addMessageToCache(this.id, data);
|
|
1653
|
-
return new Message(this.client, data);
|
|
1654
|
-
}
|
|
1655
|
-
get messages() {
|
|
1656
|
-
if (!this.#messages) {
|
|
1657
|
-
this.#messages = new MessageManager(this.client, this.id);
|
|
1658
|
-
}
|
|
1659
|
-
return this.#messages;
|
|
1660
|
-
}
|
|
1661
|
-
createMessageCollector(options) {
|
|
1662
|
-
return new MessageCollector(this.client, this.id, options);
|
|
2220
|
+
return this.client.channels.send(this.id, options);
|
|
1663
2221
|
}
|
|
2222
|
+
/** Fetch pinned messages in this channel. */
|
|
1664
2223
|
async fetchPinnedMessages(options) {
|
|
1665
2224
|
return (await this.fetchPinnedMessagesPage(options)).messages;
|
|
1666
2225
|
}
|
|
2226
|
+
/** Fetch a page of pinned messages plus pagination metadata. */
|
|
1667
2227
|
async fetchPinnedMessagesPage(options) {
|
|
1668
2228
|
return fetchPinnedMessagesPageFor(this.client, this.id, options);
|
|
1669
2229
|
}
|
|
@@ -1689,7 +2249,38 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1689
2249
|
this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
|
|
1690
2250
|
this.nicks = full.nicks ?? {};
|
|
1691
2251
|
}
|
|
1692
|
-
/**
|
|
2252
|
+
/**
|
|
2253
|
+
* Apply DM/group-DM fields in place.
|
|
2254
|
+
* @internal
|
|
2255
|
+
*/
|
|
2256
|
+
_patch(data) {
|
|
2257
|
+
super._patch(data);
|
|
2258
|
+
const full = data;
|
|
2259
|
+
if ("last_message_id" in full && full.last_message_id !== void 0) {
|
|
2260
|
+
this.lastMessageId = full.last_message_id ?? null;
|
|
2261
|
+
}
|
|
2262
|
+
if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
|
|
2263
|
+
if ("recipients" in full && full.recipients !== void 0) {
|
|
2264
|
+
this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2265
|
+
}
|
|
2266
|
+
if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
|
|
2267
|
+
}
|
|
2268
|
+
/**
|
|
2269
|
+
* Edit this group DM (name, icon, nicks).
|
|
2270
|
+
* Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
|
|
2271
|
+
*/
|
|
2272
|
+
async edit(options) {
|
|
2273
|
+
const data = await this.client.rest.patch(Routes9.channel(this.id), {
|
|
2274
|
+
body: toGroupDmEditBody(options),
|
|
2275
|
+
auth: true
|
|
2276
|
+
});
|
|
2277
|
+
this._patch(data);
|
|
2278
|
+
return this;
|
|
2279
|
+
}
|
|
2280
|
+
/**
|
|
2281
|
+
* Purge all messages from personal notes. Only works on personal notes channels.
|
|
2282
|
+
* Notes-only; bots usually skip this.
|
|
2283
|
+
*/
|
|
1693
2284
|
async purgeMessages() {
|
|
1694
2285
|
if (this.type !== ChannelType2.DMPersonalNotes) {
|
|
1695
2286
|
throw new FluxerError("purgeMessages is only available on personal notes channels", {
|
|
@@ -1702,15 +2293,24 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1702
2293
|
);
|
|
1703
2294
|
return data.deleted_count;
|
|
1704
2295
|
}
|
|
1705
|
-
/**
|
|
2296
|
+
/**
|
|
2297
|
+
* Pin this DM channel to the top of the DM list.
|
|
2298
|
+
* Session-token helper; bots usually skip this.
|
|
2299
|
+
*/
|
|
1706
2300
|
async pinInList() {
|
|
1707
2301
|
await this.client.rest.put(Routes9.userMeChannelPin(this.id), { auth: true });
|
|
1708
2302
|
}
|
|
1709
|
-
/**
|
|
2303
|
+
/**
|
|
2304
|
+
* Unpin this DM channel from the DM list.
|
|
2305
|
+
* Session-token helper; bots usually skip this.
|
|
2306
|
+
*/
|
|
1710
2307
|
async unpinFromList() {
|
|
1711
2308
|
await this.client.rest.delete(Routes9.userMeChannelPin(this.id), { auth: true });
|
|
1712
2309
|
}
|
|
1713
|
-
/**
|
|
2310
|
+
/**
|
|
2311
|
+
* Add a user to this group DM.
|
|
2312
|
+
* Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
|
|
2313
|
+
*/
|
|
1714
2314
|
async addRecipient(userId) {
|
|
1715
2315
|
await this.client.rest.put(Routes9.channelRecipient(this.id, userId), { auth: true });
|
|
1716
2316
|
const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
|
|
@@ -1726,7 +2326,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1726
2326
|
};
|
|
1727
2327
|
|
|
1728
2328
|
// src/Domain/Channel/Guild.ts
|
|
1729
|
-
import { Routes as
|
|
2329
|
+
import { Routes as Routes13 } from "@fluxerjs/types";
|
|
1730
2330
|
import { PermissionFlags } from "@fluxerjs/util";
|
|
1731
2331
|
|
|
1732
2332
|
// src/Domain/Invite.ts
|
|
@@ -1734,7 +2334,6 @@ import {
|
|
|
1734
2334
|
InviteType,
|
|
1735
2335
|
isGroupDmInvite,
|
|
1736
2336
|
isGuildInvite,
|
|
1737
|
-
isPackInvite,
|
|
1738
2337
|
Routes as Routes10
|
|
1739
2338
|
} from "@fluxerjs/types";
|
|
1740
2339
|
|
|
@@ -1930,13 +2529,36 @@ function parseInviteCode(codeOrUrl) {
|
|
|
1930
2529
|
}
|
|
1931
2530
|
return code;
|
|
1932
2531
|
}
|
|
2532
|
+
function parseOptionalDate(value) {
|
|
2533
|
+
if (value == null || value === "") return null;
|
|
2534
|
+
const date = new Date(value);
|
|
2535
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
2536
|
+
}
|
|
2537
|
+
function toInviteGuild(data) {
|
|
2538
|
+
return {
|
|
2539
|
+
id: data.id,
|
|
2540
|
+
name: data.name,
|
|
2541
|
+
icon: data.icon ?? null,
|
|
2542
|
+
banner: data.banner ?? null,
|
|
2543
|
+
splash: data.splash ?? null,
|
|
2544
|
+
features: data.features ?? []
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
function toInviteChannel(data) {
|
|
2548
|
+
return {
|
|
2549
|
+
id: data.id,
|
|
2550
|
+
name: data.name ?? null,
|
|
2551
|
+
type: data.type,
|
|
2552
|
+
icon: data.icon ?? null,
|
|
2553
|
+
parentId: data.parent_id ?? null
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
1933
2556
|
var Invite = class _Invite extends Base {
|
|
1934
2557
|
client;
|
|
1935
2558
|
code;
|
|
1936
2559
|
type;
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
pack;
|
|
2560
|
+
guildSnapshot;
|
|
2561
|
+
channelSnapshot;
|
|
1940
2562
|
inviter;
|
|
1941
2563
|
memberCount;
|
|
1942
2564
|
presenceCount;
|
|
@@ -1951,15 +2573,14 @@ var Invite = class _Invite extends Base {
|
|
|
1951
2573
|
this.client = client;
|
|
1952
2574
|
this.code = data.code;
|
|
1953
2575
|
this.type = data.type;
|
|
1954
|
-
this.
|
|
1955
|
-
this.
|
|
1956
|
-
this.pack = isPackInvite(data) ? data.pack : null;
|
|
2576
|
+
this.guildSnapshot = isGuildInvite(data) ? toInviteGuild(data.guild) : null;
|
|
2577
|
+
this.channelSnapshot = isGuildInvite(data) || isGroupDmInvite(data) ? toInviteChannel(data.channel) : null;
|
|
1957
2578
|
this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
|
|
1958
|
-
this.memberCount =
|
|
2579
|
+
this.memberCount = data.member_count ?? null;
|
|
1959
2580
|
this.presenceCount = isGuildInvite(data) ? data.presence_count ?? null : null;
|
|
1960
|
-
this.expiresAt = data.expires_at
|
|
2581
|
+
this.expiresAt = parseOptionalDate(data.expires_at);
|
|
1961
2582
|
this.temporary = data.temporary ?? null;
|
|
1962
|
-
this.createdAt = data.created_at
|
|
2583
|
+
this.createdAt = parseOptionalDate(data.created_at);
|
|
1963
2584
|
this.uses = data.uses ?? null;
|
|
1964
2585
|
this.maxUses = data.max_uses ?? null;
|
|
1965
2586
|
this.maxAge = data.max_age ?? null;
|
|
@@ -1970,16 +2591,25 @@ var Invite = class _Invite extends Base {
|
|
|
1970
2591
|
isGroupDM() {
|
|
1971
2592
|
return this.type === InviteType.GroupDM;
|
|
1972
2593
|
}
|
|
1973
|
-
isPack() {
|
|
1974
|
-
return this.type === InviteType.EmojiPack || this.type === InviteType.StickerPack;
|
|
1975
|
-
}
|
|
1976
2594
|
/** Full invite URL (uses this client's instance invite base). */
|
|
1977
2595
|
get url() {
|
|
1978
2596
|
return inviteUrl(this.client.instance.endpoints.invite, this.code);
|
|
1979
2597
|
}
|
|
1980
|
-
/**
|
|
1981
|
-
|
|
1982
|
-
|
|
2598
|
+
/**
|
|
2599
|
+
* Resolve the cached/fetched {@link Guild} for this invite, or null.
|
|
2600
|
+
* `guildSnapshot` is metadata only.
|
|
2601
|
+
*/
|
|
2602
|
+
async resolveGuild() {
|
|
2603
|
+
if (!this.guildSnapshot?.id) return null;
|
|
2604
|
+
return this.client.guilds.resolve(this.guildSnapshot.id);
|
|
2605
|
+
}
|
|
2606
|
+
/**
|
|
2607
|
+
* Resolve the cached/fetched {@link Channel} for this invite, or null.
|
|
2608
|
+
* `channelSnapshot` is metadata only.
|
|
2609
|
+
*/
|
|
2610
|
+
async resolveChannel() {
|
|
2611
|
+
if (!this.channelSnapshot?.id) return null;
|
|
2612
|
+
return this.client.channels.resolve(this.channelSnapshot.id);
|
|
1983
2613
|
}
|
|
1984
2614
|
/** Fetch invite metadata by code or URL (does not join). */
|
|
1985
2615
|
static async fetch(client, codeOrUrl) {
|
|
@@ -1997,7 +2627,7 @@ import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
|
|
|
1997
2627
|
import {
|
|
1998
2628
|
Routes as Routes11
|
|
1999
2629
|
} from "@fluxerjs/types";
|
|
2000
|
-
import { SnowflakeUtil as
|
|
2630
|
+
import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
|
|
2001
2631
|
var Webhook = class _Webhook extends Base {
|
|
2002
2632
|
/** Parent client instance. */
|
|
2003
2633
|
client;
|
|
@@ -2034,11 +2664,11 @@ var Webhook = class _Webhook extends Base {
|
|
|
2034
2664
|
}
|
|
2035
2665
|
/** Unix timestamp (ms) when this webhook was created, derived from its snowflake ID. */
|
|
2036
2666
|
get createdTimestamp() {
|
|
2037
|
-
return
|
|
2667
|
+
return SnowflakeUtil4.timestampFromSnowflake(this.id);
|
|
2038
2668
|
}
|
|
2039
2669
|
/** Date when this webhook was created, derived from its snowflake ID. */
|
|
2040
2670
|
get createdAt() {
|
|
2041
|
-
return
|
|
2671
|
+
return SnowflakeUtil4.dateFromSnowflake(this.id);
|
|
2042
2672
|
}
|
|
2043
2673
|
/** Delete this webhook (token auth when available, otherwise bot auth). */
|
|
2044
2674
|
async delete() {
|
|
@@ -2160,9 +2790,103 @@ var Webhook = class _Webhook extends Base {
|
|
|
2160
2790
|
}
|
|
2161
2791
|
};
|
|
2162
2792
|
|
|
2793
|
+
// src/Domain/Channel/PermissionOverwriteManager.ts
|
|
2794
|
+
import { Collection as Collection6 } from "@fluxerjs/collection";
|
|
2795
|
+
import { Routes as Routes12 } from "@fluxerjs/types";
|
|
2796
|
+
import { resolvePermissionsToBitfield as resolvePermissionsToBitfield3 } from "@fluxerjs/util";
|
|
2797
|
+
|
|
2798
|
+
// src/Domain/Channel/PermissionOverwrite.ts
|
|
2799
|
+
import { PermissionsBitField } from "@fluxerjs/util";
|
|
2800
|
+
var PermissionOverwrite = class {
|
|
2801
|
+
id;
|
|
2802
|
+
type;
|
|
2803
|
+
/** @internal Raw allow bitfield string. */
|
|
2804
|
+
_allow;
|
|
2805
|
+
/** @internal Raw deny bitfield string. */
|
|
2806
|
+
_deny;
|
|
2807
|
+
constructor(data) {
|
|
2808
|
+
this.id = data.id;
|
|
2809
|
+
this.type = data.type;
|
|
2810
|
+
this._allow = data.allow ?? "0";
|
|
2811
|
+
this._deny = data.deny ?? "0";
|
|
2812
|
+
}
|
|
2813
|
+
/** Allowed permissions for this overwrite. */
|
|
2814
|
+
get allow() {
|
|
2815
|
+
return new PermissionsBitField(BigInt(this._allow || "0"));
|
|
2816
|
+
}
|
|
2817
|
+
/** Denied permissions for this overwrite. */
|
|
2818
|
+
get deny() {
|
|
2819
|
+
return new PermissionsBitField(BigInt(this._deny || "0"));
|
|
2820
|
+
}
|
|
2821
|
+
/** Wire shape for permission computation / REST. */
|
|
2822
|
+
toJSON() {
|
|
2823
|
+
return {
|
|
2824
|
+
id: this.id,
|
|
2825
|
+
type: this.type,
|
|
2826
|
+
allow: this._allow,
|
|
2827
|
+
deny: this._deny
|
|
2828
|
+
};
|
|
2829
|
+
}
|
|
2830
|
+
};
|
|
2831
|
+
|
|
2832
|
+
// src/Domain/Channel/PermissionOverwriteManager.ts
|
|
2833
|
+
var PermissionOverwriteManager = class {
|
|
2834
|
+
constructor(channel, initial = []) {
|
|
2835
|
+
this.channel = channel;
|
|
2836
|
+
this._patch(initial);
|
|
2837
|
+
}
|
|
2838
|
+
_cache = new Collection6();
|
|
2839
|
+
/** Cached overwrites keyed by role/member ID. */
|
|
2840
|
+
get cache() {
|
|
2841
|
+
return this._cache;
|
|
2842
|
+
}
|
|
2843
|
+
get size() {
|
|
2844
|
+
return this._cache.size;
|
|
2845
|
+
}
|
|
2846
|
+
[Symbol.iterator]() {
|
|
2847
|
+
return this._cache.values();
|
|
2848
|
+
}
|
|
2849
|
+
/** Wire-shaped overwrites for permission computation. */
|
|
2850
|
+
toJSON() {
|
|
2851
|
+
return [...this._cache.values()].map((o) => o.toJSON());
|
|
2852
|
+
}
|
|
2853
|
+
/** Edit or create a permission overwrite. */
|
|
2854
|
+
async edit(overwriteId, options) {
|
|
2855
|
+
const allow = options.allow !== void 0 ? resolvePermissionsToBitfield3(options.allow) : "0";
|
|
2856
|
+
const deny = options.deny !== void 0 ? resolvePermissionsToBitfield3(options.deny) : "0";
|
|
2857
|
+
await this.channel.client.rest.put(Routes12.channelPermission(this.channel.id, overwriteId), {
|
|
2858
|
+
body: { type: options.type, allow, deny },
|
|
2859
|
+
auth: true
|
|
2860
|
+
});
|
|
2861
|
+
this._cache.set(
|
|
2862
|
+
overwriteId,
|
|
2863
|
+
new PermissionOverwrite({
|
|
2864
|
+
id: overwriteId,
|
|
2865
|
+
type: options.type,
|
|
2866
|
+
allow,
|
|
2867
|
+
deny
|
|
2868
|
+
})
|
|
2869
|
+
);
|
|
2870
|
+
}
|
|
2871
|
+
/** Delete a permission overwrite. */
|
|
2872
|
+
async delete(overwriteId) {
|
|
2873
|
+
await this.channel.client.rest.delete(Routes12.channelPermission(this.channel.id, overwriteId), {
|
|
2874
|
+
auth: true
|
|
2875
|
+
});
|
|
2876
|
+
this._cache.delete(overwriteId);
|
|
2877
|
+
}
|
|
2878
|
+
/** @internal Sync from an API channel payload. */
|
|
2879
|
+
_patch(overwrites) {
|
|
2880
|
+
this._cache.clear();
|
|
2881
|
+
for (const entry of overwrites ?? []) {
|
|
2882
|
+
this._cache.set(entry.id, new PermissionOverwrite(entry));
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
};
|
|
2886
|
+
|
|
2163
2887
|
// src/Domain/Channel/Guild.ts
|
|
2164
2888
|
var GuildChannel = class extends Channel {
|
|
2165
|
-
/** Guild ID this channel belongs to. */
|
|
2889
|
+
/** Guild ID this channel belongs to, or null if missing from the payload. */
|
|
2166
2890
|
guildId;
|
|
2167
2891
|
/** Position in the channel list. */
|
|
2168
2892
|
position;
|
|
@@ -2172,11 +2896,14 @@ var GuildChannel = class extends Channel {
|
|
|
2172
2896
|
permissionOverwrites;
|
|
2173
2897
|
constructor(client, data) {
|
|
2174
2898
|
super(client, data);
|
|
2175
|
-
this.guildId = data.guild_id ??
|
|
2899
|
+
this.guildId = data.guild_id ?? null;
|
|
2176
2900
|
this.name = data.name ?? null;
|
|
2177
2901
|
this.position = data.position;
|
|
2178
2902
|
this.parentId = data.parent_id ?? null;
|
|
2179
|
-
this.permissionOverwrites =
|
|
2903
|
+
this.permissionOverwrites = new PermissionOverwriteManager(
|
|
2904
|
+
this,
|
|
2905
|
+
data.permission_overwrites ?? []
|
|
2906
|
+
);
|
|
2180
2907
|
}
|
|
2181
2908
|
/**
|
|
2182
2909
|
* Apply guild-channel fields in place.
|
|
@@ -2188,13 +2915,13 @@ var GuildChannel = class extends Channel {
|
|
|
2188
2915
|
if (data.position !== void 0) this.position = data.position;
|
|
2189
2916
|
if (data.parent_id !== void 0) this.parentId = data.parent_id ?? null;
|
|
2190
2917
|
if (data.permission_overwrites !== void 0) {
|
|
2191
|
-
this.permissionOverwrites
|
|
2918
|
+
this.permissionOverwrites._patch(data.permission_overwrites ?? []);
|
|
2192
2919
|
}
|
|
2193
2920
|
this.applyEditPatch(data);
|
|
2194
2921
|
}
|
|
2195
2922
|
/** Create a webhook for this channel. Requires Manage Webhooks. */
|
|
2196
2923
|
async createWebhook(options) {
|
|
2197
|
-
const data = await this.client.rest.post(
|
|
2924
|
+
const data = await this.client.rest.post(Routes13.channelWebhooks(this.id), {
|
|
2198
2925
|
body: options,
|
|
2199
2926
|
auth: true
|
|
2200
2927
|
});
|
|
@@ -2202,13 +2929,13 @@ var GuildChannel = class extends Channel {
|
|
|
2202
2929
|
}
|
|
2203
2930
|
/** Fetch all webhooks in this channel. Requires Manage Webhooks. */
|
|
2204
2931
|
async fetchWebhooks() {
|
|
2205
|
-
const data = await this.client.rest.get(
|
|
2932
|
+
const data = await this.client.rest.get(Routes13.channelWebhooks(this.id));
|
|
2206
2933
|
return data.map((w) => new Webhook(this.client, w));
|
|
2207
2934
|
}
|
|
2208
2935
|
/** Create an invite for this channel. Requires Create Instant Invite. */
|
|
2209
2936
|
async createInvite(options) {
|
|
2210
2937
|
const body = options ? toChannelInviteBody(options) : {};
|
|
2211
|
-
const data = await this.client.rest.post(
|
|
2938
|
+
const data = await this.client.rest.post(Routes13.channelInvites(this.id), {
|
|
2212
2939
|
body: Object.keys(body).length ? body : void 0,
|
|
2213
2940
|
auth: true
|
|
2214
2941
|
});
|
|
@@ -2216,109 +2943,160 @@ var GuildChannel = class extends Channel {
|
|
|
2216
2943
|
}
|
|
2217
2944
|
/** Fetch all invites for this channel. Requires Manage Channels. */
|
|
2218
2945
|
async fetchInvites() {
|
|
2219
|
-
const data = await this.client.rest.get(
|
|
2946
|
+
const data = await this.client.rest.get(Routes13.channelInvites(this.id));
|
|
2220
2947
|
return data.map((i) => new Invite(this.client, i));
|
|
2221
2948
|
}
|
|
2222
|
-
/**
|
|
2223
|
-
async editPermission(overwriteId, options) {
|
|
2224
|
-
await this.client.rest.put(Routes12.channelPermission(this.id, overwriteId), {
|
|
2225
|
-
body: options,
|
|
2226
|
-
auth: true
|
|
2227
|
-
});
|
|
2228
|
-
const entry = {
|
|
2229
|
-
id: overwriteId,
|
|
2230
|
-
type: options.type,
|
|
2231
|
-
allow: options.allow ?? "0",
|
|
2232
|
-
deny: options.deny ?? "0"
|
|
2233
|
-
};
|
|
2234
|
-
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
2235
|
-
if (idx >= 0) this.permissionOverwrites[idx] = entry;
|
|
2236
|
-
else this.permissionOverwrites.push(entry);
|
|
2237
|
-
}
|
|
2238
|
-
/** Delete a permission overwrite. Requires Manage Roles. */
|
|
2239
|
-
async deletePermission(overwriteId) {
|
|
2240
|
-
await this.client.rest.delete(Routes12.channelPermission(this.id, overwriteId), { auth: true });
|
|
2241
|
-
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
2242
|
-
if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
|
|
2243
|
-
}
|
|
2244
|
-
/** Check if the bot can send messages in this channel (with permissions). */
|
|
2949
|
+
/** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
|
|
2245
2950
|
canSendMessage() {
|
|
2951
|
+
if (!this.guildId) return false;
|
|
2246
2952
|
const me = this.client.guilds.get(this.guildId)?.members.me;
|
|
2247
2953
|
if (!me) return false;
|
|
2248
2954
|
const perms = me.permissionsIn(this);
|
|
2249
2955
|
return perms.has(PermissionFlags.ViewChannel) && perms.has(PermissionFlags.SendMessages);
|
|
2250
2956
|
}
|
|
2957
|
+
/**
|
|
2958
|
+
* Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
|
|
2959
|
+
* Returns false when the channel has no guildId.
|
|
2960
|
+
*/
|
|
2961
|
+
async canSend() {
|
|
2962
|
+
if (!this.guildId) return false;
|
|
2963
|
+
const guild = this.client.guilds.get(this.guildId);
|
|
2964
|
+
if (!guild) return false;
|
|
2965
|
+
if (!guild.members.me) {
|
|
2966
|
+
try {
|
|
2967
|
+
await guild.members.fetchMe();
|
|
2968
|
+
} catch {
|
|
2969
|
+
return false;
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
return this.canSendMessage();
|
|
2973
|
+
}
|
|
2251
2974
|
/** Edit this channel's settings. Requires Manage Channels. */
|
|
2252
2975
|
async edit(options) {
|
|
2253
|
-
const data = await this.client.rest.patch(
|
|
2976
|
+
const data = await this.client.rest.patch(Routes13.channel(this.id), {
|
|
2254
2977
|
body: toChannelEditBody(options),
|
|
2255
2978
|
auth: true
|
|
2256
2979
|
});
|
|
2257
2980
|
this.name = data.name ?? this.name;
|
|
2258
2981
|
this.parentId = data.parent_id ?? this.parentId;
|
|
2259
|
-
|
|
2982
|
+
if (data.permission_overwrites !== void 0) {
|
|
2983
|
+
this.permissionOverwrites._patch(data.permission_overwrites);
|
|
2984
|
+
}
|
|
2260
2985
|
this.applyEditPatch(data);
|
|
2261
2986
|
return this;
|
|
2262
2987
|
}
|
|
2263
2988
|
applyEditPatch(_data) {
|
|
2264
2989
|
}
|
|
2265
|
-
/** Delete this channel. Requires Manage Channels or channel ownership. */
|
|
2266
|
-
async delete(options) {
|
|
2267
|
-
const params = new URLSearchParams();
|
|
2268
|
-
if (options?.silent) params.set("silent", "true");
|
|
2269
|
-
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2270
|
-
const qs2 = params.toString();
|
|
2271
|
-
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2272
|
-
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2273
|
-
await this.client.rest.delete(Routes12.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2274
|
-
body,
|
|
2275
|
-
auth: true
|
|
2276
|
-
});
|
|
2277
|
-
this.client.channels.delete(this.id);
|
|
2278
|
-
this.client._clearMessageCache(this.id);
|
|
2279
|
-
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
2280
|
-
}
|
|
2281
2990
|
};
|
|
2282
2991
|
var TextChannel = class extends TextCapable(GuildChannel) {
|
|
2283
2992
|
/** Channel topic. */
|
|
2284
2993
|
topic;
|
|
2285
2994
|
/** Whether this channel is marked as NSFW. */
|
|
2286
2995
|
nsfw;
|
|
2996
|
+
/** Per-channel NSFW override (`null` inherits). */
|
|
2997
|
+
nsfwOverride;
|
|
2287
2998
|
/** Slowmode rate limit in seconds. */
|
|
2288
2999
|
rateLimitPerUser;
|
|
2289
3000
|
/** ID of the last message sent in this channel. */
|
|
2290
3001
|
lastMessageId;
|
|
3002
|
+
/** Content warning level. */
|
|
3003
|
+
contentWarningLevel;
|
|
3004
|
+
/** Custom content warning text. */
|
|
3005
|
+
contentWarningText;
|
|
2291
3006
|
constructor(client, data) {
|
|
2292
3007
|
super(client, data);
|
|
2293
3008
|
this.topic = data.topic ?? null;
|
|
2294
3009
|
this.nsfw = data.nsfw ?? false;
|
|
3010
|
+
this.nsfwOverride = data.nsfw_override ?? null;
|
|
2295
3011
|
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
2296
3012
|
this.lastMessageId = data.last_message_id ?? null;
|
|
3013
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3014
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3015
|
+
}
|
|
3016
|
+
/**
|
|
3017
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3018
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3019
|
+
*/
|
|
3020
|
+
async setSlowmode(seconds) {
|
|
3021
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
2297
3022
|
}
|
|
2298
3023
|
applyEditPatch(data) {
|
|
2299
3024
|
if ("topic" in data) this.topic = data.topic ?? null;
|
|
2300
3025
|
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3026
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
2301
3027
|
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3028
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3029
|
+
if ("content_warning_level" in data) {
|
|
3030
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3031
|
+
}
|
|
3032
|
+
if ("content_warning_text" in data) {
|
|
3033
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3034
|
+
}
|
|
2302
3035
|
}
|
|
2303
3036
|
};
|
|
2304
3037
|
var CategoryChannel = class extends GuildChannel {
|
|
2305
3038
|
};
|
|
2306
|
-
var VoiceChannel = class extends GuildChannel {
|
|
3039
|
+
var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
3040
|
+
/** Channel topic. */
|
|
3041
|
+
topic;
|
|
3042
|
+
/** Whether this channel is marked as NSFW. */
|
|
3043
|
+
nsfw;
|
|
3044
|
+
/** Per-channel NSFW override (`null` inherits). */
|
|
3045
|
+
nsfwOverride;
|
|
3046
|
+
/** Slowmode rate limit in seconds. */
|
|
3047
|
+
rateLimitPerUser;
|
|
3048
|
+
/** ID of the last message sent in this channel. */
|
|
3049
|
+
lastMessageId;
|
|
3050
|
+
/** Content warning level. */
|
|
3051
|
+
contentWarningLevel;
|
|
3052
|
+
/** Custom content warning text. */
|
|
3053
|
+
contentWarningText;
|
|
2307
3054
|
/** Voice bitrate. */
|
|
2308
3055
|
bitrate;
|
|
2309
3056
|
/** Maximum number of users allowed. */
|
|
2310
3057
|
userLimit;
|
|
3058
|
+
/** Max active voice connections per user. */
|
|
3059
|
+
voiceConnectionLimit;
|
|
2311
3060
|
/** RTC region override for this channel. */
|
|
2312
3061
|
rtcRegion;
|
|
2313
3062
|
constructor(client, data) {
|
|
2314
3063
|
super(client, data);
|
|
3064
|
+
this.topic = data.topic ?? null;
|
|
3065
|
+
this.nsfw = data.nsfw ?? false;
|
|
3066
|
+
this.nsfwOverride = data.nsfw_override ?? null;
|
|
3067
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3068
|
+
this.lastMessageId = data.last_message_id ?? null;
|
|
3069
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3070
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
2315
3071
|
this.bitrate = data.bitrate ?? null;
|
|
2316
3072
|
this.userLimit = data.user_limit ?? null;
|
|
3073
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
2317
3074
|
this.rtcRegion = data.rtc_region ?? null;
|
|
2318
3075
|
}
|
|
3076
|
+
/**
|
|
3077
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3078
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3079
|
+
*/
|
|
3080
|
+
async setSlowmode(seconds) {
|
|
3081
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
3082
|
+
}
|
|
2319
3083
|
applyEditPatch(data) {
|
|
3084
|
+
if ("topic" in data) this.topic = data.topic ?? null;
|
|
3085
|
+
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3086
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
3087
|
+
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3088
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3089
|
+
if ("content_warning_level" in data) {
|
|
3090
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3091
|
+
}
|
|
3092
|
+
if ("content_warning_text" in data) {
|
|
3093
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3094
|
+
}
|
|
2320
3095
|
if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
|
|
2321
3096
|
if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
|
|
3097
|
+
if ("voice_connection_limit" in data) {
|
|
3098
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3099
|
+
}
|
|
2322
3100
|
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
2323
3101
|
}
|
|
2324
3102
|
};
|
|
@@ -2329,6 +3107,9 @@ var LinkChannel = class extends GuildChannel {
|
|
|
2329
3107
|
super(client, data);
|
|
2330
3108
|
this.url = data.url ?? null;
|
|
2331
3109
|
}
|
|
3110
|
+
applyEditPatch(data) {
|
|
3111
|
+
if ("url" in data) this.url = data.url ?? null;
|
|
3112
|
+
}
|
|
2332
3113
|
};
|
|
2333
3114
|
|
|
2334
3115
|
// src/Domain/Channel/Factory.ts
|
|
@@ -2444,11 +3225,11 @@ var User = class extends Base {
|
|
|
2444
3225
|
*/
|
|
2445
3226
|
/** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
|
|
2446
3227
|
get createdTimestamp() {
|
|
2447
|
-
return
|
|
3228
|
+
return SnowflakeUtil5.timestampFromSnowflake(this.id);
|
|
2448
3229
|
}
|
|
2449
3230
|
/** Date when this account was created, derived from its snowflake ID. */
|
|
2450
3231
|
get createdAt() {
|
|
2451
|
-
return
|
|
3232
|
+
return SnowflakeUtil5.dateFromSnowflake(this.id);
|
|
2452
3233
|
}
|
|
2453
3234
|
toString() {
|
|
2454
3235
|
return `<@${this.id}>`;
|
|
@@ -2458,7 +3239,7 @@ var User = class extends Base {
|
|
|
2458
3239
|
* @returns DM channel instance (cached if already open)
|
|
2459
3240
|
*/
|
|
2460
3241
|
async createDM() {
|
|
2461
|
-
const data = await this.client.rest.post(
|
|
3242
|
+
const data = await this.client.rest.post(Routes14.userMeChannels(), {
|
|
2462
3243
|
body: { recipient_id: this.id },
|
|
2463
3244
|
auth: true
|
|
2464
3245
|
});
|
|
@@ -2573,6 +3354,9 @@ var CacheController = class {
|
|
|
2573
3354
|
stickers
|
|
2574
3355
|
};
|
|
2575
3356
|
}
|
|
3357
|
+
/**
|
|
3358
|
+
* Sweep cached messages. Filter receives a hydrated {@link Message} (`createdAt`).
|
|
3359
|
+
*/
|
|
2576
3360
|
sweepMessages(filter, channelId) {
|
|
2577
3361
|
return this.client.sweepMessages(filter, channelId);
|
|
2578
3362
|
}
|
|
@@ -2641,7 +3425,7 @@ var CacheController = class {
|
|
|
2641
3425
|
* @internal
|
|
2642
3426
|
*/
|
|
2643
3427
|
cascadeChannel(channel, from = "both") {
|
|
2644
|
-
const guildId =
|
|
3428
|
+
const guildId = typeof channel.isGuild === "function" && channel.isGuild() ? channel.guildId : void 0;
|
|
2645
3429
|
const dropFromGuild = () => {
|
|
2646
3430
|
if (!guildId) return;
|
|
2647
3431
|
const guildChannels = this.client.guilds.get(guildId)?.channels;
|
|
@@ -2672,11 +3456,11 @@ var CacheController = class {
|
|
|
2672
3456
|
|
|
2673
3457
|
// src/ClientCore/ChannelManager.ts
|
|
2674
3458
|
import { LimitedCollection } from "@fluxerjs/collection";
|
|
2675
|
-
import { Routes as
|
|
3459
|
+
import { Routes as Routes20 } from "@fluxerjs/types";
|
|
2676
3460
|
|
|
2677
3461
|
// src/Domain/Guild/GuildEmoji.ts
|
|
2678
|
-
import { Routes as
|
|
2679
|
-
import { SnowflakeUtil as
|
|
3462
|
+
import { Routes as Routes15 } from "@fluxerjs/types";
|
|
3463
|
+
import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
|
|
2680
3464
|
var GuildEmoji = class extends Base {
|
|
2681
3465
|
client;
|
|
2682
3466
|
id;
|
|
@@ -2712,11 +3496,11 @@ var GuildEmoji = class extends Base {
|
|
|
2712
3496
|
}
|
|
2713
3497
|
/** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
|
|
2714
3498
|
get createdTimestamp() {
|
|
2715
|
-
return
|
|
3499
|
+
return SnowflakeUtil6.timestampFromSnowflake(this.id);
|
|
2716
3500
|
}
|
|
2717
3501
|
/** Date when this emoji was created, derived from its snowflake ID. */
|
|
2718
3502
|
get createdAt() {
|
|
2719
|
-
return
|
|
3503
|
+
return SnowflakeUtil6.dateFromSnowflake(this.id);
|
|
2720
3504
|
}
|
|
2721
3505
|
/** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
|
|
2722
3506
|
toString() {
|
|
@@ -2724,7 +3508,7 @@ var GuildEmoji = class extends Base {
|
|
|
2724
3508
|
}
|
|
2725
3509
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
2726
3510
|
async delete() {
|
|
2727
|
-
await this.client.rest.delete(
|
|
3511
|
+
await this.client.rest.delete(Routes15.guildEmoji(this.guildId, this.id), {
|
|
2728
3512
|
auth: true
|
|
2729
3513
|
});
|
|
2730
3514
|
const guild = this.client.guilds.get(this.guildId);
|
|
@@ -2735,7 +3519,7 @@ var GuildEmoji = class extends Base {
|
|
|
2735
3519
|
* Requires Manage Emojis and Stickers permission.
|
|
2736
3520
|
*/
|
|
2737
3521
|
async edit(options) {
|
|
2738
|
-
const data = await this.client.rest.patch(
|
|
3522
|
+
const data = await this.client.rest.patch(Routes15.guildEmoji(this.guildId, this.id), {
|
|
2739
3523
|
body: options,
|
|
2740
3524
|
auth: true
|
|
2741
3525
|
});
|
|
@@ -2745,8 +3529,8 @@ var GuildEmoji = class extends Base {
|
|
|
2745
3529
|
};
|
|
2746
3530
|
|
|
2747
3531
|
// src/Domain/Guild/GuildMember.ts
|
|
2748
|
-
import { Routes as
|
|
2749
|
-
import { PermissionsBitField } from "@fluxerjs/util";
|
|
3532
|
+
import { Routes as Routes17 } from "@fluxerjs/types";
|
|
3533
|
+
import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
|
|
2750
3534
|
|
|
2751
3535
|
// src/Helpers/Permissions.ts
|
|
2752
3536
|
import { OverwriteType } from "@fluxerjs/types";
|
|
@@ -2764,9 +3548,9 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
2764
3548
|
return (perms & PermissionFlags2.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT : perms;
|
|
2765
3549
|
}
|
|
2766
3550
|
|
|
2767
|
-
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
2768
|
-
import { Collection as
|
|
2769
|
-
import { Routes as
|
|
3551
|
+
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
3552
|
+
import { Collection as Collection7 } from "@fluxerjs/collection";
|
|
3553
|
+
import { Routes as Routes16 } from "@fluxerjs/types";
|
|
2770
3554
|
function roleId(roleOrId) {
|
|
2771
3555
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
2772
3556
|
}
|
|
@@ -2784,7 +3568,7 @@ var GuildMemberRoleManager = class {
|
|
|
2784
3568
|
}
|
|
2785
3569
|
/** Live Role objects from `guild.roles` for this member's role IDs. */
|
|
2786
3570
|
get cache() {
|
|
2787
|
-
const out = new
|
|
3571
|
+
const out = new Collection7();
|
|
2788
3572
|
for (const id of this.ids) {
|
|
2789
3573
|
const role = this.member.guild.roles.get(id);
|
|
2790
3574
|
if (role) out.set(id, role);
|
|
@@ -2795,7 +3579,7 @@ var GuildMemberRoleManager = class {
|
|
|
2795
3579
|
const id = roleId(roleOrId);
|
|
2796
3580
|
if (this.ids.includes(id)) return;
|
|
2797
3581
|
await this.member.client.rest.put(
|
|
2798
|
-
|
|
3582
|
+
Routes16.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2799
3583
|
);
|
|
2800
3584
|
this.ids.push(id);
|
|
2801
3585
|
}
|
|
@@ -2804,13 +3588,13 @@ var GuildMemberRoleManager = class {
|
|
|
2804
3588
|
const idx = this.ids.indexOf(id);
|
|
2805
3589
|
if (idx === -1) return;
|
|
2806
3590
|
await this.member.client.rest.delete(
|
|
2807
|
-
|
|
3591
|
+
Routes16.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2808
3592
|
);
|
|
2809
3593
|
this.ids.splice(idx, 1);
|
|
2810
3594
|
}
|
|
2811
3595
|
async set(roleIds) {
|
|
2812
3596
|
const data = await this.member.client.rest.patch(
|
|
2813
|
-
|
|
3597
|
+
Routes16.guildMember(this.member.guild.id, this.member.id),
|
|
2814
3598
|
{ body: { roles: roleIds }, auth: true }
|
|
2815
3599
|
);
|
|
2816
3600
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -2823,6 +3607,8 @@ var GuildMemberRoleManager = class {
|
|
|
2823
3607
|
|
|
2824
3608
|
// src/Domain/Guild/GuildMember.ts
|
|
2825
3609
|
var GuildMember = class _GuildMember extends Base {
|
|
3610
|
+
/** Discriminant vs {@link PartialGuildMember}: always `false` on a hydrated member. */
|
|
3611
|
+
partial = false;
|
|
2826
3612
|
/** Parent client instance. */
|
|
2827
3613
|
client;
|
|
2828
3614
|
/** User ID (same as `user.id`). */
|
|
@@ -2851,6 +3637,12 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2851
3637
|
accentColor;
|
|
2852
3638
|
/** Guild-specific profile flags. */
|
|
2853
3639
|
profileFlags;
|
|
3640
|
+
/** Per-guild reply mention preference override. */
|
|
3641
|
+
mentionFlags;
|
|
3642
|
+
/** Guild-specific bio (set from member edit; not always on GET member). */
|
|
3643
|
+
bio;
|
|
3644
|
+
/** Guild-specific pronouns (set from member edit; not always on GET member). */
|
|
3645
|
+
pronouns;
|
|
2854
3646
|
constructor(client, data, guild) {
|
|
2855
3647
|
super();
|
|
2856
3648
|
this.client = client;
|
|
@@ -2867,6 +3659,9 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2867
3659
|
this.banner = data.banner ?? null;
|
|
2868
3660
|
this.accentColor = data.accent_color ?? null;
|
|
2869
3661
|
this.profileFlags = data.profile_flags ?? null;
|
|
3662
|
+
this.mentionFlags = data.mention_flags ?? null;
|
|
3663
|
+
this.bio = data.bio ?? null;
|
|
3664
|
+
this.pronouns = data.pronouns ?? null;
|
|
2870
3665
|
}
|
|
2871
3666
|
/**
|
|
2872
3667
|
* Apply an API member payload in place (gateway GUILD_MEMBER_UPDATE / REST edit).
|
|
@@ -2885,6 +3680,9 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2885
3680
|
if (data.banner !== void 0) this.banner = data.banner ?? null;
|
|
2886
3681
|
if (data.accent_color !== void 0) this.accentColor = data.accent_color ?? null;
|
|
2887
3682
|
if (data.profile_flags !== void 0) this.profileFlags = data.profile_flags ?? null;
|
|
3683
|
+
if (data.mention_flags !== void 0) this.mentionFlags = data.mention_flags ?? null;
|
|
3684
|
+
if (data.bio !== void 0) this.bio = data.bio ?? null;
|
|
3685
|
+
if (data.pronouns !== void 0) this.pronouns = data.pronouns ?? null;
|
|
2888
3686
|
}
|
|
2889
3687
|
/**
|
|
2890
3688
|
* Snapshot for `guildMemberUpdate` old-member arg (before in-place patch).
|
|
@@ -2913,7 +3711,10 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2913
3711
|
avatar: this.avatar,
|
|
2914
3712
|
banner: this.banner,
|
|
2915
3713
|
accent_color: this.accentColor,
|
|
2916
|
-
profile_flags: this.profileFlags ?? void 0
|
|
3714
|
+
profile_flags: this.profileFlags ?? void 0,
|
|
3715
|
+
mention_flags: this.mentionFlags,
|
|
3716
|
+
bio: this.bio,
|
|
3717
|
+
pronouns: this.pronouns
|
|
2917
3718
|
},
|
|
2918
3719
|
this.guild
|
|
2919
3720
|
);
|
|
@@ -2940,15 +3741,22 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2940
3741
|
mediaBase: this.client.instance.endpoints.media
|
|
2941
3742
|
});
|
|
2942
3743
|
}
|
|
2943
|
-
/**
|
|
3744
|
+
/**
|
|
3745
|
+
* PATCH member (`/members/@me` when editing the bot).
|
|
3746
|
+
* @example
|
|
3747
|
+
* await member.edit({ nick: 'Ada' });
|
|
3748
|
+
*/
|
|
2944
3749
|
async edit(options) {
|
|
2945
3750
|
const isMe = this.client.user?.id === this.id;
|
|
2946
|
-
const route = isMe ?
|
|
3751
|
+
const route = isMe ? Routes17.guildMemberMe(this.guild.id) : Routes17.guildMember(this.guild.id, this.id);
|
|
2947
3752
|
const data = await this.client.rest.patch(route, {
|
|
2948
3753
|
body: toMemberEditBody(options),
|
|
2949
3754
|
auth: true
|
|
2950
3755
|
});
|
|
2951
3756
|
this._patch(data);
|
|
3757
|
+
if (options.bio !== void 0) this.bio = options.bio;
|
|
3758
|
+
if (options.pronouns !== void 0) this.pronouns = options.pronouns;
|
|
3759
|
+
if (options.mentionFlags !== void 0) this.mentionFlags = options.mentionFlags;
|
|
2952
3760
|
return this;
|
|
2953
3761
|
}
|
|
2954
3762
|
/**
|
|
@@ -2956,7 +3764,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2956
3764
|
* @see {@link permissionsIn} for channel-specific permissions
|
|
2957
3765
|
*/
|
|
2958
3766
|
get permissions() {
|
|
2959
|
-
return new
|
|
3767
|
+
return new PermissionsBitField2(this._effectivePermissions([], []));
|
|
2960
3768
|
}
|
|
2961
3769
|
/**
|
|
2962
3770
|
* Effective permissions in a channel (roles + overwrites).
|
|
@@ -2964,8 +3772,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2964
3772
|
* @returns Computed permissions bitfield
|
|
2965
3773
|
*/
|
|
2966
3774
|
permissionsIn(channel) {
|
|
2967
|
-
return new
|
|
2968
|
-
this._effectivePermissions(channel.permissionOverwrites, [...this.roles.roleIds])
|
|
3775
|
+
return new PermissionsBitField2(
|
|
3776
|
+
this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
|
|
2969
3777
|
);
|
|
2970
3778
|
}
|
|
2971
3779
|
/**
|
|
@@ -2976,6 +3784,63 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2976
3784
|
async move(channelId, connectionId) {
|
|
2977
3785
|
await this.edit({ channelId, connectionId });
|
|
2978
3786
|
}
|
|
3787
|
+
/** Kick this member. Requires Kick Members. */
|
|
3788
|
+
async kick() {
|
|
3789
|
+
await this.guild.kick(this.id);
|
|
3790
|
+
}
|
|
3791
|
+
/** Ban this member. Requires Ban Members. */
|
|
3792
|
+
async ban(options) {
|
|
3793
|
+
await this.guild.ban(this.id, options);
|
|
3794
|
+
}
|
|
3795
|
+
/**
|
|
3796
|
+
* Whether the bot can kick this member (cache-only; needs `members.me`).
|
|
3797
|
+
* False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
|
|
3798
|
+
*/
|
|
3799
|
+
get kickable() {
|
|
3800
|
+
return this._moderatableWith(PermissionFlags3.KickMembers);
|
|
3801
|
+
}
|
|
3802
|
+
/**
|
|
3803
|
+
* Whether the bot can ban this member (cache-only; needs `members.me`).
|
|
3804
|
+
*/
|
|
3805
|
+
get bannable() {
|
|
3806
|
+
return this._moderatableWith(PermissionFlags3.BanMembers);
|
|
3807
|
+
}
|
|
3808
|
+
/**
|
|
3809
|
+
* Whether the bot can timeout this member (cache-only; needs `members.me`).
|
|
3810
|
+
*/
|
|
3811
|
+
get moderatable() {
|
|
3812
|
+
return this._moderatableWith(PermissionFlags3.ModerateMembers);
|
|
3813
|
+
}
|
|
3814
|
+
_moderatableWith(flag) {
|
|
3815
|
+
const me = this.guild.members.me;
|
|
3816
|
+
if (!me) return false;
|
|
3817
|
+
if (this.id === me.id) return false;
|
|
3818
|
+
if (this.guild.ownerId != null && String(this.guild.ownerId) === String(this.id)) return false;
|
|
3819
|
+
if (!me.permissions.has(flag)) return false;
|
|
3820
|
+
return this._compareRolePosition(me) < 0;
|
|
3821
|
+
}
|
|
3822
|
+
/** Negative when this member's highest role is below `other`'s. */
|
|
3823
|
+
_compareRolePosition(other) {
|
|
3824
|
+
const highest = (m) => {
|
|
3825
|
+
let pos = -1;
|
|
3826
|
+
for (const role of m.roles.cache.values()) {
|
|
3827
|
+
if (role.position > pos) pos = role.position;
|
|
3828
|
+
}
|
|
3829
|
+
return pos;
|
|
3830
|
+
};
|
|
3831
|
+
return highest(this) - highest(other);
|
|
3832
|
+
}
|
|
3833
|
+
/**
|
|
3834
|
+
* Timeout this member for `durationMs` milliseconds, or pass `null` to clear.
|
|
3835
|
+
* Requires Moderate Members.
|
|
3836
|
+
*/
|
|
3837
|
+
async timeout(durationMs, reason) {
|
|
3838
|
+
const communicationDisabledUntil = durationMs == null || durationMs <= 0 ? null : new Date(Date.now() + durationMs).toISOString();
|
|
3839
|
+
return this.edit({
|
|
3840
|
+
communicationDisabledUntil,
|
|
3841
|
+
...reason !== void 0 ? { timeoutReason: reason } : {}
|
|
3842
|
+
});
|
|
3843
|
+
}
|
|
2979
3844
|
_effectivePermissions(overwrites, roleIds) {
|
|
2980
3845
|
const ownerId = this.guild.ownerId;
|
|
2981
3846
|
const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
|
|
@@ -2995,8 +3860,8 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2995
3860
|
};
|
|
2996
3861
|
|
|
2997
3862
|
// src/Domain/Guild/GuildSticker.ts
|
|
2998
|
-
import { Routes as
|
|
2999
|
-
import { SnowflakeUtil as
|
|
3863
|
+
import { Routes as Routes18 } from "@fluxerjs/types";
|
|
3864
|
+
import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
|
|
3000
3865
|
var GuildSticker = class extends Base {
|
|
3001
3866
|
client;
|
|
3002
3867
|
id;
|
|
@@ -3038,15 +3903,15 @@ var GuildSticker = class extends Base {
|
|
|
3038
3903
|
}
|
|
3039
3904
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
3040
3905
|
get createdTimestamp() {
|
|
3041
|
-
return
|
|
3906
|
+
return SnowflakeUtil7.timestampFromSnowflake(this.id);
|
|
3042
3907
|
}
|
|
3043
3908
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
3044
3909
|
get createdAt() {
|
|
3045
|
-
return
|
|
3910
|
+
return SnowflakeUtil7.dateFromSnowflake(this.id);
|
|
3046
3911
|
}
|
|
3047
3912
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3048
3913
|
async delete() {
|
|
3049
|
-
await this.client.rest.delete(
|
|
3914
|
+
await this.client.rest.delete(Routes18.guildSticker(this.guildId, this.id), {
|
|
3050
3915
|
auth: true
|
|
3051
3916
|
});
|
|
3052
3917
|
const guild = this.client.guilds.get(this.guildId);
|
|
@@ -3057,7 +3922,7 @@ var GuildSticker = class extends Base {
|
|
|
3057
3922
|
* Requires Manage Emojis and Stickers permission.
|
|
3058
3923
|
*/
|
|
3059
3924
|
async edit(options) {
|
|
3060
|
-
const data = await this.client.rest.patch(
|
|
3925
|
+
const data = await this.client.rest.patch(Routes18.guildSticker(this.guildId, this.id), {
|
|
3061
3926
|
body: options,
|
|
3062
3927
|
auth: true
|
|
3063
3928
|
});
|
|
@@ -3069,12 +3934,12 @@ var GuildSticker = class extends Base {
|
|
|
3069
3934
|
};
|
|
3070
3935
|
|
|
3071
3936
|
// src/Domain/Guild/Role.ts
|
|
3072
|
-
import { Routes as
|
|
3937
|
+
import { Routes as Routes19 } from "@fluxerjs/types";
|
|
3073
3938
|
import {
|
|
3074
3939
|
ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
|
|
3075
|
-
PermissionFlags as
|
|
3076
|
-
PermissionsBitField as
|
|
3077
|
-
SnowflakeUtil as
|
|
3940
|
+
PermissionFlags as PermissionFlags4,
|
|
3941
|
+
PermissionsBitField as PermissionsBitField3,
|
|
3942
|
+
SnowflakeUtil as SnowflakeUtil8
|
|
3078
3943
|
} from "@fluxerjs/util";
|
|
3079
3944
|
var Role = class _Role extends Base {
|
|
3080
3945
|
/** Parent client instance. */
|
|
@@ -3118,21 +3983,29 @@ var Role = class _Role extends Base {
|
|
|
3118
3983
|
*/
|
|
3119
3984
|
get permissions() {
|
|
3120
3985
|
const bits = BigInt(this._permissions);
|
|
3121
|
-
return new
|
|
3122
|
-
(bits &
|
|
3986
|
+
return new PermissionsBitField3(
|
|
3987
|
+
(bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
|
|
3123
3988
|
);
|
|
3124
3989
|
}
|
|
3990
|
+
/**
|
|
3991
|
+
* Alias of {@link permissions}.has for discord.js-style checks.
|
|
3992
|
+
* @example
|
|
3993
|
+
* if (role.has(PermissionFlags.BanMembers)) { ... }
|
|
3994
|
+
*/
|
|
3995
|
+
has(permission) {
|
|
3996
|
+
return this.permissions.has(permission);
|
|
3997
|
+
}
|
|
3125
3998
|
/**
|
|
3126
3999
|
* Format as a mention string (`<@&id>`).
|
|
3127
4000
|
* @returns Mention syntax
|
|
3128
4001
|
*/
|
|
3129
4002
|
/** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
|
|
3130
4003
|
get createdTimestamp() {
|
|
3131
|
-
return
|
|
4004
|
+
return SnowflakeUtil8.timestampFromSnowflake(this.id);
|
|
3132
4005
|
}
|
|
3133
4006
|
/** Date when this role was created, derived from its snowflake ID. */
|
|
3134
4007
|
get createdAt() {
|
|
3135
|
-
return
|
|
4008
|
+
return SnowflakeUtil8.dateFromSnowflake(this.id);
|
|
3136
4009
|
}
|
|
3137
4010
|
toString() {
|
|
3138
4011
|
return `<@&${this.id}>`;
|
|
@@ -3175,8 +4048,8 @@ var Role = class _Role extends Base {
|
|
|
3175
4048
|
* @returns This role instance (updated in-place)
|
|
3176
4049
|
*/
|
|
3177
4050
|
async edit(options) {
|
|
3178
|
-
const body =
|
|
3179
|
-
const data = await this.client.rest.patch(
|
|
4051
|
+
const body = toRoleEditBody(options);
|
|
4052
|
+
const data = await this.client.rest.patch(Routes19.guildRole(this.guildId, this.id), {
|
|
3180
4053
|
body: Object.keys(body).length ? body : void 0,
|
|
3181
4054
|
auth: true
|
|
3182
4055
|
});
|
|
@@ -3187,7 +4060,7 @@ var Role = class _Role extends Base {
|
|
|
3187
4060
|
* DELETE role. Requires Manage Roles.
|
|
3188
4061
|
*/
|
|
3189
4062
|
async delete() {
|
|
3190
|
-
await this.client.rest.delete(
|
|
4063
|
+
await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), { auth: true });
|
|
3191
4064
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
3192
4065
|
}
|
|
3193
4066
|
};
|
|
@@ -3195,17 +4068,15 @@ var Role = class _Role extends Base {
|
|
|
3195
4068
|
// src/Domain/Guild/Cache.ts
|
|
3196
4069
|
function putChannel(client, channel, guild) {
|
|
3197
4070
|
client.channels.set(channel.id, channel);
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
return guildId ? client.guilds.get(guildId) : void 0;
|
|
3201
|
-
})();
|
|
4071
|
+
if (!channel.isGuild()) return;
|
|
4072
|
+
const resolvedGuild = guild ?? (channel.guildId ? client.guilds.get(channel.guildId) : void 0);
|
|
3202
4073
|
if (resolvedGuild) {
|
|
3203
4074
|
resolvedGuild.channels.set(channel.id, channel);
|
|
3204
4075
|
}
|
|
3205
4076
|
}
|
|
3206
4077
|
function cacheChannel(guild, data) {
|
|
3207
4078
|
const existing = guild.channels.get(data.id) ?? guild.client.channels.get(data.id);
|
|
3208
|
-
if (existing &&
|
|
4079
|
+
if (existing?.isGuild() && existing.type === data.type) {
|
|
3209
4080
|
existing._patch(data);
|
|
3210
4081
|
putChannel(guild.client, existing, guild);
|
|
3211
4082
|
return existing;
|
|
@@ -3319,6 +4190,10 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3319
4190
|
});
|
|
3320
4191
|
this.client = client;
|
|
3321
4192
|
}
|
|
4193
|
+
/**
|
|
4194
|
+
* Remove a channel from cache. Does not delete it on the API.
|
|
4195
|
+
* Use {@link Channel.delete} after {@link fetch} to delete the channel.
|
|
4196
|
+
*/
|
|
3322
4197
|
delete(key) {
|
|
3323
4198
|
const channel = this.get(key);
|
|
3324
4199
|
const deleted = super.delete(key);
|
|
@@ -3332,15 +4207,20 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3332
4207
|
return this.get(channelId) ?? this.fetch(channelId);
|
|
3333
4208
|
}
|
|
3334
4209
|
/**
|
|
3335
|
-
* Fetch a channel by ID.
|
|
3336
|
-
*
|
|
4210
|
+
* Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
|
|
4211
|
+
* and {@link Channel.send} (send throws if the type is not text-based).
|
|
4212
|
+
* Returns the cached channel unless `force` is set.
|
|
4213
|
+
* @example
|
|
4214
|
+
* const channel = await client.channels.fetch(channelId);
|
|
4215
|
+
* await channel.delete();
|
|
4216
|
+
* await channel.send('hi');
|
|
3337
4217
|
* @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
|
|
3338
4218
|
*/
|
|
3339
4219
|
async fetch(channelId, options) {
|
|
3340
4220
|
const cached = this.get(channelId);
|
|
3341
4221
|
if (cached && !options?.force) return cached;
|
|
3342
4222
|
try {
|
|
3343
|
-
const data = await this.client.rest.get(
|
|
4223
|
+
const data = await this.client.rest.get(Routes20.channel(channelId));
|
|
3344
4224
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
3345
4225
|
if (guildId) {
|
|
3346
4226
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -3376,6 +4256,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3376
4256
|
}
|
|
3377
4257
|
/**
|
|
3378
4258
|
* Send to a channel by ID without resolving it first.
|
|
4259
|
+
* Prefer {@link Channel.send} after {@link fetch} when you want the channel object.
|
|
3379
4260
|
* @example
|
|
3380
4261
|
* await client.channels.send(logChannelId, 'User joined!');
|
|
3381
4262
|
*/
|
|
@@ -3384,7 +4265,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3384
4265
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
3385
4266
|
});
|
|
3386
4267
|
const data = await this.client.rest.post(
|
|
3387
|
-
|
|
4268
|
+
Routes20.channelMessages(channelId),
|
|
3388
4269
|
postPayload
|
|
3389
4270
|
);
|
|
3390
4271
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -3393,14 +4274,14 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
3393
4274
|
};
|
|
3394
4275
|
|
|
3395
4276
|
// src/ClientCore/ClientEmoji.ts
|
|
3396
|
-
import { Collection as
|
|
3397
|
-
import { Routes as
|
|
3398
|
-
import { formatEmoji, getUnicodeFromShortcode, parseEmoji
|
|
4277
|
+
import { Collection as Collection8 } from "@fluxerjs/collection";
|
|
4278
|
+
import { Routes as Routes21 } from "@fluxerjs/types";
|
|
4279
|
+
import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
|
|
3399
4280
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
3400
4281
|
if (typeof emoji === "object" && emoji.id) {
|
|
3401
4282
|
return formatEmoji({ name: emoji.name, id: emoji.id, animated: emoji.animated });
|
|
3402
4283
|
}
|
|
3403
|
-
const parsed =
|
|
4284
|
+
const parsed = parseEmoji(
|
|
3404
4285
|
typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
|
|
3405
4286
|
);
|
|
3406
4287
|
if (!parsed) {
|
|
@@ -3413,7 +4294,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
3413
4294
|
const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
|
|
3414
4295
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
3415
4296
|
if (guildId) {
|
|
3416
|
-
const emojis = await client.rest.get(
|
|
4297
|
+
const emojis = await client.rest.get(Routes21.guildEmojis(guildId));
|
|
3417
4298
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
3418
4299
|
if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
|
|
3419
4300
|
throw new FluxerError(
|
|
@@ -3430,28 +4311,31 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
3430
4311
|
return parsed.name;
|
|
3431
4312
|
}
|
|
3432
4313
|
async function fetchInstance(client) {
|
|
3433
|
-
const raw = await client.rest.get(
|
|
4314
|
+
const raw = await client.rest.get(Routes21.instanceDiscovery(), { auth: false });
|
|
3434
4315
|
return parseInstanceDiscovery(raw);
|
|
3435
4316
|
}
|
|
3436
4317
|
function fetchGatewayInfo(client) {
|
|
3437
|
-
return client.rest.get(
|
|
4318
|
+
return client.rest.get(Routes21.gatewayBot());
|
|
3438
4319
|
}
|
|
3439
4320
|
function fetchEmojiMetadata(client, emojiId) {
|
|
3440
|
-
return client.rest.get(
|
|
4321
|
+
return client.rest.get(Routes21.emojiMetadata(emojiId), { auth: true });
|
|
3441
4322
|
}
|
|
3442
4323
|
function fetchStickerMetadata(client, stickerId) {
|
|
3443
|
-
return client.rest.get(
|
|
4324
|
+
return client.rest.get(Routes21.stickerMetadata(stickerId), { auth: true });
|
|
3444
4325
|
}
|
|
3445
4326
|
function fetchApplication(client) {
|
|
3446
|
-
return client.rest.get(
|
|
4327
|
+
return client.rest.get(Routes21.applicationsMe(), { auth: true });
|
|
3447
4328
|
}
|
|
3448
4329
|
async function fetchOAuthApplications(client) {
|
|
3449
|
-
const data = await client.rest.get(
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
4330
|
+
const data = await client.rest.get(Routes21.oauth2ApplicationsMe(), { auth: true });
|
|
4331
|
+
if (Array.isArray(data)) return data;
|
|
4332
|
+
if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
|
|
4333
|
+
return data.applications;
|
|
4334
|
+
}
|
|
4335
|
+
if (data && typeof data === "object" && "id" in data && typeof data.id === "string") {
|
|
4336
|
+
return [data];
|
|
4337
|
+
}
|
|
4338
|
+
return [];
|
|
3455
4339
|
}
|
|
3456
4340
|
function assertChannelIdBatch(name, channelIds) {
|
|
3457
4341
|
if (channelIds.length < 1 || channelIds.length > 100) {
|
|
@@ -3462,14 +4346,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
3462
4346
|
}
|
|
3463
4347
|
function preloadMessages(client, channelIds) {
|
|
3464
4348
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
3465
|
-
return client.rest.post(
|
|
4349
|
+
return client.rest.post(Routes21.preloadMessages(), {
|
|
3466
4350
|
body: { channels: channelIds },
|
|
3467
4351
|
auth: true
|
|
3468
4352
|
});
|
|
3469
4353
|
}
|
|
3470
4354
|
function preloadMessagesAlt(client, channelIds) {
|
|
3471
4355
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
3472
|
-
return client.rest.post(
|
|
4356
|
+
return client.rest.post(Routes21.preloadMessagesAlt(), {
|
|
3473
4357
|
body: { channels: channelIds },
|
|
3474
4358
|
auth: true
|
|
3475
4359
|
});
|
|
@@ -3477,14 +4361,14 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
3477
4361
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
3478
4362
|
validateBulkMessageFetchRequests(requests);
|
|
3479
4363
|
const wire = toBulkFetchWire(requests);
|
|
3480
|
-
const data = await client.rest.post(
|
|
4364
|
+
const data = await client.rest.post(Routes21.channelsMessagesBulk(), {
|
|
3481
4365
|
body: { requests: wire },
|
|
3482
4366
|
auth: true
|
|
3483
4367
|
});
|
|
3484
4368
|
if (options.hydrate === false) return data;
|
|
3485
4369
|
return {
|
|
3486
4370
|
channels: data.channels.map((entry) => {
|
|
3487
|
-
const collection = new
|
|
4371
|
+
const collection = new Collection8();
|
|
3488
4372
|
for (const msg of entry.messages) {
|
|
3489
4373
|
client._addMessageToCache(entry.channel_id, msg);
|
|
3490
4374
|
collection.set(msg.id, new Message(client, msg));
|
|
@@ -3493,6 +4377,13 @@ async function bulkFetchMessages(client, requests, options = {}) {
|
|
|
3493
4377
|
})
|
|
3494
4378
|
};
|
|
3495
4379
|
}
|
|
4380
|
+
async function searchMessages(client, options = {}) {
|
|
4381
|
+
const data = await client.rest.post(Routes21.searchMessages(), {
|
|
4382
|
+
body: toMessageSearchBody(options),
|
|
4383
|
+
auth: true
|
|
4384
|
+
});
|
|
4385
|
+
return toMessageSearchResponse(data);
|
|
4386
|
+
}
|
|
3496
4387
|
|
|
3497
4388
|
// src/ClientCore/ClientEvents.ts
|
|
3498
4389
|
function createEventMethods(client) {
|
|
@@ -3508,16 +4399,16 @@ function createEventMethods(client) {
|
|
|
3508
4399
|
}
|
|
3509
4400
|
|
|
3510
4401
|
// src/ClientCore/GatewayReady.ts
|
|
3511
|
-
import { WebSocketManager } from "@fluxerjs/ws";
|
|
4402
|
+
import { GatewayCloseCodes, WebSocketManager } from "@fluxerjs/ws";
|
|
3512
4403
|
|
|
3513
4404
|
// src/Domain/Guild/Guild.ts
|
|
3514
|
-
import { LimitedCollection as
|
|
4405
|
+
import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
|
|
3515
4406
|
import { GuildNSFWLevel } from "@fluxerjs/types";
|
|
3516
|
-
import { SnowflakeUtil as
|
|
4407
|
+
import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
|
|
3517
4408
|
|
|
3518
4409
|
// src/ClientCore/GuildMemberManager.ts
|
|
3519
4410
|
import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
|
|
3520
|
-
import { Routes as
|
|
4411
|
+
import { Routes as Routes22 } from "@fluxerjs/types";
|
|
3521
4412
|
var GuildMemberManager = class extends LimitedCollection2 {
|
|
3522
4413
|
constructor(guild) {
|
|
3523
4414
|
super({ maxSize: guild.client.cache.limits.members });
|
|
@@ -3534,7 +4425,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3534
4425
|
* console.log(member.displayName);
|
|
3535
4426
|
*/
|
|
3536
4427
|
async resolve(userId) {
|
|
3537
|
-
return this.get(userId) ?? this.
|
|
4428
|
+
return this.get(userId) ?? this.fetch(userId);
|
|
3538
4429
|
}
|
|
3539
4430
|
/**
|
|
3540
4431
|
* The current bot user as a GuildMember in this guild.
|
|
@@ -3561,17 +4452,20 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3561
4452
|
async fetchMe() {
|
|
3562
4453
|
return this.guild.fetchMe();
|
|
3563
4454
|
}
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
4455
|
+
async fetch(userIdOrOptions, options) {
|
|
4456
|
+
if (typeof userIdOrOptions === "string") {
|
|
4457
|
+
const cached = this.get(userIdOrOptions);
|
|
4458
|
+
if (cached && !options?.force) return cached;
|
|
4459
|
+
return this.guild.fetchMember(userIdOrOptions);
|
|
4460
|
+
}
|
|
4461
|
+
return this.fetchMany(userIdOrOptions);
|
|
4462
|
+
}
|
|
4463
|
+
async fetchMany(options) {
|
|
3570
4464
|
const params = new URLSearchParams();
|
|
3571
4465
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
3572
4466
|
if (options?.after) params.set("after", options.after);
|
|
3573
4467
|
const qs2 = params.toString();
|
|
3574
|
-
const url =
|
|
4468
|
+
const url = Routes22.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
3575
4469
|
const data = await this.guild.client.rest.get(url, { auth: true });
|
|
3576
4470
|
const members = [];
|
|
3577
4471
|
for (const m of data) {
|
|
@@ -3594,7 +4488,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3594
4488
|
*/
|
|
3595
4489
|
async search(options = {}) {
|
|
3596
4490
|
const data = await this.guild.client.rest.post(
|
|
3597
|
-
|
|
4491
|
+
Routes22.guildMembersSearch(this.guild.id),
|
|
3598
4492
|
{ body: toMemberSearchBody(options), auth: true }
|
|
3599
4493
|
);
|
|
3600
4494
|
const offset = options.offset ?? 0;
|
|
@@ -3620,7 +4514,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
3620
4514
|
};
|
|
3621
4515
|
|
|
3622
4516
|
// src/Domain/Guild/Admin.ts
|
|
3623
|
-
import { Routes as
|
|
4517
|
+
import { Routes as Routes23 } from "@fluxerjs/types";
|
|
3624
4518
|
function toAuditLogEntryPayload(entry, guildId) {
|
|
3625
4519
|
return {
|
|
3626
4520
|
id: entry.id,
|
|
@@ -3641,7 +4535,7 @@ function toVanityPayload(data) {
|
|
|
3641
4535
|
return { code: data.code ?? null, uses: data.uses };
|
|
3642
4536
|
}
|
|
3643
4537
|
async function fetchAuditLogs(guild, options) {
|
|
3644
|
-
const url =
|
|
4538
|
+
const url = Routes23.guildAuditLogs(guild.id) + qs({
|
|
3645
4539
|
limit: options?.limit,
|
|
3646
4540
|
before: options?.before,
|
|
3647
4541
|
after: options?.after,
|
|
@@ -3665,7 +4559,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
3665
4559
|
};
|
|
3666
4560
|
}
|
|
3667
4561
|
async function editGuild(guild, options) {
|
|
3668
|
-
const data = await guild.client.rest.patch(
|
|
4562
|
+
const data = await guild.client.rest.patch(Routes23.guild(guild.id), {
|
|
3669
4563
|
body: toGuildEditBody(options),
|
|
3670
4564
|
auth: true
|
|
3671
4565
|
});
|
|
@@ -3673,13 +4567,13 @@ async function editGuild(guild, options) {
|
|
|
3673
4567
|
return guild;
|
|
3674
4568
|
}
|
|
3675
4569
|
async function fetchVanityURL(guild) {
|
|
3676
|
-
const data = await guild.client.rest.get(
|
|
4570
|
+
const data = await guild.client.rest.get(Routes23.guildVanityUrl(guild.id), {
|
|
3677
4571
|
auth: true
|
|
3678
4572
|
});
|
|
3679
4573
|
return toVanityPayload(data);
|
|
3680
4574
|
}
|
|
3681
4575
|
async function editVanityURL(guild, code) {
|
|
3682
|
-
const data = await guild.client.rest.patch(
|
|
4576
|
+
const data = await guild.client.rest.patch(Routes23.guildVanityUrl(guild.id), {
|
|
3683
4577
|
body: { code },
|
|
3684
4578
|
auth: true
|
|
3685
4579
|
});
|
|
@@ -3687,14 +4581,14 @@ async function editVanityURL(guild, code) {
|
|
|
3687
4581
|
return toVanityPayload(data);
|
|
3688
4582
|
}
|
|
3689
4583
|
async function fetchDiscoveryStatus(guild) {
|
|
3690
|
-
const data = await guild.client.rest.get(
|
|
4584
|
+
const data = await guild.client.rest.get(Routes23.guildDiscovery(guild.id), {
|
|
3691
4585
|
auth: true
|
|
3692
4586
|
});
|
|
3693
4587
|
return toDiscoveryStatusPayload(data);
|
|
3694
4588
|
}
|
|
3695
4589
|
async function applyForDiscovery(guild, options) {
|
|
3696
4590
|
const data = await guild.client.rest.post(
|
|
3697
|
-
|
|
4591
|
+
Routes23.guildDiscovery(guild.id),
|
|
3698
4592
|
{
|
|
3699
4593
|
body: toDiscoveryBody(options),
|
|
3700
4594
|
auth: true
|
|
@@ -3704,7 +4598,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
3704
4598
|
}
|
|
3705
4599
|
async function editDiscoveryApplication(guild, options) {
|
|
3706
4600
|
const data = await guild.client.rest.patch(
|
|
3707
|
-
|
|
4601
|
+
Routes23.guildDiscovery(guild.id),
|
|
3708
4602
|
{
|
|
3709
4603
|
body: toDiscoveryBody(options),
|
|
3710
4604
|
auth: true
|
|
@@ -3713,34 +4607,34 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
3713
4607
|
return toDiscoveryApplicationPayload(data);
|
|
3714
4608
|
}
|
|
3715
4609
|
async function withdrawDiscoveryApplication(guild) {
|
|
3716
|
-
await guild.client.rest.delete(
|
|
4610
|
+
await guild.client.rest.delete(Routes23.guildDiscovery(guild.id), { auth: true });
|
|
3717
4611
|
}
|
|
3718
4612
|
async function deleteGuild(guild, options) {
|
|
3719
4613
|
const body = options ? toSudoBody(options) : {};
|
|
3720
|
-
await guild.client.rest.post(
|
|
4614
|
+
await guild.client.rest.post(Routes23.guildDelete(guild.id), {
|
|
3721
4615
|
body,
|
|
3722
4616
|
auth: true
|
|
3723
4617
|
});
|
|
3724
4618
|
guild.client.guilds.delete(guild.id);
|
|
3725
4619
|
}
|
|
3726
4620
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
3727
|
-
await guild.client.rest.post(
|
|
4621
|
+
await guild.client.rest.post(Routes23.guildTransferOwnership(guild.id), {
|
|
3728
4622
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
3729
4623
|
auth: true
|
|
3730
4624
|
});
|
|
3731
4625
|
}
|
|
3732
4626
|
|
|
3733
4627
|
// src/Domain/Guild/Channels.ts
|
|
3734
|
-
import { Routes as
|
|
3735
|
-
async function createChannel(guild,
|
|
3736
|
-
const created = await guild.client.rest.post(
|
|
3737
|
-
body:
|
|
4628
|
+
import { Routes as Routes24 } from "@fluxerjs/types";
|
|
4629
|
+
async function createChannel(guild, options) {
|
|
4630
|
+
const created = await guild.client.rest.post(Routes24.guildChannels(guild.id), {
|
|
4631
|
+
body: toChannelCreateBody(options),
|
|
3738
4632
|
auth: true
|
|
3739
4633
|
});
|
|
3740
4634
|
return cacheChannel(guild, created);
|
|
3741
4635
|
}
|
|
3742
4636
|
async function fetchChannels(guild) {
|
|
3743
|
-
const data = await guild.client.rest.get(
|
|
4637
|
+
const data = await guild.client.rest.get(Routes24.guildChannels(guild.id));
|
|
3744
4638
|
const channels = [];
|
|
3745
4639
|
for (const ch of data) {
|
|
3746
4640
|
const channel = cacheChannel(guild, ch);
|
|
@@ -3749,17 +4643,17 @@ async function fetchChannels(guild) {
|
|
|
3749
4643
|
return channels;
|
|
3750
4644
|
}
|
|
3751
4645
|
async function setChannelPositions(guild, updates) {
|
|
3752
|
-
await guild.client.rest.patch(
|
|
4646
|
+
await guild.client.rest.patch(Routes24.guildChannels(guild.id), {
|
|
3753
4647
|
body: toChannelPositionBody(updates),
|
|
3754
4648
|
auth: true
|
|
3755
4649
|
});
|
|
3756
4650
|
}
|
|
3757
4651
|
async function fetchWebhooks(guild) {
|
|
3758
|
-
const data = await guild.client.rest.get(
|
|
4652
|
+
const data = await guild.client.rest.get(Routes24.guildWebhooks(guild.id));
|
|
3759
4653
|
return data.map((w) => new Webhook(guild.client, w));
|
|
3760
4654
|
}
|
|
3761
4655
|
async function fetchInvites(guild) {
|
|
3762
|
-
const data = await guild.client.rest.get(
|
|
4656
|
+
const data = await guild.client.rest.get(Routes24.guildInvites(guild.id));
|
|
3763
4657
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
3764
4658
|
}
|
|
3765
4659
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -3779,14 +4673,14 @@ function resolveGuildOnlineCount(data) {
|
|
|
3779
4673
|
}
|
|
3780
4674
|
|
|
3781
4675
|
// src/Domain/Guild/Emojis.ts
|
|
3782
|
-
import { Routes as
|
|
4676
|
+
import { Routes as Routes25 } from "@fluxerjs/types";
|
|
3783
4677
|
async function fetchEmojis(guild) {
|
|
3784
|
-
const data = await guild.client.rest.get(
|
|
4678
|
+
const data = await guild.client.rest.get(Routes25.guildEmojis(guild.id));
|
|
3785
4679
|
return data.map((e) => cacheEmoji(guild, e));
|
|
3786
4680
|
}
|
|
3787
4681
|
async function fetchEmoji(guild, emojiId) {
|
|
3788
4682
|
try {
|
|
3789
|
-
const data = await guild.client.rest.get(
|
|
4683
|
+
const data = await guild.client.rest.get(Routes25.guildEmoji(guild.id, emojiId));
|
|
3790
4684
|
return cacheEmoji(guild, data);
|
|
3791
4685
|
} catch (err) {
|
|
3792
4686
|
rethrowMapped(err, {
|
|
@@ -3796,14 +4690,14 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
3796
4690
|
}
|
|
3797
4691
|
}
|
|
3798
4692
|
async function createEmoji(guild, options) {
|
|
3799
|
-
const data = await guild.client.rest.post(
|
|
4693
|
+
const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
|
|
3800
4694
|
body: options,
|
|
3801
4695
|
auth: true
|
|
3802
4696
|
});
|
|
3803
4697
|
return cacheEmoji(guild, data);
|
|
3804
4698
|
}
|
|
3805
4699
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
3806
|
-
const data = await guild.client.rest.post(
|
|
4700
|
+
const data = await guild.client.rest.post(Routes25.guildEmojisClone(guild.id), {
|
|
3807
4701
|
body: { source_emoji_id: sourceEmojiId },
|
|
3808
4702
|
auth: true
|
|
3809
4703
|
});
|
|
@@ -3811,18 +4705,18 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
3811
4705
|
}
|
|
3812
4706
|
async function createEmojisBulk(guild, emojis) {
|
|
3813
4707
|
const data = await guild.client.rest.post(
|
|
3814
|
-
|
|
4708
|
+
Routes25.guildEmojisBulk(guild.id),
|
|
3815
4709
|
{ body: { emojis }, auth: true }
|
|
3816
4710
|
);
|
|
3817
4711
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
3818
4712
|
}
|
|
3819
4713
|
|
|
3820
4714
|
// src/Domain/Guild/MemberHttp.ts
|
|
3821
|
-
import { Routes as
|
|
4715
|
+
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
3822
4716
|
async function fetchMember(guild, userId) {
|
|
3823
4717
|
try {
|
|
3824
4718
|
const data = await guild.client.rest.get(
|
|
3825
|
-
|
|
4719
|
+
Routes26.guildMember(guild.id, userId)
|
|
3826
4720
|
);
|
|
3827
4721
|
return cacheMember(guild, data);
|
|
3828
4722
|
} catch (err) {
|
|
@@ -3837,23 +4731,28 @@ async function fetchMember(guild, userId) {
|
|
|
3837
4731
|
}
|
|
3838
4732
|
async function fetchMe(guild) {
|
|
3839
4733
|
const data = await guild.client.rest.get(
|
|
3840
|
-
|
|
4734
|
+
Routes26.guildMemberMe(guild.id),
|
|
3841
4735
|
{ auth: true }
|
|
3842
4736
|
);
|
|
3843
4737
|
return cacheMember(guild, data);
|
|
3844
4738
|
}
|
|
3845
4739
|
|
|
3846
4740
|
// src/Domain/Guild/Moderation.ts
|
|
3847
|
-
import { Routes as
|
|
4741
|
+
import { Routes as Routes28 } from "@fluxerjs/types";
|
|
3848
4742
|
|
|
3849
4743
|
// src/Domain/Guild/GuildBan.ts
|
|
3850
|
-
import { Routes as
|
|
4744
|
+
import { Routes as Routes27 } from "@fluxerjs/types";
|
|
4745
|
+
function parseOptionalDate2(value) {
|
|
4746
|
+
if (value == null || value === "") return null;
|
|
4747
|
+
const date = new Date(value);
|
|
4748
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
4749
|
+
}
|
|
3851
4750
|
var GuildBan = class extends Base {
|
|
3852
4751
|
client;
|
|
3853
4752
|
guildId;
|
|
3854
4753
|
user;
|
|
3855
4754
|
reason;
|
|
3856
|
-
/**
|
|
4755
|
+
/** When a temporary ban expires. Null for permanent bans. */
|
|
3857
4756
|
expiresAt;
|
|
3858
4757
|
/** @param data - API ban from GET /guilds/{id}/bans or gateway GUILD_BAN_ADD */
|
|
3859
4758
|
constructor(client, data, guildId) {
|
|
@@ -3862,14 +4761,14 @@ var GuildBan = class extends Base {
|
|
|
3862
4761
|
this.guildId = data.guild_id ?? guildId;
|
|
3863
4762
|
this.user = client.getOrCreateUser(data.user);
|
|
3864
4763
|
this.reason = data.reason ?? null;
|
|
3865
|
-
this.expiresAt = data.expires_at
|
|
4764
|
+
this.expiresAt = parseOptionalDate2(data.expires_at);
|
|
3866
4765
|
}
|
|
3867
4766
|
/**
|
|
3868
4767
|
* Remove this ban (unban the user).
|
|
3869
4768
|
* Requires Ban Members permission.
|
|
3870
4769
|
*/
|
|
3871
4770
|
async unban() {
|
|
3872
|
-
await this.client.rest.delete(
|
|
4771
|
+
await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
|
|
3873
4772
|
auth: true
|
|
3874
4773
|
});
|
|
3875
4774
|
}
|
|
@@ -3878,40 +4777,53 @@ var GuildBan = class extends Base {
|
|
|
3878
4777
|
// src/Domain/Guild/Moderation.ts
|
|
3879
4778
|
async function ban(guild, userId, options) {
|
|
3880
4779
|
const body = options ? toGuildBanBody(options) : {};
|
|
3881
|
-
await guild.client.rest.put(
|
|
4780
|
+
await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
|
|
3882
4781
|
body: Object.keys(body).length ? body : void 0,
|
|
3883
4782
|
auth: true
|
|
3884
4783
|
});
|
|
3885
4784
|
}
|
|
3886
4785
|
async function fetchBans(guild) {
|
|
3887
|
-
const data = await guild.client.rest.get(
|
|
4786
|
+
const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
|
|
3888
4787
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
3889
4788
|
}
|
|
3890
4789
|
async function unban(guild, userId) {
|
|
3891
|
-
await guild.client.rest.delete(
|
|
4790
|
+
await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), { auth: true });
|
|
3892
4791
|
}
|
|
3893
4792
|
async function kick(guild, userId) {
|
|
3894
|
-
await guild.client.rest.delete(
|
|
4793
|
+
await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), { auth: true });
|
|
3895
4794
|
}
|
|
3896
4795
|
|
|
4796
|
+
// src/Domain/Guild/GuildRoleManager.ts
|
|
4797
|
+
import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
|
|
4798
|
+
var GuildRoleManager = class extends LimitedCollection3 {
|
|
4799
|
+
constructor(guildId, options) {
|
|
4800
|
+
super(options);
|
|
4801
|
+
this.guildId = guildId;
|
|
4802
|
+
}
|
|
4803
|
+
/** The @everyone role (`id === guild.id`), or undefined if uncached. */
|
|
4804
|
+
get everyone() {
|
|
4805
|
+
return this.get(this.guildId);
|
|
4806
|
+
}
|
|
4807
|
+
};
|
|
4808
|
+
|
|
3897
4809
|
// src/Domain/Guild/Roles.ts
|
|
3898
|
-
import { Routes as
|
|
4810
|
+
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
3899
4811
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
3900
4812
|
async function createRole(guild, options = {}) {
|
|
3901
|
-
const body =
|
|
3902
|
-
const data = await guild.client.rest.post(
|
|
4813
|
+
const body = toRoleCreateBody(options);
|
|
4814
|
+
const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
|
|
3903
4815
|
body: Object.keys(body).length ? body : void 0,
|
|
3904
4816
|
auth: true
|
|
3905
4817
|
});
|
|
3906
4818
|
return cacheRole(guild, data);
|
|
3907
4819
|
}
|
|
3908
4820
|
async function fetchRoles(guild) {
|
|
3909
|
-
const data = await guild.client.rest.get(
|
|
4821
|
+
const data = await guild.client.rest.get(Routes29.guildRoles(guild.id));
|
|
3910
4822
|
return data.map((r) => cacheRole(guild, r));
|
|
3911
4823
|
}
|
|
3912
4824
|
async function fetchRole(guild, roleId2) {
|
|
3913
4825
|
try {
|
|
3914
|
-
const data = await guild.client.rest.get(
|
|
4826
|
+
const data = await guild.client.rest.get(Routes29.guildRole(guild.id, roleId2));
|
|
3915
4827
|
return cacheRole(guild, data);
|
|
3916
4828
|
} catch (err) {
|
|
3917
4829
|
rethrowMapped(err, {
|
|
@@ -3928,7 +4840,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3928
4840
|
const needle = trimmed.toLowerCase();
|
|
3929
4841
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3930
4842
|
if (cached) return cached.id;
|
|
3931
|
-
const roles = await guild.client.rest.get(
|
|
4843
|
+
const roles = await guild.client.rest.get(Routes29.guildRoles(guild.id));
|
|
3932
4844
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3933
4845
|
if (!role) return null;
|
|
3934
4846
|
cacheRole(guild, role);
|
|
@@ -3937,7 +4849,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3937
4849
|
async function setRolePositions(guild, updates) {
|
|
3938
4850
|
return replaceRoles(
|
|
3939
4851
|
guild,
|
|
3940
|
-
await guild.client.rest.patch(
|
|
4852
|
+
await guild.client.rest.patch(Routes29.guildRoles(guild.id), {
|
|
3941
4853
|
body: updates,
|
|
3942
4854
|
auth: true
|
|
3943
4855
|
})
|
|
@@ -3946,7 +4858,7 @@ async function setRolePositions(guild, updates) {
|
|
|
3946
4858
|
async function setRoleHoistPositions(guild, updates) {
|
|
3947
4859
|
return replaceRoles(
|
|
3948
4860
|
guild,
|
|
3949
|
-
await guild.client.rest.patch(
|
|
4861
|
+
await guild.client.rest.patch(Routes29.guildRolesHoistPositions(guild.id), {
|
|
3950
4862
|
body: updates.map((u) => ({
|
|
3951
4863
|
id: u.id,
|
|
3952
4864
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -3958,23 +4870,23 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
3958
4870
|
async function resetRoleHoistPositions(guild) {
|
|
3959
4871
|
return replaceRoles(
|
|
3960
4872
|
guild,
|
|
3961
|
-
await guild.client.rest.delete(
|
|
4873
|
+
await guild.client.rest.delete(Routes29.guildRolesHoistPositions(guild.id), {
|
|
3962
4874
|
auth: true
|
|
3963
4875
|
})
|
|
3964
4876
|
);
|
|
3965
4877
|
}
|
|
3966
4878
|
|
|
3967
4879
|
// src/Domain/Guild/Stickers.ts
|
|
3968
|
-
import { Routes as
|
|
4880
|
+
import { Routes as Routes30 } from "@fluxerjs/types";
|
|
3969
4881
|
async function createSticker(guild, options) {
|
|
3970
|
-
const data = await guild.client.rest.post(
|
|
4882
|
+
const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
|
|
3971
4883
|
body: options,
|
|
3972
4884
|
auth: true
|
|
3973
4885
|
});
|
|
3974
4886
|
return cacheSticker(guild, data);
|
|
3975
4887
|
}
|
|
3976
4888
|
async function cloneSticker(guild, sourceStickerId) {
|
|
3977
|
-
const data = await guild.client.rest.post(
|
|
4889
|
+
const data = await guild.client.rest.post(Routes30.guildStickersClone(guild.id), {
|
|
3978
4890
|
body: { source_sticker_id: sourceStickerId },
|
|
3979
4891
|
auth: true
|
|
3980
4892
|
});
|
|
@@ -3982,17 +4894,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
3982
4894
|
}
|
|
3983
4895
|
async function createStickersBulk(guild, stickers) {
|
|
3984
4896
|
const data = await guild.client.rest.post(
|
|
3985
|
-
|
|
4897
|
+
Routes30.guildStickersBulk(guild.id),
|
|
3986
4898
|
{ body: { stickers }, auth: true }
|
|
3987
4899
|
);
|
|
3988
4900
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
3989
4901
|
}
|
|
3990
4902
|
async function fetchStickers(guild) {
|
|
3991
|
-
const data = await guild.client.rest.get(
|
|
4903
|
+
const data = await guild.client.rest.get(Routes30.guildStickers(guild.id));
|
|
3992
4904
|
return data.map((s) => cacheSticker(guild, s));
|
|
3993
4905
|
}
|
|
3994
4906
|
async function fetchSticker(guild, stickerId) {
|
|
3995
|
-
const data = await guild.client.rest.get(
|
|
4907
|
+
const data = await guild.client.rest.get(Routes30.guildSticker(guild.id, stickerId));
|
|
3996
4908
|
return cacheSticker(guild, data);
|
|
3997
4909
|
}
|
|
3998
4910
|
|
|
@@ -4032,8 +4944,26 @@ var Guild = class extends Base {
|
|
|
4032
4944
|
systemChannelId;
|
|
4033
4945
|
/** Rules channel ID (for Community guilds), or null if none. */
|
|
4034
4946
|
rulesChannelId;
|
|
4947
|
+
/** {@link SystemChannelFlags} bitfield. */
|
|
4948
|
+
systemChannelFlags;
|
|
4949
|
+
/** Splash card alignment. */
|
|
4950
|
+
splashCardAlignment;
|
|
4951
|
+
/** Embed splash hash. */
|
|
4952
|
+
embedSplash;
|
|
4035
4953
|
/** NSFW level for this guild. */
|
|
4036
4954
|
nsfwLevel;
|
|
4955
|
+
/** Whether the guild is marked as adult (18+) content. */
|
|
4956
|
+
nsfw;
|
|
4957
|
+
/** Content warning level. */
|
|
4958
|
+
contentWarningLevel;
|
|
4959
|
+
/** Custom guild-wide content warning text. */
|
|
4960
|
+
contentWarningText;
|
|
4961
|
+
/** {@link GuildOperations} bitfield of disabled operations. */
|
|
4962
|
+
disabledOperations;
|
|
4963
|
+
/** ISO-8601 timestamp before which message history is not available. */
|
|
4964
|
+
messageHistoryCutoff;
|
|
4965
|
+
/** Permissions for the current member in this guild (bitfield string). */
|
|
4966
|
+
permissions;
|
|
4037
4967
|
/** MFA level required for moderation actions. */
|
|
4038
4968
|
mfaLevel;
|
|
4039
4969
|
/** Banner width in pixels. */
|
|
@@ -4067,13 +4997,13 @@ var Guild = class extends Base {
|
|
|
4067
4997
|
this.client = client;
|
|
4068
4998
|
this.id = data.id;
|
|
4069
4999
|
this.members = new GuildMemberManager(this);
|
|
4070
|
-
this.channels = new
|
|
5000
|
+
this.channels = new LimitedCollection4({
|
|
4071
5001
|
maxSize: Number.POSITIVE_INFINITY,
|
|
4072
5002
|
onEvict: (_id, channel) => client.cache.cascadeChannel(channel, "guild")
|
|
4073
5003
|
});
|
|
4074
|
-
this.roles = new
|
|
4075
|
-
this.emojis = new
|
|
4076
|
-
this.stickers = new
|
|
5004
|
+
this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
|
|
5005
|
+
this.emojis = new LimitedCollection4({ maxSize: client.cache.limits.emojis });
|
|
5006
|
+
this.stickers = new LimitedCollection4({ maxSize: client.cache.limits.stickers });
|
|
4077
5007
|
this.name = data.name ?? "";
|
|
4078
5008
|
this.icon = data.icon ?? null;
|
|
4079
5009
|
this.banner = data.banner ?? null;
|
|
@@ -4088,7 +5018,16 @@ var Guild = class extends Base {
|
|
|
4088
5018
|
this.afkTimeout = data.afk_timeout ?? 0;
|
|
4089
5019
|
this.systemChannelId = data.system_channel_id ?? null;
|
|
4090
5020
|
this.rulesChannelId = data.rules_channel_id ?? null;
|
|
5021
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
5022
|
+
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
5023
|
+
this.embedSplash = data.embed_splash ?? null;
|
|
4091
5024
|
this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
|
|
5025
|
+
this.nsfw = data.nsfw ?? false;
|
|
5026
|
+
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
5027
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
5028
|
+
this.disabledOperations = data.disabled_operations ?? 0;
|
|
5029
|
+
this.messageHistoryCutoff = data.message_history_cutoff ?? null;
|
|
5030
|
+
this.permissions = data.permissions ?? null;
|
|
4092
5031
|
this.mfaLevel = data.mfa_level ?? 0;
|
|
4093
5032
|
this.bannerWidth = data.banner_width ?? null;
|
|
4094
5033
|
this.bannerHeight = data.banner_height ?? null;
|
|
@@ -4123,7 +5062,28 @@ var Guild = class extends Base {
|
|
|
4123
5062
|
if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
|
|
4124
5063
|
if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
|
|
4125
5064
|
if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
|
|
5065
|
+
if (data.system_channel_flags !== void 0) {
|
|
5066
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
5067
|
+
}
|
|
5068
|
+
if (data.splash_card_alignment !== void 0) {
|
|
5069
|
+
this.splashCardAlignment = data.splash_card_alignment ?? 0;
|
|
5070
|
+
}
|
|
5071
|
+
if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
|
|
4126
5072
|
if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
|
|
5073
|
+
if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
|
|
5074
|
+
if (data.content_warning_level !== void 0) {
|
|
5075
|
+
this.contentWarningLevel = data.content_warning_level ?? 0;
|
|
5076
|
+
}
|
|
5077
|
+
if (data.content_warning_text !== void 0) {
|
|
5078
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
5079
|
+
}
|
|
5080
|
+
if (data.disabled_operations !== void 0) {
|
|
5081
|
+
this.disabledOperations = data.disabled_operations ?? 0;
|
|
5082
|
+
}
|
|
5083
|
+
if (data.message_history_cutoff !== void 0) {
|
|
5084
|
+
this.messageHistoryCutoff = data.message_history_cutoff ?? null;
|
|
5085
|
+
}
|
|
5086
|
+
if (data.permissions !== void 0) this.permissions = data.permissions ?? null;
|
|
4127
5087
|
if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
|
|
4128
5088
|
if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
|
|
4129
5089
|
if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
|
|
@@ -4144,11 +5104,11 @@ var Guild = class extends Base {
|
|
|
4144
5104
|
}
|
|
4145
5105
|
/** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
|
|
4146
5106
|
get createdTimestamp() {
|
|
4147
|
-
return
|
|
5107
|
+
return SnowflakeUtil9.timestampFromSnowflake(this.id);
|
|
4148
5108
|
}
|
|
4149
5109
|
/** Date when this guild was created, derived from its snowflake ID. */
|
|
4150
5110
|
get createdAt() {
|
|
4151
|
-
return
|
|
5111
|
+
return SnowflakeUtil9.dateFromSnowflake(this.id);
|
|
4152
5112
|
}
|
|
4153
5113
|
/** The guild's name. */
|
|
4154
5114
|
toString() {
|
|
@@ -4176,11 +5136,11 @@ var Guild = class extends Base {
|
|
|
4176
5136
|
});
|
|
4177
5137
|
}
|
|
4178
5138
|
/**
|
|
4179
|
-
* Create a channel. `
|
|
5139
|
+
* Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
|
|
4180
5140
|
* Requires Manage Channels.
|
|
4181
5141
|
*/
|
|
4182
|
-
createChannel(
|
|
4183
|
-
return createChannel(this,
|
|
5142
|
+
createChannel(options) {
|
|
5143
|
+
return createChannel(this, options);
|
|
4184
5144
|
}
|
|
4185
5145
|
/** Fetch all channels in this guild from the API. */
|
|
4186
5146
|
fetchChannels() {
|
|
@@ -4242,7 +5202,7 @@ var Guild = class extends Base {
|
|
|
4242
5202
|
resetRoleHoistPositions() {
|
|
4243
5203
|
return resetRoleHoistPositions(this);
|
|
4244
5204
|
}
|
|
4245
|
-
/** Ban a user from the guild. Requires Ban Members. `
|
|
5205
|
+
/** Ban a user from the guild. Requires Ban Members. `banDurationSeconds`: 0 = permanent. */
|
|
4246
5206
|
ban(userId, options) {
|
|
4247
5207
|
return ban(this, userId, options);
|
|
4248
5208
|
}
|
|
@@ -4442,23 +5402,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
4442
5402
|
}
|
|
4443
5403
|
|
|
4444
5404
|
// src/ClientCore/ClientUser.ts
|
|
4445
|
-
import { GatewayOpcodes, Routes as
|
|
5405
|
+
import { GatewayOpcodes, Routes as Routes31 } from "@fluxerjs/types";
|
|
4446
5406
|
var ClientUser = class extends User {
|
|
4447
5407
|
/** Broadcast presence (gateway opcode 3) on all shards. */
|
|
4448
5408
|
setPresence(presence) {
|
|
5409
|
+
this.client.options.presence = presence;
|
|
4449
5410
|
const wire = toPresenceWire(presence);
|
|
4450
|
-
this.client.options.presence = wire;
|
|
4451
5411
|
this.client._sendToAllShards({ op: GatewayOpcodes.PresenceUpdate, d: wire });
|
|
4452
5412
|
}
|
|
4453
5413
|
/** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
|
|
4454
5414
|
async fetch() {
|
|
4455
|
-
const data = await this.client.rest.get(
|
|
5415
|
+
const data = await this.client.rest.get(Routes31.currentUser(), { auth: true });
|
|
4456
5416
|
this._patch(data);
|
|
4457
5417
|
return this;
|
|
4458
5418
|
}
|
|
4459
5419
|
/** GET /users/@me/guilds — returns camelCase partial guilds. */
|
|
4460
5420
|
async fetchGuilds(options) {
|
|
4461
|
-
const path =
|
|
5421
|
+
const path = Routes31.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
|
|
4462
5422
|
const data = await this.client.rest.get(path, { auth: true });
|
|
4463
5423
|
return data.map((g) => ({
|
|
4464
5424
|
id: g.id,
|
|
@@ -4471,10 +5431,18 @@ var ClientUser = class extends User {
|
|
|
4471
5431
|
...g.approximate_presence_count !== void 0 ? { approximatePresenceCount: g.approximate_presence_count } : {}
|
|
4472
5432
|
}));
|
|
4473
5433
|
}
|
|
4474
|
-
/**
|
|
5434
|
+
/**
|
|
5435
|
+
* Leave a guild (`client.user.leaveGuild`).
|
|
5436
|
+
* DELETE /users/@me/guilds/{guild_id}.
|
|
5437
|
+
*
|
|
5438
|
+
* @param guildId - Guild to leave
|
|
5439
|
+
* @param options - Optional sudo / MFA body for user accounts
|
|
5440
|
+
* @example
|
|
5441
|
+
* await client.user.leaveGuild(guildId);
|
|
5442
|
+
*/
|
|
4475
5443
|
async leaveGuild(guildId, options) {
|
|
4476
5444
|
const body = options ? toSudoBody(options) : void 0;
|
|
4477
|
-
await this.client.rest.delete(
|
|
5445
|
+
await this.client.rest.delete(Routes31.leaveGuild(guildId), {
|
|
4478
5446
|
body: body && Object.keys(body).length ? body : void 0,
|
|
4479
5447
|
auth: true
|
|
4480
5448
|
});
|
|
@@ -4482,7 +5450,7 @@ var ClientUser = class extends User {
|
|
|
4482
5450
|
/** Delete every message authored by the caller across a guild (sudo). */
|
|
4483
5451
|
async bulkDeleteMyMessagesInGuild(guildId, options) {
|
|
4484
5452
|
const body = options ? toSudoBody(options) : void 0;
|
|
4485
|
-
await this.client.rest.post(
|
|
5453
|
+
await this.client.rest.post(Routes31.guildBulkDeleteMine(guildId), {
|
|
4486
5454
|
body: body && Object.keys(body).length ? body : void 0,
|
|
4487
5455
|
auth: true
|
|
4488
5456
|
});
|
|
@@ -4649,7 +5617,7 @@ var guildResourceHandlers = {
|
|
|
4649
5617
|
role = new Role(client, data.role, data.guild_id);
|
|
4650
5618
|
guild?.roles.set(role.id, role);
|
|
4651
5619
|
}
|
|
4652
|
-
client.emit(Events.GuildRoleUpdate,
|
|
5620
|
+
client.emit(Events.GuildRoleUpdate, oldRole, role);
|
|
4653
5621
|
},
|
|
4654
5622
|
GUILD_ROLE_UPDATE_BULK(client, d) {
|
|
4655
5623
|
const data = d;
|
|
@@ -4665,11 +5633,7 @@ var guildResourceHandlers = {
|
|
|
4665
5633
|
const guild = client.guilds.get(data.guild_id);
|
|
4666
5634
|
const role = guild?.roles.get(data.role_id) ?? null;
|
|
4667
5635
|
guild?.roles.delete(data.role_id);
|
|
4668
|
-
client.emit(Events.GuildRoleDelete,
|
|
4669
|
-
roleId: data.role_id,
|
|
4670
|
-
guildId: data.guild_id,
|
|
4671
|
-
role
|
|
4672
|
-
});
|
|
5636
|
+
client.emit(Events.GuildRoleDelete, role, data.guild_id, data.role_id);
|
|
4673
5637
|
},
|
|
4674
5638
|
GUILD_BAN_ADD(client, d) {
|
|
4675
5639
|
const data = d;
|
|
@@ -4778,7 +5742,7 @@ function normalizeInviteCreate(client, payload) {
|
|
|
4778
5742
|
const code = str(raw?.code);
|
|
4779
5743
|
if (!raw || !code) return null;
|
|
4780
5744
|
const typeNum = num(raw.type);
|
|
4781
|
-
const type = typeNum === InviteType2.GroupDM
|
|
5745
|
+
const type = typeNum === InviteType2.GroupDM ? InviteType2.GroupDM : InviteType2.Guild;
|
|
4782
5746
|
const shared = {
|
|
4783
5747
|
code,
|
|
4784
5748
|
inviter: raw.inviter ?? null,
|
|
@@ -4790,11 +5754,6 @@ function normalizeInviteCreate(client, payload) {
|
|
|
4790
5754
|
max_uses: num(raw.max_uses),
|
|
4791
5755
|
max_age: num(raw.max_age)
|
|
4792
5756
|
};
|
|
4793
|
-
if (type === InviteType2.EmojiPack || type === InviteType2.StickerPack) {
|
|
4794
|
-
const pack = asRecord(raw.pack);
|
|
4795
|
-
if (!pack || !str(pack.id) || !str(pack.name)) return null;
|
|
4796
|
-
return { ...shared, type, pack };
|
|
4797
|
-
}
|
|
4798
5757
|
const guildObj = asRecord(raw.guild);
|
|
4799
5758
|
const channelObj = asRecord(raw.channel);
|
|
4800
5759
|
const guildId = str(guildObj?.id) ?? str(raw.guild_id) ?? "0";
|
|
@@ -4846,6 +5805,30 @@ var inviteHandlers = {
|
|
|
4846
5805
|
}
|
|
4847
5806
|
};
|
|
4848
5807
|
|
|
5808
|
+
// src/Domain/Guild/PartialGuildMember.ts
|
|
5809
|
+
var PartialGuildMember = class {
|
|
5810
|
+
partial = true;
|
|
5811
|
+
client;
|
|
5812
|
+
id;
|
|
5813
|
+
user;
|
|
5814
|
+
guildId;
|
|
5815
|
+
guild;
|
|
5816
|
+
constructor(data) {
|
|
5817
|
+
this.client = data.client;
|
|
5818
|
+
this.id = data.id;
|
|
5819
|
+
this.user = data.user;
|
|
5820
|
+
this.guild = data.guild;
|
|
5821
|
+
this.guildId = data.guild.id;
|
|
5822
|
+
}
|
|
5823
|
+
/**
|
|
5824
|
+
* Fetch the full {@link GuildMember} from the API (cache-aware via `guild.members.fetch`).
|
|
5825
|
+
* @throws FluxerError with MEMBER_NOT_FOUND if the user is not in the guild
|
|
5826
|
+
*/
|
|
5827
|
+
async fetch() {
|
|
5828
|
+
return this.guild.members.fetch(this.id);
|
|
5829
|
+
}
|
|
5830
|
+
};
|
|
5831
|
+
|
|
4849
5832
|
// src/ClientCore/EventHandlers/Members.ts
|
|
4850
5833
|
var memberHandlers = {
|
|
4851
5834
|
GUILD_MEMBER_ADD(client, d) {
|
|
@@ -4872,28 +5855,15 @@ var memberHandlers = {
|
|
|
4872
5855
|
const data = d;
|
|
4873
5856
|
const guild = client.guilds.get(data.guild_id);
|
|
4874
5857
|
if (!guild || !data.user?.id) return;
|
|
4875
|
-
|
|
4876
|
-
if (
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
...data.user,
|
|
4885
|
-
username: data.user.username ?? "Unknown",
|
|
4886
|
-
discriminator: data.user.discriminator ?? "0"
|
|
4887
|
-
},
|
|
4888
|
-
roles: [],
|
|
4889
|
-
joined_at: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
4890
|
-
nick: null,
|
|
4891
|
-
mute: false,
|
|
4892
|
-
deaf: false
|
|
4893
|
-
},
|
|
4894
|
-
guild
|
|
4895
|
-
);
|
|
4896
|
-
}
|
|
5858
|
+
const cached = guild.members.get(data.user.id);
|
|
5859
|
+
if (cached) guild.members.delete(data.user.id);
|
|
5860
|
+
const user = client.getOrCreateUser(data.user);
|
|
5861
|
+
const member = cached ?? new PartialGuildMember({
|
|
5862
|
+
client,
|
|
5863
|
+
id: data.user.id,
|
|
5864
|
+
user,
|
|
5865
|
+
guild
|
|
5866
|
+
});
|
|
4897
5867
|
guild.adjustMemberCount(-1);
|
|
4898
5868
|
client.emit(Events.GuildMemberRemove, member);
|
|
4899
5869
|
},
|
|
@@ -4912,7 +5882,7 @@ var memberHandlers = {
|
|
|
4912
5882
|
members,
|
|
4913
5883
|
chunkIndex: data.chunk_index,
|
|
4914
5884
|
chunkCount: data.chunk_count,
|
|
4915
|
-
notFound: [],
|
|
5885
|
+
notFound: data.not_found ?? [],
|
|
4916
5886
|
nonce: data.nonce ?? null
|
|
4917
5887
|
};
|
|
4918
5888
|
client.emit(Events.GuildMembersChunk, payload);
|
|
@@ -4920,7 +5890,35 @@ var memberHandlers = {
|
|
|
4920
5890
|
};
|
|
4921
5891
|
|
|
4922
5892
|
// src/ClientCore/EventHandlers/Messages.ts
|
|
4923
|
-
|
|
5893
|
+
import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
|
|
5894
|
+
function cachedTextChannel(client, channelId) {
|
|
5895
|
+
const channel = client.channels.get(channelId);
|
|
5896
|
+
return channel?.isTextBased() ? channel : null;
|
|
5897
|
+
}
|
|
5898
|
+
function cachedMessage(client, channelId, messageId) {
|
|
5899
|
+
const data = client._getMessageCache(channelId)?.get(messageId);
|
|
5900
|
+
return data ? new Message(client, data) : null;
|
|
5901
|
+
}
|
|
5902
|
+
function isHydratableMessage(data) {
|
|
5903
|
+
return Boolean(data.author?.id && data.timestamp);
|
|
5904
|
+
}
|
|
5905
|
+
function toPartialMessage(client, args) {
|
|
5906
|
+
const cached = args.cached;
|
|
5907
|
+
const authorId = args.authorId ?? cached?.author?.id ?? null;
|
|
5908
|
+
const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
|
|
5909
|
+
const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil10.isValid(args.id) ? SnowflakeUtil10.dateFromSnowflake(args.id) : null;
|
|
5910
|
+
return new PartialMessage(client, {
|
|
5911
|
+
id: args.id,
|
|
5912
|
+
channelId: args.channelId,
|
|
5913
|
+
guildId: args.guildId ?? cached?.guild_id ?? null,
|
|
5914
|
+
channel: cachedTextChannel(client, args.channelId),
|
|
5915
|
+
content: args.content ?? cached?.content ?? null,
|
|
5916
|
+
authorId,
|
|
5917
|
+
author,
|
|
5918
|
+
createdAt
|
|
5919
|
+
});
|
|
5920
|
+
}
|
|
5921
|
+
function toReactionEmoji(emoji) {
|
|
4924
5922
|
return {
|
|
4925
5923
|
name: emoji.name,
|
|
4926
5924
|
...emoji.id !== void 0 ? { id: emoji.id } : {},
|
|
@@ -4937,9 +5935,12 @@ function emitReaction(event) {
|
|
|
4937
5935
|
const payload = {
|
|
4938
5936
|
reaction,
|
|
4939
5937
|
user,
|
|
5938
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
5939
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
5940
|
+
member,
|
|
4940
5941
|
messageId: data.message_id,
|
|
4941
5942
|
channelId: data.channel_id,
|
|
4942
|
-
emoji:
|
|
5943
|
+
emoji: toReactionEmoji(data.emoji),
|
|
4943
5944
|
userId: data.user_id
|
|
4944
5945
|
};
|
|
4945
5946
|
client.emit(event, payload);
|
|
@@ -4959,37 +5960,60 @@ var messageHandlers = {
|
|
|
4959
5960
|
},
|
|
4960
5961
|
MESSAGE_UPDATE(client, d) {
|
|
4961
5962
|
const partial = d;
|
|
4962
|
-
const
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
if (
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
mergedData = { ...oldData, ...partial };
|
|
4970
|
-
}
|
|
5963
|
+
const oldData = client._getMessageCache(partial.channel_id)?.get(partial.id);
|
|
5964
|
+
const oldMessage = oldData ? new Message(client, oldData) : null;
|
|
5965
|
+
const mergedData = oldData ? { ...oldData, ...partial } : partial;
|
|
5966
|
+
if (isHydratableMessage(mergedData)) {
|
|
5967
|
+
client._addMessageToCache(partial.channel_id, mergedData);
|
|
5968
|
+
client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
|
|
5969
|
+
return;
|
|
4971
5970
|
}
|
|
4972
|
-
client.
|
|
4973
|
-
|
|
5971
|
+
client.emit(
|
|
5972
|
+
Events.MessageUpdate,
|
|
5973
|
+
oldMessage,
|
|
5974
|
+
toPartialMessage(client, {
|
|
5975
|
+
id: partial.id,
|
|
5976
|
+
channelId: partial.channel_id,
|
|
5977
|
+
guildId: partial.guild_id ?? oldData?.guild_id ?? null,
|
|
5978
|
+
content: partial.content ?? oldData?.content ?? null,
|
|
5979
|
+
authorId: partial.author?.id ?? oldData?.author?.id ?? null,
|
|
5980
|
+
cached: oldData
|
|
5981
|
+
})
|
|
5982
|
+
);
|
|
4974
5983
|
},
|
|
4975
5984
|
MESSAGE_DELETE(client, d) {
|
|
4976
5985
|
const data = d;
|
|
4977
|
-
client.
|
|
4978
|
-
client
|
|
5986
|
+
const cached = client._getMessageCache(data.channel_id)?.get(data.id);
|
|
5987
|
+
const payload = toPartialMessage(client, {
|
|
4979
5988
|
id: data.id,
|
|
4980
5989
|
channelId: data.channel_id,
|
|
4981
|
-
|
|
4982
|
-
content: data.content ?? null,
|
|
4983
|
-
authorId: data.author_id ?? null
|
|
5990
|
+
guildId: data.guild_id ?? cached?.guild_id ?? null,
|
|
5991
|
+
content: data.content ?? cached?.content ?? null,
|
|
5992
|
+
authorId: data.author_id ?? cached?.author?.id ?? null,
|
|
5993
|
+
cached
|
|
4984
5994
|
});
|
|
5995
|
+
client._removeMessageFromCache(data.channel_id, data.id);
|
|
5996
|
+
client.emit(Events.MessageDelete, payload);
|
|
4985
5997
|
},
|
|
4986
5998
|
MESSAGE_DELETE_BULK(client, d) {
|
|
4987
5999
|
const data = d;
|
|
4988
|
-
|
|
6000
|
+
const ids = data.ids ?? [];
|
|
6001
|
+
const cache = client._getMessageCache(data.channel_id);
|
|
6002
|
+
const messages = ids.map(
|
|
6003
|
+
(id) => toPartialMessage(client, {
|
|
6004
|
+
id,
|
|
6005
|
+
channelId: data.channel_id,
|
|
6006
|
+
guildId: data.guild_id ?? cache?.get(id)?.guild_id ?? null,
|
|
6007
|
+
cached: cache?.get(id)
|
|
6008
|
+
})
|
|
6009
|
+
);
|
|
6010
|
+
for (const id of ids) client._removeMessageFromCache(data.channel_id, id);
|
|
4989
6011
|
client.emit(Events.MessageDeleteBulk, {
|
|
4990
|
-
ids
|
|
6012
|
+
ids,
|
|
4991
6013
|
channelId: data.channel_id,
|
|
4992
|
-
guildId: data.guild_id ?? null
|
|
6014
|
+
guildId: data.guild_id ?? null,
|
|
6015
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
6016
|
+
messages
|
|
4993
6017
|
});
|
|
4994
6018
|
},
|
|
4995
6019
|
MESSAGE_REACTION_ADD: emitReaction(Events.MessageReactionAdd),
|
|
@@ -4999,7 +6023,9 @@ var messageHandlers = {
|
|
|
4999
6023
|
const payload = {
|
|
5000
6024
|
messageId: data.message_id,
|
|
5001
6025
|
channelId: data.channel_id,
|
|
5002
|
-
guildId: data.guild_id ?? null
|
|
6026
|
+
guildId: data.guild_id ?? null,
|
|
6027
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6028
|
+
channel: cachedTextChannel(client, data.channel_id)
|
|
5003
6029
|
};
|
|
5004
6030
|
client.emit(Events.MessageReactionRemoveAll, payload);
|
|
5005
6031
|
},
|
|
@@ -5009,7 +6035,9 @@ var messageHandlers = {
|
|
|
5009
6035
|
messageId: data.message_id,
|
|
5010
6036
|
channelId: data.channel_id,
|
|
5011
6037
|
guildId: data.guild_id ?? null,
|
|
5012
|
-
emoji:
|
|
6038
|
+
emoji: toReactionEmoji(data.emoji),
|
|
6039
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6040
|
+
channel: cachedTextChannel(client, data.channel_id)
|
|
5013
6041
|
};
|
|
5014
6042
|
client.emit(Events.MessageReactionRemoveEmoji, payload);
|
|
5015
6043
|
},
|
|
@@ -5028,7 +6056,7 @@ var messageHandlers = {
|
|
|
5028
6056
|
}
|
|
5029
6057
|
reactions.push({
|
|
5030
6058
|
userId: entry.user_id,
|
|
5031
|
-
emoji:
|
|
6059
|
+
emoji: toReactionEmoji(entry.emoji),
|
|
5032
6060
|
member
|
|
5033
6061
|
});
|
|
5034
6062
|
}
|
|
@@ -5036,6 +6064,8 @@ var messageHandlers = {
|
|
|
5036
6064
|
channelId: data.channel_id,
|
|
5037
6065
|
messageId: data.message_id,
|
|
5038
6066
|
guildId: data.guild_id ?? null,
|
|
6067
|
+
message: cachedMessage(client, data.channel_id, data.message_id),
|
|
6068
|
+
channel: cachedTextChannel(client, data.channel_id),
|
|
5039
6069
|
reactions
|
|
5040
6070
|
};
|
|
5041
6071
|
client.emit(Events.MessageReactionAddMany, payload);
|
|
@@ -5246,15 +6276,27 @@ function handleReadyPayload(client, data) {
|
|
|
5246
6276
|
const waitForGuilds = client.options.waitForGuilds === true;
|
|
5247
6277
|
const guilds = data.guilds ?? [];
|
|
5248
6278
|
const pending = hydrateReadyGuilds(client, guilds, waitForGuilds);
|
|
6279
|
+
if (client.readyAt !== null) {
|
|
6280
|
+
if (pending !== null && pending.size > 0) {
|
|
6281
|
+
const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
|
|
6282
|
+
for (const id of pending) existing.add(id);
|
|
6283
|
+
client._pendingGuildIds = existing;
|
|
6284
|
+
}
|
|
6285
|
+
return;
|
|
6286
|
+
}
|
|
5249
6287
|
if (pending !== null && pending.size > 0) {
|
|
5250
|
-
client._pendingGuildIds
|
|
6288
|
+
const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
|
|
6289
|
+
for (const id of pending) existing.add(id);
|
|
6290
|
+
client._pendingGuildIds = existing;
|
|
5251
6291
|
return;
|
|
5252
6292
|
}
|
|
5253
6293
|
if (waitForGuilds && guilds.length === 0) {
|
|
5254
|
-
client._guildStreamSettleTimeout
|
|
5255
|
-
client._guildStreamSettleTimeout =
|
|
5256
|
-
|
|
5257
|
-
|
|
6294
|
+
if (client._guildStreamSettleTimeout === null) {
|
|
6295
|
+
client._guildStreamSettleTimeout = setTimeout(() => {
|
|
6296
|
+
client._guildStreamSettleTimeout = null;
|
|
6297
|
+
if (client.readyAt === null) finalizeClientReady(client);
|
|
6298
|
+
}, GUILD_STREAM_SETTLE_MS);
|
|
6299
|
+
}
|
|
5258
6300
|
return;
|
|
5259
6301
|
}
|
|
5260
6302
|
finalizeClientReady(client);
|
|
@@ -5266,7 +6308,7 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5266
6308
|
const ws = new WebSocketManager({
|
|
5267
6309
|
token,
|
|
5268
6310
|
intents: client.options.intents ?? 0,
|
|
5269
|
-
presence: client.options.presence,
|
|
6311
|
+
presence: client.options.presence ? toPresenceWire(client.options.presence) : void 0,
|
|
5270
6312
|
flags: client.options.identifyFlags,
|
|
5271
6313
|
ignoredEvents: client.options.ignoredEvents,
|
|
5272
6314
|
initialGuildId: client.options.initialGuildId,
|
|
@@ -5275,24 +6317,57 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5275
6317
|
},
|
|
5276
6318
|
version: client.options.rest?.version ?? "1",
|
|
5277
6319
|
debug: client.options.gatewayDebug !== false,
|
|
5278
|
-
WebSocket: client.options.WebSocket
|
|
6320
|
+
WebSocket: client.options.WebSocket,
|
|
6321
|
+
shardCount: client.options.shardCount ?? client.options.totalShards,
|
|
6322
|
+
shardIds: client.options.shardIds ?? client.options.shardList,
|
|
6323
|
+
guildsPerShard: client.options.guildsPerShard,
|
|
6324
|
+
buildStrategy: client.options.buildStrategy,
|
|
6325
|
+
sessionStore: client.options.sessionStore,
|
|
6326
|
+
identifyThrottler: client.options.identifyThrottler
|
|
5279
6327
|
});
|
|
5280
6328
|
ws.on("dispatch", ({ payload }) => {
|
|
5281
6329
|
handleGatewayDispatch(client, payload, client._deferredGatewayDispatches).catch(
|
|
5282
6330
|
(err) => emitClientError(client, err)
|
|
5283
6331
|
);
|
|
5284
6332
|
});
|
|
5285
|
-
ws.on("ready", ({ data }) => {
|
|
5286
|
-
|
|
6333
|
+
ws.on("ready", ({ shardId, data }) => {
|
|
6334
|
+
client.emit(Events.ShardReady, shardId);
|
|
6335
|
+
try {
|
|
6336
|
+
handleReadyPayload(client, data);
|
|
6337
|
+
} catch (err) {
|
|
6338
|
+
emitClientError(client, err);
|
|
6339
|
+
}
|
|
6340
|
+
});
|
|
6341
|
+
ws.on("resumed", (shardId) => {
|
|
6342
|
+
client.emit(Events.ShardResumed, shardId);
|
|
6343
|
+
});
|
|
6344
|
+
ws.on("close", ({ shardId, code }) => {
|
|
6345
|
+
client.emit(Events.ShardDisconnect, shardId, code);
|
|
6346
|
+
if (code === GatewayCloseCodes.AuthenticationFailed) {
|
|
6347
|
+
emitClientError(
|
|
6348
|
+
client,
|
|
6349
|
+
new FluxerError("Gateway authentication failed (4004). Check the bot token.", {
|
|
6350
|
+
code: ErrorCodes.InvalidToken
|
|
6351
|
+
})
|
|
6352
|
+
);
|
|
6353
|
+
}
|
|
5287
6354
|
});
|
|
5288
|
-
ws.on("error", ({ error }) => {
|
|
5289
|
-
|
|
6355
|
+
ws.on("error", ({ shardId, error }) => {
|
|
6356
|
+
if (shardId >= 0) client.emit(Events.ShardError, shardId, error);
|
|
6357
|
+
client.logger.error("gateway error", {
|
|
6358
|
+
error: error.message,
|
|
6359
|
+
name: error.name,
|
|
6360
|
+
shardId
|
|
6361
|
+
});
|
|
5290
6362
|
client.emit(Events.Error, error);
|
|
5291
6363
|
});
|
|
5292
6364
|
ws.on("debug", (msg) => {
|
|
5293
6365
|
client.logger.debug(msg);
|
|
5294
6366
|
client.emit(Events.Debug, msg);
|
|
5295
6367
|
});
|
|
6368
|
+
ws.on("shardingRequired", (payload) => {
|
|
6369
|
+
client.emit(Events.ShardingRequired, payload);
|
|
6370
|
+
});
|
|
5296
6371
|
client._ws = ws;
|
|
5297
6372
|
const onAbort = () => {
|
|
5298
6373
|
ws.destroy();
|
|
@@ -5318,9 +6393,9 @@ async function connectClientGateway(client, token, signal) {
|
|
|
5318
6393
|
}
|
|
5319
6394
|
|
|
5320
6395
|
// src/ClientCore/GuildManager.ts
|
|
5321
|
-
import { LimitedCollection as
|
|
5322
|
-
import { Routes as
|
|
5323
|
-
var GuildManager = class extends
|
|
6396
|
+
import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
|
|
6397
|
+
import { Routes as Routes32 } from "@fluxerjs/types";
|
|
6398
|
+
var GuildManager = class extends LimitedCollection5 {
|
|
5324
6399
|
constructor(client) {
|
|
5325
6400
|
super({
|
|
5326
6401
|
maxSize: client.cache.limits.guilds,
|
|
@@ -5329,8 +6404,8 @@ var GuildManager = class extends LimitedCollection4 {
|
|
|
5329
6404
|
this.client = client;
|
|
5330
6405
|
}
|
|
5331
6406
|
/**
|
|
5332
|
-
* Remove a guild and cascade its channels / message caches.
|
|
5333
|
-
*
|
|
6407
|
+
* Remove a guild from cache and cascade its channels / message caches.
|
|
6408
|
+
* Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
|
|
5334
6409
|
*/
|
|
5335
6410
|
delete(key) {
|
|
5336
6411
|
const guild = this.get(key);
|
|
@@ -5358,7 +6433,7 @@ var GuildManager = class extends LimitedCollection4 {
|
|
|
5358
6433
|
const cached = this.get(guildId);
|
|
5359
6434
|
if (cached && !options?.force) return cached;
|
|
5360
6435
|
try {
|
|
5361
|
-
const data = await this.client.rest.get(
|
|
6436
|
+
const data = await this.client.rest.get(Routes32.guild(guildId));
|
|
5362
6437
|
if (cached) {
|
|
5363
6438
|
cached._patch(data);
|
|
5364
6439
|
return cached;
|
|
@@ -5443,184 +6518,13 @@ var MessageCache = class {
|
|
|
5443
6518
|
}
|
|
5444
6519
|
};
|
|
5445
6520
|
|
|
5446
|
-
// src/ClientCore/PackManager.ts
|
|
5447
|
-
import {
|
|
5448
|
-
Routes as Routes32
|
|
5449
|
-
} from "@fluxerjs/types";
|
|
5450
|
-
function toPackSummaryPayload(data) {
|
|
5451
|
-
return {
|
|
5452
|
-
id: data.id,
|
|
5453
|
-
name: data.name,
|
|
5454
|
-
description: data.description,
|
|
5455
|
-
type: data.type,
|
|
5456
|
-
creatorId: data.creator_id,
|
|
5457
|
-
createdAt: data.created_at,
|
|
5458
|
-
updatedAt: data.updated_at,
|
|
5459
|
-
...data.installed_at !== void 0 ? { installedAt: data.installed_at } : {}
|
|
5460
|
-
};
|
|
5461
|
-
}
|
|
5462
|
-
function toEmojiPayload(data) {
|
|
5463
|
-
return {
|
|
5464
|
-
id: data.id,
|
|
5465
|
-
name: data.name,
|
|
5466
|
-
animated: data.animated
|
|
5467
|
-
};
|
|
5468
|
-
}
|
|
5469
|
-
function toStickerPayload(data) {
|
|
5470
|
-
return {
|
|
5471
|
-
id: data.id,
|
|
5472
|
-
name: data.name,
|
|
5473
|
-
description: data.description,
|
|
5474
|
-
tags: data.tags,
|
|
5475
|
-
animated: data.animated,
|
|
5476
|
-
nsfw: data.nsfw
|
|
5477
|
-
};
|
|
5478
|
-
}
|
|
5479
|
-
function toInvitePayload(data) {
|
|
5480
|
-
return {
|
|
5481
|
-
code: data.code,
|
|
5482
|
-
...data.max_uses !== void 0 ? { maxUses: data.max_uses } : {},
|
|
5483
|
-
...data.max_age !== void 0 ? { maxAge: data.max_age } : {},
|
|
5484
|
-
...data.uses !== void 0 ? { uses: data.uses } : {},
|
|
5485
|
-
...data.temporary !== void 0 ? { temporary: data.temporary } : {},
|
|
5486
|
-
...data.created_at !== void 0 ? { createdAt: data.created_at } : {},
|
|
5487
|
-
...data.expires_at !== void 0 ? { expiresAt: data.expires_at } : {}
|
|
5488
|
-
};
|
|
5489
|
-
}
|
|
5490
|
-
function mapDashboardSection(section) {
|
|
5491
|
-
return {
|
|
5492
|
-
installedLimit: section.installed_limit,
|
|
5493
|
-
createdLimit: section.created_limit,
|
|
5494
|
-
installed: section.installed.map(toPackSummaryPayload),
|
|
5495
|
-
created: section.created.map(toPackSummaryPayload)
|
|
5496
|
-
};
|
|
5497
|
-
}
|
|
5498
|
-
var PackManager = class {
|
|
5499
|
-
constructor(client) {
|
|
5500
|
-
this.client = client;
|
|
5501
|
-
}
|
|
5502
|
-
/** Fetch the current user's pack dashboard (camelCase summaries). */
|
|
5503
|
-
async fetchDashboard() {
|
|
5504
|
-
const data = await this.client.rest.get(Routes32.packs());
|
|
5505
|
-
return {
|
|
5506
|
-
emoji: mapDashboardSection(data.emoji),
|
|
5507
|
-
sticker: mapDashboardSection(data.sticker)
|
|
5508
|
-
};
|
|
5509
|
-
}
|
|
5510
|
-
/** Create a pack. */
|
|
5511
|
-
async create(packType, body) {
|
|
5512
|
-
const data = await this.client.rest.post(Routes32.packsByType(packType), {
|
|
5513
|
-
body
|
|
5514
|
-
});
|
|
5515
|
-
return toPackSummaryPayload(data);
|
|
5516
|
-
}
|
|
5517
|
-
/** Edit a pack. */
|
|
5518
|
-
async edit(packId, body) {
|
|
5519
|
-
const data = await this.client.rest.patch(Routes32.pack(packId), { body });
|
|
5520
|
-
return toPackSummaryPayload(data);
|
|
5521
|
-
}
|
|
5522
|
-
/** Delete a pack. */
|
|
5523
|
-
async delete(packId) {
|
|
5524
|
-
await this.client.rest.delete(Routes32.pack(packId));
|
|
5525
|
-
}
|
|
5526
|
-
/** Install a pack for the current user. */
|
|
5527
|
-
async install(packId) {
|
|
5528
|
-
await this.client.rest.post(Routes32.packInstall(packId));
|
|
5529
|
-
}
|
|
5530
|
-
/** Uninstall a pack for the current user. */
|
|
5531
|
-
async uninstall(packId) {
|
|
5532
|
-
await this.client.rest.delete(Routes32.packInstall(packId));
|
|
5533
|
-
}
|
|
5534
|
-
/** List invites for a pack. */
|
|
5535
|
-
async listInvites(packId) {
|
|
5536
|
-
const data = await this.client.rest.get(Routes32.packInvites(packId));
|
|
5537
|
-
return data.map(toInvitePayload);
|
|
5538
|
-
}
|
|
5539
|
-
/** Create an invite for a pack. */
|
|
5540
|
-
async createInvite(packId, options = {}) {
|
|
5541
|
-
const body = toPackInviteBody(options);
|
|
5542
|
-
const data = await this.client.rest.post(Routes32.packInvites(packId), {
|
|
5543
|
-
body: Object.keys(body).length ? body : void 0
|
|
5544
|
-
});
|
|
5545
|
-
return toInvitePayload(data);
|
|
5546
|
-
}
|
|
5547
|
-
/** List emojis in a pack. */
|
|
5548
|
-
async listEmojis(packId) {
|
|
5549
|
-
const data = await this.client.rest.get(Routes32.packEmojis(packId));
|
|
5550
|
-
return data.map(toEmojiPayload);
|
|
5551
|
-
}
|
|
5552
|
-
/** Create an emoji in a pack. */
|
|
5553
|
-
async createEmoji(packId, options) {
|
|
5554
|
-
const data = await this.client.rest.post(Routes32.packEmojis(packId), {
|
|
5555
|
-
body: toEmojiCreateBody(options)
|
|
5556
|
-
});
|
|
5557
|
-
return toEmojiPayload(data);
|
|
5558
|
-
}
|
|
5559
|
-
/** Bulk-create emojis in a pack. */
|
|
5560
|
-
async createEmojisBulk(packId, emojis) {
|
|
5561
|
-
const data = await this.client.rest.post(
|
|
5562
|
-
Routes32.packEmojisBulk(packId),
|
|
5563
|
-
{ body: { emojis: emojis.map(toEmojiCreateBody) } }
|
|
5564
|
-
);
|
|
5565
|
-
return {
|
|
5566
|
-
success: data.success.map(toEmojiPayload),
|
|
5567
|
-
failed: data.failed
|
|
5568
|
-
};
|
|
5569
|
-
}
|
|
5570
|
-
/** Edit an emoji in a pack. */
|
|
5571
|
-
async editEmoji(packId, emojiId, options) {
|
|
5572
|
-
const data = await this.client.rest.patch(Routes32.packEmoji(packId, emojiId), {
|
|
5573
|
-
body: toEmojiEditBody(options)
|
|
5574
|
-
});
|
|
5575
|
-
return toEmojiPayload(data);
|
|
5576
|
-
}
|
|
5577
|
-
/** Delete an emoji from a pack. */
|
|
5578
|
-
async deleteEmoji(packId, emojiId) {
|
|
5579
|
-
await this.client.rest.delete(Routes32.packEmoji(packId, emojiId));
|
|
5580
|
-
}
|
|
5581
|
-
/** List stickers in a pack. */
|
|
5582
|
-
async listStickers(packId) {
|
|
5583
|
-
const data = await this.client.rest.get(Routes32.packStickers(packId));
|
|
5584
|
-
return data.map(toStickerPayload);
|
|
5585
|
-
}
|
|
5586
|
-
/** Create a sticker in a pack. */
|
|
5587
|
-
async createSticker(packId, options) {
|
|
5588
|
-
const data = await this.client.rest.post(Routes32.packStickers(packId), {
|
|
5589
|
-
body: toStickerCreateBody(options)
|
|
5590
|
-
});
|
|
5591
|
-
return toStickerPayload(data);
|
|
5592
|
-
}
|
|
5593
|
-
/** Bulk-create stickers in a pack. */
|
|
5594
|
-
async createStickersBulk(packId, stickers) {
|
|
5595
|
-
const data = await this.client.rest.post(
|
|
5596
|
-
Routes32.packStickersBulk(packId),
|
|
5597
|
-
{ body: { stickers: stickers.map(toStickerCreateBody) } }
|
|
5598
|
-
);
|
|
5599
|
-
return {
|
|
5600
|
-
success: data.success.map(toStickerPayload),
|
|
5601
|
-
failed: data.failed
|
|
5602
|
-
};
|
|
5603
|
-
}
|
|
5604
|
-
/** Edit a sticker in a pack. */
|
|
5605
|
-
async editSticker(packId, stickerId, options) {
|
|
5606
|
-
const data = await this.client.rest.patch(Routes32.packSticker(packId, stickerId), {
|
|
5607
|
-
body: toStickerEditBody(options)
|
|
5608
|
-
});
|
|
5609
|
-
return toStickerPayload(data);
|
|
5610
|
-
}
|
|
5611
|
-
/** Delete a sticker from a pack. */
|
|
5612
|
-
async deleteSticker(packId, stickerId) {
|
|
5613
|
-
await this.client.rest.delete(Routes32.packSticker(packId, stickerId));
|
|
5614
|
-
}
|
|
5615
|
-
};
|
|
5616
|
-
|
|
5617
6521
|
// src/ClientCore/UserManager.ts
|
|
5618
|
-
import { LimitedCollection as
|
|
6522
|
+
import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
|
|
5619
6523
|
import {
|
|
5620
6524
|
Routes as Routes33
|
|
5621
6525
|
} from "@fluxerjs/types";
|
|
5622
6526
|
var soft = (p) => p.catch(() => null);
|
|
5623
|
-
var UserManager = class extends
|
|
6527
|
+
var UserManager = class extends LimitedCollection6 {
|
|
5624
6528
|
constructor(client) {
|
|
5625
6529
|
super({ maxSize: client.cache.limits.users });
|
|
5626
6530
|
this.client = client;
|
|
@@ -5638,11 +6542,17 @@ var UserManager = class extends LimitedCollection5 {
|
|
|
5638
6542
|
}
|
|
5639
6543
|
return removed;
|
|
5640
6544
|
}
|
|
5641
|
-
/** Fetch a user by ID and update cache. */
|
|
5642
|
-
async fetch(userId) {
|
|
6545
|
+
/** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
|
|
6546
|
+
async fetch(userId, options) {
|
|
6547
|
+
const cached = this.get(userId);
|
|
6548
|
+
if (cached && !options?.force) return cached;
|
|
5643
6549
|
const data = await this.client.rest.get(Routes33.user(userId));
|
|
5644
6550
|
return this.client.getOrCreateUser(data);
|
|
5645
6551
|
}
|
|
6552
|
+
/** Return a cached user, otherwise {@link fetch}. */
|
|
6553
|
+
async resolve(userId) {
|
|
6554
|
+
return this.get(userId) ?? this.fetch(userId);
|
|
6555
|
+
}
|
|
5646
6556
|
/**
|
|
5647
6557
|
* Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
|
|
5648
6558
|
* @example
|
|
@@ -5702,14 +6612,22 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5702
6612
|
users;
|
|
5703
6613
|
/** Cache limits, stats, sweeps, and cascade entry points. */
|
|
5704
6614
|
cache;
|
|
5705
|
-
/**
|
|
5706
|
-
packs = new PackManager(this);
|
|
5707
|
-
/** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
|
|
6615
|
+
/** Typed event handlers. Prefer `client.on(Events.*, ...)`. */
|
|
5708
6616
|
events;
|
|
5709
6617
|
/** The authenticated bot user. Null until READY is received. */
|
|
5710
6618
|
user = null;
|
|
5711
6619
|
/** Timestamp when the client became ready. Null until READY is received. */
|
|
5712
6620
|
readyAt = null;
|
|
6621
|
+
/**
|
|
6622
|
+
* Milliseconds since {@link readyAt}, or `null` if the client is not ready.
|
|
6623
|
+
* @example
|
|
6624
|
+
* client.on(Events.Ready, () => {
|
|
6625
|
+
* console.log(client.uptime);
|
|
6626
|
+
* });
|
|
6627
|
+
*/
|
|
6628
|
+
get uptime() {
|
|
6629
|
+
return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
|
|
6630
|
+
}
|
|
5713
6631
|
/** @internal WebSocket manager. */
|
|
5714
6632
|
_ws = null;
|
|
5715
6633
|
/** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
|
|
@@ -5850,33 +6768,23 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5850
6768
|
return fetchApplication(this);
|
|
5851
6769
|
}
|
|
5852
6770
|
/**
|
|
5853
|
-
* Fetch OAuth2 applications
|
|
5854
|
-
*
|
|
6771
|
+
* Fetch OAuth2 applications (`GET /oauth2/applications/@me`).
|
|
6772
|
+
* A bot token returns the bot application object (normalized to a one-element array).
|
|
6773
|
+
* A user token returns the owner's application list.
|
|
5855
6774
|
*/
|
|
5856
6775
|
fetchOAuthApplications() {
|
|
5857
6776
|
return fetchOAuthApplications(this);
|
|
5858
6777
|
}
|
|
5859
|
-
/**
|
|
5860
|
-
* Check username#discriminator availability.
|
|
5861
|
-
* @param username - Username to check
|
|
5862
|
-
* @param discriminator - Discriminator to check
|
|
5863
|
-
* @returns Availability result
|
|
5864
|
-
*/
|
|
5865
|
-
checkUsernameTag(username, discriminator) {
|
|
5866
|
-
return checkUsernameTag(this, username, discriminator);
|
|
5867
|
-
}
|
|
5868
6778
|
/**
|
|
5869
6779
|
* Preload recent messages for multiple channels (batch endpoint).
|
|
5870
|
-
* @
|
|
5871
|
-
* @returns Preload response with message counts/timestamps
|
|
6780
|
+
* Prefer this over {@link bulkFetchMessages} for bots (`bulkFetchMessages` is user-account only).
|
|
5872
6781
|
*/
|
|
5873
6782
|
preloadMessages(channelIds) {
|
|
5874
6783
|
return preloadMessages(this, channelIds);
|
|
5875
6784
|
}
|
|
5876
6785
|
/**
|
|
5877
6786
|
* Preload recent messages (alternate endpoint).
|
|
5878
|
-
*
|
|
5879
|
-
* @returns Preload response with message counts/timestamps
|
|
6787
|
+
* Prefer this over {@link bulkFetchMessages} for bots.
|
|
5880
6788
|
*/
|
|
5881
6789
|
preloadMessagesAlt(channelIds) {
|
|
5882
6790
|
return preloadMessagesAlt(this, channelIds);
|
|
@@ -5884,6 +6792,14 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5884
6792
|
bulkFetchMessages(requests, options = {}) {
|
|
5885
6793
|
return bulkFetchMessages(this, requests, options);
|
|
5886
6794
|
}
|
|
6795
|
+
/**
|
|
6796
|
+
* Search messages in the current bot scope (`POST /search/messages`, `scope: current`).
|
|
6797
|
+
* Other scopes are denied for bots (`BOT_SEARCH_SCOPE_UNAVAILABLE`).
|
|
6798
|
+
* Returns camelCase results (`hitsPerPage`) or `{ indexing: true }` while channels are indexed.
|
|
6799
|
+
*/
|
|
6800
|
+
searchMessages(options) {
|
|
6801
|
+
return searchMessages(this, options);
|
|
6802
|
+
}
|
|
5887
6803
|
/** @internal */
|
|
5888
6804
|
_getMessageCache(channelId) {
|
|
5889
6805
|
return this._messageCache.get(channelId);
|
|
@@ -5907,12 +6823,16 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5907
6823
|
/**
|
|
5908
6824
|
* Sweep cached messages (remove entries matching filter).
|
|
5909
6825
|
* Prefer {@link CacheController.sweepMessages} (`client.cache.sweepMessages`).
|
|
6826
|
+
* The filter receives a hydrated {@link Message} (`createdAt`), not the stored wire payload.
|
|
5910
6827
|
* @param filter - Predicate to test each message (return true to remove)
|
|
5911
6828
|
* @param channelId - Optional channel ID to scope sweep
|
|
5912
6829
|
* @returns Count of messages removed
|
|
5913
6830
|
*/
|
|
5914
6831
|
sweepMessages(filter, channelId) {
|
|
5915
|
-
return this._messageCache.sweep(
|
|
6832
|
+
return this._messageCache.sweep(
|
|
6833
|
+
filter ? (data, chId) => filter(new Message(this, data), chId) : void 0,
|
|
6834
|
+
channelId
|
|
6835
|
+
);
|
|
5916
6836
|
}
|
|
5917
6837
|
/**
|
|
5918
6838
|
* Sweep cached members across all guilds (remove entries matching filter).
|
|
@@ -5945,6 +6865,9 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5945
6865
|
}
|
|
5946
6866
|
/**
|
|
5947
6867
|
* The underlying {@link WebSocketManager} (throws if not logged in).
|
|
6868
|
+
* Gateway heartbeat ACK latency: `client.ws.ping` (ms, or `-1` before the first ACK).
|
|
6869
|
+
* @example
|
|
6870
|
+
* console.log(client.ws.ping);
|
|
5948
6871
|
* @throws {@link FluxerError} with {@link ErrorCodes.NotLoggedIn}
|
|
5949
6872
|
*/
|
|
5950
6873
|
get ws() {
|
|
@@ -5983,6 +6906,37 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5983
6906
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
5984
6907
|
this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildMembers, d: data });
|
|
5985
6908
|
}
|
|
6909
|
+
/**
|
|
6910
|
+
* Request guild member/online counts via gateway opcode 15.
|
|
6911
|
+
* Listen for `guildCountsUpdate`. Cached `guild.memberCount` / `guild.onlineCount` update when that event arrives.
|
|
6912
|
+
*/
|
|
6913
|
+
requestGuildCounts(options) {
|
|
6914
|
+
const guildIds = [...new Set(options.guildIds.filter(Boolean))];
|
|
6915
|
+
if (!guildIds.length) {
|
|
6916
|
+
throw new FluxerError("requestGuildCounts requires at least one guildId", {
|
|
6917
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
6918
|
+
});
|
|
6919
|
+
}
|
|
6920
|
+
const data = { guild_ids: guildIds };
|
|
6921
|
+
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
6922
|
+
this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildCounts, d: data });
|
|
6923
|
+
}
|
|
6924
|
+
/**
|
|
6925
|
+
* Request per-channel member counts via gateway opcode 16.
|
|
6926
|
+
* Event-only: listen for `channelMemberCountsUpdate`. There is no `channel.memberCount` field.
|
|
6927
|
+
*/
|
|
6928
|
+
requestChannelMemberCounts(options) {
|
|
6929
|
+
if (!options.guildId) {
|
|
6930
|
+
throw new FluxerError("requestChannelMemberCounts requires guildId", {
|
|
6931
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
6932
|
+
});
|
|
6933
|
+
}
|
|
6934
|
+
const data = { guild_id: options.guildId };
|
|
6935
|
+
if (options.channelId !== void 0) data.channel_id = options.channelId;
|
|
6936
|
+
if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
|
|
6937
|
+
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
6938
|
+
this._sendToAllShards({ op: GatewayOpcodes2.RequestChannelMemberCounts, d: data });
|
|
6939
|
+
}
|
|
5986
6940
|
/**
|
|
5987
6941
|
* Broadcast a gateway payload to all shards.
|
|
5988
6942
|
* @param payload - Gateway send payload
|
|
@@ -5996,9 +6950,13 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
5996
6950
|
}
|
|
5997
6951
|
/**
|
|
5998
6952
|
* Connect to the gateway with a bot token.
|
|
6953
|
+
* @example
|
|
6954
|
+
* const client = new Client();
|
|
6955
|
+
* client.on(Events.Ready, () => console.log('Ready!'));
|
|
6956
|
+
* await client.login(process.env.FLUXER_BOT_TOKEN);
|
|
5999
6957
|
* @param token - Bot token from the developer portal
|
|
6000
6958
|
* @param options - Optional abort signal for cancellation
|
|
6001
|
-
* @returns
|
|
6959
|
+
* @returns This client (for chaining)
|
|
6002
6960
|
* @throws {@link FluxerError} if already logged in or token is invalid
|
|
6003
6961
|
*/
|
|
6004
6962
|
async login(token, options) {
|
|
@@ -6013,7 +6971,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6013
6971
|
this.rest.setToken(token);
|
|
6014
6972
|
try {
|
|
6015
6973
|
this._ws = await connectClientGateway(this, token, options?.signal);
|
|
6016
|
-
return
|
|
6974
|
+
return this;
|
|
6017
6975
|
} catch (err) {
|
|
6018
6976
|
this._ws?.destroy();
|
|
6019
6977
|
this._ws = null;
|
|
@@ -6066,6 +7024,20 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
6066
7024
|
);
|
|
6067
7025
|
}
|
|
6068
7026
|
}
|
|
7027
|
+
/**
|
|
7028
|
+
* REST path helpers ({@link Routes}). Pass the path to {@link REST client.rest}.
|
|
7029
|
+
* Prefer high-level helpers (`channel.send()`, `guild.members.fetch()`) when they exist.
|
|
7030
|
+
*
|
|
7031
|
+
* @example
|
|
7032
|
+
* const channel = await client.rest.get(Client.Routes.channel(channelId));
|
|
7033
|
+
*
|
|
7034
|
+
* @example
|
|
7035
|
+
* await client.rest.post(Client.Routes.channelMessages(channelId), {
|
|
7036
|
+
* body: { content: 'hello' },
|
|
7037
|
+
* });
|
|
7038
|
+
*
|
|
7039
|
+
* @see {@link Routes}
|
|
7040
|
+
*/
|
|
6069
7041
|
static get Routes() {
|
|
6070
7042
|
return Routes34;
|
|
6071
7043
|
}
|