seyfert 1.3.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/lib/api/Router.js +3 -1
- package/lib/api/Routes/guilds.d.ts +4 -1
- package/lib/api/api.js +13 -7
- package/lib/builders/Attachment.d.ts +1 -4
- package/lib/builders/Attachment.js +4 -4
- package/lib/cache/adapters/workeradapter.js +7 -3
- package/lib/cache/index.d.ts +6 -2
- package/lib/cache/index.js +18 -0
- package/lib/cache/resources/bans.d.ts +12 -0
- package/lib/cache/resources/bans.js +35 -0
- package/lib/cache/resources/default/base.d.ts +1 -2
- package/lib/cache/resources/default/guild-based.d.ts +1 -2
- package/lib/cache/resources/members.js +4 -4
- package/lib/cache/resources/messages.js +8 -6
- package/lib/client/base.d.ts +33 -7
- package/lib/client/base.js +80 -21
- package/lib/client/client.d.ts +18 -6
- package/lib/client/client.js +45 -37
- package/lib/client/collectors.d.ts +36 -0
- package/lib/client/collectors.js +85 -0
- package/lib/client/httpclient.d.ts +7 -8
- package/lib/client/httpclient.js +96 -17
- package/lib/client/oninteractioncreate.d.ts +2 -2
- package/lib/client/oninteractioncreate.js +15 -7
- package/lib/client/onmessagecreate.d.ts +12 -2
- package/lib/client/onmessagecreate.js +105 -82
- package/lib/client/workerclient.d.ts +5 -2
- package/lib/client/workerclient.js +66 -63
- package/lib/collection.d.ts +2 -2
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +11 -10
- package/lib/commands/applications/chat.js +23 -8
- package/lib/commands/applications/chatcontext.d.ts +1 -1
- package/lib/commands/applications/chatcontext.js +2 -2
- package/lib/commands/applications/menu.d.ts +8 -7
- package/lib/commands/applications/menu.js +3 -50
- package/lib/commands/applications/menucontext.d.ts +1 -1
- package/lib/commands/applications/menucontext.js +3 -3
- package/lib/commands/applications/options.d.ts +3 -1
- package/lib/commands/applications/shared.d.ts +12 -0
- package/lib/commands/basecontext.d.ts +26 -0
- package/lib/commands/{basecontex.js → basecontext.js} +24 -0
- package/lib/commands/decorators.d.ts +11 -17
- package/lib/commands/decorators.js +7 -14
- package/lib/commands/handler.d.ts +6 -1
- package/lib/commands/handler.js +161 -29
- package/lib/common/bot/watcher.d.ts +1 -2
- package/lib/common/bot/watcher.js +9 -4
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +3 -1
- package/lib/common/it/formatter.d.ts +155 -0
- package/lib/common/it/formatter.js +184 -0
- package/lib/common/it/logger.d.ts +1 -1
- package/lib/common/it/logger.js +14 -13
- package/lib/common/it/utils.d.ts +2 -0
- package/lib/common/it/utils.js +21 -9
- package/lib/common/shorters/bans.d.ts +43 -0
- package/lib/common/shorters/bans.js +78 -0
- package/lib/common/shorters/emojis.d.ts +1 -1
- package/lib/common/shorters/emojis.js +4 -3
- package/lib/common/shorters/interaction.js +9 -7
- package/lib/common/shorters/messages.js +2 -2
- package/lib/common/shorters/webhook.js +2 -2
- package/lib/components/componentcommand.d.ts +22 -0
- package/lib/components/{command.js → componentcommand.js} +3 -5
- package/lib/components/componentcontext.d.ts +20 -16
- package/lib/components/componentcontext.js +27 -9
- package/lib/components/handler.d.ts +11 -6
- package/lib/components/handler.js +106 -32
- package/lib/components/index.d.ts +3 -1
- package/lib/components/index.js +3 -1
- package/lib/components/modalcommand.d.ts +16 -0
- package/lib/components/modalcommand.js +10 -0
- package/lib/components/modalcontext.d.ts +104 -0
- package/lib/components/modalcontext.js +132 -0
- package/lib/events/event.d.ts +4 -3
- package/lib/events/handler.d.ts +12 -6
- package/lib/events/handler.js +60 -20
- package/lib/events/hooks/application_command.d.ts +2 -2
- package/lib/events/hooks/auto_moderation.d.ts +5 -5
- package/lib/events/hooks/channel.d.ts +5 -5
- package/lib/events/hooks/custom.d.ts +3 -3
- package/lib/events/hooks/dispatch.d.ts +4 -4
- package/lib/events/hooks/entitlement.d.ts +4 -4
- package/lib/events/hooks/guild.d.ts +41 -96
- package/lib/events/hooks/guild.js +6 -6
- package/lib/events/hooks/integration.d.ts +61 -4
- package/lib/events/hooks/interactions.d.ts +2 -2
- package/lib/events/hooks/invite.d.ts +6 -3
- package/lib/events/hooks/message.d.ts +23 -18
- package/lib/events/hooks/message.js +1 -1
- package/lib/events/hooks/presence.d.ts +11 -3
- package/lib/events/hooks/presence.js +2 -2
- package/lib/events/hooks/stage.d.ts +7 -13
- package/lib/events/hooks/stage.js +2 -2
- package/lib/events/hooks/thread.d.ts +21 -10
- package/lib/events/hooks/thread.js +2 -2
- package/lib/events/hooks/typing.d.ts +3 -2
- package/lib/events/hooks/user.d.ts +2 -2
- package/lib/events/hooks/user.js +2 -2
- package/lib/events/hooks/voice.d.ts +5 -45
- package/lib/events/hooks/voice.js +4 -7
- package/lib/events/hooks/webhook.d.ts +2 -2
- package/lib/index.d.ts +4 -4
- package/lib/index.js +11 -5
- package/lib/langs/handler.d.ts +4 -1
- package/lib/langs/handler.js +3 -3
- package/lib/structures/Guild.d.ts +9 -1
- package/lib/structures/Guild.js +2 -0
- package/lib/structures/GuildBan.d.ts +25 -0
- package/lib/structures/GuildBan.js +36 -0
- package/lib/structures/GuildEmoji.d.ts +1 -1
- package/lib/structures/GuildMember.d.ts +7 -2
- package/lib/structures/GuildMember.js +4 -4
- package/lib/structures/Interaction.d.ts +4 -3
- package/lib/structures/Interaction.js +29 -12
- package/lib/structures/Message.d.ts +69 -8
- package/lib/structures/Message.js +59 -17
- package/lib/structures/Sticker.d.ts +3 -3
- package/lib/structures/User.d.ts +1 -0
- package/lib/structures/User.js +4 -1
- package/lib/structures/VoiceState.d.ts +6 -5
- package/lib/structures/VoiceState.js +6 -3
- package/lib/structures/channels.d.ts +4 -1
- package/lib/structures/channels.js +37 -6
- package/lib/structures/extra/functions.js +1 -1
- package/lib/websocket/discord/basesocket.d.ts +1 -0
- package/lib/websocket/discord/basesocket.js +17 -0
- package/lib/websocket/discord/shard.d.ts +1 -0
- package/lib/websocket/discord/shard.js +6 -0
- package/lib/websocket/discord/sharder.js +10 -3
- package/lib/websocket/discord/shared.d.ts +1 -0
- package/lib/websocket/discord/workermanager.d.ts +2 -3
- package/lib/websocket/discord/workermanager.js +4 -2
- package/package.json +7 -7
- package/lib/commands/basecontex.d.ts +0 -15
- package/lib/components/command.d.ts +0 -24
package/lib/client/httpclient.js
CHANGED
|
@@ -5,6 +5,7 @@ const v10_1 = require("discord-api-types/v10");
|
|
|
5
5
|
const magic_bytes_js_1 = require("magic-bytes.js");
|
|
6
6
|
const api_1 = require("../api");
|
|
7
7
|
const utils_1 = require("../api/utils/utils");
|
|
8
|
+
const common_1 = require("../common");
|
|
8
9
|
const base_1 = require("./base");
|
|
9
10
|
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
10
11
|
let UWS;
|
|
@@ -27,9 +28,9 @@ class HttpClient extends base_1.BaseClient {
|
|
|
27
28
|
publicKeyHex;
|
|
28
29
|
constructor(options) {
|
|
29
30
|
super(options);
|
|
30
|
-
if (!UWS) {
|
|
31
|
-
|
|
32
|
-
}
|
|
31
|
+
// if (!UWS) {
|
|
32
|
+
// throw new Error('No uws installed.');
|
|
33
|
+
// }
|
|
33
34
|
if (!nacl) {
|
|
34
35
|
throw new Error('No tweetnacl installed.');
|
|
35
36
|
}
|
|
@@ -60,8 +61,8 @@ class HttpClient extends base_1.BaseClient {
|
|
|
60
61
|
async execute(options) {
|
|
61
62
|
await super.execute();
|
|
62
63
|
const { publicKey: publicKeyRC, port: portRC, applicationId: applicationIdRC, } = await this.getRC();
|
|
63
|
-
const publicKey = options
|
|
64
|
-
const port = options
|
|
64
|
+
const publicKey = options.publicKey ?? publicKeyRC;
|
|
65
|
+
const port = options.port ?? portRC;
|
|
65
66
|
if (!publicKey) {
|
|
66
67
|
throw new Error('Expected a publicKey, check your config file');
|
|
67
68
|
}
|
|
@@ -73,17 +74,33 @@ class HttpClient extends base_1.BaseClient {
|
|
|
73
74
|
}
|
|
74
75
|
this.publicKey = publicKey;
|
|
75
76
|
this.publicKeyHex = Buffer.from(this.publicKey, 'hex');
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.
|
|
82
|
-
|
|
77
|
+
if (UWS && options.useUWS) {
|
|
78
|
+
this.app = UWS.App();
|
|
79
|
+
this.app.post('/interactions', (res, req) => {
|
|
80
|
+
return this.onPacket(res, req);
|
|
81
|
+
});
|
|
82
|
+
this.app.listen(port, () => {
|
|
83
|
+
this.logger.info(`Listening to <url>:${port}/interactions`);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (options.useUWS)
|
|
88
|
+
return this.logger.warn('No uWebSockets installed.');
|
|
89
|
+
this.logger.info('Use your preferred http server and invoke <HttpClient>.fetch(<Request>) to get started');
|
|
90
|
+
}
|
|
83
91
|
}
|
|
84
92
|
async start(options = {}) {
|
|
85
93
|
await super.start(options);
|
|
86
|
-
return this.execute(options.httpConnection);
|
|
94
|
+
return this.execute((0, common_1.MergeOptions)({ useUWS: true }, options.httpConnection));
|
|
95
|
+
}
|
|
96
|
+
async verifySignatureGenericRequest(req) {
|
|
97
|
+
const timestamp = req.headers.get('x-signature-timestamp');
|
|
98
|
+
const ed25519 = req.headers.get('x-signature-ed25519') ?? '';
|
|
99
|
+
const body = (await req.json());
|
|
100
|
+
if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
|
|
101
|
+
return body;
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
87
104
|
}
|
|
88
105
|
// https://discord.com/developers/docs/interactions/receiving-and-responding#security-and-authorization
|
|
89
106
|
async verifySignature(res, req) {
|
|
@@ -95,14 +112,71 @@ class HttpClient extends base_1.BaseClient {
|
|
|
95
112
|
}
|
|
96
113
|
return;
|
|
97
114
|
}
|
|
98
|
-
async
|
|
99
|
-
const rawBody = await this.
|
|
115
|
+
async fetch(req) {
|
|
116
|
+
const rawBody = await this.verifySignatureGenericRequest(req);
|
|
100
117
|
if (!rawBody) {
|
|
101
118
|
this.debugger?.debug('Invalid request/No info, returning 418 status.');
|
|
102
119
|
// I'm a teapot
|
|
103
|
-
|
|
120
|
+
return new Response('', { status: 418 });
|
|
104
121
|
}
|
|
105
|
-
|
|
122
|
+
switch (rawBody.type) {
|
|
123
|
+
case v10_1.InteractionType.Ping:
|
|
124
|
+
this.debugger?.debug('Ping interaction received, responding.');
|
|
125
|
+
return Response.json({ type: v10_1.InteractionResponseType.Pong }, {
|
|
126
|
+
headers: {
|
|
127
|
+
'Content-Type': 'application/json',
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
default:
|
|
131
|
+
return new Promise(r => {
|
|
132
|
+
if ((0, common_1.isCloudfareWorker)())
|
|
133
|
+
return (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1)
|
|
134
|
+
.then(() => r(new Response()))
|
|
135
|
+
.catch(() => r(new Response()));
|
|
136
|
+
return (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1, async ({ body, files }) => {
|
|
137
|
+
let response;
|
|
138
|
+
const headers = {};
|
|
139
|
+
if (files) {
|
|
140
|
+
response = new FormData();
|
|
141
|
+
for (const [index, file] of files.entries()) {
|
|
142
|
+
const fileKey = file.key ?? `files[${index}]`;
|
|
143
|
+
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
144
|
+
let contentType = file.contentType;
|
|
145
|
+
if (!contentType) {
|
|
146
|
+
const [parsedType] = (0, magic_bytes_js_1.filetypeinfo)(file.data);
|
|
147
|
+
if (parsedType) {
|
|
148
|
+
contentType =
|
|
149
|
+
api_1.OverwrittenMimeTypes[parsedType.mime] ??
|
|
150
|
+
parsedType.mime ??
|
|
151
|
+
'application/octet-stream';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (body) {
|
|
161
|
+
response.append('payload_json', JSON.stringify(body));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
response = body ?? {};
|
|
166
|
+
headers['Content-Type'] = 'application/json';
|
|
167
|
+
}
|
|
168
|
+
r(response instanceof FormData
|
|
169
|
+
? new Response(response, { headers })
|
|
170
|
+
: Response.json(response, {
|
|
171
|
+
headers,
|
|
172
|
+
}));
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async onPacket(res, req) {
|
|
178
|
+
const rawBody = await this.verifySignature(res, req);
|
|
179
|
+
if (rawBody) {
|
|
106
180
|
switch (rawBody.type) {
|
|
107
181
|
case v10_1.InteractionType.Ping:
|
|
108
182
|
this.debugger?.debug('Ping interaction received, responding.');
|
|
@@ -153,6 +227,11 @@ class HttpClient extends base_1.BaseClient {
|
|
|
153
227
|
break;
|
|
154
228
|
}
|
|
155
229
|
}
|
|
230
|
+
else {
|
|
231
|
+
this.debugger?.debug('Invalid request/No info, returning 418 status.');
|
|
232
|
+
// I'm a teapot
|
|
233
|
+
res.writeStatus('418').end();
|
|
234
|
+
}
|
|
156
235
|
}
|
|
157
236
|
}
|
|
158
237
|
exports.HttpClient = HttpClient;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type APIInteraction } from 'discord-api-types/v10';
|
|
2
|
+
import { type UsingClient } from '../commands';
|
|
2
3
|
import type { __InternalReplyFunction } from '../structures';
|
|
3
|
-
|
|
4
|
-
export declare function onInteractionCreate(self: BaseClient, body: APIInteraction, shardId: number, __reply?: __InternalReplyFunction): Promise<any>;
|
|
4
|
+
export declare function onInteractionCreate(self: UsingClient, body: APIInteraction, shardId: number, __reply?: __InternalReplyFunction): Promise<any>;
|
|
@@ -4,6 +4,7 @@ exports.onInteractionCreate = void 0;
|
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const commands_1 = require("../commands");
|
|
6
6
|
const structures_1 = require("../structures");
|
|
7
|
+
const components_1 = require("../components");
|
|
7
8
|
async function onInteractionCreate(self, body, shardId, __reply) {
|
|
8
9
|
self.debugger?.debug(`[${v10_1.InteractionType[body.type] ?? body.type}] Interaction received.`);
|
|
9
10
|
switch (body.type) {
|
|
@@ -16,7 +17,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
16
17
|
return x.name === body.data.name;
|
|
17
18
|
});
|
|
18
19
|
const optionsResolver = new commands_1.OptionResolver(self, body.data.options ?? [], parentCommand, body.guild_id, body.data.resolved);
|
|
19
|
-
const interaction = new structures_1.AutocompleteInteraction(self, body, __reply);
|
|
20
|
+
const interaction = new structures_1.AutocompleteInteraction(self, body, optionsResolver, __reply);
|
|
20
21
|
const command = optionsResolver.getAutocomplete();
|
|
21
22
|
// idc, is a YOU problem
|
|
22
23
|
if (!command?.autocomplete)
|
|
@@ -64,17 +65,17 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
64
65
|
if (command.botPermissions && interaction.appPermissions) {
|
|
65
66
|
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values([command.botPermissions]));
|
|
66
67
|
if (!interaction.appPermissions.has('Administrator') && permissions.length) {
|
|
67
|
-
return command.onBotPermissionsFail
|
|
68
|
+
return command.onBotPermissionsFail(context, interaction.appPermissions.keys(permissions));
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
const resultRunGlobalMiddlewares = await
|
|
71
|
+
const resultRunGlobalMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, (self.options?.globalMiddlewares ?? []), true);
|
|
71
72
|
if (resultRunGlobalMiddlewares.pass) {
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
if ('error' in resultRunGlobalMiddlewares) {
|
|
75
76
|
return command.onMiddlewaresError(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
|
|
76
77
|
}
|
|
77
|
-
const resultRunMiddlewares = await
|
|
78
|
+
const resultRunMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, command.middlewares, false);
|
|
78
79
|
if (resultRunMiddlewares.pass) {
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
@@ -86,7 +87,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
86
87
|
await command.onAfterRun?.(context, undefined);
|
|
87
88
|
}
|
|
88
89
|
catch (error) {
|
|
89
|
-
await command.onRunError
|
|
90
|
+
await command.onRunError(context, error);
|
|
90
91
|
await command.onAfterRun?.(context, error);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -170,7 +171,10 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
170
171
|
await self.components.onModalSubmit(interaction);
|
|
171
172
|
}
|
|
172
173
|
else {
|
|
173
|
-
|
|
174
|
+
const context = new components_1.ModalContext(self, interaction);
|
|
175
|
+
const extended = self.options?.context?.(interaction) ?? {};
|
|
176
|
+
Object.assign(context, extended);
|
|
177
|
+
await self.components?.executeModal(context);
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
break;
|
|
@@ -181,7 +185,11 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
181
185
|
await self.components.onComponent(body.message.id, interaction);
|
|
182
186
|
}
|
|
183
187
|
else {
|
|
184
|
-
|
|
188
|
+
//@ts-expect-error
|
|
189
|
+
const context = new components_1.ComponentContext(self, interaction);
|
|
190
|
+
const extended = self.options?.context?.(interaction) ?? {};
|
|
191
|
+
Object.assign(context, extended);
|
|
192
|
+
await self.components?.executeComponent(context);
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
break;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import { type GatewayMessageCreateDispatchData } from 'discord-api-types/v10';
|
|
2
|
-
import { type Client, type WorkerClient } from '..';
|
|
1
|
+
import { type APIApplicationCommandInteractionDataOption, type GatewayMessageCreateDispatchData } from 'discord-api-types/v10';
|
|
2
|
+
import { Command, type MessageCommandOptionErrors, SubCommand, type UsingClient, type Client, type ContextOptionsResolved, type WorkerClient } from '..';
|
|
3
|
+
import type { MakeRequired } from '../common';
|
|
3
4
|
export declare function onMessageCreate(self: Client | WorkerClient, rawMessage: GatewayMessageCreateDispatchData, shardId: number): Promise<any>;
|
|
5
|
+
export declare function defaultOptionsParser(self: UsingClient, command: Command | SubCommand, message: GatewayMessageCreateDispatchData, args: Partial<Record<string, string>>, resolved: MakeRequired<ContextOptionsResolved>): Promise<{
|
|
6
|
+
errors: {
|
|
7
|
+
name: string;
|
|
8
|
+
error: string;
|
|
9
|
+
fullError: MessageCommandOptionErrors;
|
|
10
|
+
}[];
|
|
11
|
+
options: APIApplicationCommandInteractionDataOption[];
|
|
12
|
+
}>;
|
|
13
|
+
export declare function defaultArgsParser(content: string): Record<string, string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onMessageCreate = void 0;
|
|
3
|
+
exports.defaultArgsParser = exports.defaultOptionsParser = exports.onMessageCreate = void 0;
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const __1 = require("..");
|
|
6
6
|
const structures_1 = require("../structures");
|
|
@@ -45,7 +45,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
45
45
|
const message = new structures_1.Message(self, rawMessage);
|
|
46
46
|
const prefixes = (await self.options.commands.prefix(message)).sort((a, b) => b.length - a.length);
|
|
47
47
|
const prefix = prefixes.find(x => message.content.startsWith(x));
|
|
48
|
-
if (!prefix
|
|
48
|
+
if (!(prefix !== undefined && message.content.startsWith(prefix)))
|
|
49
49
|
return;
|
|
50
50
|
const content = message.content.slice(prefix.length).trimStart();
|
|
51
51
|
const { fullCommandName, command, parent } = getCommandFromContent(content
|
|
@@ -56,7 +56,9 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
56
56
|
return;
|
|
57
57
|
if (!command.run)
|
|
58
58
|
return self.logger.warn(`${fullCommandName} command does not have 'run' callback`);
|
|
59
|
-
if (!command.contexts
|
|
59
|
+
if (!command.contexts.includes(v10_1.InteractionContextType.BotDM) && !message.guildId)
|
|
60
|
+
return;
|
|
61
|
+
if (!command.contexts.includes(v10_1.InteractionContextType.Guild) && message.guildId)
|
|
60
62
|
return;
|
|
61
63
|
if (command.guildId && !command.guildId?.includes(message.guildId))
|
|
62
64
|
return;
|
|
@@ -67,14 +69,30 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
67
69
|
members: {},
|
|
68
70
|
attachments: {},
|
|
69
71
|
};
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
+
let newContent = content;
|
|
73
|
+
for (const i of fullCommandName.split(' ')) {
|
|
74
|
+
newContent = newContent.slice(newContent.indexOf(i) + i.length);
|
|
75
|
+
}
|
|
76
|
+
const args = self.options.commands.argsParser(newContent.slice(1), command, message);
|
|
77
|
+
const { options, errors } = await self.options.commands.optionsParser(self, command, rawMessage, args, resolved);
|
|
72
78
|
const optionsResolver = new __1.OptionResolver(self, options, parent, message.guildId, resolved);
|
|
73
79
|
const context = new __1.CommandContext(self, message, optionsResolver, shardId, command);
|
|
74
80
|
//@ts-expect-error
|
|
75
81
|
const extendContext = self.options?.context?.(message) ?? {};
|
|
76
82
|
Object.assign(context, extendContext);
|
|
77
83
|
try {
|
|
84
|
+
if (errors.length) {
|
|
85
|
+
return command.onOptionsError?.(context, Object.fromEntries(errors.map(x => {
|
|
86
|
+
return [
|
|
87
|
+
x.name,
|
|
88
|
+
{
|
|
89
|
+
failed: true,
|
|
90
|
+
value: x.error,
|
|
91
|
+
parseError: x.fullError,
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
})));
|
|
95
|
+
}
|
|
78
96
|
if (command.defaultMemberPermissions && message.guildId) {
|
|
79
97
|
const memberPermissions = await self.members.permissions(message.guildId, message.author.id);
|
|
80
98
|
const permissions = memberPermissions.missings(...memberPermissions.values([command.defaultMemberPermissions]));
|
|
@@ -94,17 +112,6 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
94
112
|
return command.onBotPermissionsFail?.(context, appPermissions.keys(permissions));
|
|
95
113
|
}
|
|
96
114
|
}
|
|
97
|
-
if (errors.length) {
|
|
98
|
-
return command.onOptionsError?.(context, Object.fromEntries(errors.map(x => {
|
|
99
|
-
return [
|
|
100
|
-
x.name,
|
|
101
|
-
{
|
|
102
|
-
failed: true,
|
|
103
|
-
value: x.error,
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
})));
|
|
107
|
-
}
|
|
108
115
|
const [erroredOptions, result] = await command.__runOptions(context, optionsResolver);
|
|
109
116
|
if (erroredOptions) {
|
|
110
117
|
return command.onOptionsError?.(context, result);
|
|
@@ -142,7 +149,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
exports.onMessageCreate = onMessageCreate;
|
|
145
|
-
async function
|
|
152
|
+
async function defaultOptionsParser(self, command, message, args, resolved) {
|
|
146
153
|
const options = [];
|
|
147
154
|
const errors = [];
|
|
148
155
|
for (const i of (command.options ?? [])) {
|
|
@@ -175,6 +182,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
175
182
|
error: `The entered channel type is not one of ${i
|
|
176
183
|
.channel_types.map(t => v10_1.ChannelType[t])
|
|
177
184
|
.join(', ')}`,
|
|
185
|
+
fullError: ['CHANNEL_TYPES', i.channel_types],
|
|
178
186
|
});
|
|
179
187
|
break;
|
|
180
188
|
}
|
|
@@ -262,95 +270,105 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
262
270
|
{
|
|
263
271
|
value = args[i.name];
|
|
264
272
|
const option = i;
|
|
265
|
-
if (value)
|
|
266
|
-
if (option.min_length) {
|
|
267
|
-
if (value.length < option.min_length) {
|
|
268
|
-
value = undefined;
|
|
269
|
-
errors.push({
|
|
270
|
-
name: i.name,
|
|
271
|
-
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
|
272
|
-
});
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (option.max_length) {
|
|
277
|
-
if (value.length > option.max_length) {
|
|
278
|
-
value = undefined;
|
|
279
|
-
errors.push({
|
|
280
|
-
name: i.name,
|
|
281
|
-
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
|
282
|
-
});
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (option.choices?.length) {
|
|
287
|
-
if (!option.choices.some(x => x.name === value)) {
|
|
288
|
-
value = undefined;
|
|
289
|
-
errors.push({
|
|
290
|
-
name: i.name,
|
|
291
|
-
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
292
|
-
.map(x => x.name)
|
|
293
|
-
.join(', ')}.`,
|
|
294
|
-
});
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
value = option.choices.find(x => x.name === value).value;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
break;
|
|
302
|
-
case v10_1.ApplicationCommandOptionType.Number:
|
|
303
|
-
case v10_1.ApplicationCommandOptionType.Integer:
|
|
304
|
-
{
|
|
305
|
-
value = Number(args[i.name]);
|
|
306
|
-
if (args[i.name] === undefined) {
|
|
307
|
-
value = undefined;
|
|
273
|
+
if (!value)
|
|
308
274
|
break;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
value = undefined;
|
|
312
|
-
errors.push({
|
|
313
|
-
name: i.name,
|
|
314
|
-
error: 'The entered choice is an invalid number.',
|
|
315
|
-
});
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
const option = i;
|
|
319
|
-
if (option.min_value) {
|
|
320
|
-
if (value < option.min_value) {
|
|
275
|
+
if (option.min_length) {
|
|
276
|
+
if (value.length < option.min_length) {
|
|
321
277
|
value = undefined;
|
|
322
278
|
errors.push({
|
|
323
279
|
name: i.name,
|
|
324
|
-
error: `The entered
|
|
280
|
+
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
|
281
|
+
fullError: ['STRING_MIN_LENGTH', option.min_length],
|
|
325
282
|
});
|
|
326
283
|
break;
|
|
327
284
|
}
|
|
328
285
|
}
|
|
329
|
-
if (option.
|
|
330
|
-
if (value > option.
|
|
286
|
+
if (option.max_length) {
|
|
287
|
+
if (value.length > option.max_length) {
|
|
331
288
|
value = undefined;
|
|
332
289
|
errors.push({
|
|
333
290
|
name: i.name,
|
|
334
|
-
error: `The entered
|
|
291
|
+
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
|
292
|
+
fullError: ['STRING_MAX_LENGTH', option.max_length],
|
|
335
293
|
});
|
|
336
294
|
break;
|
|
337
295
|
}
|
|
338
296
|
}
|
|
339
297
|
if (option.choices?.length) {
|
|
340
|
-
|
|
298
|
+
const choice = option.choices.find(x => x.name === value);
|
|
299
|
+
if (!choice) {
|
|
341
300
|
value = undefined;
|
|
342
301
|
errors.push({
|
|
343
302
|
name: i.name,
|
|
344
303
|
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
345
304
|
.map(x => x.name)
|
|
346
305
|
.join(', ')}.`,
|
|
306
|
+
fullError: ['STRING_INVALID_CHOICE', option.choices],
|
|
347
307
|
});
|
|
348
308
|
break;
|
|
349
309
|
}
|
|
350
|
-
value =
|
|
310
|
+
value = choice.value;
|
|
351
311
|
}
|
|
352
312
|
}
|
|
353
313
|
break;
|
|
314
|
+
case v10_1.ApplicationCommandOptionType.Number:
|
|
315
|
+
case v10_1.ApplicationCommandOptionType.Integer:
|
|
316
|
+
{
|
|
317
|
+
const option = i;
|
|
318
|
+
if (!option.choices?.length) {
|
|
319
|
+
value = Number(args[i.name]);
|
|
320
|
+
if (args[i.name] === undefined) {
|
|
321
|
+
value = undefined;
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
if (Number.isNaN(value)) {
|
|
325
|
+
value = undefined;
|
|
326
|
+
errors.push({
|
|
327
|
+
name: i.name,
|
|
328
|
+
error: 'The entered choice is an invalid number.',
|
|
329
|
+
fullError: ['NUMBER_NAN', args[i.name]],
|
|
330
|
+
});
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
if (option.min_value) {
|
|
334
|
+
if (value < option.min_value) {
|
|
335
|
+
value = undefined;
|
|
336
|
+
errors.push({
|
|
337
|
+
name: i.name,
|
|
338
|
+
error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
|
|
339
|
+
fullError: ['NUMBER_MIN_VALUE', option.min_value],
|
|
340
|
+
});
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (option.max_value) {
|
|
345
|
+
if (value > option.max_value) {
|
|
346
|
+
value = undefined;
|
|
347
|
+
errors.push({
|
|
348
|
+
name: i.name,
|
|
349
|
+
error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
|
|
350
|
+
fullError: ['NUMBER_MAX_VALUE', option.max_value],
|
|
351
|
+
});
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
const choice = option.choices.find(x => x.name === args[i.name]);
|
|
358
|
+
if (!choice) {
|
|
359
|
+
value = undefined;
|
|
360
|
+
errors.push({
|
|
361
|
+
name: i.name,
|
|
362
|
+
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
363
|
+
.map(x => x.name)
|
|
364
|
+
.join(', ')}.`,
|
|
365
|
+
fullError: ['NUMBER_INVALID_CHOICE', option.choices],
|
|
366
|
+
});
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
value = choice.value;
|
|
370
|
+
}
|
|
371
|
+
break;
|
|
354
372
|
default:
|
|
355
373
|
break;
|
|
356
374
|
}
|
|
@@ -362,20 +380,24 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
362
380
|
});
|
|
363
381
|
}
|
|
364
382
|
else if (i.required)
|
|
365
|
-
errors.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
383
|
+
if (!errors.some(x => x.name === i.name))
|
|
384
|
+
errors.push({
|
|
385
|
+
error: 'Option is required but returned undefined',
|
|
386
|
+
name: i.name,
|
|
387
|
+
fullError: ['OPTION_REQUIRED'],
|
|
388
|
+
});
|
|
369
389
|
}
|
|
370
390
|
catch (e) {
|
|
371
391
|
errors.push({
|
|
372
392
|
error: e && typeof e === 'object' && 'message' in e ? e.message : `${e}`,
|
|
373
393
|
name: i.name,
|
|
394
|
+
fullError: ['UNKNOWN', e],
|
|
374
395
|
});
|
|
375
396
|
}
|
|
376
397
|
}
|
|
377
398
|
return { errors, options };
|
|
378
399
|
}
|
|
400
|
+
exports.defaultOptionsParser = defaultOptionsParser;
|
|
379
401
|
function defaultArgsParser(content) {
|
|
380
402
|
const args = {};
|
|
381
403
|
for (const i of content.match(/-(.*?)(?=\s-|$)/gs) ?? []) {
|
|
@@ -383,5 +405,6 @@ function defaultArgsParser(content) {
|
|
|
383
405
|
}
|
|
384
406
|
return args;
|
|
385
407
|
}
|
|
408
|
+
exports.defaultArgsParser = defaultArgsParser;
|
|
386
409
|
//-(.*?)(?=\s-|$)/gs
|
|
387
410
|
//-(?<text>[^-]*)/gm
|
|
@@ -14,10 +14,12 @@ import type { WorkerShardInfo } from '../websocket/discord/worker';
|
|
|
14
14
|
import type { ManagerMessages } from '../websocket/discord/workermanager';
|
|
15
15
|
import type { BaseClientOptions, ServicesOptions, StartOptions } from './base';
|
|
16
16
|
import { BaseClient } from './base';
|
|
17
|
-
import type { Client } from './client';
|
|
17
|
+
import type { Client, ClientOptions } from './client';
|
|
18
|
+
import { Collectors } from './collectors';
|
|
18
19
|
export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
|
|
19
20
|
private __handleGuilds?;
|
|
20
21
|
logger: Logger;
|
|
22
|
+
collectors: Collectors;
|
|
21
23
|
events?: EventHandler | undefined;
|
|
22
24
|
me: When<Ready, ClientUser>;
|
|
23
25
|
promises: Map<string, {
|
|
@@ -25,7 +27,7 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
25
27
|
timeout: NodeJS.Timeout;
|
|
26
28
|
}>;
|
|
27
29
|
shards: Map<number, Shard>;
|
|
28
|
-
options: WorkerClientOptions
|
|
30
|
+
options: WorkerClientOptions;
|
|
29
31
|
constructor(options?: WorkerClientOptions);
|
|
30
32
|
get workerId(): number;
|
|
31
33
|
get latency(): number;
|
|
@@ -48,5 +50,6 @@ interface WorkerClientOptions extends BaseClientOptions {
|
|
|
48
50
|
disabledCache: Cache['disabledCache'];
|
|
49
51
|
commands?: NonNullable<Client['options']>['commands'];
|
|
50
52
|
handlePayload?: ShardManagerOptions['handlePayload'];
|
|
53
|
+
gateway?: ClientOptions['gateway'];
|
|
51
54
|
}
|
|
52
55
|
export {};
|