lunibee 0.3.3 → 0.4.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 +1 -1
- package/dist/builders/commands.d.ts +1 -1
- package/dist/builders/components.d.ts +9 -11
- package/dist/builders/embed.d.ts +1 -1
- package/dist/builders/index.d.ts +1 -1
- package/dist/builders/index.js +87 -1298
- package/dist/builders/index.js.map +3 -11
- package/dist/chunks/index-0wn81eng.js +2492 -0
- package/dist/chunks/index-0wn81eng.js.map +17 -0
- package/dist/chunks/index-2en489j6.js +40 -0
- package/dist/chunks/index-2en489j6.js.map +10 -0
- package/dist/chunks/index-3hyps48a.js +203 -0
- package/dist/chunks/index-3hyps48a.js.map +11 -0
- package/dist/chunks/index-57c5n3ms.js +2274 -0
- package/dist/chunks/index-57c5n3ms.js.map +19 -0
- package/dist/chunks/index-5yx92e36.js +1170 -0
- package/dist/chunks/index-5yx92e36.js.map +14 -0
- package/dist/chunks/index-690bp093.js +95 -0
- package/dist/chunks/index-690bp093.js.map +10 -0
- package/dist/chunks/index-7fp2hvmg.js +2155 -0
- package/dist/chunks/index-7fp2hvmg.js.map +24 -0
- package/dist/chunks/index-cnmsajvk.js +1119 -0
- package/dist/chunks/index-cnmsajvk.js.map +12 -0
- package/dist/chunks/index-fdvgk2sw.js +1310 -0
- package/dist/chunks/index-fdvgk2sw.js.map +21 -0
- package/dist/chunks/index-gyvps8b9.js +214 -0
- package/dist/chunks/index-gyvps8b9.js.map +12 -0
- package/dist/chunks/index-jzg4bh99.js +1533 -0
- package/dist/chunks/index-jzg4bh99.js.map +21 -0
- package/dist/chunks/index-mgw2yvrm.js +3547 -0
- package/dist/chunks/index-mgw2yvrm.js.map +25 -0
- package/dist/chunks/index-yh76b55h.js +3449 -0
- package/dist/chunks/index-yh76b55h.js.map +29 -0
- package/dist/collection/index.js +9 -1118
- package/dist/collection/index.js.map +3 -6
- package/dist/core/api.d.ts +3 -3
- package/dist/core/channel-create.d.ts +2 -2
- package/dist/core/commands.d.ts +3 -3
- package/dist/core/events.d.ts +4 -4
- package/dist/core/handles.d.ts +4 -4
- package/dist/core/index.d.ts +25 -20
- package/dist/core/index.js +68 -10130
- package/dist/core/index.js.map +3 -65
- package/dist/core/permissions.d.ts +1 -1
- package/dist/core/redis-cache.d.ts +1 -1
- package/dist/formatters/index.js +41 -110
- package/dist/formatters/index.js.map +3 -4
- package/dist/handlers/index.js +5 -37
- package/dist/handlers/index.js.map +3 -4
- package/dist/index.d.ts +21 -21
- package/dist/index.js +641 -16325
- package/dist/index.js.map +3 -92
- package/dist/managers/advanced.d.ts +3 -3
- package/dist/managers/application.d.ts +2 -2
- package/dist/managers/base.d.ts +1 -1
- package/dist/managers/emoji.d.ts +2 -2
- package/dist/managers/guild-resources.d.ts +6 -6
- package/dist/managers/guild.d.ts +3 -3
- package/dist/managers/index.d.ts +4 -8
- package/dist/managers/index.js +51 -4060
- package/dist/managers/index.js.map +3 -29
- package/dist/managers/member.d.ts +2 -2
- package/dist/managers/message.d.ts +14 -6
- package/dist/managers/role.d.ts +2 -2
- package/dist/managers/thread.d.ts +3 -3
- package/dist/managers/user.d.ts +7 -4
- package/dist/rest/index.d.ts +10 -35
- package/dist/rest/index.js +57 -2184
- package/dist/rest/index.js.map +3 -18
- package/dist/rest/limiter.d.ts +9 -1
- package/dist/rest/webhook.d.ts +2 -8
- package/dist/sharding/bus.d.ts +2 -2
- package/dist/sharding/cluster.d.ts +45 -5
- package/dist/sharding/context.d.ts +45 -3
- package/dist/sharding/gateway-bot.d.ts +2 -1
- package/dist/sharding/health.d.ts +1 -1
- package/dist/sharding/identify.d.ts +12 -0
- package/dist/sharding/index.d.ts +44 -11
- package/dist/sharding/index.js +60 -4620
- package/dist/sharding/index.js.map +3 -33
- package/dist/sharding/supervisor.d.ts +4 -2
- package/dist/structures/audit-log.d.ts +1 -1
- package/dist/structures/base.d.ts +6 -6
- package/dist/structures/channels.d.ts +1 -1
- package/dist/structures/embed.d.ts +1 -1
- package/dist/structures/index.d.ts +14 -14
- package/dist/structures/index.js +109 -2382
- package/dist/structures/index.js.map +3 -16
- package/dist/structures/interactions.d.ts +13 -9
- package/dist/structures/options.d.ts +1 -1
- package/dist/structures/permissions.d.ts +2 -2
- package/dist/structures/resources.d.ts +10 -10
- package/dist/structures/sticker.d.ts +1 -1
- package/dist/types/gateway.d.ts +2 -79
- package/dist/types/index.d.ts +0 -6
- package/dist/types/index.js +41 -272
- package/dist/types/index.js.map +3 -6
- package/dist/utils/index.js +23 -209
- package/dist/utils/index.js.map +3 -5
- package/dist/voice/connection.d.ts +200 -0
- package/dist/voice/crypto.d.ts +50 -0
- package/dist/voice/dave.d.ts +85 -0
- package/dist/voice/effects.d.ts +31 -0
- package/dist/voice/emitter.d.ts +14 -0
- package/dist/voice/gateway.d.ts +59 -0
- package/dist/voice/index.d.ts +25 -228
- package/dist/voice/index.js +111 -442
- package/dist/voice/index.js.map +3 -4
- package/dist/voice/libopus.d.ts +88 -0
- package/dist/voice/networking.d.ts +80 -0
- package/dist/voice/ogg.d.ts +24 -0
- package/dist/voice/opus.d.ts +18 -0
- package/dist/voice/player.d.ts +79 -0
- package/dist/voice/protocol.d.ts +76 -0
- package/dist/voice/receiver.d.ts +59 -0
- package/dist/voice/resource.d.ts +102 -0
- package/dist/voice/udp.d.ts +40 -0
- package/dist/ws/close-codes.d.ts +1 -1
- package/dist/ws/index.d.ts +25 -4
- package/dist/ws/index.js +47 -1336
- package/dist/ws/index.js.map +3 -17
- package/dist/ws/protocol.d.ts +1 -1
- package/dist/ws/send-budget.d.ts +0 -2
- package/dist/ws/state.d.ts +0 -10
- package/package.json +19 -16
|
@@ -0,0 +1,2274 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
channelKindOf2,
|
|
4
|
+
InteractionResponseEnum2,
|
|
5
|
+
StickerFormatEnum2
|
|
6
|
+
} from "./index-gyvps8b9.js";
|
|
7
|
+
|
|
8
|
+
// packages/structures/src/base.ts
|
|
9
|
+
class BaseStructure2 {
|
|
10
|
+
id;
|
|
11
|
+
constructor(id) {
|
|
12
|
+
if (!/^\d{1,20}$/.test(id))
|
|
13
|
+
throw new TypeError("A Discord structure requires a valid snowflake ID.");
|
|
14
|
+
this.id = id;
|
|
15
|
+
}
|
|
16
|
+
toString() {
|
|
17
|
+
return this.id;
|
|
18
|
+
}
|
|
19
|
+
get createdTimestamp() {
|
|
20
|
+
return Number((BigInt(this.id) >> 22n) + 1420070400000n);
|
|
21
|
+
}
|
|
22
|
+
get createdAt() {
|
|
23
|
+
return new Date(this.createdTimestamp);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var CDN_BASE2 = "https://cdn.discordapp.com";
|
|
27
|
+
function cdnURL2(path, hash, options = {}) {
|
|
28
|
+
const isAnimated = hash.startsWith("a_") && !options.forceStatic;
|
|
29
|
+
const ext = options.extension ?? (isAnimated ? "gif" : "png");
|
|
30
|
+
const size = options.size ? `?size=${options.size}` : "";
|
|
31
|
+
return `${CDN_BASE2}${path}/${encodeURIComponent(hash)}.${ext}${size}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class User2 extends BaseStructure2 {
|
|
35
|
+
username;
|
|
36
|
+
globalName;
|
|
37
|
+
avatar;
|
|
38
|
+
bot;
|
|
39
|
+
system;
|
|
40
|
+
flags;
|
|
41
|
+
discriminator;
|
|
42
|
+
constructor(data) {
|
|
43
|
+
super(data.id);
|
|
44
|
+
if (!data.username)
|
|
45
|
+
throw new TypeError("A Discord user requires a username.");
|
|
46
|
+
this.username = data.username;
|
|
47
|
+
this.globalName = data.global_name ?? null;
|
|
48
|
+
this.avatar = data.avatar ?? null;
|
|
49
|
+
this.bot = data.bot ?? false;
|
|
50
|
+
this.system = data.system ?? false;
|
|
51
|
+
this.flags = data.public_flags ?? 0;
|
|
52
|
+
this.discriminator = data.discriminator && data.discriminator !== "0" ? data.discriminator : null;
|
|
53
|
+
}
|
|
54
|
+
get displayName() {
|
|
55
|
+
return this.globalName ?? this.username;
|
|
56
|
+
}
|
|
57
|
+
avatarURL(options = {}) {
|
|
58
|
+
if (!this.avatar)
|
|
59
|
+
return null;
|
|
60
|
+
return cdnURL2(`/avatars/${this.id}`, this.avatar, options);
|
|
61
|
+
}
|
|
62
|
+
defaultAvatarURL() {
|
|
63
|
+
const index = this.discriminator ? Number(this.discriminator) % 5 : Number((BigInt(this.id) >> 22n) % 6n);
|
|
64
|
+
return `${CDN_BASE2}/embed/avatars/${index}.png`;
|
|
65
|
+
}
|
|
66
|
+
displayAvatarURL(options = {}) {
|
|
67
|
+
return this.avatarURL(options) ?? this.defaultAvatarURL();
|
|
68
|
+
}
|
|
69
|
+
toString() {
|
|
70
|
+
return `<@${this.id}>`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class Channel2 extends BaseStructure2 {
|
|
75
|
+
type;
|
|
76
|
+
name;
|
|
77
|
+
guildId;
|
|
78
|
+
topic;
|
|
79
|
+
parentId;
|
|
80
|
+
nsfw;
|
|
81
|
+
rateLimitPerUser;
|
|
82
|
+
position;
|
|
83
|
+
permissionOverwrites;
|
|
84
|
+
partial;
|
|
85
|
+
#context;
|
|
86
|
+
constructor(data, context, options) {
|
|
87
|
+
super(data.id);
|
|
88
|
+
if (!Number.isInteger(data.type) || data.type < 0)
|
|
89
|
+
throw new RangeError("A Discord channel requires a valid channel type.");
|
|
90
|
+
this.type = data.type;
|
|
91
|
+
this.name = data.name;
|
|
92
|
+
this.guildId = data.guild_id;
|
|
93
|
+
this.topic = data.topic;
|
|
94
|
+
this.parentId = data.parent_id;
|
|
95
|
+
this.nsfw = data.nsfw;
|
|
96
|
+
this.rateLimitPerUser = data.rate_limit_per_user;
|
|
97
|
+
this.position = data.position;
|
|
98
|
+
this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
|
|
99
|
+
this.partial = options?.partial ?? false;
|
|
100
|
+
this.#context = context;
|
|
101
|
+
}
|
|
102
|
+
send(options) {
|
|
103
|
+
if (!this.#context)
|
|
104
|
+
throw new Error("This channel is not attached to a client.");
|
|
105
|
+
return this.#context.sendMessage(this.id, options);
|
|
106
|
+
}
|
|
107
|
+
edit(options) {
|
|
108
|
+
if (!this.#context?.editChannel)
|
|
109
|
+
throw new Error("This channel is not attached to a client.");
|
|
110
|
+
return this.#context.editChannel(this.id, options);
|
|
111
|
+
}
|
|
112
|
+
editName(name) {
|
|
113
|
+
if (!name.trim())
|
|
114
|
+
throw new TypeError("Channel name cannot be empty.");
|
|
115
|
+
return this.edit({ name });
|
|
116
|
+
}
|
|
117
|
+
editTopic(topic) {
|
|
118
|
+
return this.edit({ topic });
|
|
119
|
+
}
|
|
120
|
+
editPermissionOverwrite(targetId, changes, options) {
|
|
121
|
+
if (!this.#context?.editPermissionOverwrite)
|
|
122
|
+
throw new Error("This channel is not attached to a client.");
|
|
123
|
+
return this.#context.editPermissionOverwrite(this.id, targetId, changes, options);
|
|
124
|
+
}
|
|
125
|
+
editParent(parentId) {
|
|
126
|
+
return this.edit({ parent_id: parentId });
|
|
127
|
+
}
|
|
128
|
+
delete(reason) {
|
|
129
|
+
if (!this.#context?.deleteChannel)
|
|
130
|
+
throw new Error("This channel is not attached to a client.");
|
|
131
|
+
return this.#context.deleteChannel(this.id, reason);
|
|
132
|
+
}
|
|
133
|
+
update(options) {
|
|
134
|
+
return this.edit(options);
|
|
135
|
+
}
|
|
136
|
+
get kind() {
|
|
137
|
+
return channelKindOf2(this.type);
|
|
138
|
+
}
|
|
139
|
+
is(...kinds) {
|
|
140
|
+
return kinds.includes(this.kind);
|
|
141
|
+
}
|
|
142
|
+
as(...kinds) {
|
|
143
|
+
if (!this.is(...kinds))
|
|
144
|
+
throw new TypeError(`Channel ${this.id} is a ${this.kind} channel, not ${kinds.join(" or ")}.`);
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
isThread() {
|
|
148
|
+
return this.type === 10 || this.type === 11 || this.type === 12;
|
|
149
|
+
}
|
|
150
|
+
isTextBased() {
|
|
151
|
+
return [0, 1, 2, 3, 5, 10, 11, 12, 13].includes(this.type);
|
|
152
|
+
}
|
|
153
|
+
isVoiceBased() {
|
|
154
|
+
return this.type === 2 || this.type === 13;
|
|
155
|
+
}
|
|
156
|
+
isDMBased() {
|
|
157
|
+
return this.type === 1 || this.type === 3;
|
|
158
|
+
}
|
|
159
|
+
toString() {
|
|
160
|
+
return `<#${this.id}>`;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
class Guild2 extends BaseStructure2 {
|
|
165
|
+
name;
|
|
166
|
+
icon;
|
|
167
|
+
splash;
|
|
168
|
+
banner;
|
|
169
|
+
description;
|
|
170
|
+
preferredLocale;
|
|
171
|
+
ownerId;
|
|
172
|
+
features;
|
|
173
|
+
verificationLevel;
|
|
174
|
+
premiumTier;
|
|
175
|
+
premiumSubscriptionCount;
|
|
176
|
+
memberCount;
|
|
177
|
+
approximateMemberCount;
|
|
178
|
+
approximatePresenceCount;
|
|
179
|
+
vanityUrlCode;
|
|
180
|
+
nsfwLevel;
|
|
181
|
+
discoverySplash;
|
|
182
|
+
rulesChannelId;
|
|
183
|
+
systemChannelId;
|
|
184
|
+
systemChannelFlags;
|
|
185
|
+
maxMembers;
|
|
186
|
+
mfaLevel;
|
|
187
|
+
explicitContentFilter;
|
|
188
|
+
defaultMessageNotifications;
|
|
189
|
+
afkChannelId;
|
|
190
|
+
afkTimeout;
|
|
191
|
+
widgetEnabled;
|
|
192
|
+
widgetChannelId;
|
|
193
|
+
applicationId;
|
|
194
|
+
publicUpdatesChannelId;
|
|
195
|
+
safetyAlertsChannelId;
|
|
196
|
+
maxPresences;
|
|
197
|
+
maxVideoChannelUsers;
|
|
198
|
+
premiumProgressBarEnabled;
|
|
199
|
+
constructor(data) {
|
|
200
|
+
super(data.id);
|
|
201
|
+
if (!data.name)
|
|
202
|
+
throw new TypeError("A Discord guild requires a name.");
|
|
203
|
+
this.name = data.name;
|
|
204
|
+
this.icon = data.icon ?? null;
|
|
205
|
+
this.splash = data.splash ?? null;
|
|
206
|
+
this.banner = data.banner ?? null;
|
|
207
|
+
this.description = data.description ?? null;
|
|
208
|
+
this.preferredLocale = data.preferred_locale ?? "en-US";
|
|
209
|
+
this.ownerId = data.owner_id;
|
|
210
|
+
this.features = data.features ?? [];
|
|
211
|
+
this.verificationLevel = data.verification_level ?? 0;
|
|
212
|
+
this.premiumTier = data.premium_tier ?? 0;
|
|
213
|
+
this.premiumSubscriptionCount = data.premium_subscription_count ?? 0;
|
|
214
|
+
this.memberCount = data.member_count ?? data.approximate_member_count;
|
|
215
|
+
this.approximateMemberCount = data.approximate_member_count;
|
|
216
|
+
this.approximatePresenceCount = data.approximate_presence_count;
|
|
217
|
+
this.vanityUrlCode = data.vanity_url_code ?? null;
|
|
218
|
+
this.nsfwLevel = data.nsfw_level ?? 0;
|
|
219
|
+
this.discoverySplash = data.discovery_splash ?? null;
|
|
220
|
+
this.rulesChannelId = data.rules_channel_id ?? null;
|
|
221
|
+
this.systemChannelId = data.system_channel_id ?? null;
|
|
222
|
+
this.systemChannelFlags = data.system_channel_flags ?? 0;
|
|
223
|
+
this.maxMembers = data.max_members ?? 0;
|
|
224
|
+
this.mfaLevel = data.mfa_level ?? 0;
|
|
225
|
+
this.explicitContentFilter = data.explicit_content_filter ?? 0;
|
|
226
|
+
this.defaultMessageNotifications = data.default_message_notifications ?? 0;
|
|
227
|
+
this.afkChannelId = data.afk_channel_id ?? null;
|
|
228
|
+
this.afkTimeout = data.afk_timeout;
|
|
229
|
+
this.widgetEnabled = data.widget_enabled ?? false;
|
|
230
|
+
this.widgetChannelId = data.widget_channel_id ?? null;
|
|
231
|
+
this.applicationId = data.application_id ?? null;
|
|
232
|
+
this.publicUpdatesChannelId = data.public_updates_channel_id ?? null;
|
|
233
|
+
this.safetyAlertsChannelId = data.safety_alerts_channel_id ?? null;
|
|
234
|
+
this.maxPresences = data.max_presences ?? null;
|
|
235
|
+
this.maxVideoChannelUsers = data.max_video_channel_users;
|
|
236
|
+
this.premiumProgressBarEnabled = data.premium_progress_bar_enabled ?? false;
|
|
237
|
+
}
|
|
238
|
+
iconURL(options = {}) {
|
|
239
|
+
if (!this.icon)
|
|
240
|
+
return null;
|
|
241
|
+
return cdnURL2(`/icons/${this.id}`, this.icon, options);
|
|
242
|
+
}
|
|
243
|
+
splashURL(options = {}) {
|
|
244
|
+
if (!this.splash)
|
|
245
|
+
return null;
|
|
246
|
+
return cdnURL2(`/splashes/${this.id}`, this.splash, options);
|
|
247
|
+
}
|
|
248
|
+
bannerURL(options = {}) {
|
|
249
|
+
if (!this.banner)
|
|
250
|
+
return null;
|
|
251
|
+
return cdnURL2(`/banners/${this.id}`, this.banner, options);
|
|
252
|
+
}
|
|
253
|
+
discoverySplashURL(options = {}) {
|
|
254
|
+
if (!this.discoverySplash)
|
|
255
|
+
return null;
|
|
256
|
+
return cdnURL2(`/discovery-splashes/${this.id}`, this.discoverySplash, options);
|
|
257
|
+
}
|
|
258
|
+
widgetImageURL(style = "shield") {
|
|
259
|
+
return `https://discord.com/api/guilds/${this.id}/widget.png?style=${style}`;
|
|
260
|
+
}
|
|
261
|
+
hasFeature(feature) {
|
|
262
|
+
return this.features.includes(feature);
|
|
263
|
+
}
|
|
264
|
+
get isCommunity() {
|
|
265
|
+
return this.hasFeature("COMMUNITY");
|
|
266
|
+
}
|
|
267
|
+
get isPartnered() {
|
|
268
|
+
return this.hasFeature("PARTNERED");
|
|
269
|
+
}
|
|
270
|
+
get isVerified() {
|
|
271
|
+
return this.hasFeature("VERIFIED");
|
|
272
|
+
}
|
|
273
|
+
get isBoosted() {
|
|
274
|
+
return this.premiumSubscriptionCount > 0;
|
|
275
|
+
}
|
|
276
|
+
get boostLevel() {
|
|
277
|
+
return this.premiumTier;
|
|
278
|
+
}
|
|
279
|
+
get hasVanityUrl() {
|
|
280
|
+
return this.vanityUrlCode !== null;
|
|
281
|
+
}
|
|
282
|
+
get vanityURL() {
|
|
283
|
+
return this.vanityUrlCode ? `https://discord.gg/${this.vanityUrlCode}` : null;
|
|
284
|
+
}
|
|
285
|
+
toString() {
|
|
286
|
+
return this.name;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// packages/structures/src/permissions.ts
|
|
291
|
+
var PermissionOverwriteEnum2;
|
|
292
|
+
((PermissionOverwriteEnum) => {
|
|
293
|
+
PermissionOverwriteEnum[PermissionOverwriteEnum["Role"] = 0] = "Role";
|
|
294
|
+
PermissionOverwriteEnum[PermissionOverwriteEnum["Member"] = 1] = "Member";
|
|
295
|
+
})(PermissionOverwriteEnum2 ||= {});
|
|
296
|
+
var Permission2 = {
|
|
297
|
+
createInstantInvite: 1n << 0n,
|
|
298
|
+
kickMembers: 1n << 1n,
|
|
299
|
+
banMembers: 1n << 2n,
|
|
300
|
+
administrator: 1n << 3n,
|
|
301
|
+
manageChannels: 1n << 4n,
|
|
302
|
+
manageGuild: 1n << 5n,
|
|
303
|
+
addReactions: 1n << 6n,
|
|
304
|
+
viewAuditLog: 1n << 7n,
|
|
305
|
+
prioritySpeaker: 1n << 8n,
|
|
306
|
+
stream: 1n << 9n,
|
|
307
|
+
viewChannel: 1n << 10n,
|
|
308
|
+
sendMessages: 1n << 11n,
|
|
309
|
+
sendTTSMessages: 1n << 12n,
|
|
310
|
+
manageMessages: 1n << 13n,
|
|
311
|
+
embedLinks: 1n << 14n,
|
|
312
|
+
attachFiles: 1n << 15n,
|
|
313
|
+
readMessageHistory: 1n << 16n,
|
|
314
|
+
mentionEveryone: 1n << 17n,
|
|
315
|
+
useExternalEmojis: 1n << 18n,
|
|
316
|
+
viewGuildInsights: 1n << 19n,
|
|
317
|
+
connect: 1n << 20n,
|
|
318
|
+
speak: 1n << 21n,
|
|
319
|
+
muteMembers: 1n << 22n,
|
|
320
|
+
deafenMembers: 1n << 23n,
|
|
321
|
+
moveMembers: 1n << 24n,
|
|
322
|
+
useVAD: 1n << 25n,
|
|
323
|
+
changeNickname: 1n << 26n,
|
|
324
|
+
manageNicknames: 1n << 27n,
|
|
325
|
+
manageRoles: 1n << 28n,
|
|
326
|
+
manageWebhooks: 1n << 29n,
|
|
327
|
+
manageGuildExpressions: 1n << 30n,
|
|
328
|
+
useApplicationCommands: 1n << 31n,
|
|
329
|
+
requestToSpeak: 1n << 32n,
|
|
330
|
+
manageEvents: 1n << 33n,
|
|
331
|
+
manageThreads: 1n << 34n,
|
|
332
|
+
createPublicThreads: 1n << 35n,
|
|
333
|
+
createPrivateThreads: 1n << 36n,
|
|
334
|
+
useExternalStickers: 1n << 37n,
|
|
335
|
+
sendMessagesInThreads: 1n << 38n,
|
|
336
|
+
useEmbeddedActivities: 1n << 39n,
|
|
337
|
+
moderateMembers: 1n << 40n,
|
|
338
|
+
viewCreatorMonetizationAnalytics: 1n << 41n,
|
|
339
|
+
useSoundboard: 1n << 42n,
|
|
340
|
+
createGuildExpressions: 1n << 43n,
|
|
341
|
+
createEvents: 1n << 44n,
|
|
342
|
+
useExternalSounds: 1n << 45n,
|
|
343
|
+
sendVoiceMessages: 1n << 46n,
|
|
344
|
+
setVoiceChannelStatus: 1n << 48n,
|
|
345
|
+
sendPolls: 1n << 49n,
|
|
346
|
+
useExternalApps: 1n << 50n,
|
|
347
|
+
pinMessages: 1n << 51n,
|
|
348
|
+
bypassSlowmode: 1n << 52n
|
|
349
|
+
};
|
|
350
|
+
var Permissions2 = {
|
|
351
|
+
CreateInstantInvite: 1n << 0n,
|
|
352
|
+
KickMembers: 1n << 1n,
|
|
353
|
+
BanMembers: 1n << 2n,
|
|
354
|
+
Administrator: 1n << 3n,
|
|
355
|
+
ManageChannels: 1n << 4n,
|
|
356
|
+
ManageGuild: 1n << 5n,
|
|
357
|
+
AddReactions: 1n << 6n,
|
|
358
|
+
ViewAuditLog: 1n << 7n,
|
|
359
|
+
PrioritySpeaker: 1n << 8n,
|
|
360
|
+
Stream: 1n << 9n,
|
|
361
|
+
ViewChannel: 1n << 10n,
|
|
362
|
+
SendMessages: 1n << 11n,
|
|
363
|
+
SendTTSMessages: 1n << 12n,
|
|
364
|
+
ManageMessages: 1n << 13n,
|
|
365
|
+
EmbedLinks: 1n << 14n,
|
|
366
|
+
AttachFiles: 1n << 15n,
|
|
367
|
+
ReadMessageHistory: 1n << 16n,
|
|
368
|
+
MentionEveryone: 1n << 17n,
|
|
369
|
+
UseExternalEmojis: 1n << 18n,
|
|
370
|
+
ViewGuildInsights: 1n << 19n,
|
|
371
|
+
Connect: 1n << 20n,
|
|
372
|
+
Speak: 1n << 21n,
|
|
373
|
+
MuteMembers: 1n << 22n,
|
|
374
|
+
DeafenMembers: 1n << 23n,
|
|
375
|
+
MoveMembers: 1n << 24n,
|
|
376
|
+
UseVAD: 1n << 25n,
|
|
377
|
+
ChangeNickname: 1n << 26n,
|
|
378
|
+
ManageNicknames: 1n << 27n,
|
|
379
|
+
ManageRoles: 1n << 28n,
|
|
380
|
+
ManageWebhooks: 1n << 29n,
|
|
381
|
+
ManageGuildExpressions: 1n << 30n,
|
|
382
|
+
UseApplicationCommands: 1n << 31n,
|
|
383
|
+
RequestToSpeak: 1n << 32n,
|
|
384
|
+
ManageEvents: 1n << 33n,
|
|
385
|
+
ManageThreads: 1n << 34n,
|
|
386
|
+
CreatePublicThreads: 1n << 35n,
|
|
387
|
+
CreatePrivateThreads: 1n << 36n,
|
|
388
|
+
UseExternalStickers: 1n << 37n,
|
|
389
|
+
SendMessagesInThreads: 1n << 38n,
|
|
390
|
+
UseEmbeddedActivities: 1n << 39n,
|
|
391
|
+
ModerateMembers: 1n << 40n,
|
|
392
|
+
ViewCreatorMonetizationAnalytics: 1n << 41n,
|
|
393
|
+
UseSoundboard: 1n << 42n,
|
|
394
|
+
CreateGuildExpressions: 1n << 43n,
|
|
395
|
+
CreateEvents: 1n << 44n,
|
|
396
|
+
UseExternalSounds: 1n << 45n,
|
|
397
|
+
SendVoiceMessages: 1n << 46n,
|
|
398
|
+
SetVoiceChannelStatus: 1n << 48n,
|
|
399
|
+
SendPolls: 1n << 49n,
|
|
400
|
+
UseExternalApps: 1n << 50n,
|
|
401
|
+
PinMessages: 1n << 51n,
|
|
402
|
+
BypassSlowmode: 1n << 52n
|
|
403
|
+
};
|
|
404
|
+
var PermissionFlagsBits2 = Permissions2;
|
|
405
|
+
|
|
406
|
+
class PermissionSet2 {
|
|
407
|
+
bitfield;
|
|
408
|
+
constructor(value = 0n) {
|
|
409
|
+
try {
|
|
410
|
+
if (Array.isArray(value)) {
|
|
411
|
+
let bit = 0n;
|
|
412
|
+
for (const item of value) {
|
|
413
|
+
bit |= this.#resolve(item);
|
|
414
|
+
}
|
|
415
|
+
this.bitfield = bit;
|
|
416
|
+
} else if (value instanceof PermissionSet2) {
|
|
417
|
+
this.bitfield = value.bitfield;
|
|
418
|
+
} else {
|
|
419
|
+
const bitfield = this.#resolve(value);
|
|
420
|
+
if (bitfield < 0n)
|
|
421
|
+
throw new RangeError("Permission bitfield cannot be negative.");
|
|
422
|
+
this.bitfield = bitfield;
|
|
423
|
+
}
|
|
424
|
+
} catch (error) {
|
|
425
|
+
if (error instanceof RangeError)
|
|
426
|
+
throw error;
|
|
427
|
+
throw new TypeError("Permission bitfield must be a valid non-negative integer.", { cause: error });
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
get createInstantInvite() {
|
|
431
|
+
return (this.bitfield & Permission2.createInstantInvite) === Permission2.createInstantInvite;
|
|
432
|
+
}
|
|
433
|
+
get kickMembers() {
|
|
434
|
+
return (this.bitfield & Permission2.kickMembers) === Permission2.kickMembers;
|
|
435
|
+
}
|
|
436
|
+
get banMembers() {
|
|
437
|
+
return (this.bitfield & Permission2.banMembers) === Permission2.banMembers;
|
|
438
|
+
}
|
|
439
|
+
get administrator() {
|
|
440
|
+
return (this.bitfield & Permission2.administrator) === Permission2.administrator;
|
|
441
|
+
}
|
|
442
|
+
get manageChannels() {
|
|
443
|
+
return (this.bitfield & Permission2.manageChannels) === Permission2.manageChannels;
|
|
444
|
+
}
|
|
445
|
+
get manageGuild() {
|
|
446
|
+
return (this.bitfield & Permission2.manageGuild) === Permission2.manageGuild;
|
|
447
|
+
}
|
|
448
|
+
get addReactions() {
|
|
449
|
+
return (this.bitfield & Permission2.addReactions) === Permission2.addReactions;
|
|
450
|
+
}
|
|
451
|
+
get viewAuditLog() {
|
|
452
|
+
return (this.bitfield & Permission2.viewAuditLog) === Permission2.viewAuditLog;
|
|
453
|
+
}
|
|
454
|
+
get prioritySpeaker() {
|
|
455
|
+
return (this.bitfield & Permission2.prioritySpeaker) === Permission2.prioritySpeaker;
|
|
456
|
+
}
|
|
457
|
+
get stream() {
|
|
458
|
+
return (this.bitfield & Permission2.stream) === Permission2.stream;
|
|
459
|
+
}
|
|
460
|
+
get viewChannel() {
|
|
461
|
+
return (this.bitfield & Permission2.viewChannel) === Permission2.viewChannel;
|
|
462
|
+
}
|
|
463
|
+
get sendMessages() {
|
|
464
|
+
return (this.bitfield & Permission2.sendMessages) === Permission2.sendMessages;
|
|
465
|
+
}
|
|
466
|
+
get sendTTSMessages() {
|
|
467
|
+
return (this.bitfield & Permission2.sendTTSMessages) === Permission2.sendTTSMessages;
|
|
468
|
+
}
|
|
469
|
+
get manageMessages() {
|
|
470
|
+
return (this.bitfield & Permission2.manageMessages) === Permission2.manageMessages;
|
|
471
|
+
}
|
|
472
|
+
get embedLinks() {
|
|
473
|
+
return (this.bitfield & Permission2.embedLinks) === Permission2.embedLinks;
|
|
474
|
+
}
|
|
475
|
+
get attachFiles() {
|
|
476
|
+
return (this.bitfield & Permission2.attachFiles) === Permission2.attachFiles;
|
|
477
|
+
}
|
|
478
|
+
get readMessageHistory() {
|
|
479
|
+
return (this.bitfield & Permission2.readMessageHistory) === Permission2.readMessageHistory;
|
|
480
|
+
}
|
|
481
|
+
get mentionEveryone() {
|
|
482
|
+
return (this.bitfield & Permission2.mentionEveryone) === Permission2.mentionEveryone;
|
|
483
|
+
}
|
|
484
|
+
get useExternalEmojis() {
|
|
485
|
+
return (this.bitfield & Permission2.useExternalEmojis) === Permission2.useExternalEmojis;
|
|
486
|
+
}
|
|
487
|
+
get viewGuildInsights() {
|
|
488
|
+
return (this.bitfield & Permission2.viewGuildInsights) === Permission2.viewGuildInsights;
|
|
489
|
+
}
|
|
490
|
+
get connect() {
|
|
491
|
+
return (this.bitfield & Permission2.connect) === Permission2.connect;
|
|
492
|
+
}
|
|
493
|
+
get speak() {
|
|
494
|
+
return (this.bitfield & Permission2.speak) === Permission2.speak;
|
|
495
|
+
}
|
|
496
|
+
get muteMembers() {
|
|
497
|
+
return (this.bitfield & Permission2.muteMembers) === Permission2.muteMembers;
|
|
498
|
+
}
|
|
499
|
+
get deafenMembers() {
|
|
500
|
+
return (this.bitfield & Permission2.deafenMembers) === Permission2.deafenMembers;
|
|
501
|
+
}
|
|
502
|
+
get moveMembers() {
|
|
503
|
+
return (this.bitfield & Permission2.moveMembers) === Permission2.moveMembers;
|
|
504
|
+
}
|
|
505
|
+
get useVAD() {
|
|
506
|
+
return (this.bitfield & Permission2.useVAD) === Permission2.useVAD;
|
|
507
|
+
}
|
|
508
|
+
get changeNickname() {
|
|
509
|
+
return (this.bitfield & Permission2.changeNickname) === Permission2.changeNickname;
|
|
510
|
+
}
|
|
511
|
+
get manageNicknames() {
|
|
512
|
+
return (this.bitfield & Permission2.manageNicknames) === Permission2.manageNicknames;
|
|
513
|
+
}
|
|
514
|
+
get manageRoles() {
|
|
515
|
+
return (this.bitfield & Permission2.manageRoles) === Permission2.manageRoles;
|
|
516
|
+
}
|
|
517
|
+
get manageWebhooks() {
|
|
518
|
+
return (this.bitfield & Permission2.manageWebhooks) === Permission2.manageWebhooks;
|
|
519
|
+
}
|
|
520
|
+
get manageGuildExpressions() {
|
|
521
|
+
return (this.bitfield & Permission2.manageGuildExpressions) === Permission2.manageGuildExpressions;
|
|
522
|
+
}
|
|
523
|
+
get useApplicationCommands() {
|
|
524
|
+
return (this.bitfield & Permission2.useApplicationCommands) === Permission2.useApplicationCommands;
|
|
525
|
+
}
|
|
526
|
+
get requestToSpeak() {
|
|
527
|
+
return (this.bitfield & Permission2.requestToSpeak) === Permission2.requestToSpeak;
|
|
528
|
+
}
|
|
529
|
+
get manageEvents() {
|
|
530
|
+
return (this.bitfield & Permission2.manageEvents) === Permission2.manageEvents;
|
|
531
|
+
}
|
|
532
|
+
get manageThreads() {
|
|
533
|
+
return (this.bitfield & Permission2.manageThreads) === Permission2.manageThreads;
|
|
534
|
+
}
|
|
535
|
+
get createPublicThreads() {
|
|
536
|
+
return (this.bitfield & Permission2.createPublicThreads) === Permission2.createPublicThreads;
|
|
537
|
+
}
|
|
538
|
+
get createPrivateThreads() {
|
|
539
|
+
return (this.bitfield & Permission2.createPrivateThreads) === Permission2.createPrivateThreads;
|
|
540
|
+
}
|
|
541
|
+
get useExternalStickers() {
|
|
542
|
+
return (this.bitfield & Permission2.useExternalStickers) === Permission2.useExternalStickers;
|
|
543
|
+
}
|
|
544
|
+
get sendMessagesInThreads() {
|
|
545
|
+
return (this.bitfield & Permission2.sendMessagesInThreads) === Permission2.sendMessagesInThreads;
|
|
546
|
+
}
|
|
547
|
+
get useEmbeddedActivities() {
|
|
548
|
+
return (this.bitfield & Permission2.useEmbeddedActivities) === Permission2.useEmbeddedActivities;
|
|
549
|
+
}
|
|
550
|
+
get moderateMembers() {
|
|
551
|
+
return (this.bitfield & Permission2.moderateMembers) === Permission2.moderateMembers;
|
|
552
|
+
}
|
|
553
|
+
get viewCreatorMonetizationAnalytics() {
|
|
554
|
+
return (this.bitfield & Permission2.viewCreatorMonetizationAnalytics) === Permission2.viewCreatorMonetizationAnalytics;
|
|
555
|
+
}
|
|
556
|
+
get useSoundboard() {
|
|
557
|
+
return (this.bitfield & Permission2.useSoundboard) === Permission2.useSoundboard;
|
|
558
|
+
}
|
|
559
|
+
get createGuildExpressions() {
|
|
560
|
+
return (this.bitfield & Permission2.createGuildExpressions) === Permission2.createGuildExpressions;
|
|
561
|
+
}
|
|
562
|
+
get createEvents() {
|
|
563
|
+
return (this.bitfield & Permission2.createEvents) === Permission2.createEvents;
|
|
564
|
+
}
|
|
565
|
+
get useExternalSounds() {
|
|
566
|
+
return (this.bitfield & Permission2.useExternalSounds) === Permission2.useExternalSounds;
|
|
567
|
+
}
|
|
568
|
+
get sendVoiceMessages() {
|
|
569
|
+
return (this.bitfield & Permission2.sendVoiceMessages) === Permission2.sendVoiceMessages;
|
|
570
|
+
}
|
|
571
|
+
get sendPolls() {
|
|
572
|
+
return (this.bitfield & Permission2.sendPolls) === Permission2.sendPolls;
|
|
573
|
+
}
|
|
574
|
+
get useExternalApps() {
|
|
575
|
+
return (this.bitfield & Permission2.useExternalApps) === Permission2.useExternalApps;
|
|
576
|
+
}
|
|
577
|
+
get setVoiceChannelStatus() {
|
|
578
|
+
return (this.bitfield & Permission2.setVoiceChannelStatus) === Permission2.setVoiceChannelStatus;
|
|
579
|
+
}
|
|
580
|
+
get pinMessages() {
|
|
581
|
+
return (this.bitfield & Permission2.pinMessages) === Permission2.pinMessages;
|
|
582
|
+
}
|
|
583
|
+
get bypassSlowmode() {
|
|
584
|
+
return (this.bitfield & Permission2.bypassSlowmode) === Permission2.bypassSlowmode;
|
|
585
|
+
}
|
|
586
|
+
has(...permissions) {
|
|
587
|
+
if (permissions.length === 1) {
|
|
588
|
+
const p = permissions[0];
|
|
589
|
+
const bit = typeof p === "bigint" ? p : this.#resolve(p);
|
|
590
|
+
return (this.bitfield & bit) === bit;
|
|
591
|
+
}
|
|
592
|
+
for (let i = 0;i < permissions.length; i++) {
|
|
593
|
+
const p = permissions[i];
|
|
594
|
+
const bit = typeof p === "bigint" ? p : this.#resolve(p);
|
|
595
|
+
if ((this.bitfield & bit) !== bit)
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
any(...permissions) {
|
|
601
|
+
if (permissions.length === 1) {
|
|
602
|
+
const p = permissions[0];
|
|
603
|
+
const bit = typeof p === "bigint" ? p : this.#resolve(p);
|
|
604
|
+
return (this.bitfield & bit) !== 0n;
|
|
605
|
+
}
|
|
606
|
+
for (let i = 0;i < permissions.length; i++) {
|
|
607
|
+
const p = permissions[i];
|
|
608
|
+
const bit = typeof p === "bigint" ? p : this.#resolve(p);
|
|
609
|
+
if ((this.bitfield & bit) !== 0n)
|
|
610
|
+
return true;
|
|
611
|
+
}
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
missing(...permissions) {
|
|
615
|
+
const wanted = new PermissionSet2(permissions);
|
|
616
|
+
return wanted.toArray().filter((name) => !this.has(name));
|
|
617
|
+
}
|
|
618
|
+
add(...permissions) {
|
|
619
|
+
let bitfield = this.bitfield;
|
|
620
|
+
for (let i = 0;i < permissions.length; i++) {
|
|
621
|
+
const p = permissions[i];
|
|
622
|
+
bitfield |= typeof p === "bigint" ? p : this.#resolve(p);
|
|
623
|
+
}
|
|
624
|
+
return new PermissionSet2(bitfield);
|
|
625
|
+
}
|
|
626
|
+
remove(...permissions) {
|
|
627
|
+
let bitfield = this.bitfield;
|
|
628
|
+
for (let i = 0;i < permissions.length; i++) {
|
|
629
|
+
const p = permissions[i];
|
|
630
|
+
bitfield &= ~(typeof p === "bigint" ? p : this.#resolve(p));
|
|
631
|
+
}
|
|
632
|
+
return new PermissionSet2(bitfield);
|
|
633
|
+
}
|
|
634
|
+
equals(other) {
|
|
635
|
+
return this.bitfield === (other instanceof PermissionSet2 ? other.bitfield : new PermissionSet2(other).bitfield);
|
|
636
|
+
}
|
|
637
|
+
toString() {
|
|
638
|
+
return this.bitfield.toString();
|
|
639
|
+
}
|
|
640
|
+
toArray() {
|
|
641
|
+
return Object.keys(Permission2).filter((permission) => this.has(permission));
|
|
642
|
+
}
|
|
643
|
+
static #renamed = {
|
|
644
|
+
ManageEmojisAndStickers: "ManageGuildExpressions",
|
|
645
|
+
ManageEmojis: "ManageGuildExpressions",
|
|
646
|
+
UseSlashCommands: "UseApplicationCommands"
|
|
647
|
+
};
|
|
648
|
+
#resolve(permission) {
|
|
649
|
+
if (typeof permission === "bigint")
|
|
650
|
+
return permission;
|
|
651
|
+
if (typeof permission === "number")
|
|
652
|
+
return BigInt(permission);
|
|
653
|
+
if (permission instanceof PermissionSet2)
|
|
654
|
+
return permission.bitfield;
|
|
655
|
+
if (Array.isArray(permission)) {
|
|
656
|
+
let bit = 0n;
|
|
657
|
+
for (let i = 0;i < permission.length; i++)
|
|
658
|
+
bit |= this.#resolve(permission[i]);
|
|
659
|
+
return bit;
|
|
660
|
+
}
|
|
661
|
+
if (typeof permission === "string") {
|
|
662
|
+
const renamed = PermissionSet2.#renamed[permission];
|
|
663
|
+
if (renamed)
|
|
664
|
+
return this.#resolve(renamed);
|
|
665
|
+
if (permission in Permission2)
|
|
666
|
+
return Permission2[permission];
|
|
667
|
+
if (permission in Permissions2)
|
|
668
|
+
return Permissions2[permission];
|
|
669
|
+
if (permission in PermissionFlagsBits2)
|
|
670
|
+
return PermissionFlagsBits2[permission];
|
|
671
|
+
const lower = permission.charAt(0).toLowerCase() + permission.slice(1);
|
|
672
|
+
if (lower in Permission2)
|
|
673
|
+
return Permission2[lower];
|
|
674
|
+
return BigInt(permission);
|
|
675
|
+
}
|
|
676
|
+
return 0n;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
class PermissionsBitField2 extends PermissionSet2 {
|
|
681
|
+
static Flags = PermissionFlagsBits2;
|
|
682
|
+
static All = Permission2;
|
|
683
|
+
constructor(value = 0n) {
|
|
684
|
+
super(value);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
var ALL_PERMISSIONS = Object.values(Permission2).reduce((bits, bit) => bits | bit, 0n);
|
|
688
|
+
var bits = (value) => new PermissionSet2(value).bitfield;
|
|
689
|
+
function computePermissions2(context) {
|
|
690
|
+
if (context.ownerId !== undefined && context.ownerId === context.memberId)
|
|
691
|
+
return new PermissionSet2(ALL_PERMISSIONS);
|
|
692
|
+
const roles = new Map(context.roles.map((role) => [role.id, role]));
|
|
693
|
+
let base = bits(roles.get(context.guildId)?.permissions ?? 0n);
|
|
694
|
+
for (const id of context.memberRoleIds)
|
|
695
|
+
base |= bits(roles.get(id)?.permissions ?? 0n);
|
|
696
|
+
if (base & Permission2.administrator)
|
|
697
|
+
return new PermissionSet2(ALL_PERMISSIONS);
|
|
698
|
+
const overwrites = context.overwrites ?? [];
|
|
699
|
+
const everyone = overwrites.find((o) => o.id === context.guildId);
|
|
700
|
+
if (everyone)
|
|
701
|
+
base = base & ~bits(everyone.deny) | bits(everyone.allow);
|
|
702
|
+
const memberRoles = new Set(context.memberRoleIds);
|
|
703
|
+
let allow = 0n;
|
|
704
|
+
let deny = 0n;
|
|
705
|
+
for (const overwrite of overwrites)
|
|
706
|
+
if (overwrite.type === 0 /* Role */ && overwrite.id !== context.guildId && memberRoles.has(overwrite.id)) {
|
|
707
|
+
allow |= bits(overwrite.allow);
|
|
708
|
+
deny |= bits(overwrite.deny);
|
|
709
|
+
}
|
|
710
|
+
base = base & ~deny | allow;
|
|
711
|
+
const member = overwrites.find((o) => o.type === 1 /* Member */ && o.id === context.memberId);
|
|
712
|
+
if (member)
|
|
713
|
+
base = base & ~bits(member.deny) | bits(member.allow);
|
|
714
|
+
const until = context.timedOutUntil instanceof Date ? context.timedOutUntil.getTime() : context.timedOutUntil ?? 0;
|
|
715
|
+
if (until > Date.now())
|
|
716
|
+
base &= Permission2.viewChannel | Permission2.readMessageHistory;
|
|
717
|
+
return new PermissionSet2(base);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// packages/structures/src/resources.ts
|
|
721
|
+
function toDateOrNull(value) {
|
|
722
|
+
if (!value)
|
|
723
|
+
return null;
|
|
724
|
+
const date = new Date(value);
|
|
725
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
class GuildMember2 {
|
|
729
|
+
user;
|
|
730
|
+
guildId;
|
|
731
|
+
nickname;
|
|
732
|
+
roleIds;
|
|
733
|
+
pending;
|
|
734
|
+
joinedAt;
|
|
735
|
+
avatarHash;
|
|
736
|
+
premiumSince;
|
|
737
|
+
timedOutUntil;
|
|
738
|
+
flags;
|
|
739
|
+
#suppliedPermissions;
|
|
740
|
+
#context;
|
|
741
|
+
constructor(data, context) {
|
|
742
|
+
this.user = new User2(data.user);
|
|
743
|
+
this.#context = context;
|
|
744
|
+
if (!/^\d{1,20}$/.test(data.guild_id))
|
|
745
|
+
throw new TypeError("Member guild_id must be a valid snowflake.");
|
|
746
|
+
this.guildId = data.guild_id;
|
|
747
|
+
this.nickname = data.nick ?? null;
|
|
748
|
+
this.roleIds = [...data.roles ?? []];
|
|
749
|
+
this.pending = data.pending ?? false;
|
|
750
|
+
this.joinedAt = data.joined_at ? new Date(data.joined_at) : undefined;
|
|
751
|
+
if (this.joinedAt?.toString() === "Invalid Date")
|
|
752
|
+
throw new RangeError("Member joined_at must be a valid date.");
|
|
753
|
+
if (data.permissions !== undefined)
|
|
754
|
+
this.#suppliedPermissions = new PermissionsBitField2(data.permissions);
|
|
755
|
+
this.avatarHash = data.avatar ?? null;
|
|
756
|
+
this.premiumSince = toDateOrNull(data.premium_since);
|
|
757
|
+
this.timedOutUntil = toDateOrNull(data.communication_disabled_until);
|
|
758
|
+
this.flags = data.flags ?? 0;
|
|
759
|
+
}
|
|
760
|
+
get permissions() {
|
|
761
|
+
if (this.#suppliedPermissions)
|
|
762
|
+
return this.#suppliedPermissions;
|
|
763
|
+
return new PermissionsBitField2(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, undefined, this.timedOutUntil) ?? 0n);
|
|
764
|
+
}
|
|
765
|
+
permissionsIn(channelId) {
|
|
766
|
+
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId, this.timedOutUntil);
|
|
767
|
+
return computed ? new PermissionsBitField2(computed) : null;
|
|
768
|
+
}
|
|
769
|
+
#action(name) {
|
|
770
|
+
const action = this.#context?.[name];
|
|
771
|
+
if (!action)
|
|
772
|
+
throw new Error("This member is not attached to a client.");
|
|
773
|
+
return action;
|
|
774
|
+
}
|
|
775
|
+
kick(reason) {
|
|
776
|
+
return this.#action("kickMember")(this.guildId, this.user.id, reason);
|
|
777
|
+
}
|
|
778
|
+
ban(options = {}) {
|
|
779
|
+
return this.#action("banMember")(this.guildId, this.user.id, options);
|
|
780
|
+
}
|
|
781
|
+
edit(options, reason) {
|
|
782
|
+
return this.#action("editMember")(this.guildId, this.user.id, options, reason);
|
|
783
|
+
}
|
|
784
|
+
timeout(milliseconds, reason) {
|
|
785
|
+
if (milliseconds !== null && !(milliseconds > 0))
|
|
786
|
+
throw new RangeError("Timeout length must be a positive number of milliseconds.");
|
|
787
|
+
return this.edit({
|
|
788
|
+
communication_disabled_until: milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString()
|
|
789
|
+
}, reason);
|
|
790
|
+
}
|
|
791
|
+
setNickname(nickname, reason) {
|
|
792
|
+
return this.edit({ nick: nickname }, reason);
|
|
793
|
+
}
|
|
794
|
+
addRole(roleId, reason) {
|
|
795
|
+
return this.#action("addMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
796
|
+
}
|
|
797
|
+
removeRole(roleId, reason) {
|
|
798
|
+
return this.#action("removeMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
799
|
+
}
|
|
800
|
+
get displayName() {
|
|
801
|
+
return this.nickname ?? this.user.displayName;
|
|
802
|
+
}
|
|
803
|
+
get isTimedOut() {
|
|
804
|
+
return this.timedOutUntil !== null && this.timedOutUntil > new Date;
|
|
805
|
+
}
|
|
806
|
+
avatarURL(options = {}) {
|
|
807
|
+
if (this.avatarHash)
|
|
808
|
+
return cdnURL2(`/guilds/${this.guildId}/users/${this.user.id}/avatars`, this.avatarHash, options);
|
|
809
|
+
return this.user.avatarURL(options);
|
|
810
|
+
}
|
|
811
|
+
displayAvatarURL(options = {}) {
|
|
812
|
+
return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
|
|
813
|
+
}
|
|
814
|
+
toString() {
|
|
815
|
+
return this.user.toString();
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
class Role2 extends BaseStructure2 {
|
|
820
|
+
name;
|
|
821
|
+
color;
|
|
822
|
+
hoist;
|
|
823
|
+
permissions;
|
|
824
|
+
managed;
|
|
825
|
+
mentionable;
|
|
826
|
+
position;
|
|
827
|
+
unicodeEmoji;
|
|
828
|
+
iconHash;
|
|
829
|
+
colors;
|
|
830
|
+
tags;
|
|
831
|
+
constructor(data) {
|
|
832
|
+
super(data.id);
|
|
833
|
+
if (!data.name)
|
|
834
|
+
throw new TypeError("Role name cannot be empty.");
|
|
835
|
+
this.name = data.name;
|
|
836
|
+
this.color = data.color ?? 0;
|
|
837
|
+
this.hoist = data.hoist ?? false;
|
|
838
|
+
this.permissions = new PermissionsBitField2(data.permissions ?? 0n);
|
|
839
|
+
this.managed = data.managed ?? false;
|
|
840
|
+
this.mentionable = data.mentionable ?? false;
|
|
841
|
+
this.position = data.position ?? 0;
|
|
842
|
+
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
843
|
+
this.colors = data.colors ? {
|
|
844
|
+
primary: data.colors.primary_color,
|
|
845
|
+
secondary: data.colors.secondary_color,
|
|
846
|
+
tertiary: data.colors.tertiary_color
|
|
847
|
+
} : null;
|
|
848
|
+
this.iconHash = data.icon ?? null;
|
|
849
|
+
this.tags = data.tags ?? null;
|
|
850
|
+
}
|
|
851
|
+
get colorHex() {
|
|
852
|
+
return `#${this.color.toString(16).padStart(6, "0").toUpperCase()}`;
|
|
853
|
+
}
|
|
854
|
+
iconURL(options = {}) {
|
|
855
|
+
if (!this.iconHash)
|
|
856
|
+
return null;
|
|
857
|
+
return cdnURL2(`/role-icons/${this.id}`, this.iconHash, options);
|
|
858
|
+
}
|
|
859
|
+
isEveryone(guildId) {
|
|
860
|
+
return this.id === guildId;
|
|
861
|
+
}
|
|
862
|
+
toString() {
|
|
863
|
+
return `<@&${this.id}>`;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
class TextChannel2 extends Channel2 {
|
|
868
|
+
constructor(data, context) {
|
|
869
|
+
super(data, context);
|
|
870
|
+
}
|
|
871
|
+
toString() {
|
|
872
|
+
return `<#${this.id}>`;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
class Invite2 {
|
|
877
|
+
code;
|
|
878
|
+
guildId;
|
|
879
|
+
channelId;
|
|
880
|
+
inviter;
|
|
881
|
+
uses;
|
|
882
|
+
maxUses;
|
|
883
|
+
maxAge;
|
|
884
|
+
temporary;
|
|
885
|
+
createdAt;
|
|
886
|
+
expiresAt;
|
|
887
|
+
constructor(data) {
|
|
888
|
+
if (!data.code)
|
|
889
|
+
throw new TypeError("An invite requires a code.");
|
|
890
|
+
this.code = data.code;
|
|
891
|
+
this.guildId = data.guild?.id ?? null;
|
|
892
|
+
this.channelId = data.channel?.id ?? null;
|
|
893
|
+
this.inviter = data.inviter ? new User2(data.inviter) : null;
|
|
894
|
+
this.uses = data.uses ?? 0;
|
|
895
|
+
this.maxUses = data.max_uses ?? 0;
|
|
896
|
+
this.maxAge = data.max_age ?? 0;
|
|
897
|
+
this.temporary = data.temporary ?? false;
|
|
898
|
+
this.createdAt = data.created_at ? new Date(data.created_at) : null;
|
|
899
|
+
this.expiresAt = data.expires_at ? new Date(data.expires_at) : null;
|
|
900
|
+
}
|
|
901
|
+
get url() {
|
|
902
|
+
return `https://discord.gg/${this.code}`;
|
|
903
|
+
}
|
|
904
|
+
toString() {
|
|
905
|
+
return this.url;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
var WebhookEnum2 = {
|
|
909
|
+
Incoming: 1,
|
|
910
|
+
ChannelFollower: 2,
|
|
911
|
+
Application: 3
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
class Webhook2 extends BaseStructure2 {
|
|
915
|
+
type;
|
|
916
|
+
name;
|
|
917
|
+
avatarHash;
|
|
918
|
+
channelId;
|
|
919
|
+
guildId;
|
|
920
|
+
applicationId;
|
|
921
|
+
token;
|
|
922
|
+
constructor(data) {
|
|
923
|
+
super(data.id);
|
|
924
|
+
this.type = data.type ?? WebhookEnum2.Incoming;
|
|
925
|
+
this.name = data.name ?? null;
|
|
926
|
+
this.avatarHash = data.avatar ?? null;
|
|
927
|
+
this.channelId = data.channel_id ?? null;
|
|
928
|
+
this.guildId = data.guild_id ?? null;
|
|
929
|
+
this.applicationId = data.application_id ?? null;
|
|
930
|
+
this.token = data.token ?? null;
|
|
931
|
+
}
|
|
932
|
+
avatarURL(options = {}) {
|
|
933
|
+
if (!this.avatarHash)
|
|
934
|
+
return null;
|
|
935
|
+
return cdnURL2(`/avatars/${this.id}`, this.avatarHash, options);
|
|
936
|
+
}
|
|
937
|
+
get url() {
|
|
938
|
+
return this.token ? `https://discord.com/api/webhooks/${this.id}/${this.token}` : null;
|
|
939
|
+
}
|
|
940
|
+
toString() {
|
|
941
|
+
return this.url ?? this.id;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
class Emoji2 extends BaseStructure2 {
|
|
946
|
+
name;
|
|
947
|
+
roleIds;
|
|
948
|
+
user;
|
|
949
|
+
requireColons;
|
|
950
|
+
managed;
|
|
951
|
+
animated;
|
|
952
|
+
available;
|
|
953
|
+
constructor(data) {
|
|
954
|
+
super(data.id ?? "0");
|
|
955
|
+
if (data.id === null)
|
|
956
|
+
this.id = "unicode";
|
|
957
|
+
this.name = data.name;
|
|
958
|
+
this.roleIds = data.roles ?? [];
|
|
959
|
+
this.user = data.user ? new User2(data.user) : null;
|
|
960
|
+
this.requireColons = data.require_colons ?? false;
|
|
961
|
+
this.managed = data.managed ?? false;
|
|
962
|
+
this.animated = data.animated ?? false;
|
|
963
|
+
this.available = data.available ?? true;
|
|
964
|
+
}
|
|
965
|
+
url(options = {}) {
|
|
966
|
+
if (!this.id || this.id === "unicode")
|
|
967
|
+
return null;
|
|
968
|
+
const ext = options.extension ?? (this.animated ? "gif" : "png");
|
|
969
|
+
const size = options.size ? `?size=${options.size}` : "";
|
|
970
|
+
return `${CDN_BASE2}/emojis/${this.id}.${ext}${size}`;
|
|
971
|
+
}
|
|
972
|
+
toString() {
|
|
973
|
+
return this.id !== "unicode" ? `<${this.animated ? "a" : ""}:${this.name}:${this.id}>` : this.name ?? "";
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
class AutoModerationRule2 extends BaseStructure2 {
|
|
978
|
+
guildId;
|
|
979
|
+
name;
|
|
980
|
+
creatorId;
|
|
981
|
+
eventType;
|
|
982
|
+
triggerType;
|
|
983
|
+
triggerMetadata;
|
|
984
|
+
actions;
|
|
985
|
+
enabled;
|
|
986
|
+
exemptRoles;
|
|
987
|
+
exemptChannels;
|
|
988
|
+
constructor(data) {
|
|
989
|
+
super(data.id);
|
|
990
|
+
if (!/^\d{1,20}$/.test(data.guild_id))
|
|
991
|
+
throw new TypeError("AutoModerationRule guild_id must be a valid snowflake.");
|
|
992
|
+
this.guildId = data.guild_id;
|
|
993
|
+
this.name = data.name;
|
|
994
|
+
this.creatorId = data.creator_id;
|
|
995
|
+
this.eventType = data.event_type;
|
|
996
|
+
this.triggerType = data.trigger_type;
|
|
997
|
+
this.triggerMetadata = data.trigger_metadata;
|
|
998
|
+
this.actions = data.actions;
|
|
999
|
+
this.enabled = data.enabled;
|
|
1000
|
+
this.exemptRoles = data.exempt_roles;
|
|
1001
|
+
this.exemptChannels = data.exempt_channels;
|
|
1002
|
+
}
|
|
1003
|
+
toJSON() {
|
|
1004
|
+
return {
|
|
1005
|
+
id: this.id,
|
|
1006
|
+
guildId: this.guildId,
|
|
1007
|
+
name: this.name,
|
|
1008
|
+
creatorId: this.creatorId,
|
|
1009
|
+
eventType: this.eventType,
|
|
1010
|
+
triggerType: this.triggerType,
|
|
1011
|
+
triggerMetadata: this.triggerMetadata,
|
|
1012
|
+
actions: this.actions,
|
|
1013
|
+
enabled: this.enabled,
|
|
1014
|
+
exemptRoles: this.exemptRoles,
|
|
1015
|
+
exemptChannels: this.exemptChannels
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
class WelcomeScreenChannel2 {
|
|
1021
|
+
channelId;
|
|
1022
|
+
description;
|
|
1023
|
+
emojiId;
|
|
1024
|
+
emojiName;
|
|
1025
|
+
constructor(data) {
|
|
1026
|
+
this.channelId = data.channel_id;
|
|
1027
|
+
this.description = data.description;
|
|
1028
|
+
this.emojiId = data.emoji_id;
|
|
1029
|
+
this.emojiName = data.emoji_name;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
class GuildWelcomeScreen2 {
|
|
1034
|
+
description;
|
|
1035
|
+
channels;
|
|
1036
|
+
constructor(data) {
|
|
1037
|
+
this.description = data.description;
|
|
1038
|
+
this.channels = data.welcome_channels.map((c) => new WelcomeScreenChannel2(c));
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
class OnboardingPromptOption2 extends BaseStructure2 {
|
|
1043
|
+
channelIds;
|
|
1044
|
+
roleIds;
|
|
1045
|
+
emoji;
|
|
1046
|
+
title;
|
|
1047
|
+
description;
|
|
1048
|
+
constructor(data) {
|
|
1049
|
+
super(data.id);
|
|
1050
|
+
this.channelIds = data.channel_ids;
|
|
1051
|
+
this.roleIds = data.role_ids;
|
|
1052
|
+
this.emoji = data.emoji;
|
|
1053
|
+
this.title = data.title;
|
|
1054
|
+
this.description = data.description;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
class OnboardingPrompt2 extends BaseStructure2 {
|
|
1059
|
+
type;
|
|
1060
|
+
options;
|
|
1061
|
+
title;
|
|
1062
|
+
singleSelect;
|
|
1063
|
+
required;
|
|
1064
|
+
inOnboarding;
|
|
1065
|
+
constructor(data) {
|
|
1066
|
+
super(data.id);
|
|
1067
|
+
this.type = data.type;
|
|
1068
|
+
this.options = data.options.map((o) => new OnboardingPromptOption2(o));
|
|
1069
|
+
this.title = data.title;
|
|
1070
|
+
this.singleSelect = data.single_select;
|
|
1071
|
+
this.required = data.required;
|
|
1072
|
+
this.inOnboarding = data.in_onboarding;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
class GuildOnboarding2 extends BaseStructure2 {
|
|
1077
|
+
prompts;
|
|
1078
|
+
defaultChannelIds;
|
|
1079
|
+
enabled;
|
|
1080
|
+
mode;
|
|
1081
|
+
constructor(data) {
|
|
1082
|
+
super(data.guild_id);
|
|
1083
|
+
this.prompts = data.prompts.map((p) => new OnboardingPrompt2(p));
|
|
1084
|
+
this.defaultChannelIds = data.default_channel_ids;
|
|
1085
|
+
this.enabled = data.enabled;
|
|
1086
|
+
this.mode = data.mode;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
// packages/structures/src/channels.ts
|
|
1090
|
+
class NewsChannel2 extends TextChannel2 {
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
class DMChannel2 extends Channel2 {
|
|
1094
|
+
recipients;
|
|
1095
|
+
ownerId;
|
|
1096
|
+
constructor(data, context) {
|
|
1097
|
+
super(data, context);
|
|
1098
|
+
this.recipients = (data.recipients ?? []).map((u) => new User2(u));
|
|
1099
|
+
this.ownerId = data.owner_id ?? null;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
class VoiceChannel2 extends Channel2 {
|
|
1104
|
+
bitrate;
|
|
1105
|
+
userLimit;
|
|
1106
|
+
rtcRegion;
|
|
1107
|
+
videoQualityMode;
|
|
1108
|
+
constructor(data, context) {
|
|
1109
|
+
super(data, context);
|
|
1110
|
+
this.bitrate = data.bitrate ?? 64000;
|
|
1111
|
+
this.userLimit = data.user_limit ?? 0;
|
|
1112
|
+
this.rtcRegion = data.rtc_region ?? null;
|
|
1113
|
+
this.videoQualityMode = data.video_quality_mode ?? 1;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
class StageChannel2 extends VoiceChannel2 {
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
class CategoryChannel2 extends Channel2 {
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
class ThreadChannel2 extends Channel2 {
|
|
1124
|
+
ownerId;
|
|
1125
|
+
messageCount;
|
|
1126
|
+
memberCount;
|
|
1127
|
+
metadata;
|
|
1128
|
+
constructor(data, context) {
|
|
1129
|
+
super(data, context);
|
|
1130
|
+
this.ownerId = data.owner_id ?? null;
|
|
1131
|
+
this.messageCount = data.message_count ?? 0;
|
|
1132
|
+
this.memberCount = data.member_count ?? 0;
|
|
1133
|
+
this.metadata = data.thread_metadata ?? null;
|
|
1134
|
+
}
|
|
1135
|
+
get archived() {
|
|
1136
|
+
return this.metadata?.archived ?? false;
|
|
1137
|
+
}
|
|
1138
|
+
get locked() {
|
|
1139
|
+
return this.metadata?.locked ?? false;
|
|
1140
|
+
}
|
|
1141
|
+
get autoArchiveDuration() {
|
|
1142
|
+
return this.metadata?.auto_archive_duration ?? null;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
class ForumChannel2 extends Channel2 {
|
|
1147
|
+
availableTags;
|
|
1148
|
+
defaultReactionEmoji;
|
|
1149
|
+
defaultThreadRateLimitPerUser;
|
|
1150
|
+
defaultAutoArchiveDuration;
|
|
1151
|
+
constructor(data, context) {
|
|
1152
|
+
super(data, context);
|
|
1153
|
+
this.availableTags = data.available_tags ?? [];
|
|
1154
|
+
this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
|
|
1155
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? 0;
|
|
1156
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
class MediaChannel2 extends ForumChannel2 {
|
|
1161
|
+
}
|
|
1162
|
+
function createChannel2(data, context) {
|
|
1163
|
+
switch (data.type) {
|
|
1164
|
+
case 0:
|
|
1165
|
+
return new TextChannel2(data, context);
|
|
1166
|
+
case 1:
|
|
1167
|
+
case 3:
|
|
1168
|
+
return new DMChannel2(data, context);
|
|
1169
|
+
case 2:
|
|
1170
|
+
return new VoiceChannel2(data, context);
|
|
1171
|
+
case 4:
|
|
1172
|
+
return new CategoryChannel2(data, context);
|
|
1173
|
+
case 5:
|
|
1174
|
+
return new NewsChannel2(data, context);
|
|
1175
|
+
case 10:
|
|
1176
|
+
case 11:
|
|
1177
|
+
case 12:
|
|
1178
|
+
return new ThreadChannel2(data, context);
|
|
1179
|
+
case 13:
|
|
1180
|
+
return new StageChannel2(data, context);
|
|
1181
|
+
case 15:
|
|
1182
|
+
return new ForumChannel2(data, context);
|
|
1183
|
+
case 16:
|
|
1184
|
+
return new MediaChannel2(data, context);
|
|
1185
|
+
default:
|
|
1186
|
+
return new Channel2(data, context);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
// packages/structures/src/options.ts
|
|
1190
|
+
var OptionType = {
|
|
1191
|
+
SubCommand: 1,
|
|
1192
|
+
SubCommandGroup: 2,
|
|
1193
|
+
String: 3,
|
|
1194
|
+
Integer: 4,
|
|
1195
|
+
Boolean: 5,
|
|
1196
|
+
User: 6,
|
|
1197
|
+
Channel: 7,
|
|
1198
|
+
Role: 8,
|
|
1199
|
+
Mentionable: 9,
|
|
1200
|
+
Number: 10,
|
|
1201
|
+
Attachment: 11
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
class CommandOptions2 {
|
|
1205
|
+
#options;
|
|
1206
|
+
#resolved;
|
|
1207
|
+
#lookup(kind, id) {
|
|
1208
|
+
const group = this.#resolved?.[kind];
|
|
1209
|
+
if (typeof group !== "object" || group === null)
|
|
1210
|
+
return;
|
|
1211
|
+
const entry = group[id];
|
|
1212
|
+
return typeof entry === "object" && entry !== null ? entry : undefined;
|
|
1213
|
+
}
|
|
1214
|
+
constructor(options, resolved = {}) {
|
|
1215
|
+
let currentOptions = options;
|
|
1216
|
+
let group = null;
|
|
1217
|
+
let sub = null;
|
|
1218
|
+
while (currentOptions.length === 1) {
|
|
1219
|
+
const opt = currentOptions[0];
|
|
1220
|
+
if (opt.type === OptionType.SubCommandGroup) {
|
|
1221
|
+
group = opt.name;
|
|
1222
|
+
currentOptions = opt.options ?? [];
|
|
1223
|
+
} else if (opt.type === OptionType.SubCommand) {
|
|
1224
|
+
sub = opt.name;
|
|
1225
|
+
currentOptions = opt.options ?? [];
|
|
1226
|
+
} else {
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
this.#options = currentOptions;
|
|
1231
|
+
this.#resolved = resolved;
|
|
1232
|
+
this.#subcommandGroup = group;
|
|
1233
|
+
this.#subcommand = sub;
|
|
1234
|
+
}
|
|
1235
|
+
#subcommandGroup;
|
|
1236
|
+
#subcommand;
|
|
1237
|
+
#get(name) {
|
|
1238
|
+
return this.#options.find((o) => o.name.toLowerCase() === name.toLowerCase());
|
|
1239
|
+
}
|
|
1240
|
+
getSubcommand(required = false) {
|
|
1241
|
+
if (!this.#subcommand && required) {
|
|
1242
|
+
throw new TypeError("No subcommand was provided.");
|
|
1243
|
+
}
|
|
1244
|
+
return this.#subcommand;
|
|
1245
|
+
}
|
|
1246
|
+
getSubcommandGroup(required = false) {
|
|
1247
|
+
if (!this.#subcommandGroup && required) {
|
|
1248
|
+
throw new TypeError("No subcommand group was provided.");
|
|
1249
|
+
}
|
|
1250
|
+
return this.#subcommandGroup;
|
|
1251
|
+
}
|
|
1252
|
+
getFocused(full = false) {
|
|
1253
|
+
const focused = this.#options.find((o) => o.focused);
|
|
1254
|
+
if (!focused)
|
|
1255
|
+
throw new TypeError("No focused option was provided.");
|
|
1256
|
+
return full ? focused : focused.value ?? "";
|
|
1257
|
+
}
|
|
1258
|
+
getString(name, required = false) {
|
|
1259
|
+
const opt = this.#get(name);
|
|
1260
|
+
if (!opt || opt.type !== OptionType.String) {
|
|
1261
|
+
if (required)
|
|
1262
|
+
throw new TypeError(`Required option "${name}" (string) is missing.`);
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
return typeof opt.value === "string" ? opt.value : null;
|
|
1266
|
+
}
|
|
1267
|
+
getInteger(name, required = false) {
|
|
1268
|
+
const opt = this.#get(name);
|
|
1269
|
+
if (!opt || opt.type !== OptionType.Integer) {
|
|
1270
|
+
if (required)
|
|
1271
|
+
throw new TypeError(`Required option "${name}" (integer) is missing.`);
|
|
1272
|
+
return null;
|
|
1273
|
+
}
|
|
1274
|
+
return typeof opt.value === "number" ? Math.trunc(opt.value) : null;
|
|
1275
|
+
}
|
|
1276
|
+
getNumber(name, required = false) {
|
|
1277
|
+
const opt = this.#get(name);
|
|
1278
|
+
if (!opt || opt.type !== OptionType.Number) {
|
|
1279
|
+
if (required)
|
|
1280
|
+
throw new TypeError(`Required option "${name}" (number) is missing.`);
|
|
1281
|
+
return null;
|
|
1282
|
+
}
|
|
1283
|
+
return typeof opt.value === "number" ? opt.value : null;
|
|
1284
|
+
}
|
|
1285
|
+
getBoolean(name, required = false) {
|
|
1286
|
+
const opt = this.#get(name);
|
|
1287
|
+
if (!opt || opt.type !== OptionType.Boolean) {
|
|
1288
|
+
if (required)
|
|
1289
|
+
throw new TypeError(`Required option "${name}" (boolean) is missing.`);
|
|
1290
|
+
return null;
|
|
1291
|
+
}
|
|
1292
|
+
return typeof opt.value === "boolean" ? opt.value : null;
|
|
1293
|
+
}
|
|
1294
|
+
getUser(name, required = false) {
|
|
1295
|
+
const opt = this.#get(name);
|
|
1296
|
+
if (!opt || opt.type !== OptionType.User) {
|
|
1297
|
+
if (required)
|
|
1298
|
+
throw new TypeError(`Required option "${name}" (user) is missing.`);
|
|
1299
|
+
return null;
|
|
1300
|
+
}
|
|
1301
|
+
const userId = String(opt.value);
|
|
1302
|
+
const resolved = this.#lookup("users", userId) ?? null;
|
|
1303
|
+
if (!resolved && required)
|
|
1304
|
+
throw new TypeError(`Resolved user for option "${name}" is missing.`);
|
|
1305
|
+
return resolved;
|
|
1306
|
+
}
|
|
1307
|
+
getChannel(name, required = false) {
|
|
1308
|
+
const opt = this.#get(name);
|
|
1309
|
+
if (!opt || opt.type !== OptionType.Channel) {
|
|
1310
|
+
if (required)
|
|
1311
|
+
throw new TypeError(`Required option "${name}" (channel) is missing.`);
|
|
1312
|
+
return null;
|
|
1313
|
+
}
|
|
1314
|
+
const channelId = String(opt.value);
|
|
1315
|
+
const resolved = this.#lookup("channels", channelId) ?? null;
|
|
1316
|
+
if (!resolved && required)
|
|
1317
|
+
throw new TypeError(`Resolved channel for option "${name}" is missing.`);
|
|
1318
|
+
return resolved;
|
|
1319
|
+
}
|
|
1320
|
+
getRole(name, required = false) {
|
|
1321
|
+
const opt = this.#get(name);
|
|
1322
|
+
if (!opt || opt.type !== OptionType.Role) {
|
|
1323
|
+
if (required)
|
|
1324
|
+
throw new TypeError(`Required option "${name}" (role) is missing.`);
|
|
1325
|
+
return null;
|
|
1326
|
+
}
|
|
1327
|
+
const roleId = String(opt.value);
|
|
1328
|
+
const resolved = this.#lookup("roles", roleId) ?? null;
|
|
1329
|
+
if (!resolved && required)
|
|
1330
|
+
throw new TypeError(`Resolved role for option "${name}" is missing.`);
|
|
1331
|
+
return resolved;
|
|
1332
|
+
}
|
|
1333
|
+
getMentionable(name, required = false) {
|
|
1334
|
+
const opt = this.#get(name);
|
|
1335
|
+
if (!opt || opt.type !== OptionType.Mentionable) {
|
|
1336
|
+
if (required)
|
|
1337
|
+
throw new TypeError(`Required option "${name}" (mentionable) is missing.`);
|
|
1338
|
+
return null;
|
|
1339
|
+
}
|
|
1340
|
+
const id = String(opt.value);
|
|
1341
|
+
const resolved = this.#lookup("users", id) ?? this.#lookup("roles", id) ?? null;
|
|
1342
|
+
if (!resolved && required)
|
|
1343
|
+
throw new TypeError(`Resolved mentionable for option "${name}" is missing.`);
|
|
1344
|
+
return resolved;
|
|
1345
|
+
}
|
|
1346
|
+
getMentionableType(name) {
|
|
1347
|
+
const opt = this.#get(name);
|
|
1348
|
+
if (!opt || opt.type !== OptionType.Mentionable)
|
|
1349
|
+
return null;
|
|
1350
|
+
const id = String(opt.value);
|
|
1351
|
+
if (this.#lookup("users", id))
|
|
1352
|
+
return "user";
|
|
1353
|
+
if (this.#lookup("roles", id))
|
|
1354
|
+
return "role";
|
|
1355
|
+
return null;
|
|
1356
|
+
}
|
|
1357
|
+
getAttachment(name, required = false) {
|
|
1358
|
+
const opt = this.#get(name);
|
|
1359
|
+
if (!opt || opt.type !== OptionType.Attachment) {
|
|
1360
|
+
if (required)
|
|
1361
|
+
throw new TypeError(`Required option "${name}" (attachment) is missing.`);
|
|
1362
|
+
return null;
|
|
1363
|
+
}
|
|
1364
|
+
const attachmentId = String(opt.value);
|
|
1365
|
+
const resolved = this.#lookup("attachments", attachmentId) ?? null;
|
|
1366
|
+
if (!resolved && required)
|
|
1367
|
+
throw new TypeError(`Resolved attachment for option "${name}" is missing.`);
|
|
1368
|
+
return resolved;
|
|
1369
|
+
}
|
|
1370
|
+
get raw() {
|
|
1371
|
+
return this.#options;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
// packages/structures/src/interactions.ts
|
|
1375
|
+
var InteractionEnum2 = {
|
|
1376
|
+
Ping: 1,
|
|
1377
|
+
ApplicationCommand: 2,
|
|
1378
|
+
MessageComponent: 3,
|
|
1379
|
+
ApplicationCommandAutocomplete: 4,
|
|
1380
|
+
ModalSubmit: 5
|
|
1381
|
+
};
|
|
1382
|
+
var EPHEMERAL = 64;
|
|
1383
|
+
var COMMAND_CHAT_INPUT = 1;
|
|
1384
|
+
var COMMAND_USER = 2;
|
|
1385
|
+
var COMMAND_MESSAGE = 3;
|
|
1386
|
+
var TOKEN_LIFETIME_MS = 15 * 60000;
|
|
1387
|
+
var DISCORD_EPOCH = 1420070400000n;
|
|
1388
|
+
function splitWithResponse(options) {
|
|
1389
|
+
if (typeof options === "string")
|
|
1390
|
+
return { withResponse: false, rest: options };
|
|
1391
|
+
const { withResponse, ...rest } = options;
|
|
1392
|
+
return { withResponse: withResponse === true, rest };
|
|
1393
|
+
}
|
|
1394
|
+
function toMessageData(options) {
|
|
1395
|
+
if (typeof options === "string")
|
|
1396
|
+
return { content: options };
|
|
1397
|
+
const { ephemeral, ...data } = options;
|
|
1398
|
+
if (ephemeral)
|
|
1399
|
+
data.flags = (typeof data.flags === "number" ? data.flags : 0) | EPHEMERAL;
|
|
1400
|
+
return data;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
class InteractionResponse2 {
|
|
1404
|
+
type;
|
|
1405
|
+
data;
|
|
1406
|
+
withResponse = false;
|
|
1407
|
+
constructor(type, data) {
|
|
1408
|
+
if (!Number.isFinite(type))
|
|
1409
|
+
throw new TypeError("Interaction response type must be finite.");
|
|
1410
|
+
this.type = type;
|
|
1411
|
+
this.data = data;
|
|
1412
|
+
}
|
|
1413
|
+
toJSON() {
|
|
1414
|
+
return this.data === undefined ? { type: this.type } : { type: this.type, data: this.data };
|
|
1415
|
+
}
|
|
1416
|
+
static message(options) {
|
|
1417
|
+
return new InteractionResponse2(InteractionResponseEnum2.ChannelMessage, toMessageData(options));
|
|
1418
|
+
}
|
|
1419
|
+
static defer(ephemeral = false) {
|
|
1420
|
+
return new InteractionResponse2(InteractionResponseEnum2.DeferredChannelMessage, ephemeral ? { flags: EPHEMERAL } : undefined);
|
|
1421
|
+
}
|
|
1422
|
+
static pong() {
|
|
1423
|
+
return new InteractionResponse2(InteractionResponseEnum2.Pong);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
class Interaction2 {
|
|
1428
|
+
id;
|
|
1429
|
+
applicationId;
|
|
1430
|
+
token;
|
|
1431
|
+
guildId;
|
|
1432
|
+
channelId;
|
|
1433
|
+
type;
|
|
1434
|
+
data;
|
|
1435
|
+
replied = false;
|
|
1436
|
+
deferred = false;
|
|
1437
|
+
#client;
|
|
1438
|
+
#acknowledging = false;
|
|
1439
|
+
#responseType;
|
|
1440
|
+
constructor(client, data) {
|
|
1441
|
+
if (!data.id || !data.token)
|
|
1442
|
+
throw new TypeError("Interaction ID and token are required.");
|
|
1443
|
+
this.#client = client;
|
|
1444
|
+
this.id = data.id;
|
|
1445
|
+
this.applicationId = data.application_id;
|
|
1446
|
+
this.token = data.token;
|
|
1447
|
+
this.guildId = data.guild_id;
|
|
1448
|
+
this.channelId = data.channel_id;
|
|
1449
|
+
this.type = data.type;
|
|
1450
|
+
this.data = data;
|
|
1451
|
+
}
|
|
1452
|
+
get entitlements() {
|
|
1453
|
+
const entitlements = this.data.entitlements;
|
|
1454
|
+
return Array.isArray(entitlements) ? entitlements : [];
|
|
1455
|
+
}
|
|
1456
|
+
hasEntitlement(skuId) {
|
|
1457
|
+
const now = Date.now();
|
|
1458
|
+
return this.entitlements.some((entitlement) => entitlement.sku_id === skuId && !entitlement.deleted && (!entitlement.ends_at || Date.parse(entitlement.ends_at) > now));
|
|
1459
|
+
}
|
|
1460
|
+
#commandType() {
|
|
1461
|
+
if (this.type !== InteractionEnum2.ApplicationCommand)
|
|
1462
|
+
return 0;
|
|
1463
|
+
const type = this.data.data?.type;
|
|
1464
|
+
return typeof type === "number" ? type : COMMAND_CHAT_INPUT;
|
|
1465
|
+
}
|
|
1466
|
+
isCommand() {
|
|
1467
|
+
return this.type === InteractionEnum2.ApplicationCommand;
|
|
1468
|
+
}
|
|
1469
|
+
isChatInputCommand() {
|
|
1470
|
+
return this.#commandType() === COMMAND_CHAT_INPUT;
|
|
1471
|
+
}
|
|
1472
|
+
isContextMenuCommand() {
|
|
1473
|
+
const type = this.#commandType();
|
|
1474
|
+
return type === COMMAND_USER || type === COMMAND_MESSAGE;
|
|
1475
|
+
}
|
|
1476
|
+
isUserContextMenuCommand() {
|
|
1477
|
+
return this.#commandType() === COMMAND_USER;
|
|
1478
|
+
}
|
|
1479
|
+
isMessageContextMenuCommand() {
|
|
1480
|
+
return this.#commandType() === COMMAND_MESSAGE;
|
|
1481
|
+
}
|
|
1482
|
+
get resourceContext() {
|
|
1483
|
+
return this.#client.resourceContext;
|
|
1484
|
+
}
|
|
1485
|
+
awaitModalSubmit(options) {
|
|
1486
|
+
const collect = this.#client.resourceContext?.collectInteractions;
|
|
1487
|
+
if (!collect)
|
|
1488
|
+
return Promise.reject(new Error("This interaction is not attached to a client."));
|
|
1489
|
+
if (!(options.time > 0))
|
|
1490
|
+
return Promise.reject(new RangeError("awaitModalSubmit needs a positive time."));
|
|
1491
|
+
const userId = this.user?.id;
|
|
1492
|
+
const collector = collect({
|
|
1493
|
+
time: options.time,
|
|
1494
|
+
max: 1,
|
|
1495
|
+
filter: async (interaction) => interaction.isModalSubmit() && interaction.user?.id === userId && (options.customId === undefined || interaction.customId === options.customId) && (options.filter ? await options.filter(interaction) : true)
|
|
1496
|
+
});
|
|
1497
|
+
return collector.next();
|
|
1498
|
+
}
|
|
1499
|
+
isMessageComponent() {
|
|
1500
|
+
return this.type === InteractionEnum2.MessageComponent;
|
|
1501
|
+
}
|
|
1502
|
+
isModalSubmit() {
|
|
1503
|
+
return this.type === InteractionEnum2.ModalSubmit;
|
|
1504
|
+
}
|
|
1505
|
+
isAutocomplete() {
|
|
1506
|
+
return this.type === InteractionEnum2.ApplicationCommandAutocomplete;
|
|
1507
|
+
}
|
|
1508
|
+
#componentType() {
|
|
1509
|
+
return this.isMessageComponent() ? this.data.data?.component_type ?? 0 : 0;
|
|
1510
|
+
}
|
|
1511
|
+
isButton() {
|
|
1512
|
+
return this.#componentType() === 2;
|
|
1513
|
+
}
|
|
1514
|
+
isStringSelectMenu() {
|
|
1515
|
+
return this.#componentType() === 3;
|
|
1516
|
+
}
|
|
1517
|
+
isUserSelectMenu() {
|
|
1518
|
+
return this.#componentType() === 5;
|
|
1519
|
+
}
|
|
1520
|
+
isRoleSelectMenu() {
|
|
1521
|
+
return this.#componentType() === 6;
|
|
1522
|
+
}
|
|
1523
|
+
isMentionableSelectMenu() {
|
|
1524
|
+
return this.#componentType() === 7;
|
|
1525
|
+
}
|
|
1526
|
+
isChannelSelectMenu() {
|
|
1527
|
+
return this.#componentType() === 8;
|
|
1528
|
+
}
|
|
1529
|
+
isAnySelectMenu() {
|
|
1530
|
+
return [3, 5, 6, 7, 8].includes(this.#componentType());
|
|
1531
|
+
}
|
|
1532
|
+
assertUnacknowledged() {
|
|
1533
|
+
if (this.replied || this.deferred || this.#acknowledging)
|
|
1534
|
+
throw new Error("Interaction has already been acknowledged.");
|
|
1535
|
+
}
|
|
1536
|
+
async acknowledge(response, state) {
|
|
1537
|
+
this.assertUnacknowledged();
|
|
1538
|
+
this.#acknowledging = true;
|
|
1539
|
+
try {
|
|
1540
|
+
const result = await this.postResponse(response);
|
|
1541
|
+
this[state] = true;
|
|
1542
|
+
this.#responseType = response.type;
|
|
1543
|
+
return result;
|
|
1544
|
+
} catch (error) {
|
|
1545
|
+
if (error?.code === 40060) {
|
|
1546
|
+
this[state] = true;
|
|
1547
|
+
this.#responseType = response.type;
|
|
1548
|
+
}
|
|
1549
|
+
throw error;
|
|
1550
|
+
} finally {
|
|
1551
|
+
this.#acknowledging = false;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
get user() {
|
|
1555
|
+
const raw = this.data.member?.user ?? this.data.user;
|
|
1556
|
+
return raw ? new User2(raw) : null;
|
|
1557
|
+
}
|
|
1558
|
+
get member() {
|
|
1559
|
+
const raw = this.data.member;
|
|
1560
|
+
if (!raw || !this.guildId)
|
|
1561
|
+
return null;
|
|
1562
|
+
return new GuildMember2({
|
|
1563
|
+
...raw,
|
|
1564
|
+
guild_id: this.guildId
|
|
1565
|
+
}, this.#client.resourceContext);
|
|
1566
|
+
}
|
|
1567
|
+
get createdTimestamp() {
|
|
1568
|
+
return Number((BigInt(this.id) >> 22n) + DISCORD_EPOCH);
|
|
1569
|
+
}
|
|
1570
|
+
get expiresAt() {
|
|
1571
|
+
return new Date(this.createdTimestamp + TOKEN_LIFETIME_MS);
|
|
1572
|
+
}
|
|
1573
|
+
get isExpired() {
|
|
1574
|
+
return Date.now() >= this.createdTimestamp + TOKEN_LIFETIME_MS;
|
|
1575
|
+
}
|
|
1576
|
+
#webhookMessage(method, messageId, data) {
|
|
1577
|
+
if (!this.#client.interactionWebhookMessage)
|
|
1578
|
+
return Promise.reject(new Error("This interaction client does not support webhook message access."));
|
|
1579
|
+
return this.#client.interactionWebhookMessage(method, this.applicationId, this.token, messageId, data);
|
|
1580
|
+
}
|
|
1581
|
+
fetchReply() {
|
|
1582
|
+
this.assertHasReply();
|
|
1583
|
+
return this.#webhookMessage("GET", "@original");
|
|
1584
|
+
}
|
|
1585
|
+
editFollowUp(messageId, options) {
|
|
1586
|
+
return this.#webhookMessage("PATCH", messageId, toMessageData(options));
|
|
1587
|
+
}
|
|
1588
|
+
async deleteFollowUp(messageId) {
|
|
1589
|
+
await this.#webhookMessage("DELETE", messageId);
|
|
1590
|
+
}
|
|
1591
|
+
assertAcknowledged() {
|
|
1592
|
+
if (!this.replied && !this.deferred)
|
|
1593
|
+
throw new Error("Interaction has not been acknowledged.");
|
|
1594
|
+
}
|
|
1595
|
+
assertHasReply() {
|
|
1596
|
+
this.assertAcknowledged();
|
|
1597
|
+
if (this.#responseType === InteractionResponseEnum2.Modal || this.#responseType === InteractionResponseEnum2.Autocomplete)
|
|
1598
|
+
throw new Error("Interaction was answered with a modal or autocomplete choices and has no reply message.");
|
|
1599
|
+
}
|
|
1600
|
+
postResponse(response) {
|
|
1601
|
+
return this.#client.postInteractionResponse(this.id, this.token, response);
|
|
1602
|
+
}
|
|
1603
|
+
async acknowledgeWith(response, state, withResponse) {
|
|
1604
|
+
response.withResponse = withResponse;
|
|
1605
|
+
const result = await this.acknowledge(response, state);
|
|
1606
|
+
if (!withResponse)
|
|
1607
|
+
return result;
|
|
1608
|
+
const message = result?.resource?.message;
|
|
1609
|
+
return message ? new Message2(message, this.#client.resourceContext) : null;
|
|
1610
|
+
}
|
|
1611
|
+
async reply(options) {
|
|
1612
|
+
const { withResponse, rest } = splitWithResponse(options);
|
|
1613
|
+
return this.acknowledgeWith(InteractionResponse2.message(toMessageData(rest)), "replied", withResponse);
|
|
1614
|
+
}
|
|
1615
|
+
async deferReply(options = false) {
|
|
1616
|
+
const ephemeral = typeof options === "boolean" ? options : options.ephemeral === true;
|
|
1617
|
+
const withResponse = typeof options === "object" && options.withResponse === true;
|
|
1618
|
+
const result = await this.acknowledgeWith(InteractionResponse2.defer(ephemeral), "deferred", withResponse);
|
|
1619
|
+
if (withResponse)
|
|
1620
|
+
return result;
|
|
1621
|
+
}
|
|
1622
|
+
editReply(options) {
|
|
1623
|
+
this.assertHasReply();
|
|
1624
|
+
return this.#client.editInteractionReply(this.token, toMessageData(options), this.applicationId);
|
|
1625
|
+
}
|
|
1626
|
+
deleteReply() {
|
|
1627
|
+
this.assertHasReply();
|
|
1628
|
+
return this.#client.deleteInteractionReply(this.token, this.applicationId);
|
|
1629
|
+
}
|
|
1630
|
+
followUp(options) {
|
|
1631
|
+
this.assertAcknowledged();
|
|
1632
|
+
return this.#client.followUpInteraction(this.token, toMessageData(options), this.applicationId);
|
|
1633
|
+
}
|
|
1634
|
+
async update(options) {
|
|
1635
|
+
this.assertOnMessage("update");
|
|
1636
|
+
const { withResponse, rest } = splitWithResponse(options);
|
|
1637
|
+
return this.acknowledgeWith(new InteractionResponse2(InteractionResponseEnum2.MessageUpdate, toMessageData(rest)), "replied", withResponse);
|
|
1638
|
+
}
|
|
1639
|
+
assertOnMessage(method) {
|
|
1640
|
+
if (this.type === InteractionEnum2.MessageComponent || this.type === InteractionEnum2.ModalSubmit && this.data.message)
|
|
1641
|
+
return;
|
|
1642
|
+
throw new Error(`Interaction ${method}() only works on component interactions and modals opened from a component; use reply() instead.`);
|
|
1643
|
+
}
|
|
1644
|
+
async showModal(modal) {
|
|
1645
|
+
const data = "toJSON" in modal && typeof modal.toJSON === "function" ? modal.toJSON() : modal;
|
|
1646
|
+
return this.acknowledge(new InteractionResponse2(InteractionResponseEnum2.Modal, data), "replied");
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
class CommandInteraction2 extends Interaction2 {
|
|
1651
|
+
options;
|
|
1652
|
+
get commandName() {
|
|
1653
|
+
return typeof this.data.data?.name === "string" ? this.data.data.name : "";
|
|
1654
|
+
}
|
|
1655
|
+
constructor(client, data) {
|
|
1656
|
+
super(client, data);
|
|
1657
|
+
const rawOptions = data.data?.options ?? [];
|
|
1658
|
+
const resolved = data.data?.resolved ?? {};
|
|
1659
|
+
this.options = new CommandOptions2(rawOptions, resolved);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
class ContextMenuCommandInteraction2 extends CommandInteraction2 {
|
|
1664
|
+
#resolved() {
|
|
1665
|
+
return this.data.data?.resolved ?? {};
|
|
1666
|
+
}
|
|
1667
|
+
get targetId() {
|
|
1668
|
+
const id = this.data.data?.target_id;
|
|
1669
|
+
return typeof id === "string" ? id : null;
|
|
1670
|
+
}
|
|
1671
|
+
get targetUser() {
|
|
1672
|
+
const id = this.targetId;
|
|
1673
|
+
const raw = id ? this.#resolved().users?.[id] : undefined;
|
|
1674
|
+
return raw ? new User2(raw) : null;
|
|
1675
|
+
}
|
|
1676
|
+
get targetMember() {
|
|
1677
|
+
const id = this.targetId;
|
|
1678
|
+
const raw = id ? this.#resolved().members?.[id] : undefined;
|
|
1679
|
+
const user = id ? this.#resolved().users?.[id] : undefined;
|
|
1680
|
+
if (!raw || !user || !this.guildId)
|
|
1681
|
+
return null;
|
|
1682
|
+
return new GuildMember2({
|
|
1683
|
+
...raw,
|
|
1684
|
+
user,
|
|
1685
|
+
guild_id: this.guildId
|
|
1686
|
+
}, this.resourceContext);
|
|
1687
|
+
}
|
|
1688
|
+
get targetMessage() {
|
|
1689
|
+
const id = this.targetId;
|
|
1690
|
+
const raw = id ? this.#resolved().messages?.[id] : undefined;
|
|
1691
|
+
return raw ? new Message2(raw, this.resourceContext) : null;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
class ComponentInteraction2 extends Interaction2 {
|
|
1696
|
+
get customId() {
|
|
1697
|
+
const id = this.data.data?.custom_id;
|
|
1698
|
+
return typeof id === "string" ? id : "";
|
|
1699
|
+
}
|
|
1700
|
+
get messageId() {
|
|
1701
|
+
return this.data.message?.id;
|
|
1702
|
+
}
|
|
1703
|
+
get componentType() {
|
|
1704
|
+
const type = this.data.data?.component_type;
|
|
1705
|
+
return typeof type === "number" ? type : 0;
|
|
1706
|
+
}
|
|
1707
|
+
get values() {
|
|
1708
|
+
const values = this.data.data?.values;
|
|
1709
|
+
return Array.isArray(values) ? values : [];
|
|
1710
|
+
}
|
|
1711
|
+
async deferUpdate(options = {}) {
|
|
1712
|
+
this.assertOnMessage("deferUpdate");
|
|
1713
|
+
const withResponse = options.withResponse === true;
|
|
1714
|
+
const result = await this.acknowledgeWith(new InteractionResponse2(InteractionResponseEnum2.DeferredMessageUpdate), "deferred", withResponse);
|
|
1715
|
+
if (withResponse)
|
|
1716
|
+
return result;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
class ModalSubmitInteraction2 extends Interaction2 {
|
|
1721
|
+
get customId() {
|
|
1722
|
+
const id = this.data.data?.custom_id;
|
|
1723
|
+
return typeof id === "string" ? id : "";
|
|
1724
|
+
}
|
|
1725
|
+
getInputValue(customId) {
|
|
1726
|
+
const rows = this.data.data?.components ?? [];
|
|
1727
|
+
for (const row of rows) {
|
|
1728
|
+
for (const comp of row.components ?? []) {
|
|
1729
|
+
if (comp.custom_id === customId)
|
|
1730
|
+
return comp.value;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
getRequiredInputValue(customId) {
|
|
1736
|
+
const value = this.getInputValue(customId);
|
|
1737
|
+
if (value === undefined)
|
|
1738
|
+
throw new TypeError(`Modal input "${customId}" was not found in the submission.`);
|
|
1739
|
+
return value;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
class AutocompleteInteraction2 extends Interaction2 {
|
|
1744
|
+
options;
|
|
1745
|
+
constructor(client, data) {
|
|
1746
|
+
super(client, data);
|
|
1747
|
+
this.options = new CommandOptions2(data.data?.options ?? []);
|
|
1748
|
+
}
|
|
1749
|
+
get commandName() {
|
|
1750
|
+
const name = this.data.data?.name;
|
|
1751
|
+
return typeof name === "string" ? name : "";
|
|
1752
|
+
}
|
|
1753
|
+
get focusedOption() {
|
|
1754
|
+
const options = this.data.data?.options;
|
|
1755
|
+
return findFocused(Array.isArray(options) ? options : []);
|
|
1756
|
+
}
|
|
1757
|
+
async respond(choices) {
|
|
1758
|
+
if (!Array.isArray(choices))
|
|
1759
|
+
throw new TypeError("Autocomplete choices must be an array.");
|
|
1760
|
+
const response = new InteractionResponse2(InteractionResponseEnum2.Autocomplete, { choices });
|
|
1761
|
+
await this.acknowledge(response, "replied");
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
function findFocused(options) {
|
|
1765
|
+
for (const opt of options) {
|
|
1766
|
+
if (opt.focused)
|
|
1767
|
+
return { name: opt.name, value: opt.value, type: opt.type };
|
|
1768
|
+
if (Array.isArray(opt.options)) {
|
|
1769
|
+
const found = findFocused(opt.options);
|
|
1770
|
+
if (found)
|
|
1771
|
+
return found;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
function createInteraction2(client, data) {
|
|
1777
|
+
switch (data.type) {
|
|
1778
|
+
case InteractionEnum2.ApplicationCommand: {
|
|
1779
|
+
const commandType = data.data?.type;
|
|
1780
|
+
return commandType === COMMAND_USER || commandType === COMMAND_MESSAGE ? new ContextMenuCommandInteraction2(client, data) : new CommandInteraction2(client, data);
|
|
1781
|
+
}
|
|
1782
|
+
case InteractionEnum2.ApplicationCommandAutocomplete:
|
|
1783
|
+
return new AutocompleteInteraction2(client, data);
|
|
1784
|
+
case InteractionEnum2.MessageComponent:
|
|
1785
|
+
return new ComponentInteraction2(client, data);
|
|
1786
|
+
case InteractionEnum2.ModalSubmit:
|
|
1787
|
+
return new ModalSubmitInteraction2(client, data);
|
|
1788
|
+
default:
|
|
1789
|
+
return new Interaction2(client, data);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
// packages/structures/src/embed.ts
|
|
1793
|
+
class Embed2 {
|
|
1794
|
+
#data;
|
|
1795
|
+
constructor(data = {}) {
|
|
1796
|
+
this.#data = { ...data };
|
|
1797
|
+
if (this.#data.fields)
|
|
1798
|
+
this.#data.fields = [...this.#data.fields];
|
|
1799
|
+
}
|
|
1800
|
+
get title() {
|
|
1801
|
+
return this.#data.title;
|
|
1802
|
+
}
|
|
1803
|
+
get description() {
|
|
1804
|
+
return this.#data.description;
|
|
1805
|
+
}
|
|
1806
|
+
get url() {
|
|
1807
|
+
return this.#data.url;
|
|
1808
|
+
}
|
|
1809
|
+
get color() {
|
|
1810
|
+
return this.#data.color;
|
|
1811
|
+
}
|
|
1812
|
+
get timestamp() {
|
|
1813
|
+
return this.#data.timestamp;
|
|
1814
|
+
}
|
|
1815
|
+
get createdAt() {
|
|
1816
|
+
return this.#data.timestamp ? new Date(this.#data.timestamp) : undefined;
|
|
1817
|
+
}
|
|
1818
|
+
get footer() {
|
|
1819
|
+
return this.#data.footer;
|
|
1820
|
+
}
|
|
1821
|
+
get image() {
|
|
1822
|
+
return this.#data.image;
|
|
1823
|
+
}
|
|
1824
|
+
get thumbnail() {
|
|
1825
|
+
return this.#data.thumbnail;
|
|
1826
|
+
}
|
|
1827
|
+
get video() {
|
|
1828
|
+
return this.#data.video;
|
|
1829
|
+
}
|
|
1830
|
+
get author() {
|
|
1831
|
+
return this.#data.author;
|
|
1832
|
+
}
|
|
1833
|
+
get fields() {
|
|
1834
|
+
return this.#data.fields ?? [];
|
|
1835
|
+
}
|
|
1836
|
+
setTitle(title) {
|
|
1837
|
+
if (title.length > 256)
|
|
1838
|
+
throw new TypeError("Embed title must not exceed 256 characters.");
|
|
1839
|
+
this.#data.title = title;
|
|
1840
|
+
return this;
|
|
1841
|
+
}
|
|
1842
|
+
setDescription(description) {
|
|
1843
|
+
if (description.length > 4096)
|
|
1844
|
+
throw new TypeError("Embed description must not exceed 4096 characters.");
|
|
1845
|
+
this.#data.description = description;
|
|
1846
|
+
return this;
|
|
1847
|
+
}
|
|
1848
|
+
setURL(url) {
|
|
1849
|
+
this.#data.url = url;
|
|
1850
|
+
return this;
|
|
1851
|
+
}
|
|
1852
|
+
setColor(color) {
|
|
1853
|
+
if (typeof color === "string") {
|
|
1854
|
+
const hex = color.replace(/^#/, "");
|
|
1855
|
+
this.#data.color = parseInt(hex, 16);
|
|
1856
|
+
} else {
|
|
1857
|
+
this.#data.color = color;
|
|
1858
|
+
}
|
|
1859
|
+
return this;
|
|
1860
|
+
}
|
|
1861
|
+
setTimestamp(timestamp = Date.now()) {
|
|
1862
|
+
this.#data.timestamp = new Date(timestamp).toISOString();
|
|
1863
|
+
return this;
|
|
1864
|
+
}
|
|
1865
|
+
setFooter(text, iconURL) {
|
|
1866
|
+
if (text.length > 2048)
|
|
1867
|
+
throw new TypeError("Embed footer text must not exceed 2048 characters.");
|
|
1868
|
+
this.#data.footer = iconURL ? { text, icon_url: iconURL } : { text };
|
|
1869
|
+
return this;
|
|
1870
|
+
}
|
|
1871
|
+
setImage(url) {
|
|
1872
|
+
this.#data.image = { url };
|
|
1873
|
+
return this;
|
|
1874
|
+
}
|
|
1875
|
+
setThumbnail(url) {
|
|
1876
|
+
this.#data.thumbnail = { url };
|
|
1877
|
+
return this;
|
|
1878
|
+
}
|
|
1879
|
+
setAuthor(name, options = {}) {
|
|
1880
|
+
if (name.length > 256)
|
|
1881
|
+
throw new TypeError("Embed author name must not exceed 256 characters.");
|
|
1882
|
+
this.#data.author = {
|
|
1883
|
+
name,
|
|
1884
|
+
url: options.url,
|
|
1885
|
+
icon_url: options.iconURL
|
|
1886
|
+
};
|
|
1887
|
+
return this;
|
|
1888
|
+
}
|
|
1889
|
+
addFields(...fields) {
|
|
1890
|
+
const existing = this.#data.fields ?? [];
|
|
1891
|
+
if (existing.length + fields.length > 25)
|
|
1892
|
+
throw new TypeError("Embeds cannot have more than 25 fields.");
|
|
1893
|
+
for (const field of fields) {
|
|
1894
|
+
if (field.name.length > 256)
|
|
1895
|
+
throw new TypeError("Embed field name must not exceed 256 characters.");
|
|
1896
|
+
if (field.value.length > 1024)
|
|
1897
|
+
throw new TypeError("Embed field value must not exceed 1024 characters.");
|
|
1898
|
+
}
|
|
1899
|
+
this.#data.fields = [...existing, ...fields];
|
|
1900
|
+
return this;
|
|
1901
|
+
}
|
|
1902
|
+
clearFields() {
|
|
1903
|
+
this.#data.fields = [];
|
|
1904
|
+
return this;
|
|
1905
|
+
}
|
|
1906
|
+
spliceFields(index, deleteCount, ...fields) {
|
|
1907
|
+
const next = [...this.#data.fields ?? []];
|
|
1908
|
+
next.splice(index, deleteCount, ...fields);
|
|
1909
|
+
if (next.length > 25)
|
|
1910
|
+
throw new TypeError("Embeds cannot have more than 25 fields.");
|
|
1911
|
+
for (const field of fields) {
|
|
1912
|
+
if (field.name.length > 256)
|
|
1913
|
+
throw new TypeError("Embed field name must not exceed 256 characters.");
|
|
1914
|
+
if (field.value.length > 1024)
|
|
1915
|
+
throw new TypeError("Embed field value must not exceed 1024 characters.");
|
|
1916
|
+
}
|
|
1917
|
+
this.#data.fields = next;
|
|
1918
|
+
return this;
|
|
1919
|
+
}
|
|
1920
|
+
toJSON() {
|
|
1921
|
+
const json = { ...this.#data };
|
|
1922
|
+
if (json.fields)
|
|
1923
|
+
json.fields = [...json.fields];
|
|
1924
|
+
return json;
|
|
1925
|
+
}
|
|
1926
|
+
static from(data) {
|
|
1927
|
+
return new Embed2(data);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
// packages/structures/src/audit-log.ts
|
|
1931
|
+
function int(value) {
|
|
1932
|
+
return Number(value ?? 0);
|
|
1933
|
+
}
|
|
1934
|
+
function parseInfo(type, options) {
|
|
1935
|
+
if (!options)
|
|
1936
|
+
return;
|
|
1937
|
+
switch (type) {
|
|
1938
|
+
case 13:
|
|
1939
|
+
case 14:
|
|
1940
|
+
case 15:
|
|
1941
|
+
return {
|
|
1942
|
+
id: options.id ?? "",
|
|
1943
|
+
type: int(options.type),
|
|
1944
|
+
roleName: options.role_name
|
|
1945
|
+
};
|
|
1946
|
+
case 21:
|
|
1947
|
+
return {
|
|
1948
|
+
deleteMemberDays: int(options.delete_member_days),
|
|
1949
|
+
membersRemoved: int(options.members_removed)
|
|
1950
|
+
};
|
|
1951
|
+
case 26:
|
|
1952
|
+
case 72:
|
|
1953
|
+
return {
|
|
1954
|
+
channelId: options.channel_id ?? "",
|
|
1955
|
+
count: int(options.count)
|
|
1956
|
+
};
|
|
1957
|
+
case 27:
|
|
1958
|
+
case 73:
|
|
1959
|
+
return { count: int(options.count) };
|
|
1960
|
+
case 74:
|
|
1961
|
+
case 75:
|
|
1962
|
+
return {
|
|
1963
|
+
channelId: options.channel_id ?? "",
|
|
1964
|
+
messageId: options.message_id ?? ""
|
|
1965
|
+
};
|
|
1966
|
+
case 83:
|
|
1967
|
+
case 84:
|
|
1968
|
+
case 85:
|
|
1969
|
+
return { channelId: options.channel_id ?? "" };
|
|
1970
|
+
case 121:
|
|
1971
|
+
return { applicationId: options.app_id ?? "" };
|
|
1972
|
+
case 143:
|
|
1973
|
+
case 144:
|
|
1974
|
+
case 145:
|
|
1975
|
+
return {
|
|
1976
|
+
ruleName: options.auto_moderation_rule_name ?? "",
|
|
1977
|
+
ruleTriggerType: int(options.auto_moderation_rule_trigger_type),
|
|
1978
|
+
channelId: options.channel_id
|
|
1979
|
+
};
|
|
1980
|
+
default:
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
class AuditLogEntry2 extends BaseStructure2 {
|
|
1986
|
+
targetId;
|
|
1987
|
+
userId;
|
|
1988
|
+
actionType;
|
|
1989
|
+
changes;
|
|
1990
|
+
options;
|
|
1991
|
+
info;
|
|
1992
|
+
reason;
|
|
1993
|
+
constructor(data) {
|
|
1994
|
+
super(data.id);
|
|
1995
|
+
this.targetId = data.target_id;
|
|
1996
|
+
this.userId = data.user_id;
|
|
1997
|
+
this.actionType = data.action_type;
|
|
1998
|
+
this.info = parseInfo(data.action_type, data.options);
|
|
1999
|
+
this.changes = data.changes ?? [];
|
|
2000
|
+
this.options = data.options ?? null;
|
|
2001
|
+
this.reason = data.reason ?? null;
|
|
2002
|
+
}
|
|
2003
|
+
is(type) {
|
|
2004
|
+
return this.actionType === type;
|
|
2005
|
+
}
|
|
2006
|
+
change(key) {
|
|
2007
|
+
const found = this.changes.find((change) => change.key === key);
|
|
2008
|
+
return found && { old: found.old_value, new: found.new_value };
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
class AuditLog2 {
|
|
2013
|
+
entries;
|
|
2014
|
+
constructor(data) {
|
|
2015
|
+
this.entries = new Map;
|
|
2016
|
+
for (const entryData of data.audit_log_entries) {
|
|
2017
|
+
this.entries.set(entryData.id, new AuditLogEntry2(entryData));
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
filter(query) {
|
|
2021
|
+
const types = query.type === undefined ? undefined : Array.isArray(query.type) ? query.type : [query.type];
|
|
2022
|
+
const since = query.since === undefined ? undefined : new Date(query.since).getTime();
|
|
2023
|
+
const matches = [];
|
|
2024
|
+
for (const entry of this.entries.values()) {
|
|
2025
|
+
if (types && !types.includes(entry.actionType))
|
|
2026
|
+
continue;
|
|
2027
|
+
if (query.targetId !== undefined && entry.targetId !== query.targetId)
|
|
2028
|
+
continue;
|
|
2029
|
+
if (query.userId !== undefined && entry.userId !== query.userId)
|
|
2030
|
+
continue;
|
|
2031
|
+
if (since !== undefined && entry.createdAt.getTime() < since)
|
|
2032
|
+
continue;
|
|
2033
|
+
matches.push(entry);
|
|
2034
|
+
}
|
|
2035
|
+
return matches;
|
|
2036
|
+
}
|
|
2037
|
+
find(query) {
|
|
2038
|
+
return this.filter(query)[0];
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
// packages/structures/src/sticker.ts
|
|
2042
|
+
function stickerURL2(id, format, options = {}) {
|
|
2043
|
+
const size = options.size === undefined ? "" : `?size=${options.size}`;
|
|
2044
|
+
if (format === StickerFormatEnum2.Lottie)
|
|
2045
|
+
return `https://cdn.discordapp.com/stickers/${id}.json`;
|
|
2046
|
+
if (format === StickerFormatEnum2.GIF)
|
|
2047
|
+
return `https://media.discordapp.net/stickers/${id}.gif${size}`;
|
|
2048
|
+
return `https://cdn.discordapp.com/stickers/${id}.png${size}`;
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
class Sticker2 extends BaseStructure2 {
|
|
2052
|
+
name;
|
|
2053
|
+
description;
|
|
2054
|
+
tags;
|
|
2055
|
+
type;
|
|
2056
|
+
formatType;
|
|
2057
|
+
available;
|
|
2058
|
+
guildId;
|
|
2059
|
+
packId;
|
|
2060
|
+
sortValue;
|
|
2061
|
+
user;
|
|
2062
|
+
constructor(data) {
|
|
2063
|
+
super(data.id);
|
|
2064
|
+
this.name = data.name;
|
|
2065
|
+
this.description = data.description ?? null;
|
|
2066
|
+
this.tags = data.tags ?? "";
|
|
2067
|
+
this.type = data.type ?? 2;
|
|
2068
|
+
this.formatType = data.format_type;
|
|
2069
|
+
this.available = data.available ?? true;
|
|
2070
|
+
this.guildId = data.guild_id ?? null;
|
|
2071
|
+
this.packId = data.pack_id ?? null;
|
|
2072
|
+
this.sortValue = data.sort_value ?? null;
|
|
2073
|
+
this.user = data.user ?? null;
|
|
2074
|
+
}
|
|
2075
|
+
get animated() {
|
|
2076
|
+
return this.formatType !== StickerFormatEnum2.PNG;
|
|
2077
|
+
}
|
|
2078
|
+
url(options = {}) {
|
|
2079
|
+
return stickerURL2(this.id, this.formatType, options);
|
|
2080
|
+
}
|
|
2081
|
+
toItem() {
|
|
2082
|
+
return { id: this.id, name: this.name, format_type: this.formatType };
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
// packages/structures/src/index.ts
|
|
2087
|
+
var COMPONENT_COLLECTOR_DEFAULT_TIME = 15 * 60000;
|
|
2088
|
+
var NON_SYSTEM_MESSAGE_TYPES = new Set([0, 19, 20, 23]);
|
|
2089
|
+
|
|
2090
|
+
class Message2 extends BaseStructure2 {
|
|
2091
|
+
content;
|
|
2092
|
+
author;
|
|
2093
|
+
channelId;
|
|
2094
|
+
channel;
|
|
2095
|
+
guildId;
|
|
2096
|
+
flags;
|
|
2097
|
+
timestamp;
|
|
2098
|
+
attachments;
|
|
2099
|
+
embeds;
|
|
2100
|
+
mentions;
|
|
2101
|
+
mentionRoles;
|
|
2102
|
+
pinned;
|
|
2103
|
+
mentionEveryone;
|
|
2104
|
+
type;
|
|
2105
|
+
reference;
|
|
2106
|
+
components;
|
|
2107
|
+
referencedMessage;
|
|
2108
|
+
stickers;
|
|
2109
|
+
poll;
|
|
2110
|
+
messageSnapshots;
|
|
2111
|
+
member;
|
|
2112
|
+
#context;
|
|
2113
|
+
constructor(data, context) {
|
|
2114
|
+
super(data.id);
|
|
2115
|
+
if (!/^\d{1,20}$/.test(data.channel_id))
|
|
2116
|
+
throw new TypeError("Message channel_id must be a valid snowflake.");
|
|
2117
|
+
this.content = data.content ?? "";
|
|
2118
|
+
this.author = new User2(data.author);
|
|
2119
|
+
this.channelId = data.channel_id;
|
|
2120
|
+
this.guildId = data.guild_id;
|
|
2121
|
+
this.flags = data.flags ?? 0;
|
|
2122
|
+
this.timestamp = new Date(data.timestamp ?? Number((BigInt(this.id) >> 22n) + 1420070400000n));
|
|
2123
|
+
this.attachments = data.attachments ?? [];
|
|
2124
|
+
this.embeds = data.embeds ?? [];
|
|
2125
|
+
this.components = data.components ?? [];
|
|
2126
|
+
this.mentions = (data.mentions ?? []).map((user) => new User2(user));
|
|
2127
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
2128
|
+
this.pinned = data.pinned ?? false;
|
|
2129
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
2130
|
+
this.type = data.type ?? 0;
|
|
2131
|
+
this.reference = data.message_reference;
|
|
2132
|
+
this.stickers = data.sticker_items ?? (data.stickers ?? []).map(({ id, name, format_type }) => ({
|
|
2133
|
+
id,
|
|
2134
|
+
name,
|
|
2135
|
+
format_type
|
|
2136
|
+
}));
|
|
2137
|
+
this.poll = data.poll ?? null;
|
|
2138
|
+
this.messageSnapshots = data.message_snapshots ?? [];
|
|
2139
|
+
this.referencedMessage = data.referenced_message ? new Message2(data.referenced_message, context) : data.referenced_message === null ? null : undefined;
|
|
2140
|
+
this.#context = context;
|
|
2141
|
+
this.member = data.member && data.guild_id ? new GuildMember2({
|
|
2142
|
+
...data.member,
|
|
2143
|
+
user: data.member.user ?? data.author,
|
|
2144
|
+
guild_id: data.guild_id
|
|
2145
|
+
}, context) : null;
|
|
2146
|
+
this.channel = context?.cachedChannel?.(data.channel_id) ?? new Channel2({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context, { partial: true });
|
|
2147
|
+
}
|
|
2148
|
+
get embedsSuppressed() {
|
|
2149
|
+
return (this.flags & 4) !== 0;
|
|
2150
|
+
}
|
|
2151
|
+
get createdTimestamp() {
|
|
2152
|
+
return this.timestamp.getTime();
|
|
2153
|
+
}
|
|
2154
|
+
get createdAt() {
|
|
2155
|
+
return this.timestamp;
|
|
2156
|
+
}
|
|
2157
|
+
edit(options) {
|
|
2158
|
+
if (!this.#context)
|
|
2159
|
+
throw new Error("This message is not attached to a client.");
|
|
2160
|
+
return this.#context.editMessage(this.channelId, this.id, options);
|
|
2161
|
+
}
|
|
2162
|
+
update(options) {
|
|
2163
|
+
return this.edit(options);
|
|
2164
|
+
}
|
|
2165
|
+
delete(reason) {
|
|
2166
|
+
if (!this.#context)
|
|
2167
|
+
throw new Error("This message is not attached to a client.");
|
|
2168
|
+
return this.#context.deleteMessage(this.channelId, this.id, reason);
|
|
2169
|
+
}
|
|
2170
|
+
reply(options) {
|
|
2171
|
+
if (!this.#context)
|
|
2172
|
+
throw new Error("This message is not attached to a client.");
|
|
2173
|
+
const payload = typeof options === "string" ? { content: options } : { ...options };
|
|
2174
|
+
payload.message_reference = {
|
|
2175
|
+
message_id: this.id,
|
|
2176
|
+
channel_id: this.channelId,
|
|
2177
|
+
guild_id: this.guildId
|
|
2178
|
+
};
|
|
2179
|
+
return this.#context.sendMessage(this.channelId, payload);
|
|
2180
|
+
}
|
|
2181
|
+
crosspost() {
|
|
2182
|
+
if (!this.#context)
|
|
2183
|
+
throw new Error("This message is not attached to a client.");
|
|
2184
|
+
return this.#context.crosspostMessage(this.channelId, this.id);
|
|
2185
|
+
}
|
|
2186
|
+
createComponentCollector(options = {}) {
|
|
2187
|
+
const collect = this.#context?.collectInteractions;
|
|
2188
|
+
if (!collect)
|
|
2189
|
+
throw new Error("This message is not attached to a client.");
|
|
2190
|
+
const { componentType, filter, ...rest } = options;
|
|
2191
|
+
return collect({
|
|
2192
|
+
...rest,
|
|
2193
|
+
time: rest.time ?? (rest.idle ? undefined : COMPONENT_COLLECTOR_DEFAULT_TIME),
|
|
2194
|
+
filter: async (interaction) => interaction.isMessageComponent() && interaction.messageId === this.id && (componentType === undefined || interaction.componentType === componentType) && (filter ? await filter(interaction) : true)
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
awaitComponent(options = {}) {
|
|
2198
|
+
return this.createComponentCollector({ ...options, max: 1 }).next();
|
|
2199
|
+
}
|
|
2200
|
+
react(emoji) {
|
|
2201
|
+
if (!this.#context?.addReaction)
|
|
2202
|
+
throw new Error("This message is not attached to a client.");
|
|
2203
|
+
return this.#context.addReaction(this.channelId, this.id, emoji);
|
|
2204
|
+
}
|
|
2205
|
+
removeReaction(emoji, userId) {
|
|
2206
|
+
if (!this.#context)
|
|
2207
|
+
throw new Error("This message is not attached to a client.");
|
|
2208
|
+
return userId ? this.#context.removeReaction?.(this.channelId, this.id, emoji, userId) ?? Promise.reject(new Error("Reaction operations are unavailable.")) : this.#context.removeOwnReaction?.(this.channelId, this.id, emoji) ?? Promise.reject(new Error("Reaction operations are unavailable."));
|
|
2209
|
+
}
|
|
2210
|
+
removeAllReactions() {
|
|
2211
|
+
if (!this.#context?.removeAllReactions)
|
|
2212
|
+
throw new Error("This message is not attached to a client.");
|
|
2213
|
+
return this.#context.removeAllReactions(this.channelId, this.id);
|
|
2214
|
+
}
|
|
2215
|
+
pin(reason) {
|
|
2216
|
+
if (!this.#context?.pinMessage)
|
|
2217
|
+
throw new Error("This message is not attached to a client.");
|
|
2218
|
+
return this.#context.pinMessage(this.channelId, this.id, reason);
|
|
2219
|
+
}
|
|
2220
|
+
unpin(reason) {
|
|
2221
|
+
if (!this.#context?.unpinMessage)
|
|
2222
|
+
throw new Error("This message is not attached to a client.");
|
|
2223
|
+
return this.#context.unpinMessage(this.channelId, this.id, reason);
|
|
2224
|
+
}
|
|
2225
|
+
get isEphemeral() {
|
|
2226
|
+
return (this.flags & 64) !== 0;
|
|
2227
|
+
}
|
|
2228
|
+
get isPinned() {
|
|
2229
|
+
return this.pinned;
|
|
2230
|
+
}
|
|
2231
|
+
get isSystemMessage() {
|
|
2232
|
+
return !NON_SYSTEM_MESSAGE_TYPES.has(this.type);
|
|
2233
|
+
}
|
|
2234
|
+
get isCrosspost() {
|
|
2235
|
+
return (this.flags & 2) !== 0;
|
|
2236
|
+
}
|
|
2237
|
+
get hasAttachments() {
|
|
2238
|
+
return this.attachments.length > 0;
|
|
2239
|
+
}
|
|
2240
|
+
get hasEmbeds() {
|
|
2241
|
+
return this.embeds.length > 0;
|
|
2242
|
+
}
|
|
2243
|
+
get hasComponents() {
|
|
2244
|
+
return this.components.length > 0;
|
|
2245
|
+
}
|
|
2246
|
+
suppressEmbeds() {
|
|
2247
|
+
return this.edit({ flags: this.flags | 4 });
|
|
2248
|
+
}
|
|
2249
|
+
toJSON() {
|
|
2250
|
+
return {
|
|
2251
|
+
id: this.id,
|
|
2252
|
+
content: this.content,
|
|
2253
|
+
channelId: this.channelId,
|
|
2254
|
+
guildId: this.guildId,
|
|
2255
|
+
flags: this.flags,
|
|
2256
|
+
pinned: this.pinned,
|
|
2257
|
+
mentionEveryone: this.mentionEveryone,
|
|
2258
|
+
type: this.type,
|
|
2259
|
+
timestamp: this.timestamp.toISOString(),
|
|
2260
|
+
author: { id: this.author.id, username: this.author.username },
|
|
2261
|
+
attachments: [...this.attachments],
|
|
2262
|
+
embeds: [...this.embeds],
|
|
2263
|
+
components: [...this.components],
|
|
2264
|
+
mentions: this.mentions.map((u) => u.id),
|
|
2265
|
+
mentionRoles: [...this.mentionRoles],
|
|
2266
|
+
reference: this.reference,
|
|
2267
|
+
referencedMessage: this.referencedMessage ? this.referencedMessage.id : this.referencedMessage
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
export { BaseStructure2, CDN_BASE2, cdnURL2, User2, Channel2, Guild2, PermissionOverwriteEnum2, Permission2, Permissions2, PermissionFlagsBits2, PermissionSet2, PermissionsBitField2, computePermissions2, GuildMember2, Role2, TextChannel2, Invite2, WebhookEnum2, Webhook2, Emoji2, AutoModerationRule2, WelcomeScreenChannel2, GuildWelcomeScreen2, OnboardingPromptOption2, OnboardingPrompt2, GuildOnboarding2, NewsChannel2, DMChannel2, VoiceChannel2, StageChannel2, CategoryChannel2, ThreadChannel2, ForumChannel2, MediaChannel2, createChannel2, CommandOptions2, InteractionEnum2, InteractionResponse2, Interaction2, CommandInteraction2, ContextMenuCommandInteraction2, ComponentInteraction2, ModalSubmitInteraction2, AutocompleteInteraction2, createInteraction2, Embed2, AuditLogEntry2, AuditLog2, stickerURL2, Sticker2, Message2 };
|
|
2273
|
+
|
|
2274
|
+
//# debugId=9E26DAC6B3AA530F64756E2164756E21
|