lunibee 0.1.0 → 0.1.2
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 +229 -0
- package/dist/builders/attachment.d.ts +20 -0
- package/dist/builders/commands.d.ts +118 -0
- package/dist/builders/components.d.ts +151 -0
- package/dist/builders/embed.d.ts +59 -0
- package/dist/builders/index.d.ts +5 -0
- package/dist/builders/index.js +828 -0
- package/dist/builders/index.js.map +13 -0
- package/dist/collection/cache.d.ts +37 -0
- package/dist/collection/index.d.ts +47 -0
- package/dist/collection/index.js +214 -0
- package/dist/collection/index.js.map +11 -0
- package/dist/core/client-state.d.ts +10 -0
- package/dist/core/collector.d.ts +27 -0
- package/dist/core/events.d.ts +5 -0
- package/dist/core/index.d.ts +111 -0
- package/dist/core/index.js +3188 -0
- package/dist/core/index.js.map +29 -0
- package/dist/core/permissions.d.ts +293 -0
- package/dist/formatters/index.d.ts +10 -0
- package/dist/formatters/index.js +43 -0
- package/dist/formatters/index.js.map +10 -0
- package/dist/handlers/index.d.ts +16 -0
- package/dist/handlers/index.js +37 -0
- package/dist/handlers/index.js.map +10 -0
- package/{src/index.ts → dist/index.d.ts} +2 -29
- package/dist/index.js +4182 -0
- package/dist/index.js.map +41 -0
- package/dist/managers/application.d.ts +28 -0
- package/dist/managers/base.d.ts +28 -0
- package/dist/managers/index.d.ts +96 -0
- package/dist/managers/index.js +947 -0
- package/dist/managers/index.js.map +22 -0
- package/dist/managers/member.d.ts +35 -0
- package/dist/managers/message.d.ts +25 -0
- package/dist/managers/role.d.ts +34 -0
- package/dist/managers/thread.d.ts +14 -0
- package/dist/rest/index.d.ts +49 -0
- package/dist/rest/index.js +344 -0
- package/dist/rest/index.js.map +12 -0
- package/dist/rest/routes.d.ts +44 -0
- package/dist/rest/types.d.ts +26 -0
- package/dist/rest/webhook.d.ts +40 -0
- package/dist/sharding/bus.d.ts +22 -0
- package/dist/sharding/index.d.ts +34 -0
- package/dist/sharding/index.js +732 -0
- package/dist/sharding/index.js.map +13 -0
- package/dist/structures/base.d.ts +75 -0
- package/dist/structures/index.d.ts +39 -0
- package/dist/structures/index.js +571 -0
- package/dist/structures/index.js.map +14 -0
- package/dist/structures/interactions.d.ts +136 -0
- package/dist/structures/permissions.d.ts +73 -0
- package/dist/structures/resources.d.ts +64 -0
- package/dist/types/index.d.ts +535 -0
- package/dist/types/index.js +132 -0
- package/dist/types/index.js.map +10 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +10 -0
- package/dist/voice/index.d.ts +97 -0
- package/dist/voice/index.js +161 -0
- package/dist/voice/index.js.map +10 -0
- package/dist/ws/index.d.ts +76 -0
- package/dist/ws/index.js +582 -0
- package/dist/ws/index.js.map +11 -0
- package/package.json +113 -28
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/structures/src/base.ts
|
|
3
|
+
class BaseStructure {
|
|
4
|
+
id;
|
|
5
|
+
constructor(id) {
|
|
6
|
+
if (!/^\d{1,20}$/.test(id))
|
|
7
|
+
throw new TypeError("A Discord structure requires a valid snowflake ID.");
|
|
8
|
+
this.id = id;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return this.id;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class User extends BaseStructure {
|
|
16
|
+
username;
|
|
17
|
+
globalName;
|
|
18
|
+
avatar;
|
|
19
|
+
bot;
|
|
20
|
+
system;
|
|
21
|
+
flags;
|
|
22
|
+
constructor(data) {
|
|
23
|
+
super(data.id);
|
|
24
|
+
if (!data.username)
|
|
25
|
+
throw new TypeError("A Discord user requires a username.");
|
|
26
|
+
this.username = data.username;
|
|
27
|
+
this.globalName = data.global_name ?? null;
|
|
28
|
+
this.avatar = data.avatar ?? null;
|
|
29
|
+
this.bot = data.bot ?? false;
|
|
30
|
+
this.system = data.system ?? false;
|
|
31
|
+
this.flags = data.public_flags ?? 0;
|
|
32
|
+
}
|
|
33
|
+
get displayName() {
|
|
34
|
+
return this.globalName ?? this.username;
|
|
35
|
+
}
|
|
36
|
+
avatarURL(options = {}) {
|
|
37
|
+
if (!this.avatar)
|
|
38
|
+
return null;
|
|
39
|
+
const extension = options.extension ?? (this.avatar.startsWith("a_") ? "gif" : "png");
|
|
40
|
+
return `https://cdn.discordapp.com/avatars/${this.id}/${this.avatar}.${extension}${options.size ? `?size=${options.size}` : ""}`;
|
|
41
|
+
}
|
|
42
|
+
defaultAvatarURL() {
|
|
43
|
+
return `https://cdn.discordapp.com/embed/avatars/${Number(BigInt(this.id) % 5n)}.png`;
|
|
44
|
+
}
|
|
45
|
+
displayAvatarURL(options = {}) {
|
|
46
|
+
return this.avatarURL(options) ?? this.defaultAvatarURL();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class Channel extends BaseStructure {
|
|
51
|
+
type;
|
|
52
|
+
name;
|
|
53
|
+
guildId;
|
|
54
|
+
#context;
|
|
55
|
+
constructor(data, context) {
|
|
56
|
+
super(data.id);
|
|
57
|
+
if (!Number.isInteger(data.type) || data.type < 0)
|
|
58
|
+
throw new RangeError("A Discord channel requires a valid channel type.");
|
|
59
|
+
this.type = data.type;
|
|
60
|
+
this.name = data.name;
|
|
61
|
+
this.guildId = data.guild_id;
|
|
62
|
+
this.#context = context;
|
|
63
|
+
}
|
|
64
|
+
sendMessage(options) {
|
|
65
|
+
if (!this.#context)
|
|
66
|
+
throw new Error("This channel is not attached to a client.");
|
|
67
|
+
return this.#context.sendMessage(this.id, options);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class Guild extends BaseStructure {
|
|
72
|
+
name;
|
|
73
|
+
preferredLocale;
|
|
74
|
+
ownerId;
|
|
75
|
+
constructor(data) {
|
|
76
|
+
super(data.id);
|
|
77
|
+
if (!data.name)
|
|
78
|
+
throw new TypeError("A Discord guild requires a name.");
|
|
79
|
+
this.name = data.name;
|
|
80
|
+
this.preferredLocale = data.preferred_locale;
|
|
81
|
+
this.ownerId = data.owner_id;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// packages/structures/src/permissions.ts
|
|
85
|
+
var Permissions = {
|
|
86
|
+
CreateInstantInvite: 1n << 0n,
|
|
87
|
+
KickMembers: 1n << 1n,
|
|
88
|
+
BanMembers: 1n << 2n,
|
|
89
|
+
Administrator: 1n << 3n,
|
|
90
|
+
ManageChannels: 1n << 4n,
|
|
91
|
+
ManageGuild: 1n << 5n,
|
|
92
|
+
AddReactions: 1n << 6n,
|
|
93
|
+
ViewAuditLog: 1n << 7n,
|
|
94
|
+
PrioritySpeaker: 1n << 8n,
|
|
95
|
+
Stream: 1n << 9n,
|
|
96
|
+
ViewChannel: 1n << 10n,
|
|
97
|
+
SendMessages: 1n << 11n,
|
|
98
|
+
SendTTSMessages: 1n << 12n,
|
|
99
|
+
ManageMessages: 1n << 13n,
|
|
100
|
+
EmbedLinks: 1n << 14n,
|
|
101
|
+
AttachFiles: 1n << 15n,
|
|
102
|
+
ReadMessageHistory: 1n << 16n,
|
|
103
|
+
MentionEveryone: 1n << 17n,
|
|
104
|
+
UseExternalEmojis: 1n << 18n,
|
|
105
|
+
ViewGuildInsights: 1n << 19n,
|
|
106
|
+
Connect: 1n << 20n,
|
|
107
|
+
Speak: 1n << 21n,
|
|
108
|
+
MuteMembers: 1n << 22n,
|
|
109
|
+
DeafenMembers: 1n << 23n,
|
|
110
|
+
MoveMembers: 1n << 24n,
|
|
111
|
+
UseVAD: 1n << 25n,
|
|
112
|
+
ChangeNickname: 1n << 26n,
|
|
113
|
+
ManageNicknames: 1n << 27n,
|
|
114
|
+
ManageRoles: 1n << 28n,
|
|
115
|
+
ManageWebhooks: 1n << 29n,
|
|
116
|
+
ManageGuildExpressions: 1n << 30n,
|
|
117
|
+
UseApplicationCommands: 1n << 31n,
|
|
118
|
+
RequestToSpeak: 1n << 32n,
|
|
119
|
+
ManageEvents: 1n << 33n,
|
|
120
|
+
ManageThreads: 1n << 34n,
|
|
121
|
+
CreatePublicThreads: 1n << 35n,
|
|
122
|
+
CreatePrivateThreads: 1n << 36n,
|
|
123
|
+
UseExternalStickers: 1n << 37n,
|
|
124
|
+
SendMessagesInThreads: 1n << 38n,
|
|
125
|
+
UseEmbeddedActivities: 1n << 39n,
|
|
126
|
+
ModerateMembers: 1n << 40n,
|
|
127
|
+
ViewCreatorMonetizationAnalytics: 1n << 41n,
|
|
128
|
+
UseSoundboard: 1n << 42n,
|
|
129
|
+
CreateGuildExpressions: 1n << 43n,
|
|
130
|
+
CreateEvents: 1n << 44n,
|
|
131
|
+
UseExternalSounds: 1n << 45n,
|
|
132
|
+
SendVoiceMessages: 1n << 46n,
|
|
133
|
+
SendPolls: 1n << 49n,
|
|
134
|
+
UseExternalApps: 1n << 50n
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
class PermissionSet {
|
|
138
|
+
bitfield;
|
|
139
|
+
constructor(value = 0n) {
|
|
140
|
+
try {
|
|
141
|
+
if (Array.isArray(value)) {
|
|
142
|
+
let bit = 0n;
|
|
143
|
+
for (const item of value)
|
|
144
|
+
bit |= this.#resolve(item);
|
|
145
|
+
this.bitfield = bit;
|
|
146
|
+
} else if (value instanceof PermissionSet) {
|
|
147
|
+
this.bitfield = value.bitfield;
|
|
148
|
+
} else {
|
|
149
|
+
const bitfield = this.#resolve(value);
|
|
150
|
+
if (bitfield < 0n)
|
|
151
|
+
throw new RangeError("Permission bitfield cannot be negative.");
|
|
152
|
+
this.bitfield = bitfield;
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (error instanceof RangeError)
|
|
156
|
+
throw error;
|
|
157
|
+
throw new TypeError("Permission bitfield must be a valid non-negative integer.", { cause: error });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
has(...permissions) {
|
|
161
|
+
return permissions.every((permission) => (this.bitfield & this.#resolve(permission)) === this.#resolve(permission));
|
|
162
|
+
}
|
|
163
|
+
any(...permissions) {
|
|
164
|
+
return permissions.some((permission) => (this.bitfield & this.#resolve(permission)) !== 0n);
|
|
165
|
+
}
|
|
166
|
+
add(...permissions) {
|
|
167
|
+
let bitfield = this.bitfield;
|
|
168
|
+
for (const permission of permissions)
|
|
169
|
+
bitfield |= this.#resolve(permission);
|
|
170
|
+
return new PermissionSet(bitfield);
|
|
171
|
+
}
|
|
172
|
+
remove(...permissions) {
|
|
173
|
+
let bitfield = this.bitfield;
|
|
174
|
+
for (const permission of permissions)
|
|
175
|
+
bitfield &= ~this.#resolve(permission);
|
|
176
|
+
return new PermissionSet(bitfield);
|
|
177
|
+
}
|
|
178
|
+
equals(other) {
|
|
179
|
+
return this.bitfield === (other instanceof PermissionSet ? other.bitfield : new PermissionSet(other).bitfield);
|
|
180
|
+
}
|
|
181
|
+
toString() {
|
|
182
|
+
return this.bitfield.toString();
|
|
183
|
+
}
|
|
184
|
+
toArray() {
|
|
185
|
+
return Object.keys(Permissions).filter((permission) => this.has(permission));
|
|
186
|
+
}
|
|
187
|
+
#resolve(permission) {
|
|
188
|
+
if (permission instanceof PermissionSet)
|
|
189
|
+
return permission.bitfield;
|
|
190
|
+
if (typeof permission === "bigint")
|
|
191
|
+
return permission;
|
|
192
|
+
if (typeof permission === "number")
|
|
193
|
+
return BigInt(permission);
|
|
194
|
+
if (Array.isArray(permission)) {
|
|
195
|
+
let bit = 0n;
|
|
196
|
+
for (const p of permission)
|
|
197
|
+
bit |= this.#resolve(p);
|
|
198
|
+
return bit;
|
|
199
|
+
}
|
|
200
|
+
if (typeof permission === "string") {
|
|
201
|
+
if (permission in Permissions)
|
|
202
|
+
return Permissions[permission];
|
|
203
|
+
const matchedKey = Object.keys(Permissions).find((k) => k.toLowerCase() === permission.toLowerCase());
|
|
204
|
+
if (matchedKey)
|
|
205
|
+
return Permissions[matchedKey];
|
|
206
|
+
return BigInt(permission);
|
|
207
|
+
}
|
|
208
|
+
return 0n;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
class PermissionsBitField extends PermissionSet {
|
|
213
|
+
constructor(value = 0n) {
|
|
214
|
+
super(value);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// packages/structures/src/resources.ts
|
|
219
|
+
class GuildMember {
|
|
220
|
+
user;
|
|
221
|
+
guildId;
|
|
222
|
+
nickname;
|
|
223
|
+
roleIds;
|
|
224
|
+
pending;
|
|
225
|
+
joinedAt;
|
|
226
|
+
permissions;
|
|
227
|
+
constructor(data) {
|
|
228
|
+
this.user = new User(data.user);
|
|
229
|
+
if (!/^\d{1,20}$/.test(data.guild_id))
|
|
230
|
+
throw new TypeError("Member guild_id must be a valid snowflake.");
|
|
231
|
+
this.guildId = data.guild_id;
|
|
232
|
+
this.nickname = data.nick ?? null;
|
|
233
|
+
this.roleIds = [...data.roles ?? []];
|
|
234
|
+
this.pending = data.pending ?? false;
|
|
235
|
+
this.joinedAt = data.joined_at ? new Date(data.joined_at) : undefined;
|
|
236
|
+
if (this.joinedAt?.toString() === "Invalid Date")
|
|
237
|
+
throw new RangeError("Member joined_at must be a valid date.");
|
|
238
|
+
this.permissions = new PermissionsBitField(data.permissions ?? 0n);
|
|
239
|
+
}
|
|
240
|
+
get displayName() {
|
|
241
|
+
return this.nickname ?? this.user.displayName;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
class Role extends BaseStructure {
|
|
246
|
+
name;
|
|
247
|
+
color;
|
|
248
|
+
hoist;
|
|
249
|
+
permissions;
|
|
250
|
+
managed;
|
|
251
|
+
mentionable;
|
|
252
|
+
constructor(data) {
|
|
253
|
+
super(data.id);
|
|
254
|
+
if (!data.name)
|
|
255
|
+
throw new TypeError("Role name cannot be empty.");
|
|
256
|
+
this.name = data.name;
|
|
257
|
+
this.color = data.color ?? 0;
|
|
258
|
+
this.hoist = data.hoist ?? false;
|
|
259
|
+
this.permissions = new PermissionsBitField(data.permissions ?? 0n);
|
|
260
|
+
this.managed = data.managed ?? false;
|
|
261
|
+
this.mentionable = data.mentionable ?? false;
|
|
262
|
+
}
|
|
263
|
+
toString() {
|
|
264
|
+
return `<@&${this.id}>`;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
class TextChannel extends Channel {
|
|
269
|
+
parentId;
|
|
270
|
+
constructor(data) {
|
|
271
|
+
super(data);
|
|
272
|
+
this.parentId = data.parent_id;
|
|
273
|
+
}
|
|
274
|
+
toString() {
|
|
275
|
+
return `<#${this.id}>`;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// packages/structures/src/interactions.ts
|
|
279
|
+
var InteractionType = {
|
|
280
|
+
Ping: 1,
|
|
281
|
+
ApplicationCommand: 2,
|
|
282
|
+
MessageComponent: 3,
|
|
283
|
+
ApplicationCommandAutocomplete: 4,
|
|
284
|
+
ModalSubmit: 5
|
|
285
|
+
};
|
|
286
|
+
var InteractionResponseType = {
|
|
287
|
+
Pong: 1,
|
|
288
|
+
ChannelMessage: 4,
|
|
289
|
+
DeferredChannelMessage: 5,
|
|
290
|
+
DeferredMessageUpdate: 6,
|
|
291
|
+
MessageUpdate: 7,
|
|
292
|
+
Autocomplete: 8,
|
|
293
|
+
Modal: 9
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
class InteractionResponse {
|
|
297
|
+
type;
|
|
298
|
+
data;
|
|
299
|
+
constructor(type, data) {
|
|
300
|
+
if (!Number.isFinite(type))
|
|
301
|
+
throw new TypeError("Interaction response type must be finite.");
|
|
302
|
+
this.type = type;
|
|
303
|
+
this.data = data;
|
|
304
|
+
}
|
|
305
|
+
toJSON() {
|
|
306
|
+
return this.data === undefined ? { type: this.type } : { type: this.type, data: this.data };
|
|
307
|
+
}
|
|
308
|
+
static message(options) {
|
|
309
|
+
const data = { ...options };
|
|
310
|
+
if (options.ephemeral) {
|
|
311
|
+
data.flags = (typeof options.flags === "number" ? options.flags : 0) | 64;
|
|
312
|
+
}
|
|
313
|
+
return new InteractionResponse(InteractionResponseType.ChannelMessage, data);
|
|
314
|
+
}
|
|
315
|
+
static defer(ephemeral = false) {
|
|
316
|
+
return new InteractionResponse(InteractionResponseType.DeferredChannelMessage, ephemeral ? { flags: 64 } : undefined);
|
|
317
|
+
}
|
|
318
|
+
static pong() {
|
|
319
|
+
return new InteractionResponse(InteractionResponseType.Pong);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
class Interaction {
|
|
324
|
+
id;
|
|
325
|
+
applicationId;
|
|
326
|
+
token;
|
|
327
|
+
guildId;
|
|
328
|
+
channelId;
|
|
329
|
+
type;
|
|
330
|
+
data;
|
|
331
|
+
replied = false;
|
|
332
|
+
deferred = false;
|
|
333
|
+
#client;
|
|
334
|
+
constructor(client, data) {
|
|
335
|
+
if (!data.id || !data.token)
|
|
336
|
+
throw new TypeError("Interaction ID and token are required.");
|
|
337
|
+
this.#client = client;
|
|
338
|
+
this.id = data.id;
|
|
339
|
+
this.applicationId = data.application_id;
|
|
340
|
+
this.token = data.token;
|
|
341
|
+
this.guildId = data.guild_id;
|
|
342
|
+
this.channelId = data.channel_id;
|
|
343
|
+
this.type = data.type;
|
|
344
|
+
this.data = data;
|
|
345
|
+
}
|
|
346
|
+
isChatInputCommand() {
|
|
347
|
+
return this.type === InteractionType.ApplicationCommand;
|
|
348
|
+
}
|
|
349
|
+
isMessageComponent() {
|
|
350
|
+
return this.type === InteractionType.MessageComponent;
|
|
351
|
+
}
|
|
352
|
+
isModalSubmit() {
|
|
353
|
+
return this.type === InteractionType.ModalSubmit;
|
|
354
|
+
}
|
|
355
|
+
isAutocomplete() {
|
|
356
|
+
return this.type === InteractionType.ApplicationCommandAutocomplete;
|
|
357
|
+
}
|
|
358
|
+
assertUnacknowledged() {
|
|
359
|
+
if (this.replied || this.deferred)
|
|
360
|
+
throw new Error("Interaction has already been acknowledged.");
|
|
361
|
+
}
|
|
362
|
+
assertAcknowledged() {
|
|
363
|
+
if (!this.replied && !this.deferred)
|
|
364
|
+
throw new Error("Interaction has not been acknowledged.");
|
|
365
|
+
}
|
|
366
|
+
postResponse(response) {
|
|
367
|
+
return this.#client.postInteractionResponse(this.id, this.token, response);
|
|
368
|
+
}
|
|
369
|
+
async reply(options) {
|
|
370
|
+
this.assertUnacknowledged();
|
|
371
|
+
const payload = typeof options === "string" ? { content: options } : options;
|
|
372
|
+
const result = await this.#client.postInteractionResponse(this.id, this.token, InteractionResponse.message(payload));
|
|
373
|
+
this.replied = true;
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
async deferReply(ephemeral = false) {
|
|
377
|
+
this.assertUnacknowledged();
|
|
378
|
+
await this.#client.postInteractionResponse(this.id, this.token, InteractionResponse.defer(ephemeral));
|
|
379
|
+
this.deferred = true;
|
|
380
|
+
}
|
|
381
|
+
editReply(options) {
|
|
382
|
+
this.assertAcknowledged();
|
|
383
|
+
return this.#client.editInteractionReply(this.token, options);
|
|
384
|
+
}
|
|
385
|
+
deleteReply() {
|
|
386
|
+
this.assertAcknowledged();
|
|
387
|
+
return this.#client.deleteInteractionReply(this.token);
|
|
388
|
+
}
|
|
389
|
+
followUp(options) {
|
|
390
|
+
const payload = typeof options === "string" ? { content: options } : options;
|
|
391
|
+
return this.#client.followUpInteraction(this.token, payload);
|
|
392
|
+
}
|
|
393
|
+
async update(options) {
|
|
394
|
+
this.assertUnacknowledged();
|
|
395
|
+
const payload = typeof options === "string" ? { content: options } : options;
|
|
396
|
+
const result = await this.#client.postInteractionResponse(this.id, this.token, new InteractionResponse(InteractionResponseType.MessageUpdate, payload));
|
|
397
|
+
this.replied = true;
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
async showModal(modal) {
|
|
401
|
+
this.assertUnacknowledged();
|
|
402
|
+
const result = await this.#client.postInteractionResponse(this.id, this.token, new InteractionResponse(InteractionResponseType.Modal, modal));
|
|
403
|
+
this.replied = true;
|
|
404
|
+
return result;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
class CommandInteraction extends Interaction {
|
|
409
|
+
get commandName() {
|
|
410
|
+
return typeof this.data.data?.name === "string" ? this.data.data.name : "";
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
class ComponentInteraction extends Interaction {
|
|
415
|
+
get customId() {
|
|
416
|
+
return this.data?.data?.custom_id ?? "";
|
|
417
|
+
}
|
|
418
|
+
get componentType() {
|
|
419
|
+
return this.data?.data?.component_type ?? 0;
|
|
420
|
+
}
|
|
421
|
+
get values() {
|
|
422
|
+
return this.data?.data?.values ?? [];
|
|
423
|
+
}
|
|
424
|
+
async deferUpdate() {
|
|
425
|
+
this.assertUnacknowledged();
|
|
426
|
+
await this.postResponse(new InteractionResponse(InteractionResponseType.DeferredMessageUpdate));
|
|
427
|
+
this.deferred = true;
|
|
428
|
+
}
|
|
429
|
+
async update(options) {
|
|
430
|
+
this.assertUnacknowledged();
|
|
431
|
+
const payload = typeof options === "string" ? { content: options } : options;
|
|
432
|
+
const result = await this.postResponse(new InteractionResponse(InteractionResponseType.MessageUpdate, payload));
|
|
433
|
+
this.replied = true;
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function createInteraction(client, data) {
|
|
438
|
+
switch (data.type) {
|
|
439
|
+
case InteractionType.ApplicationCommand:
|
|
440
|
+
case InteractionType.ApplicationCommandAutocomplete:
|
|
441
|
+
return new CommandInteraction(client, data);
|
|
442
|
+
case InteractionType.MessageComponent:
|
|
443
|
+
case InteractionType.ModalSubmit:
|
|
444
|
+
return new ComponentInteraction(client, data);
|
|
445
|
+
default:
|
|
446
|
+
return new Interaction(client, data);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
class ModalSubmitInteraction extends Interaction {
|
|
451
|
+
get customId() {
|
|
452
|
+
return this.data?.data?.custom_id ?? "";
|
|
453
|
+
}
|
|
454
|
+
getInputValue(customId) {
|
|
455
|
+
const rows = this.data?.data?.components ?? [];
|
|
456
|
+
for (const row of rows) {
|
|
457
|
+
for (const comp of row.components ?? []) {
|
|
458
|
+
if (comp.custom_id === customId)
|
|
459
|
+
return comp.value;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
class AutocompleteInteraction extends Interaction {
|
|
467
|
+
get commandName() {
|
|
468
|
+
return this.data?.data?.name ?? "";
|
|
469
|
+
}
|
|
470
|
+
get focusedOption() {
|
|
471
|
+
const options = this.data?.data?.options ?? [];
|
|
472
|
+
return options.find((opt) => opt.focused);
|
|
473
|
+
}
|
|
474
|
+
async respond(choices) {
|
|
475
|
+
const response = new InteractionResponse(InteractionResponseType.Autocomplete, { choices });
|
|
476
|
+
await this.postResponse(response);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// packages/structures/src/index.ts
|
|
481
|
+
class Message extends BaseStructure {
|
|
482
|
+
content;
|
|
483
|
+
author;
|
|
484
|
+
channelId;
|
|
485
|
+
channel;
|
|
486
|
+
guildId;
|
|
487
|
+
flags;
|
|
488
|
+
createdAt;
|
|
489
|
+
attachments;
|
|
490
|
+
embeds;
|
|
491
|
+
mentions;
|
|
492
|
+
mentionRoles;
|
|
493
|
+
pinned;
|
|
494
|
+
mentionEveryone;
|
|
495
|
+
type;
|
|
496
|
+
reference;
|
|
497
|
+
referencedMessage;
|
|
498
|
+
#context;
|
|
499
|
+
constructor(data, context) {
|
|
500
|
+
super(data.id);
|
|
501
|
+
if (!/^\d{1,20}$/.test(data.channel_id))
|
|
502
|
+
throw new TypeError("Message channel_id must be a valid snowflake.");
|
|
503
|
+
this.content = data.content ?? "";
|
|
504
|
+
this.author = new User(data.author);
|
|
505
|
+
this.channelId = data.channel_id;
|
|
506
|
+
this.guildId = data.guild_id;
|
|
507
|
+
this.flags = data.flags ?? 0;
|
|
508
|
+
this.createdAt = new Date(data.timestamp ?? Number((BigInt(this.id) >> 22n) + 1420070400000n));
|
|
509
|
+
this.attachments = data.attachments ?? [];
|
|
510
|
+
this.embeds = data.embeds ?? [];
|
|
511
|
+
this.mentions = (data.mentions ?? []).map((user) => new User(user));
|
|
512
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
513
|
+
this.pinned = data.pinned ?? false;
|
|
514
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
515
|
+
this.type = data.type ?? 0;
|
|
516
|
+
this.reference = data.message_reference;
|
|
517
|
+
this.referencedMessage = data.referenced_message ? new Message(data.referenced_message, context) : data.referenced_message === null ? null : undefined;
|
|
518
|
+
this.#context = context;
|
|
519
|
+
this.channel = new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context);
|
|
520
|
+
}
|
|
521
|
+
get embedsSuppressed() {
|
|
522
|
+
return (this.flags & 4) !== 0;
|
|
523
|
+
}
|
|
524
|
+
edit(options) {
|
|
525
|
+
if (!this.#context)
|
|
526
|
+
throw new Error("This message is not attached to a client.");
|
|
527
|
+
return this.#context.editMessage(this.channelId, this.id, options);
|
|
528
|
+
}
|
|
529
|
+
delete() {
|
|
530
|
+
if (!this.#context)
|
|
531
|
+
throw new Error("This message is not attached to a client.");
|
|
532
|
+
return this.#context.deleteMessage(this.channelId, this.id);
|
|
533
|
+
}
|
|
534
|
+
crosspost() {
|
|
535
|
+
if (!this.#context)
|
|
536
|
+
throw new Error("This message is not attached to a client.");
|
|
537
|
+
return this.#context.crosspostMessage(this.channelId, this.id);
|
|
538
|
+
}
|
|
539
|
+
reply(options) {
|
|
540
|
+
if (!this.#context)
|
|
541
|
+
throw new Error("This message is not attached to a client.");
|
|
542
|
+
const payload = typeof options === "string" ? { content: options } : { ...options };
|
|
543
|
+
payload.message_reference = {
|
|
544
|
+
message_id: this.id,
|
|
545
|
+
channel_id: this.channelId,
|
|
546
|
+
guild_id: this.guildId
|
|
547
|
+
};
|
|
548
|
+
return this.#context.sendMessage(this.channelId, payload);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
export {
|
|
552
|
+
AutocompleteInteraction,
|
|
553
|
+
BaseStructure,
|
|
554
|
+
Channel,
|
|
555
|
+
CommandInteraction,
|
|
556
|
+
ComponentInteraction,
|
|
557
|
+
Guild,
|
|
558
|
+
GuildMember,
|
|
559
|
+
Interaction,
|
|
560
|
+
InteractionResponse,
|
|
561
|
+
InteractionResponseType,
|
|
562
|
+
InteractionType,
|
|
563
|
+
Message,
|
|
564
|
+
ModalSubmitInteraction,
|
|
565
|
+
Role,
|
|
566
|
+
TextChannel,
|
|
567
|
+
User,
|
|
568
|
+
createInteraction
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
//# debugId=EDF445FCBD7D61B564756E2164756E21
|