@pikokr/command.ts 3.0.0-dev.a94f324 → 3.0.0-dev.ca01eb5
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/.prettierrc +2 -1
- package/README.md +2 -2
- package/dist/builtinModules/BuiltinCommandConverters.d.ts +9 -1
- package/dist/builtinModules/BuiltinCommandConverters.js +53 -0
- package/dist/builtinModules/BuiltinSlashCommandConverters.d.ts +9 -0
- package/dist/builtinModules/BuiltinSlashCommandConverters.js +32 -0
- package/dist/builtinModules/CommandHandler.d.ts +4 -2
- package/dist/builtinModules/CommandHandler.js +152 -53
- package/dist/builtinModules/index.d.ts +1 -0
- package/dist/builtinModules/index.js +1 -0
- package/dist/command/ArgumentConverter.d.ts +7 -1
- package/dist/command/ArgumentConverter.js +11 -1
- package/dist/command/Command.d.ts +8 -2
- package/dist/command/Command.js +7 -1
- package/dist/command/cooldown/adapter.d.ts +10 -0
- package/dist/command/cooldown/adapter.js +30 -0
- package/dist/command/cooldown/decorator.d.ts +2 -0
- package/dist/command/cooldown/decorator.js +72 -0
- package/dist/command/cooldown/error.d.ts +4 -0
- package/dist/command/cooldown/error.js +10 -0
- package/dist/command/cooldown/index.d.ts +5 -0
- package/dist/command/cooldown/index.js +17 -0
- package/dist/command/cooldown/type.d.ts +8 -0
- package/dist/command/cooldown/type.js +12 -0
- package/dist/command/decorator.d.ts +9 -1
- package/dist/command/decorator.js +70 -12
- package/dist/command/index.d.ts +2 -0
- package/dist/command/index.js +2 -0
- package/dist/command/utils.d.ts +2 -0
- package/dist/command/utils.js +29 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +7 -1
- package/dist/error/ArgumentConverterNotFound.d.ts +7 -1
- package/dist/error/ArgumentConverterNotFound.js +9 -1
- package/dist/error/ArgumentNotProvided.d.ts +3 -1
- package/dist/error/ArgumentNotProvided.js +2 -1
- package/dist/error/CommandCheckFailed.d.ts +13 -0
- package/dist/error/CommandCheckFailed.js +19 -0
- package/dist/error/PermissionRequired.d.ts +10 -0
- package/dist/error/PermissionRequired.js +18 -0
- package/dist/error/index.d.ts +2 -0
- package/dist/error/index.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/slashCommand/SlashCommand.d.ts +19 -0
- package/dist/slashCommand/SlashCommand.js +21 -0
- package/dist/slashCommand/decorator.d.ts +10 -0
- package/dist/slashCommand/decorator.js +37 -0
- package/dist/slashCommand/index.d.ts +2 -0
- package/dist/slashCommand/index.js +14 -0
- package/dist/structures/CommandClient.d.ts +14 -3
- package/dist/structures/CommandClient.js +27 -12
- package/dist/structures/Module.d.ts +5 -1
- package/dist/structures/Module.js +9 -0
- package/dist/structures/Registry.d.ts +16 -6
- package/dist/structures/Registry.js +130 -40
- package/dist/typings.d.ts +18 -0
- package/dist/typings.js +2 -0
- package/package.json +4 -1
- package/src/builtinModules/BuiltinCommandConverters.ts +42 -1
- package/src/builtinModules/BuiltinSlashCommandConverters.ts +18 -0
- package/src/builtinModules/CommandHandler.ts +155 -63
- package/src/builtinModules/index.ts +1 -0
- package/src/command/ArgumentConverter.ts +10 -6
- package/src/command/Command.ts +12 -1
- package/src/command/cooldown/adapter.ts +18 -0
- package/src/command/cooldown/decorator.ts +62 -0
- package/src/command/cooldown/error.ts +5 -0
- package/src/command/cooldown/index.ts +5 -0
- package/src/command/cooldown/type.ts +8 -0
- package/src/command/decorator.ts +102 -36
- package/src/command/index.ts +2 -0
- package/src/command/utils.ts +29 -0
- package/src/constants.ts +12 -0
- package/src/error/ArgumentConverterNotFound.ts +7 -1
- package/src/error/ArgumentNotProvided.ts +2 -1
- package/src/error/CommandCheckFailed.ts +15 -0
- package/src/error/PermissionRequired.ts +13 -0
- package/src/error/index.ts +2 -0
- package/src/index.ts +3 -0
- package/src/slashCommand/SlashCommand.ts +29 -0
- package/src/slashCommand/decorator.ts +58 -0
- package/src/slashCommand/index.ts +2 -0
- package/src/structures/CommandClient.ts +31 -19
- package/src/structures/Module.ts +15 -2
- package/src/structures/Registry.ts +96 -29
- package/src/typings.ts +19 -0
- package/test/index.ts +4 -0
- package/test/modules/test.ts +32 -5
- package/pagesconfig.json +0 -13
package/.prettierrc
CHANGED
package/README.md
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Command framework for discord.js
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[Discord](https://discord.gg/EEhcPzsGHV) [가이드](https://pikokr.notion.site/a60262db37724fd38e4b7fc83be7e52d)
|
|
6
6
|
|
|
7
|
-
https://pikokr.
|
|
7
|
+
[V2 문서](https://command-ts-docs-ezojnktwv-pikokr.vercel.app/)
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { BuiltInModule } from './BuiltInModule';
|
|
2
|
-
import { Message } from 'discord.js';
|
|
2
|
+
import { Client, GuildMember, Message, User } from 'discord.js';
|
|
3
|
+
import { CommandClient } from '../structures';
|
|
3
4
|
export declare class BuiltinCommandConverters extends BuiltInModule {
|
|
5
|
+
private cts;
|
|
6
|
+
client: Client;
|
|
7
|
+
constructor(cts: CommandClient);
|
|
4
8
|
message(msg: Message): Message;
|
|
5
9
|
string(msg: Message, arg: string): string;
|
|
10
|
+
getUserIDByMention(mention: string): `${bigint}` | undefined;
|
|
11
|
+
user(value: string): User | null;
|
|
12
|
+
member(value: string, msg: Message): GuildMember | undefined;
|
|
13
|
+
number(value: string): number | undefined;
|
|
6
14
|
}
|
|
@@ -14,12 +14,47 @@ const BuiltInModule_1 = require("./BuiltInModule");
|
|
|
14
14
|
const command_1 = require("../command");
|
|
15
15
|
const discord_js_1 = require("discord.js");
|
|
16
16
|
class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
|
|
17
|
+
constructor(cts) {
|
|
18
|
+
super();
|
|
19
|
+
this.cts = cts;
|
|
20
|
+
this.client = cts.client;
|
|
21
|
+
}
|
|
17
22
|
message(msg) {
|
|
18
23
|
return msg;
|
|
19
24
|
}
|
|
20
25
|
string(msg, arg) {
|
|
21
26
|
return arg;
|
|
22
27
|
}
|
|
28
|
+
getUserIDByMention(mention) {
|
|
29
|
+
if (!mention)
|
|
30
|
+
return;
|
|
31
|
+
if (mention.startsWith('<@') && mention.endsWith('>')) {
|
|
32
|
+
mention = mention.slice(2, -1);
|
|
33
|
+
if (mention.startsWith('!')) {
|
|
34
|
+
mention = mention.slice(1);
|
|
35
|
+
}
|
|
36
|
+
return mention;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
user(value) {
|
|
40
|
+
const id = this.getUserIDByMention(value);
|
|
41
|
+
if (!id)
|
|
42
|
+
return null;
|
|
43
|
+
const user = this.client.users.cache.get(id);
|
|
44
|
+
return user || null;
|
|
45
|
+
}
|
|
46
|
+
member(value, msg) {
|
|
47
|
+
var _a;
|
|
48
|
+
const id = this.getUserIDByMention(value);
|
|
49
|
+
if (!id)
|
|
50
|
+
return;
|
|
51
|
+
const user = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.members.cache.get(id);
|
|
52
|
+
return user || undefined;
|
|
53
|
+
}
|
|
54
|
+
number(value) {
|
|
55
|
+
const n = Number(value);
|
|
56
|
+
return isNaN(n) ? undefined : n;
|
|
57
|
+
}
|
|
23
58
|
}
|
|
24
59
|
__decorate([
|
|
25
60
|
command_1.argumentConverter(discord_js_1.Message, false),
|
|
@@ -33,4 +68,22 @@ __decorate([
|
|
|
33
68
|
__metadata("design:paramtypes", [discord_js_1.Message, String]),
|
|
34
69
|
__metadata("design:returntype", void 0)
|
|
35
70
|
], BuiltinCommandConverters.prototype, "string", null);
|
|
71
|
+
__decorate([
|
|
72
|
+
command_1.argumentConverter(discord_js_1.User),
|
|
73
|
+
__metadata("design:type", Function),
|
|
74
|
+
__metadata("design:paramtypes", [String]),
|
|
75
|
+
__metadata("design:returntype", Object)
|
|
76
|
+
], BuiltinCommandConverters.prototype, "user", null);
|
|
77
|
+
__decorate([
|
|
78
|
+
command_1.argumentConverter(discord_js_1.GuildMember),
|
|
79
|
+
__metadata("design:type", Function),
|
|
80
|
+
__metadata("design:paramtypes", [String, discord_js_1.Message]),
|
|
81
|
+
__metadata("design:returntype", Object)
|
|
82
|
+
], BuiltinCommandConverters.prototype, "member", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
command_1.argumentConverter(Number),
|
|
85
|
+
__metadata("design:type", Function),
|
|
86
|
+
__metadata("design:paramtypes", [String]),
|
|
87
|
+
__metadata("design:returntype", void 0)
|
|
88
|
+
], BuiltinCommandConverters.prototype, "number", null);
|
|
36
89
|
exports.BuiltinCommandConverters = BuiltinCommandConverters;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuiltInModule } from './BuiltInModule';
|
|
2
|
+
import { Client, CommandInteraction } from 'discord.js';
|
|
3
|
+
import { CommandClient } from '../structures';
|
|
4
|
+
export declare class BuiltinSlashCommandConverters extends BuiltInModule {
|
|
5
|
+
private cts;
|
|
6
|
+
client: Client;
|
|
7
|
+
constructor(cts: CommandClient);
|
|
8
|
+
message(interaction: CommandInteraction): CommandInteraction;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BuiltinSlashCommandConverters = void 0;
|
|
13
|
+
const BuiltInModule_1 = require("./BuiltInModule");
|
|
14
|
+
const command_1 = require("../command");
|
|
15
|
+
const discord_js_1 = require("discord.js");
|
|
16
|
+
class BuiltinSlashCommandConverters extends BuiltInModule_1.BuiltInModule {
|
|
17
|
+
constructor(cts) {
|
|
18
|
+
super();
|
|
19
|
+
this.cts = cts;
|
|
20
|
+
this.client = cts.client;
|
|
21
|
+
}
|
|
22
|
+
message(interaction) {
|
|
23
|
+
return interaction;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
__decorate([
|
|
27
|
+
command_1.slashArgumentConverter(discord_js_1.CommandInteraction),
|
|
28
|
+
__metadata("design:type", Function),
|
|
29
|
+
__metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
|
|
30
|
+
__metadata("design:returntype", void 0)
|
|
31
|
+
], BuiltinSlashCommandConverters.prototype, "message", null);
|
|
32
|
+
exports.BuiltinSlashCommandConverters = BuiltinSlashCommandConverters;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { BuiltInModule } from './BuiltInModule';
|
|
2
2
|
import { Registry } from '../structures';
|
|
3
|
-
import { Message } from 'discord.js';
|
|
3
|
+
import { Interaction, Message } from 'discord.js';
|
|
4
4
|
export declare class CommandHandler extends BuiltInModule {
|
|
5
5
|
private registry;
|
|
6
|
-
private client;
|
|
6
|
+
private readonly client;
|
|
7
7
|
constructor(registry: Registry);
|
|
8
8
|
message(msg: Message): Promise<boolean | undefined>;
|
|
9
|
+
private command;
|
|
10
|
+
interaction(i: Interaction): Promise<void>;
|
|
9
11
|
}
|
|
@@ -33,74 +33,167 @@ class CommandHandler extends BuiltInModule_1.BuiltInModule {
|
|
|
33
33
|
message(msg) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
const error = (error) => this.client.client.emit('commandError', error, msg);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
try {
|
|
37
|
+
const prefixList = typeof this.client.options.command.prefix === 'string'
|
|
38
|
+
? this.client.options.command.prefix
|
|
39
|
+
: typeof this.client.options.command.prefix === 'function'
|
|
40
|
+
? yield this.client.options.command.prefix(msg)
|
|
41
|
+
: this.client.options.command.prefix;
|
|
42
|
+
let prefix;
|
|
43
|
+
if (typeof prefixList === 'object') {
|
|
44
|
+
const res = prefixList.find((x) => msg.content.includes(x));
|
|
45
|
+
if (!res)
|
|
46
|
+
return;
|
|
47
|
+
prefix = res;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (!msg.content.includes(prefixList))
|
|
51
|
+
return;
|
|
52
|
+
prefix = prefixList;
|
|
53
|
+
}
|
|
54
|
+
if (!msg.content.startsWith(prefix))
|
|
45
55
|
return;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!msg.content.includes(prefixList))
|
|
56
|
+
const args = msg.content.slice(prefix.length).split(' ');
|
|
57
|
+
const command = args.shift();
|
|
58
|
+
if (!command)
|
|
50
59
|
return;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (c.name === command) {
|
|
62
|
-
cmd = c;
|
|
63
|
-
break;
|
|
60
|
+
let cmd = null;
|
|
61
|
+
for (const c of this.registry.commands) {
|
|
62
|
+
if (c.name === command) {
|
|
63
|
+
cmd = c;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if ((typeof c.aliases === 'function' ? yield c.aliases(msg) : c.aliases).includes(command)) {
|
|
67
|
+
cmd = c;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
64
70
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
if (!cmd)
|
|
72
|
+
return error(new CommandNotFound_1.CommandNotFound(command));
|
|
73
|
+
msg.data = {
|
|
74
|
+
cts: this.client,
|
|
75
|
+
command: cmd,
|
|
76
|
+
prefix: prefix,
|
|
77
|
+
};
|
|
78
|
+
const module = this.registry.modules.find((x) => x.commands.includes(cmd));
|
|
79
|
+
if (!module)
|
|
80
|
+
return;
|
|
81
|
+
const argList = [];
|
|
82
|
+
for (const check of cmd.checks) {
|
|
83
|
+
if (!(yield check(msg)))
|
|
84
|
+
return error(new error_1.CommandCheckFailed(msg, cmd));
|
|
70
85
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
for (let i = 0; i < cmd.argTypes.length; i++) {
|
|
87
|
+
const argType = cmd.argTypes[i];
|
|
88
|
+
const converter = this.registry.argumentConverters.find((x) => x.type === argType.type);
|
|
89
|
+
if (argType.rest) {
|
|
90
|
+
const i = args.join(' ');
|
|
91
|
+
if (!i)
|
|
92
|
+
break;
|
|
93
|
+
argList.push(i);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
if (!converter)
|
|
97
|
+
return error(new error_1.ArgumentConverterNotFound(argType, msg));
|
|
98
|
+
if (converter.withoutParameter) {
|
|
99
|
+
argList.push(yield converter.execute(module, msg));
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const arg = args.shift();
|
|
103
|
+
if (argType.optional && !arg) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (!arg) {
|
|
107
|
+
return error(new error_1.ArgumentNotProvided(i, cmd, msg));
|
|
108
|
+
}
|
|
109
|
+
const executed = yield converter.execute(module, msg, arg);
|
|
110
|
+
if (!executed === undefined) {
|
|
111
|
+
return error(new error_1.ArgumentNotProvided(i, cmd, msg));
|
|
112
|
+
}
|
|
113
|
+
argList.push(executed);
|
|
86
114
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
break;
|
|
115
|
+
try {
|
|
116
|
+
yield cmd.execute(module, argList);
|
|
90
117
|
}
|
|
91
|
-
|
|
92
|
-
return error(
|
|
118
|
+
catch (e) {
|
|
119
|
+
return error(e);
|
|
93
120
|
}
|
|
94
|
-
argList.push(yield converter.execute(module, msg, arg));
|
|
95
121
|
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
return error(e);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
command(i) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const error = (error) => this.client.client.emit('slashCommandError', error, i);
|
|
96
130
|
try {
|
|
97
|
-
cmd.
|
|
131
|
+
const cmd = this.registry.slashCommands.find((x) => x.commandBuilder.name === i.commandName);
|
|
132
|
+
const module = this.registry.modules.find((x) => x.slashCommands.includes(cmd));
|
|
133
|
+
if (!module)
|
|
134
|
+
return;
|
|
135
|
+
const argList = [];
|
|
136
|
+
if (!cmd)
|
|
137
|
+
return i.reply({
|
|
138
|
+
content: 'Unknown command.',
|
|
139
|
+
ephemeral: true,
|
|
140
|
+
});
|
|
141
|
+
i.data = {
|
|
142
|
+
cts: this.client,
|
|
143
|
+
command: cmd,
|
|
144
|
+
};
|
|
145
|
+
for (const check of cmd.checks) {
|
|
146
|
+
if (!(yield check(i)))
|
|
147
|
+
return error(new error_1.SlashCommandCheckFailed(i, cmd));
|
|
148
|
+
}
|
|
149
|
+
for (let j = 0; j < cmd.params.length; j++) {
|
|
150
|
+
const argType = cmd.params[j];
|
|
151
|
+
const converter = this.registry.slashArgumentConverters.find((x) => x.type === argType.type);
|
|
152
|
+
if (argType.name) {
|
|
153
|
+
switch (argType.type) {
|
|
154
|
+
case String:
|
|
155
|
+
argList.push(i.options.getString(argType.name, false) || undefined);
|
|
156
|
+
break;
|
|
157
|
+
case discord_js_1.Role:
|
|
158
|
+
argList.push(i.options.getRole(argType.name, false) || undefined);
|
|
159
|
+
break;
|
|
160
|
+
case discord_js_1.User:
|
|
161
|
+
argList.push(i.options.getUser(argType.name, false) || undefined);
|
|
162
|
+
break;
|
|
163
|
+
case discord_js_1.GuildMember:
|
|
164
|
+
argList.push(i.options.getMember(argType.name, false) || undefined);
|
|
165
|
+
break;
|
|
166
|
+
case Boolean:
|
|
167
|
+
argList.push(i.options.getBoolean(argType.name, false) || undefined);
|
|
168
|
+
break;
|
|
169
|
+
case Number:
|
|
170
|
+
argList.push(i.options.getNumber(argType.name, false) || i.options.getInteger(argType.name, false) || undefined);
|
|
171
|
+
}
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (!converter)
|
|
175
|
+
return error(new error_1.SlashArgumentConverterNotFound(argType, i));
|
|
176
|
+
argList.push(yield converter.execute(module, i));
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
yield cmd.execute(module, argList);
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
return error(e);
|
|
183
|
+
}
|
|
98
184
|
}
|
|
99
185
|
catch (e) {
|
|
100
186
|
return error(e);
|
|
101
187
|
}
|
|
102
188
|
});
|
|
103
189
|
}
|
|
190
|
+
interaction(i) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
if (i.isCommand()) {
|
|
193
|
+
yield this.command(i);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
104
197
|
}
|
|
105
198
|
__decorate([
|
|
106
199
|
listener_1.listener('messageCreate'),
|
|
@@ -108,4 +201,10 @@ __decorate([
|
|
|
108
201
|
__metadata("design:paramtypes", [discord_js_1.Message]),
|
|
109
202
|
__metadata("design:returntype", Promise)
|
|
110
203
|
], CommandHandler.prototype, "message", null);
|
|
204
|
+
__decorate([
|
|
205
|
+
listener_1.listener('interactionCreate'),
|
|
206
|
+
__metadata("design:type", Function),
|
|
207
|
+
__metadata("design:paramtypes", [discord_js_1.Interaction]),
|
|
208
|
+
__metadata("design:returntype", Promise)
|
|
209
|
+
], CommandHandler.prototype, "interaction", null);
|
|
111
210
|
exports.CommandHandler = CommandHandler;
|
|
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./CommandHandler"), exports);
|
|
14
14
|
__exportStar(require("./BuiltinCommandConverters"), exports);
|
|
15
|
+
__exportStar(require("./BuiltinSlashCommandConverters"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module } from '../structures';
|
|
2
|
-
import { Message } from 'discord.js';
|
|
2
|
+
import { CommandInteraction, Message } from 'discord.js';
|
|
3
3
|
export declare class ArgumentConverter {
|
|
4
4
|
type: object;
|
|
5
5
|
private run;
|
|
@@ -7,3 +7,9 @@ export declare class ArgumentConverter {
|
|
|
7
7
|
execute(module: Module, msg: Message, arg?: string): any;
|
|
8
8
|
constructor(type: object, run: Function, withoutParameter: boolean);
|
|
9
9
|
}
|
|
10
|
+
export declare class SlashArgumentConverter {
|
|
11
|
+
type: object;
|
|
12
|
+
private run;
|
|
13
|
+
execute(module: Module, interaction: CommandInteraction): any;
|
|
14
|
+
constructor(type: object, run: Function);
|
|
15
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArgumentConverter = void 0;
|
|
3
|
+
exports.SlashArgumentConverter = exports.ArgumentConverter = void 0;
|
|
4
4
|
class ArgumentConverter {
|
|
5
5
|
constructor(type, run, withoutParameter) {
|
|
6
6
|
this.type = type;
|
|
@@ -12,3 +12,13 @@ class ArgumentConverter {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.ArgumentConverter = ArgumentConverter;
|
|
15
|
+
class SlashArgumentConverter {
|
|
16
|
+
constructor(type, run) {
|
|
17
|
+
this.type = type;
|
|
18
|
+
this.run = run;
|
|
19
|
+
}
|
|
20
|
+
execute(module, interaction) {
|
|
21
|
+
return this.run.apply(module, [interaction]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.SlashArgumentConverter = SlashArgumentConverter;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { Module } from '../structures';
|
|
2
|
-
import { Message } from 'discord.js';
|
|
2
|
+
import { CommandInteraction, Message } from 'discord.js';
|
|
3
3
|
export declare type Argument = {
|
|
4
4
|
optional: boolean;
|
|
5
5
|
type: any;
|
|
6
|
+
rest: boolean;
|
|
6
7
|
};
|
|
8
|
+
export declare type CheckFunction = (msg: Message) => boolean | Promise<boolean>;
|
|
9
|
+
export declare type SlashCheckFunction = (i: CommandInteraction) => boolean | Promise<boolean>;
|
|
7
10
|
export declare class Command {
|
|
8
11
|
private run;
|
|
9
12
|
argTypes: Argument[];
|
|
10
13
|
name: string;
|
|
11
14
|
aliases: string[] | ((msg: Message) => string[]);
|
|
15
|
+
module: Module;
|
|
16
|
+
key: symbol | string;
|
|
12
17
|
execute(module: Module, args: any[]): any;
|
|
13
|
-
|
|
18
|
+
get checks(): CheckFunction[];
|
|
19
|
+
constructor(run: Function, argTypes: Argument[], name: string, aliases: string[] | ((msg: Message) => string[]), module: Module, key: symbol | string);
|
|
14
20
|
}
|
package/dist/command/Command.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Command = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
4
5
|
class Command {
|
|
5
|
-
constructor(run, argTypes, name, aliases) {
|
|
6
|
+
constructor(run, argTypes, name, aliases, module, key) {
|
|
6
7
|
this.run = run;
|
|
7
8
|
this.argTypes = argTypes;
|
|
8
9
|
this.name = name;
|
|
9
10
|
this.aliases = aliases;
|
|
11
|
+
this.module = module;
|
|
12
|
+
this.key = key;
|
|
10
13
|
}
|
|
11
14
|
execute(module, args) {
|
|
12
15
|
return this.run.apply(module, args);
|
|
13
16
|
}
|
|
17
|
+
get checks() {
|
|
18
|
+
return Reflect.getMetadata(constants_1.KCommandChecks, this.module, this.key) || [];
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
exports.Command = Command;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Collection } from 'discord.js';
|
|
2
|
+
export interface CoolDownAdapter {
|
|
3
|
+
get(id: string): Promise<number | undefined>;
|
|
4
|
+
set(id: string, value: number): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare class DefaultCoolDownAdapter implements CoolDownAdapter {
|
|
7
|
+
map: Collection<string, number>;
|
|
8
|
+
get(id: string): Promise<number | undefined>;
|
|
9
|
+
set(id: string, value: number): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultCoolDownAdapter = void 0;
|
|
13
|
+
const discord_js_1 = require("discord.js");
|
|
14
|
+
class DefaultCoolDownAdapter {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.map = new discord_js_1.Collection();
|
|
17
|
+
}
|
|
18
|
+
get(id) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return this.map.get(id);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
set(id, value) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
this.map.set(id, value);
|
|
26
|
+
return;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.DefaultCoolDownAdapter = DefaultCoolDownAdapter;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.coolDown = void 0;
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const type_1 = require("./type");
|
|
15
|
+
const discord_js_1 = require("discord.js");
|
|
16
|
+
const error_1 = require("./error");
|
|
17
|
+
const coolDown = (type, seconds) => utils_1.createCheckDecorator((msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const a = msg.data.cts.coolDownAdapter;
|
|
19
|
+
const getKey = () => {
|
|
20
|
+
var _a;
|
|
21
|
+
switch (type) {
|
|
22
|
+
case type_1.CoolDownType.USER:
|
|
23
|
+
return msg.author.id;
|
|
24
|
+
case type_1.CoolDownType.GUILD:
|
|
25
|
+
return (msg.guild || msg.author).id;
|
|
26
|
+
case type_1.CoolDownType.CHANNEL:
|
|
27
|
+
return msg.channel.id;
|
|
28
|
+
case type_1.CoolDownType.MEMBER:
|
|
29
|
+
return `${(_a = msg.guild) === null || _a === void 0 ? void 0 : _a.id}.${msg.author.id}`;
|
|
30
|
+
case type_1.CoolDownType.ROLE:
|
|
31
|
+
return (msg.channel instanceof discord_js_1.DMChannel ? msg.channel : msg.member.roles.highest).id;
|
|
32
|
+
case type_1.CoolDownType.CATEGORY:
|
|
33
|
+
return (msg.channel.parent || msg.channel).id;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const key = getKey();
|
|
37
|
+
const data = yield a.get(key);
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
if (!data || !(now - data < seconds * 1000)) {
|
|
40
|
+
yield a.set(key, now);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
throw new error_1.CoolDownError(new Date(data + seconds * 1000));
|
|
44
|
+
}), (i) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const a = i.data.cts.coolDownAdapter;
|
|
46
|
+
const getKey = () => {
|
|
47
|
+
var _a;
|
|
48
|
+
switch (type) {
|
|
49
|
+
case type_1.CoolDownType.USER:
|
|
50
|
+
return i.user.id;
|
|
51
|
+
case type_1.CoolDownType.GUILD:
|
|
52
|
+
return (i.guild || i.user).id;
|
|
53
|
+
case type_1.CoolDownType.CHANNEL:
|
|
54
|
+
return i.channel.id;
|
|
55
|
+
case type_1.CoolDownType.MEMBER:
|
|
56
|
+
return `${(_a = i.guild) === null || _a === void 0 ? void 0 : _a.id}.${i.user.id}`;
|
|
57
|
+
case type_1.CoolDownType.ROLE:
|
|
58
|
+
return (i.channel instanceof discord_js_1.DMChannel ? i.channel : i.member.roles.highest).id;
|
|
59
|
+
case type_1.CoolDownType.CATEGORY:
|
|
60
|
+
return (i.channel.parent || i.channel).id;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const key = getKey();
|
|
64
|
+
const data = yield a.get(key);
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
if (!data || !(now - data < seconds * 1000)) {
|
|
67
|
+
yield a.set(key, now);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
throw new error_1.CoolDownError(new Date(data + seconds * 1000));
|
|
71
|
+
}));
|
|
72
|
+
exports.coolDown = coolDown;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./decorator"), exports);
|
|
14
|
+
__exportStar(require("./adapter"), exports);
|
|
15
|
+
__exportStar(require("./decorator"), exports);
|
|
16
|
+
__exportStar(require("./error"), exports);
|
|
17
|
+
__exportStar(require("./type"), exports);
|