@pikokr/command.ts 3.2.4-dev.434c22e → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/applicationCommand/AppCommand.d.ts +18 -0
- package/dist/applicationCommand/AppCommand.js +22 -0
- package/dist/applicationCommand/AppCommand.js.map +1 -0
- package/dist/applicationCommand/decorator.d.ts +10 -0
- package/dist/applicationCommand/decorator.js +39 -0
- package/dist/applicationCommand/decorator.js.map +1 -0
- package/dist/applicationCommand/index.d.ts +2 -0
- package/dist/applicationCommand/index.js +15 -0
- package/dist/applicationCommand/index.js.map +1 -0
- package/dist/builtinModules/BuiltinApplicationCommandConverters.d.ts +8 -0
- package/dist/builtinModules/BuiltinApplicationCommandConverters.js +13 -0
- package/dist/builtinModules/BuiltinApplicationCommandConverters.js.map +1 -0
- package/dist/builtinModules/CommandHandler.d.ts +4 -1
- package/dist/builtinModules/CommandHandler.js +141 -17
- package/dist/builtinModules/CommandHandler.js.map +1 -1
- package/dist/builtinModules/index.d.ts +1 -1
- package/dist/builtinModules/index.js +1 -1
- package/dist/builtinModules/index.js.map +1 -1
- package/dist/command/ArgumentConverter.d.ts +3 -3
- package/dist/command/ArgumentConverter.js +3 -3
- package/dist/command/ArgumentConverter.js.map +1 -1
- package/dist/command/Command.d.ts +2 -2
- package/dist/command/decorator.d.ts +2 -1
- package/dist/command/decorator.js +6 -5
- package/dist/command/decorator.js.map +1 -1
- package/dist/command/utils.d.ts +2 -2
- package/dist/command/utils.js +6 -6
- package/dist/command/utils.js.map +1 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +4 -3
- package/dist/constants.js.map +1 -1
- package/dist/error/ArgumentConverterNotFound.d.ts +6 -6
- package/dist/error/ArgumentConverterNotFound.js +3 -3
- package/dist/error/ArgumentConverterNotFound.js.map +1 -1
- package/dist/error/CommandCheckFailed.d.ts +6 -6
- package/dist/error/CommandCheckFailed.js +3 -3
- package/dist/error/CommandCheckFailed.js.map +1 -1
- package/dist/error/checks/SlashCommandGlobalCheckError.d.ts +5 -0
- package/dist/error/checks/SlashCommandGlobalCheckError.js +11 -0
- package/dist/error/checks/SlashCommandGlobalCheckError.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/messageComponents/base.d.ts +10 -0
- package/dist/messageComponents/base.js +15 -0
- package/dist/messageComponents/base.js.map +1 -0
- package/dist/messageComponents/button.d.ts +5 -0
- package/dist/messageComponents/button.js +28 -0
- package/dist/messageComponents/button.js.map +1 -0
- package/dist/messageComponents/index.d.ts +2 -0
- package/dist/messageComponents/index.js +15 -0
- package/dist/messageComponents/index.js.map +1 -0
- package/dist/messageComponents/selectMenu.d.ts +5 -0
- package/dist/messageComponents/selectMenu.js +28 -0
- package/dist/messageComponents/selectMenu.js.map +1 -0
- package/dist/slashCommand/decorator.d.ts +1 -0
- package/dist/slashCommand/decorator.js +2 -1
- package/dist/slashCommand/decorator.js.map +1 -1
- package/dist/structures/CommandClient.d.ts +7 -3
- package/dist/structures/CommandClient.js +7 -8
- package/dist/structures/CommandClient.js.map +1 -1
- package/dist/structures/Module.d.ts +6 -4
- package/dist/structures/Module.js +6 -3
- package/dist/structures/Module.js.map +1 -1
- package/dist/structures/Registry.d.ts +6 -4
- package/dist/structures/Registry.js +18 -15
- package/dist/structures/Registry.js.map +1 -1
- package/dist/typings.d.ts +14 -2
- package/package.json +2 -4
- package/src/applicationCommand/AppCommand.ts +28 -0
- package/src/{slashCommand → applicationCommand}/decorator.ts +10 -10
- package/src/applicationCommand/index.ts +2 -0
- package/src/builtinModules/BuiltinApplicationCommandConverters.ts +12 -0
- package/src/builtinModules/CommandHandler.ts +168 -20
- package/src/builtinModules/index.ts +1 -1
- package/src/command/ArgumentConverter.ts +3 -3
- package/src/command/Command.ts +2 -2
- package/src/command/decorator.ts +6 -5
- package/src/command/utils.ts +9 -9
- package/src/constants.ts +4 -2
- package/src/error/ArgumentConverterNotFound.ts +4 -4
- package/src/error/CommandCheckFailed.ts +4 -4
- package/src/error/checks/SlashCommandGlobalCheckError.ts +7 -0
- package/src/index.ts +2 -1
- package/src/messageComponents/base.ts +12 -0
- package/src/messageComponents/button.ts +26 -0
- package/src/messageComponents/index.ts +2 -0
- package/src/messageComponents/selectMenu.ts +26 -0
- package/src/structures/CommandClient.ts +16 -10
- package/src/structures/Module.ts +11 -6
- package/src/structures/Registry.ts +25 -19
- package/src/typings.ts +14 -2
- package/test/index.ts +2 -2
- package/test/modules/dev.ts +9 -5
- package/test/modules/test.ts +88 -15
- package/src/builtinModules/BuiltinSlashCommandConverters.ts +0 -23
- package/src/slashCommand/SlashCommand.ts +0 -29
- package/src/slashCommand/index.ts +0 -2
|
@@ -38,7 +38,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
38
38
|
const error_1 = require("../error");
|
|
39
39
|
const discord_js_1 = require("discord.js");
|
|
40
40
|
const walk_sync_1 = __importDefault(require("walk-sync"));
|
|
41
|
-
const v9_1 = require("discord-api-types/v9");
|
|
42
41
|
const fs = __importStar(require("fs"));
|
|
43
42
|
class Registry {
|
|
44
43
|
constructor(client) {
|
|
@@ -64,17 +63,24 @@ class Registry {
|
|
|
64
63
|
}
|
|
65
64
|
return result;
|
|
66
65
|
}
|
|
67
|
-
get
|
|
66
|
+
get applicationCommandArgumentConverters() {
|
|
68
67
|
const result = [];
|
|
69
68
|
for (const [, module] of this.modules) {
|
|
70
|
-
result.push(...module.
|
|
69
|
+
result.push(...module.applicationCommandArgumentConverters);
|
|
71
70
|
}
|
|
72
71
|
return result;
|
|
73
72
|
}
|
|
74
|
-
get
|
|
73
|
+
get applicationCommands() {
|
|
75
74
|
const result = [];
|
|
76
75
|
for (const [, module] of this.modules) {
|
|
77
|
-
result.push(...module.
|
|
76
|
+
result.push(...module.applicationCommands);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
get messageComponentHandlers() {
|
|
81
|
+
const result = [];
|
|
82
|
+
for (const [, module] of this.modules) {
|
|
83
|
+
result.push(...module.messageComponentHandlers);
|
|
78
84
|
}
|
|
79
85
|
return result;
|
|
80
86
|
}
|
|
@@ -127,21 +133,20 @@ class Registry {
|
|
|
127
133
|
});
|
|
128
134
|
}
|
|
129
135
|
syncCommands() {
|
|
136
|
+
var _a;
|
|
130
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
138
|
this.logger.debug(`Syncing commands...`);
|
|
132
|
-
const commands = this.
|
|
133
|
-
const guild = this.client.options.
|
|
139
|
+
const commands = this.applicationCommands.filter((x) => !x.guild);
|
|
140
|
+
const guild = this.client.options.applicationCommands.guild;
|
|
134
141
|
if (guild) {
|
|
135
142
|
const syncForGuild = (g) => __awaiter(this, void 0, void 0, function* () {
|
|
136
143
|
this.logger.debug(`Syncing for guild ${g.name}(${g.id})`);
|
|
137
144
|
const commandsToRegister = [
|
|
138
|
-
...commands.map((x) => x.
|
|
139
|
-
...this.
|
|
145
|
+
...commands.map((x) => x.command),
|
|
146
|
+
...this.applicationCommands.filter((y) => { var _a; return y.guild === g.id || ((_a = y.guild) === null || _a === void 0 ? void 0 : _a.includes(g.id)) || false; }).map((x) => x.command),
|
|
140
147
|
];
|
|
141
148
|
this.logger.debug(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`);
|
|
142
|
-
yield
|
|
143
|
-
body: commandsToRegister.map((x) => x.toJSON()),
|
|
144
|
-
});
|
|
149
|
+
yield g.commands.set(commandsToRegister);
|
|
145
150
|
});
|
|
146
151
|
if (typeof guild === 'string') {
|
|
147
152
|
yield syncForGuild(yield this.client.client.guilds.fetch(guild));
|
|
@@ -154,9 +159,7 @@ class Registry {
|
|
|
154
159
|
}
|
|
155
160
|
else {
|
|
156
161
|
this.logger.debug('Syncing global...');
|
|
157
|
-
yield
|
|
158
|
-
body: commands.map((x) => x.commandBuilder.toJSON()),
|
|
159
|
-
});
|
|
162
|
+
yield ((_a = this.client.client.application) === null || _a === void 0 ? void 0 : _a.commands.set(commands.map((x) => x.command)));
|
|
160
163
|
}
|
|
161
164
|
this.logger.debug('Syncing ended.');
|
|
162
165
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Registry.js","sourceRoot":"","sources":["../../src/structures/Registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAAiC;AAEjC,4CAAiF;AACjF,gDAAuB;AACvB,oCAAkF;AAClF,2CAA8C;AAC9C,0DAAgC;AAGhC,
|
|
1
|
+
{"version":3,"file":"Registry.js","sourceRoot":"","sources":["../../src/structures/Registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAAiC;AAEjC,4CAAiF;AACjF,gDAAuB;AACvB,oCAAkF;AAClF,2CAA8C;AAC9C,0DAAgC;AAGhC,uCAAwB;AAQxB,MAAa,QAAQ;IACnB,YAAmB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QAExC,YAAO,GAA+B,IAAI,uBAAU,EAAE,CAAA;IAFX,CAAC;IAI5C,IAAY,MAAM;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;YACvC,IAAI,EAAE,UAAU;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,QAAQ;QACV,MAAM,MAAM,GAAc,EAAE,CAAA;QAE5B,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;SAChC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED,IAAI,kBAAkB;QACpB,MAAM,MAAM,GAAwB,EAAE,CAAA;QAEtC,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,kBAAkB,CAAC,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/B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;YAC1C,MAAM,GAAG,CAAC,WAAW,EAAE,CAAA;YACvB,OAAO,IAAI,CAAA;QACb,CAAC;KAAA;IAEK,SAAS;;YACb,MAAM,OAAO,GAIP,EAAE,CAAA;YAER,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,0BAAc,EAAE,CAAC,CAAC,CAAC,EAAE;gBACxG,IAAI;oBACF,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;oBAC/B,OAAO,CAAC,IAAI,CAAC;wBACX,IAAI,EAAE,MAAM,CAAC,IAAK;wBAClB,OAAO,EAAE,IAAI;qBACd,CAAC,CAAA;iBACH;gBAAC,OAAO,CAAM,EAAE;oBACf,OAAO,CAAC,IAAI,CAAC;wBACX,KAAK,EAAE,CAAC;wBACR,IAAI,EAAE,MAAM,CAAC,IAAK;wBAClB,OAAO,EAAE,KAAK;qBACf,CAAC,CAAA;iBACH;aACF;YACD,OAAO,OAAO,CAAA;QAChB,CAAC;KAAA;CACF;AA5MD,4BA4MC"}
|
package/dist/typings.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Command } from './command';
|
|
2
2
|
import { CommandClient } from './structures';
|
|
3
|
-
import {
|
|
3
|
+
import { AppCommand } from './applicationCommand';
|
|
4
4
|
declare module 'discord.js' {
|
|
5
5
|
interface Message {
|
|
6
6
|
data: {
|
|
@@ -11,7 +11,19 @@ declare module 'discord.js' {
|
|
|
11
11
|
}
|
|
12
12
|
interface CommandInteraction {
|
|
13
13
|
data: {
|
|
14
|
-
command:
|
|
14
|
+
command: AppCommand;
|
|
15
|
+
cts: CommandClient;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface MessageComponentInteraction {
|
|
19
|
+
data: {
|
|
20
|
+
command: AppCommand;
|
|
21
|
+
cts: CommandClient;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface ContextMenuInteraction {
|
|
25
|
+
data: {
|
|
26
|
+
command: AppCommand;
|
|
15
27
|
cts: CommandClient;
|
|
16
28
|
};
|
|
17
29
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikokr/command.ts",
|
|
3
3
|
"description": "Discord.js command framework for typescript.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@discordjs/builders": "^0.6.0",
|
|
10
|
-
"@discordjs/rest": "^0.1.0-canary.0",
|
|
11
9
|
"@types/lodash": "^4.14.172",
|
|
12
10
|
"all-contributors-cli": "^6.20.0",
|
|
13
11
|
"discord.js": "^13.6.0",
|
|
@@ -33,4 +31,4 @@
|
|
|
33
31
|
"docs:dev": "typedoc",
|
|
34
32
|
"docs:build": "typedoc"
|
|
35
33
|
}
|
|
36
|
-
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Module } from '../structures'
|
|
2
|
+
import { ApplicationCommandDataResolvable, Snowflake } from 'discord.js'
|
|
3
|
+
import { KApplicationCommandChecks } from '../constants'
|
|
4
|
+
import { ApplicationCommandCheckFunction } from '../command'
|
|
5
|
+
|
|
6
|
+
export type AppCommandArgument = {
|
|
7
|
+
type: any
|
|
8
|
+
name?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class AppCommand {
|
|
12
|
+
get checks(): ApplicationCommandCheckFunction[] {
|
|
13
|
+
return Reflect.getMetadata(KApplicationCommandChecks, this.module, this.key) || []
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
execute(module: Module, args: any[]) {
|
|
17
|
+
return this.run.apply(module, args)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
public command: ApplicationCommandDataResolvable,
|
|
22
|
+
private run: Function,
|
|
23
|
+
public module: Module,
|
|
24
|
+
public params: AppCommandArgument[],
|
|
25
|
+
public guild: Snowflake | Snowflake[] | undefined,
|
|
26
|
+
private key: string | symbol,
|
|
27
|
+
) {}
|
|
28
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Collection, Snowflake } from 'discord.js'
|
|
1
|
+
import { ApplicationCommandDataResolvable, Collection, Snowflake } from 'discord.js'
|
|
2
2
|
import { checkTarget } from '../utils'
|
|
3
|
-
import { KSlashCommandOptions,
|
|
3
|
+
import { KSlashCommandOptions, KApplicationCommands } from '../constants'
|
|
4
4
|
import { Module } from '../structures'
|
|
5
|
-
import {
|
|
6
|
-
import { SlashCommandBuilder } from '@discordjs/builders'
|
|
5
|
+
import { AppCommand } from './AppCommand'
|
|
7
6
|
|
|
8
|
-
type
|
|
7
|
+
type ApplicationCommandOptions = {
|
|
9
8
|
guild: Snowflake | Snowflake[]
|
|
9
|
+
optionTypes?: any[]
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const applicationCommand = (opt: Partial<ApplicationCommandOptions> & { command: ApplicationCommandDataResolvable }) => {
|
|
13
13
|
return (
|
|
14
14
|
target: Object,
|
|
15
15
|
propertyKey: string,
|
|
@@ -17,13 +17,13 @@ export const slashCommand = (opt: Partial<SlashOptions> & { command: SlashComman
|
|
|
17
17
|
) => {
|
|
18
18
|
checkTarget(target)
|
|
19
19
|
|
|
20
|
-
let properties:
|
|
20
|
+
let properties: AppCommand[] = Reflect.getMetadata(KApplicationCommands, target)
|
|
21
21
|
|
|
22
|
-
const params: any[] = Reflect.getMetadata('design:paramtypes', target, propertyKey)
|
|
22
|
+
const params: any[] = opt.optionTypes ?? Reflect.getMetadata('design:paramtypes', target, propertyKey)
|
|
23
23
|
|
|
24
24
|
const options: Collection<number, string> = Reflect.getMetadata(KSlashCommandOptions, target, propertyKey) || new Collection<number, string>()
|
|
25
25
|
|
|
26
|
-
const command = new
|
|
26
|
+
const command = new AppCommand(
|
|
27
27
|
opt.command,
|
|
28
28
|
Reflect.get(target, propertyKey),
|
|
29
29
|
target as Module,
|
|
@@ -39,7 +39,7 @@ export const slashCommand = (opt: Partial<SlashOptions> & { command: SlashComman
|
|
|
39
39
|
properties.push(command)
|
|
40
40
|
} else {
|
|
41
41
|
properties = [command]
|
|
42
|
-
Reflect.defineMetadata(
|
|
42
|
+
Reflect.defineMetadata(KApplicationCommands, properties, target)
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BuiltInModule } from './BuiltInModule'
|
|
2
|
+
import { Client } from 'discord.js'
|
|
3
|
+
import { CommandClient } from '../structures'
|
|
4
|
+
|
|
5
|
+
export class BuiltinApplicationCommandConverters extends BuiltInModule {
|
|
6
|
+
client: Client
|
|
7
|
+
|
|
8
|
+
constructor(private cts: CommandClient) {
|
|
9
|
+
super()
|
|
10
|
+
this.client = cts.client
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { BuiltInModule } from './BuiltInModule'
|
|
2
2
|
import { Registry } from '../structures'
|
|
3
3
|
import { listener } from '../listener'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CommandInteraction,
|
|
6
|
+
CommandInteractionOptionResolver,
|
|
7
|
+
GuildMember,
|
|
8
|
+
Interaction,
|
|
9
|
+
Message,
|
|
10
|
+
MessageComponentInteraction,
|
|
11
|
+
MessageContextMenuInteraction,
|
|
12
|
+
Role,
|
|
13
|
+
User,
|
|
14
|
+
UserContextMenuInteraction,
|
|
15
|
+
} from 'discord.js'
|
|
5
16
|
import { CommandClient } from '../structures'
|
|
6
17
|
import { Command } from '../command'
|
|
7
|
-
import { ArgumentConverterNotFound, ArgumentNotProvided, CommandCheckFailed,
|
|
18
|
+
import { ArgumentConverterNotFound, ArgumentNotProvided, CommandCheckFailed, ApplicationCommandArgumentConverterNotFound, ApplicationCommandCheckFailed } from '../error'
|
|
8
19
|
import { CommandNotFound } from '../error/CommandNotFound'
|
|
20
|
+
import { SlashCommandGlobalCheckError } from '../error/checks/SlashCommandGlobalCheckError'
|
|
21
|
+
import { MessageComponentHandler } from '../messageComponents/base'
|
|
9
22
|
|
|
10
23
|
export class CommandHandler extends BuiltInModule {
|
|
11
24
|
private readonly client: CommandClient
|
|
@@ -15,6 +28,7 @@ export class CommandHandler extends BuiltInModule {
|
|
|
15
28
|
this.client = registry.client
|
|
16
29
|
}
|
|
17
30
|
|
|
31
|
+
// region message command handler
|
|
18
32
|
@listener('messageCreate')
|
|
19
33
|
async message(msg: Message) {
|
|
20
34
|
const error = (error: Error) => this.client.client.emit('commandError', error, msg)
|
|
@@ -129,36 +143,47 @@ export class CommandHandler extends BuiltInModule {
|
|
|
129
143
|
return error(e)
|
|
130
144
|
}
|
|
131
145
|
}
|
|
146
|
+
// endregion
|
|
132
147
|
|
|
148
|
+
// region slash command handler
|
|
133
149
|
private async command(i: CommandInteraction) {
|
|
134
|
-
const error = (error: Error) => this.client.client.emit('
|
|
150
|
+
const error = (error: Error) => this.client.client.emit('applicationCommandError', error, i)
|
|
135
151
|
try {
|
|
136
|
-
const cmd = this.registry.
|
|
152
|
+
const cmd = this.registry.applicationCommands.find((x) => x.command.type === 'CHAT_INPUT' && x.command.name === i.commandName)
|
|
137
153
|
|
|
138
|
-
|
|
154
|
+
if (!cmd) return
|
|
155
|
+
|
|
156
|
+
const module = this.registry.modules.find((x) => x.applicationCommands.includes(cmd))
|
|
139
157
|
|
|
140
158
|
if (!module) return
|
|
141
159
|
|
|
142
160
|
const argList: any[] = []
|
|
143
161
|
|
|
144
|
-
if (!cmd)
|
|
145
|
-
return i.reply({
|
|
146
|
-
content: 'Unknown command.',
|
|
147
|
-
ephemeral: true,
|
|
148
|
-
})
|
|
149
|
-
|
|
150
162
|
i.data = {
|
|
151
163
|
cts: this.client,
|
|
152
164
|
command: cmd,
|
|
153
165
|
}
|
|
154
166
|
|
|
167
|
+
if (!(await this.client.options.slashCommands.check(i))) {
|
|
168
|
+
return error(new SlashCommandGlobalCheckError(i))
|
|
169
|
+
}
|
|
155
170
|
for (const check of cmd.checks) {
|
|
156
|
-
if (!(await check(i))) return error(new
|
|
171
|
+
if (!(await check(i))) return error(new ApplicationCommandCheckFailed(i, cmd))
|
|
157
172
|
}
|
|
158
173
|
|
|
159
174
|
for (let j = 0; j < cmd.params.length; j++) {
|
|
160
175
|
const argType = cmd.params[j]
|
|
161
|
-
const converter = this.registry.
|
|
176
|
+
const converter = this.registry.applicationCommandArgumentConverters.find((x) => x.type === argType.type)
|
|
177
|
+
|
|
178
|
+
if (argType.type === CommandInteraction) {
|
|
179
|
+
argList.push(i)
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (argType.type === CommandInteractionOptionResolver) {
|
|
184
|
+
argList.push(i.options)
|
|
185
|
+
continue
|
|
186
|
+
}
|
|
162
187
|
|
|
163
188
|
if (argType.name) {
|
|
164
189
|
switch (argType.type) {
|
|
@@ -195,16 +220,119 @@ export class CommandHandler extends BuiltInModule {
|
|
|
195
220
|
continue
|
|
196
221
|
}
|
|
197
222
|
|
|
198
|
-
if (!converter) return error(new
|
|
223
|
+
if (!converter) return error(new ApplicationCommandArgumentConverterNotFound(argType, i))
|
|
199
224
|
|
|
200
225
|
argList.push(await converter.execute(module, i))
|
|
201
226
|
}
|
|
202
227
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
228
|
+
await cmd.execute(module, argList)
|
|
229
|
+
} catch (e) {
|
|
230
|
+
return error(e)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// endregion
|
|
234
|
+
|
|
235
|
+
private async messageComponent(i: MessageComponentInteraction) {
|
|
236
|
+
const error = (e: any) => this.client.client.emit('messageComponentError', e)
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
const handlers: MessageComponentHandler[] = []
|
|
240
|
+
|
|
241
|
+
for (const handler of this.registry.messageComponentHandlers) {
|
|
242
|
+
if (handler.componentId === handler.componentId && handler.componentType === i.componentType) {
|
|
243
|
+
handlers.push(handler)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
for (const handler of handlers) {
|
|
248
|
+
const module = this.registry.modules.find((x) => x.messageComponentHandlers.includes(handler))
|
|
249
|
+
if (!module) continue
|
|
250
|
+
await handler.run(module, i)
|
|
251
|
+
}
|
|
252
|
+
} catch (e) {
|
|
253
|
+
error(e)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private async userContextMenu(i: UserContextMenuInteraction) {
|
|
258
|
+
const error = (error: Error) => this.client.client.emit('applicationCommandError', error, i)
|
|
259
|
+
try {
|
|
260
|
+
const cmd = this.registry.applicationCommands.find((x) => x.command.type === 'USER' && x.command.name === i.commandName)
|
|
261
|
+
|
|
262
|
+
if (!cmd) return
|
|
263
|
+
|
|
264
|
+
const module = this.registry.modules.find((x) => x.applicationCommands.includes(cmd))
|
|
265
|
+
|
|
266
|
+
if (!module) return
|
|
267
|
+
|
|
268
|
+
i.data = {
|
|
269
|
+
cts: this.client,
|
|
270
|
+
command: cmd,
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
for (const check of cmd.checks) {
|
|
274
|
+
if (!(await check(i))) return error(new ApplicationCommandCheckFailed(i, cmd))
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let argList: any[] = []
|
|
278
|
+
|
|
279
|
+
for (let j = 0; j < cmd.params.length; j++) {
|
|
280
|
+
const argType = cmd.params[j]
|
|
281
|
+
const converter = this.registry.applicationCommandArgumentConverters.find((x) => x.type === argType.type)
|
|
282
|
+
|
|
283
|
+
if (argType.type === UserContextMenuInteraction) {
|
|
284
|
+
argList.push(i)
|
|
285
|
+
continue
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (!converter) return error(new ApplicationCommandArgumentConverterNotFound(argType, i))
|
|
289
|
+
|
|
290
|
+
argList.push(await converter.execute(module, i))
|
|
207
291
|
}
|
|
292
|
+
|
|
293
|
+
await cmd.execute(module, argList)
|
|
294
|
+
} catch (e) {
|
|
295
|
+
return error(e)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private async messageContextMenu(i: MessageContextMenuInteraction) {
|
|
300
|
+
const error = (error: Error) => this.client.client.emit('applicationCommandError', error, i)
|
|
301
|
+
try {
|
|
302
|
+
const cmd = this.registry.applicationCommands.find((x) => x.command.type === 'MESSAGE' && x.command.name === i.commandName)
|
|
303
|
+
|
|
304
|
+
if (!cmd) return
|
|
305
|
+
|
|
306
|
+
const module = this.registry.modules.find((x) => x.applicationCommands.includes(cmd))
|
|
307
|
+
|
|
308
|
+
if (!module) return
|
|
309
|
+
|
|
310
|
+
i.data = {
|
|
311
|
+
cts: this.client,
|
|
312
|
+
command: cmd,
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
for (const check of cmd.checks) {
|
|
316
|
+
if (!(await check(i))) return error(new ApplicationCommandCheckFailed(i, cmd))
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
let argList: any[] = []
|
|
320
|
+
|
|
321
|
+
for (let j = 0; j < cmd.params.length; j++) {
|
|
322
|
+
const argType = cmd.params[j]
|
|
323
|
+
const converter = this.registry.applicationCommandArgumentConverters.find((x) => x.type === argType.type)
|
|
324
|
+
|
|
325
|
+
if (argType.type === MessageContextMenuInteraction) {
|
|
326
|
+
argList.push(i)
|
|
327
|
+
continue
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (!converter) return error(new ApplicationCommandArgumentConverterNotFound(argType, i))
|
|
331
|
+
|
|
332
|
+
argList.push(await converter.execute(module, i))
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
await cmd.execute(module, argList)
|
|
208
336
|
} catch (e) {
|
|
209
337
|
return error(e)
|
|
210
338
|
}
|
|
@@ -212,8 +340,28 @@ export class CommandHandler extends BuiltInModule {
|
|
|
212
340
|
|
|
213
341
|
@listener('interactionCreate')
|
|
214
342
|
async interaction(i: Interaction) {
|
|
215
|
-
|
|
216
|
-
|
|
343
|
+
const error = (e: any) => this.client.client.emit('interactionError', e, i)
|
|
344
|
+
|
|
345
|
+
try {
|
|
346
|
+
await this.client.options.applicationCommands.beforeRunCheck(i)
|
|
347
|
+
if (i.isCommand()) {
|
|
348
|
+
await this.command(i)
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
if (i.isMessageComponent()) {
|
|
352
|
+
await this.messageComponent(i)
|
|
353
|
+
return
|
|
354
|
+
}
|
|
355
|
+
if (i.isMessageContextMenu()) {
|
|
356
|
+
await this.messageContextMenu(i)
|
|
357
|
+
return
|
|
358
|
+
}
|
|
359
|
+
if (i.isUserContextMenu()) {
|
|
360
|
+
await this.userContextMenu(i)
|
|
361
|
+
return
|
|
362
|
+
}
|
|
363
|
+
} catch (e) {
|
|
364
|
+
return error(e)
|
|
217
365
|
}
|
|
218
366
|
}
|
|
219
367
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module } from '../structures'
|
|
2
|
-
import { CommandInteraction, Message } from 'discord.js'
|
|
2
|
+
import { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'
|
|
3
3
|
|
|
4
4
|
export class ArgumentConverter {
|
|
5
5
|
execute(module: Module, msg: Message, arg?: string) {
|
|
@@ -9,8 +9,8 @@ export class ArgumentConverter {
|
|
|
9
9
|
constructor(public type: object, private run: Function, public withoutParameter: boolean) {}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export class
|
|
13
|
-
execute(module: Module, interaction: CommandInteraction) {
|
|
12
|
+
export class ApplicationCommandArgumentConverter {
|
|
13
|
+
execute(module: Module, interaction: CommandInteraction | ContextMenuInteraction) {
|
|
14
14
|
return this.run.apply(module, [interaction])
|
|
15
15
|
}
|
|
16
16
|
|
package/src/command/Command.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module } from '../structures'
|
|
2
|
-
import { CommandInteraction, Message } from 'discord.js'
|
|
2
|
+
import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
|
|
3
3
|
import { KCommandChecks } from '../constants'
|
|
4
4
|
|
|
5
5
|
export type Argument = {
|
|
@@ -9,7 +9,7 @@ export type Argument = {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type CheckFunction = (msg: Message) => boolean | Promise<boolean>
|
|
12
|
-
export type
|
|
12
|
+
export type ApplicationCommandCheckFunction = (i: CommandInteraction | MessageComponentInteraction | ContextMenuInteraction) => boolean | Promise<boolean>
|
|
13
13
|
|
|
14
14
|
export class Command {
|
|
15
15
|
execute(module: Module, args: any[]) {
|
package/src/command/decorator.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { KArgumentConverters, KCommands, KOptionals, KRest, KSlashArgumentConverters } from '../constants'
|
|
2
2
|
import { Command } from './Command'
|
|
3
3
|
import { checkTarget } from '../utils'
|
|
4
|
-
import { ArgumentConverter,
|
|
4
|
+
import { ArgumentConverter, ApplicationCommandArgumentConverter } from './ArgumentConverter'
|
|
5
5
|
import { Module } from '../structures'
|
|
6
6
|
import { createCheckDecorator } from './utils'
|
|
7
7
|
import { GuildMember, Message, PermissionResolvable, Permissions, TextChannel } from 'discord.js'
|
|
@@ -10,6 +10,7 @@ import { ClientPermissionRequired, DMOnlyCommandError, GuildOnlyCommandError, Ow
|
|
|
10
10
|
type CommandOptions = {
|
|
11
11
|
name: string
|
|
12
12
|
aliases: string[] | ((msg: Message) => string[])
|
|
13
|
+
optionTypes?: any[]
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const command = (options: Partial<CommandOptions> = {}) => {
|
|
@@ -22,7 +23,7 @@ export const command = (options: Partial<CommandOptions> = {}) => {
|
|
|
22
23
|
|
|
23
24
|
let properties: Command[] = Reflect.getMetadata(KCommands, target)
|
|
24
25
|
|
|
25
|
-
const params: any[] = Reflect.getMetadata('design:paramtypes', target, propertyKey)
|
|
26
|
+
const params: any[] = options.optionTypes ?? Reflect.getMetadata('design:paramtypes', target, propertyKey)
|
|
26
27
|
|
|
27
28
|
const optionals: number = Reflect.getMetadata(KOptionals, target, propertyKey) || -1
|
|
28
29
|
|
|
@@ -71,7 +72,7 @@ export const argumentConverter = (type: object, requireParameter = true) => {
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
export const
|
|
75
|
+
export const applicationCommandArgumentConverter = (type: object) => {
|
|
75
76
|
return (
|
|
76
77
|
target: Object,
|
|
77
78
|
propertyKey: string,
|
|
@@ -79,9 +80,9 @@ export const slashArgumentConverter = (type: object) => {
|
|
|
79
80
|
) => {
|
|
80
81
|
checkTarget(target)
|
|
81
82
|
|
|
82
|
-
let properties:
|
|
83
|
+
let properties: ApplicationCommandArgumentConverter[] = Reflect.getMetadata(KSlashArgumentConverters, target)
|
|
83
84
|
|
|
84
|
-
const converter = new
|
|
85
|
+
const converter = new ApplicationCommandArgumentConverter(type, Reflect.get(target, propertyKey))
|
|
85
86
|
|
|
86
87
|
if (properties) {
|
|
87
88
|
properties.push(converter)
|
package/src/command/utils.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CommandInteraction, Message } from 'discord.js'
|
|
2
|
-
import type { CheckFunction,
|
|
3
|
-
import { KCommandChecks,
|
|
1
|
+
import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
|
|
2
|
+
import type { CheckFunction, ApplicationCommandCheckFunction } from './Command'
|
|
3
|
+
import { KCommandChecks, KApplicationCommandChecks } from '../constants'
|
|
4
4
|
|
|
5
5
|
export const createCheckDecorator = (
|
|
6
6
|
execute: ((msg: Message) => boolean | Promise<boolean>) | null,
|
|
7
|
-
|
|
7
|
+
executeApplicationCommand?: (i: CommandInteraction | MessageComponentInteraction | ContextMenuInteraction) => boolean | Promise<boolean>,
|
|
8
8
|
): MethodDecorator => {
|
|
9
9
|
return (target, propertyKey) => {
|
|
10
10
|
if (execute) {
|
|
@@ -16,13 +16,13 @@ export const createCheckDecorator = (
|
|
|
16
16
|
Reflect.defineMetadata(KCommandChecks, properties, target, propertyKey)
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
if (
|
|
20
|
-
let properties:
|
|
19
|
+
if (executeApplicationCommand) {
|
|
20
|
+
let properties: ApplicationCommandCheckFunction[] = Reflect.getMetadata(KApplicationCommandChecks, target, propertyKey)
|
|
21
21
|
if (properties) {
|
|
22
|
-
properties.push(
|
|
22
|
+
properties.push(executeApplicationCommand)
|
|
23
23
|
} else {
|
|
24
|
-
properties = [
|
|
25
|
-
Reflect.defineMetadata(
|
|
24
|
+
properties = [executeApplicationCommand]
|
|
25
|
+
Reflect.defineMetadata(KApplicationCommandChecks, properties, target, propertyKey)
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const KCommands = Symbol('Command.TS Commands')
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const KApplicationCommands = Symbol('Command.TS Slash Commands')
|
|
4
4
|
|
|
5
5
|
export const KSlashCommandOptions = Symbol('Command.TS Slash Command Options')
|
|
6
6
|
|
|
@@ -22,4 +22,6 @@ export const KSlashArgumentConverters = Symbol('Command.TS Slash Argument Conver
|
|
|
22
22
|
|
|
23
23
|
export const KCommandChecks = Symbol('Command.TS Command Checks')
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const KApplicationCommandChecks = Symbol('Command.TS Slash Command Checks')
|
|
26
|
+
|
|
27
|
+
export const KMessageComponentHandlers = Symbol('Command.TS Message Component Handlers')
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CommandInteraction, Message } from 'discord.js'
|
|
1
|
+
import { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'
|
|
2
2
|
import type { Argument } from '../command'
|
|
3
|
-
import type {
|
|
3
|
+
import type { AppCommandArgument } from '../applicationCommand'
|
|
4
4
|
|
|
5
5
|
export class ArgumentConverterNotFound extends Error {
|
|
6
6
|
constructor(public type: Argument, public msg: Message) {
|
|
7
7
|
super(`Argument converter ${type.type.name} not found.`)
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
export class
|
|
11
|
-
constructor(public type:
|
|
10
|
+
export class ApplicationCommandArgumentConverterNotFound extends Error {
|
|
11
|
+
constructor(public type: AppCommandArgument, public interaction: CommandInteraction | ContextMenuInteraction) {
|
|
12
12
|
super(`Argument converter ${type.type.name} not found.`)
|
|
13
13
|
}
|
|
14
14
|
}
|