@pikokr/command.ts 3.0.0-dev.7170769 → 3.0.0-dev.85a29c3
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 +3 -1
- package/dist/builtinModules/BuiltInModule.d.ts +4 -0
- package/dist/builtinModules/BuiltInModule.js +12 -0
- package/dist/builtinModules/BuiltinCommandConverters.d.ts +14 -0
- package/dist/builtinModules/BuiltinCommandConverters.js +89 -0
- package/dist/builtinModules/CommandHandler.d.ts +9 -0
- package/dist/builtinModules/CommandHandler.js +134 -0
- package/dist/builtinModules/index.d.ts +2 -0
- package/dist/builtinModules/index.js +14 -0
- package/dist/command/ArgumentConverter.d.ts +9 -0
- package/dist/command/ArgumentConverter.js +14 -0
- package/dist/command/Command.d.ts +14 -5
- package/dist/command/Command.js +9 -4
- package/dist/command/decorator.d.ts +11 -2
- package/dist/command/decorator.js +66 -10
- 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 +17 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +9 -2
- package/dist/error/ArgumentConverterNotFound.d.ts +7 -0
- package/dist/error/ArgumentConverterNotFound.js +11 -0
- package/dist/error/ArgumentNotProvided.d.ts +8 -0
- package/dist/error/ArgumentNotProvided.js +12 -0
- package/dist/error/CommandCheckFailed.d.ts +7 -0
- package/dist/error/CommandCheckFailed.js +11 -0
- package/dist/error/CommandNotFound.d.ts +4 -0
- package/dist/error/CommandNotFound.js +10 -0
- package/dist/error/PermissionRequired.d.ts +10 -0
- package/dist/error/PermissionRequired.js +18 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/index.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/listener/Listener.d.ts +5 -0
- package/dist/listener/Listener.js +10 -0
- package/dist/listener/decorator.d.ts +2 -0
- package/dist/listener/decorator.js +21 -0
- package/dist/listener/index.d.ts +2 -0
- package/dist/listener/index.js +14 -0
- package/dist/structures/CommandClient.d.ts +0 -1
- package/dist/structures/CommandClient.js +15 -38
- package/dist/structures/Module.d.ts +7 -0
- package/dist/structures/Module.js +13 -0
- package/dist/structures/Registry.d.ts +16 -6
- package/dist/structures/Registry.js +113 -22
- package/dist/structures/index.d.ts +2 -1
- package/dist/structures/index.js +2 -1
- package/dist/typings.d.ts +11 -0
- package/dist/typings.js +2 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +10 -0
- package/package.json +3 -2
- package/src/builtinModules/BuiltInModule.ts +9 -0
- package/src/builtinModules/BuiltinCommandConverters.ts +56 -0
- package/src/builtinModules/CommandHandler.ts +120 -0
- package/src/builtinModules/index.ts +2 -0
- package/src/command/ArgumentConverter.ts +10 -0
- package/src/command/Command.ts +20 -5
- package/src/command/decorator.ts +84 -12
- package/src/command/index.ts +2 -0
- package/src/command/utils.ts +15 -0
- package/src/constants.ts +15 -1
- package/src/error/ArgumentConverterNotFound.ts +8 -0
- package/src/error/ArgumentNotProvided.ts +8 -0
- package/src/error/CommandCheckFailed.ts +8 -0
- package/src/error/CommandNotFound.ts +5 -0
- package/src/error/PermissionRequired.ts +13 -0
- package/src/error/index.ts +4 -0
- package/src/index.ts +3 -0
- package/src/listener/Listener.ts +3 -0
- package/src/listener/decorator.ts +25 -0
- package/src/listener/index.ts +2 -0
- package/src/structures/CommandClient.ts +10 -48
- package/src/structures/Module.ts +21 -0
- package/src/structures/Registry.ts +108 -19
- package/src/structures/index.ts +2 -1
- package/src/typings.ts +12 -0
- package/src/utils.ts +6 -0
- package/test/index.ts +5 -2
- package/test/modules/test.ts +44 -0
package/.prettierrc
CHANGED
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Command framework for discord.js
|
|
4
4
|
|
|
5
|
+
[Discord](https://discord.gg/EEhcPzsGHV)
|
|
6
|
+
|
|
5
7
|
# 진행상황 / Progress
|
|
6
8
|
|
|
7
|
-
https://
|
|
9
|
+
https://pikokr.notion.site/b11137d4e879413a849fdf453c74bf39?v=f12235b64e4d438182b32e436f6b3bb9
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuiltInModule = void 0;
|
|
4
|
+
const structures_1 = require("../structures");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
class BuiltInModule extends structures_1.Module {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
Reflect.defineMetadata(constants_1.KBuiltInModule, true, this);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.BuiltInModule = BuiltInModule;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BuiltInModule } from './BuiltInModule';
|
|
2
|
+
import { Client, GuildMember, Message, User } from 'discord.js';
|
|
3
|
+
import { CommandClient } from '../structures';
|
|
4
|
+
export declare class BuiltinCommandConverters extends BuiltInModule {
|
|
5
|
+
private cts;
|
|
6
|
+
client: Client;
|
|
7
|
+
constructor(cts: CommandClient);
|
|
8
|
+
message(msg: Message): Message;
|
|
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;
|
|
14
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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.BuiltinCommandConverters = void 0;
|
|
13
|
+
const BuiltInModule_1 = require("./BuiltInModule");
|
|
14
|
+
const command_1 = require("../command");
|
|
15
|
+
const discord_js_1 = require("discord.js");
|
|
16
|
+
class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
|
|
17
|
+
constructor(cts) {
|
|
18
|
+
super();
|
|
19
|
+
this.cts = cts;
|
|
20
|
+
this.client = cts.client;
|
|
21
|
+
}
|
|
22
|
+
message(msg) {
|
|
23
|
+
return msg;
|
|
24
|
+
}
|
|
25
|
+
string(msg, arg) {
|
|
26
|
+
return arg;
|
|
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
|
+
}
|
|
58
|
+
}
|
|
59
|
+
__decorate([
|
|
60
|
+
command_1.argumentConverter(discord_js_1.Message, false),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", [discord_js_1.Message]),
|
|
63
|
+
__metadata("design:returntype", void 0)
|
|
64
|
+
], BuiltinCommandConverters.prototype, "message", null);
|
|
65
|
+
__decorate([
|
|
66
|
+
command_1.argumentConverter(String),
|
|
67
|
+
__metadata("design:type", Function),
|
|
68
|
+
__metadata("design:paramtypes", [discord_js_1.Message, String]),
|
|
69
|
+
__metadata("design:returntype", void 0)
|
|
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);
|
|
89
|
+
exports.BuiltinCommandConverters = BuiltinCommandConverters;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuiltInModule } from './BuiltInModule';
|
|
2
|
+
import { Registry } from '../structures';
|
|
3
|
+
import { Message } from 'discord.js';
|
|
4
|
+
export declare class CommandHandler extends BuiltInModule {
|
|
5
|
+
private registry;
|
|
6
|
+
private client;
|
|
7
|
+
constructor(registry: Registry);
|
|
8
|
+
message(msg: Message): Promise<boolean | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.CommandHandler = void 0;
|
|
22
|
+
const BuiltInModule_1 = require("./BuiltInModule");
|
|
23
|
+
const listener_1 = require("../listener");
|
|
24
|
+
const discord_js_1 = require("discord.js");
|
|
25
|
+
const error_1 = require("../error");
|
|
26
|
+
const CommandNotFound_1 = require("../error/CommandNotFound");
|
|
27
|
+
class CommandHandler extends BuiltInModule_1.BuiltInModule {
|
|
28
|
+
constructor(registry) {
|
|
29
|
+
super();
|
|
30
|
+
this.registry = registry;
|
|
31
|
+
this.client = registry.client;
|
|
32
|
+
}
|
|
33
|
+
message(msg) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const error = (error) => this.client.client.emit('commandError', error, msg);
|
|
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))
|
|
55
|
+
return;
|
|
56
|
+
const args = msg.content.slice(prefix.length).split(' ');
|
|
57
|
+
const command = args.shift();
|
|
58
|
+
if (!command)
|
|
59
|
+
return;
|
|
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
|
+
}
|
|
70
|
+
}
|
|
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));
|
|
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);
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
cmd.execute(module, argList);
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
return error(e);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
return error(e);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
__decorate([
|
|
129
|
+
listener_1.listener('messageCreate'),
|
|
130
|
+
__metadata("design:type", Function),
|
|
131
|
+
__metadata("design:paramtypes", [discord_js_1.Message]),
|
|
132
|
+
__metadata("design:returntype", Promise)
|
|
133
|
+
], CommandHandler.prototype, "message", null);
|
|
134
|
+
exports.CommandHandler = CommandHandler;
|
|
@@ -0,0 +1,14 @@
|
|
|
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("./CommandHandler"), exports);
|
|
14
|
+
__exportStar(require("./BuiltinCommandConverters"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Module } from '../structures';
|
|
2
|
+
import { Message } from 'discord.js';
|
|
3
|
+
export declare class ArgumentConverter {
|
|
4
|
+
type: object;
|
|
5
|
+
private run;
|
|
6
|
+
withoutParameter: boolean;
|
|
7
|
+
execute(module: Module, msg: Message, arg?: string): any;
|
|
8
|
+
constructor(type: object, run: Function, withoutParameter: boolean);
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgumentConverter = void 0;
|
|
4
|
+
class ArgumentConverter {
|
|
5
|
+
constructor(type, run, withoutParameter) {
|
|
6
|
+
this.type = type;
|
|
7
|
+
this.run = run;
|
|
8
|
+
this.withoutParameter = withoutParameter;
|
|
9
|
+
}
|
|
10
|
+
execute(module, msg, arg) {
|
|
11
|
+
return this.run.apply(module, [msg, arg]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ArgumentConverter = ArgumentConverter;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { Module } from '../structures';
|
|
2
|
+
import { Message } from 'discord.js';
|
|
3
|
+
export declare type Argument = {
|
|
4
|
+
optional: boolean;
|
|
5
|
+
type: any;
|
|
6
|
+
rest: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare type CheckFunction = (msg: Message) => boolean | Promise<boolean>;
|
|
2
9
|
export declare class Command {
|
|
3
|
-
module: Module;
|
|
4
10
|
private run;
|
|
5
|
-
argTypes:
|
|
11
|
+
argTypes: Argument[];
|
|
6
12
|
name: string;
|
|
7
|
-
aliases: string[];
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
aliases: string[] | ((msg: Message) => string[]);
|
|
14
|
+
module: Module;
|
|
15
|
+
key: symbol | string;
|
|
16
|
+
execute(module: Module, args: any[]): any;
|
|
17
|
+
get checks(): CheckFunction[];
|
|
18
|
+
constructor(run: Function, argTypes: Argument[], name: string, aliases: string[] | ((msg: Message) => string[]), module: Module, key: symbol | string);
|
|
10
19
|
}
|
package/dist/command/Command.js
CHANGED
|
@@ -1,16 +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(
|
|
6
|
-
this.module = module;
|
|
6
|
+
constructor(run, argTypes, name, aliases, module, key) {
|
|
7
7
|
this.run = run;
|
|
8
8
|
this.argTypes = argTypes;
|
|
9
9
|
this.name = name;
|
|
10
10
|
this.aliases = aliases;
|
|
11
|
+
this.module = module;
|
|
12
|
+
this.key = key;
|
|
13
|
+
}
|
|
14
|
+
execute(module, args) {
|
|
15
|
+
return this.run.apply(module, args);
|
|
11
16
|
}
|
|
12
|
-
|
|
13
|
-
return
|
|
17
|
+
get checks() {
|
|
18
|
+
return Reflect.getMetadata(constants_1.KCommandChecks, this.module, this.key) || [];
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
exports.Command = Command;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { Message, PermissionResolvable } from 'discord.js';
|
|
1
2
|
declare type CommandOptions = {
|
|
2
3
|
name: string;
|
|
3
|
-
aliases: string[];
|
|
4
|
+
aliases: string[] | ((msg: Message) => string[]);
|
|
4
5
|
};
|
|
5
|
-
export declare const command: (options
|
|
6
|
+
export declare const command: (options?: Partial<CommandOptions>) => (target: Object, propertyKey: string) => void;
|
|
7
|
+
export declare const argumentConverter: (type: object, requireParameter?: boolean) => (target: Object, propertyKey: string) => void;
|
|
8
|
+
export declare const optional: ParameterDecorator;
|
|
9
|
+
export declare const rest: ParameterDecorator;
|
|
10
|
+
export declare const ownerOnly: MethodDecorator;
|
|
11
|
+
export declare const guildOnly: MethodDecorator;
|
|
12
|
+
export declare const dmOnly: MethodDecorator;
|
|
13
|
+
export declare const requireUserPermissions: (permission: PermissionResolvable) => MethodDecorator;
|
|
14
|
+
export declare const requireClientPermissions: (permission: PermissionResolvable) => MethodDecorator;
|
|
6
15
|
export {};
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.command = void 0;
|
|
3
|
+
exports.requireClientPermissions = exports.requireUserPermissions = exports.dmOnly = exports.guildOnly = exports.ownerOnly = exports.rest = exports.optional = exports.argumentConverter = exports.command = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
|
-
const structures_1 = require("../structures");
|
|
6
|
-
const error_1 = require("../error");
|
|
7
5
|
const Command_1 = require("./Command");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const ArgumentConverter_1 = require("./ArgumentConverter");
|
|
8
|
+
const utils_2 = require("./utils");
|
|
9
|
+
const discord_js_1 = require("discord.js");
|
|
10
|
+
const error_1 = require("../error");
|
|
11
|
+
const command = (options = {}) => {
|
|
13
12
|
return (target, propertyKey) => {
|
|
14
|
-
checkTarget(target);
|
|
13
|
+
utils_1.checkTarget(target);
|
|
15
14
|
let properties = Reflect.getMetadata(constants_1.KCommands, target);
|
|
16
15
|
const params = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
17
|
-
const
|
|
16
|
+
const optionals = Reflect.getMetadata(constants_1.KOptionals, target, propertyKey) || -1;
|
|
17
|
+
const rest = Reflect.getMetadata(constants_1.KRest, target, propertyKey) || -1;
|
|
18
|
+
const command = new Command_1.Command(Reflect.get(target, propertyKey), params.map((x, i) => ({
|
|
19
|
+
type: x,
|
|
20
|
+
optional: optionals === -1 ? false : optionals <= i,
|
|
21
|
+
rest: rest === -1 ? false : rest === i,
|
|
22
|
+
})), options.name || propertyKey, options.aliases || [], target, propertyKey);
|
|
18
23
|
if (properties) {
|
|
19
24
|
properties.push(command);
|
|
20
25
|
}
|
|
@@ -25,3 +30,54 @@ const command = (options) => {
|
|
|
25
30
|
};
|
|
26
31
|
};
|
|
27
32
|
exports.command = command;
|
|
33
|
+
const argumentConverter = (type, requireParameter = true) => {
|
|
34
|
+
return (target, propertyKey) => {
|
|
35
|
+
utils_1.checkTarget(target);
|
|
36
|
+
let properties = Reflect.getMetadata(constants_1.KArgumentConverters, target);
|
|
37
|
+
const converter = new ArgumentConverter_1.ArgumentConverter(type, Reflect.get(target, propertyKey), !requireParameter);
|
|
38
|
+
if (properties) {
|
|
39
|
+
properties.push(converter);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
properties = [converter];
|
|
43
|
+
Reflect.defineMetadata(constants_1.KArgumentConverters, properties, target);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.argumentConverter = argumentConverter;
|
|
48
|
+
const optional = (target, propertyKey, parameterIndex) => {
|
|
49
|
+
utils_1.checkTarget(target);
|
|
50
|
+
Reflect.defineMetadata(constants_1.KOptionals, parameterIndex, target, propertyKey);
|
|
51
|
+
};
|
|
52
|
+
exports.optional = optional;
|
|
53
|
+
const rest = (target, propertyKey, parameterIndex) => {
|
|
54
|
+
utils_1.checkTarget(target);
|
|
55
|
+
const params = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
56
|
+
if (params.length - 1 !== parameterIndex)
|
|
57
|
+
throw new Error('Rest decorator must be used at last argument.');
|
|
58
|
+
if (params[parameterIndex] !== String)
|
|
59
|
+
throw new Error('Rest argument type must be "String"');
|
|
60
|
+
Reflect.defineMetadata(constants_1.KRest, parameterIndex, target, propertyKey);
|
|
61
|
+
};
|
|
62
|
+
exports.rest = rest;
|
|
63
|
+
exports.ownerOnly = utils_2.createCheckDecorator((msg) => msg.data.cts.owners.includes(msg.author.id));
|
|
64
|
+
exports.guildOnly = utils_2.createCheckDecorator((msg) => !!msg.guild);
|
|
65
|
+
exports.dmOnly = utils_2.createCheckDecorator((msg) => !msg.guild);
|
|
66
|
+
const requireUserPermissions = (permission) => utils_2.createCheckDecorator((msg) => {
|
|
67
|
+
if (!msg.guild || !msg.member)
|
|
68
|
+
throw new Error('This command must be used in serer.');
|
|
69
|
+
if (msg.member.permissionsIn(msg.channel).has(permission)) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
throw new error_1.UserPermissionRequired(msg.member, new discord_js_1.Permissions(permission));
|
|
73
|
+
});
|
|
74
|
+
exports.requireUserPermissions = requireUserPermissions;
|
|
75
|
+
const requireClientPermissions = (permission) => utils_2.createCheckDecorator((msg) => {
|
|
76
|
+
if (!msg.guild)
|
|
77
|
+
throw new Error('This command must be used in serer.');
|
|
78
|
+
if (msg.guild.me.permissionsIn(msg.channel).has(permission)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
throw new error_1.ClientPermissionRequired(new discord_js_1.Permissions(permission));
|
|
82
|
+
});
|
|
83
|
+
exports.requireClientPermissions = requireClientPermissions;
|
package/dist/command/index.d.ts
CHANGED
package/dist/command/index.js
CHANGED
|
@@ -12,3 +12,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./Command"), exports);
|
|
14
14
|
__exportStar(require("./decorator"), exports);
|
|
15
|
+
__exportStar(require("./ArgumentConverter"), exports);
|
|
16
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCheckDecorator = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const createCheckDecorator = (execute) => {
|
|
6
|
+
return (target, propertyKey) => {
|
|
7
|
+
let properties = Reflect.getMetadata(constants_1.KCommandChecks, target, propertyKey);
|
|
8
|
+
if (properties) {
|
|
9
|
+
properties.push(execute);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
properties = [execute];
|
|
13
|
+
Reflect.defineMetadata(constants_1.KCommandChecks, properties, target, propertyKey);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.createCheckDecorator = createCheckDecorator;
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export declare const KCommands: unique symbol;
|
|
2
|
+
export declare const KListeners: unique symbol;
|
|
2
3
|
export declare const KModulePath: unique symbol;
|
|
4
|
+
export declare const KListenerExecuteCache: unique symbol;
|
|
5
|
+
export declare const KBuiltInModule: unique symbol;
|
|
6
|
+
export declare const KOptionals: unique symbol;
|
|
7
|
+
export declare const KRest: unique symbol;
|
|
8
|
+
export declare const KArgumentConverters: unique symbol;
|
|
9
|
+
export declare const KCommandChecks: unique symbol;
|
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KModulePath = exports.KCommands = void 0;
|
|
4
|
-
exports.KCommands = Symbol('Command.TS
|
|
3
|
+
exports.KCommandChecks = exports.KArgumentConverters = exports.KRest = exports.KOptionals = exports.KBuiltInModule = exports.KListenerExecuteCache = exports.KModulePath = exports.KListeners = exports.KCommands = void 0;
|
|
4
|
+
exports.KCommands = Symbol('Command.TS Commands');
|
|
5
|
+
exports.KListeners = Symbol('Command.TS Listeners');
|
|
5
6
|
exports.KModulePath = Symbol('Command.TS Module Path');
|
|
7
|
+
exports.KListenerExecuteCache = Symbol('Command.TS Module Identifier');
|
|
8
|
+
exports.KBuiltInModule = Symbol('Command.TS Built-In Module');
|
|
9
|
+
exports.KOptionals = Symbol('Command.TS Optional Parameters');
|
|
10
|
+
exports.KRest = Symbol('Command.TS Rest Parameter');
|
|
11
|
+
exports.KArgumentConverters = Symbol('Command.TS Argument Converter');
|
|
12
|
+
exports.KCommandChecks = Symbol('Command.TS Command Checks');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgumentConverterNotFound = void 0;
|
|
4
|
+
class ArgumentConverterNotFound extends Error {
|
|
5
|
+
constructor(type, msg) {
|
|
6
|
+
super(`Argument converter ${type.type.name} not found.`);
|
|
7
|
+
this.type = type;
|
|
8
|
+
this.msg = msg;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ArgumentConverterNotFound = ArgumentConverterNotFound;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgumentNotProvided = void 0;
|
|
4
|
+
class ArgumentNotProvided extends Error {
|
|
5
|
+
constructor(index, command, msg) {
|
|
6
|
+
super(`Required argument #${index} not provided.`);
|
|
7
|
+
this.index = index;
|
|
8
|
+
this.command = command;
|
|
9
|
+
this.msg = msg;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ArgumentNotProvided = ArgumentNotProvided;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandCheckFailed = void 0;
|
|
4
|
+
class CommandCheckFailed extends Error {
|
|
5
|
+
constructor(msg, command) {
|
|
6
|
+
super();
|
|
7
|
+
this.msg = msg;
|
|
8
|
+
this.command = command;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.CommandCheckFailed = CommandCheckFailed;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandNotFound = void 0;
|
|
4
|
+
class CommandNotFound extends Error {
|
|
5
|
+
constructor(commandName) {
|
|
6
|
+
super(`Command ${commandName} not found.`);
|
|
7
|
+
this.commandName = commandName;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CommandNotFound = CommandNotFound;
|