@pikokr/command.ts 3.0.1-dev.4d426ce → 3.0.3

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.
Files changed (44) hide show
  1. package/dist/argumentConverter/decorator.d.ts +5 -0
  2. package/dist/argumentConverter/decorator.js +24 -0
  3. package/dist/argumentConverter/index.d.ts +1 -0
  4. package/dist/argumentConverter/index.js +13 -0
  5. package/dist/command/CommandManager.d.ts +16 -0
  6. package/dist/command/CommandManager.js +69 -0
  7. package/dist/debugTool/DebugModule.d.ts +7 -0
  8. package/dist/debugTool/DebugModule.js +56 -0
  9. package/dist/debugTool/commands/default.d.ts +7 -0
  10. package/dist/debugTool/commands/default.js +17 -0
  11. package/dist/debugTool/commands/eval.d.ts +9 -0
  12. package/dist/debugTool/commands/eval.js +103 -0
  13. package/dist/debugTool/commands/index.d.ts +6 -0
  14. package/dist/debugTool/commands/index.js +21 -0
  15. package/dist/debugTool/commands/load.d.ts +9 -0
  16. package/dist/debugTool/commands/load.js +36 -0
  17. package/dist/debugTool/commands/reload.d.ts +9 -0
  18. package/dist/debugTool/commands/reload.js +54 -0
  19. package/dist/debugTool/commands/unload.d.ts +9 -0
  20. package/dist/debugTool/commands/unload.js +54 -0
  21. package/dist/debugTool/index.d.ts +20 -0
  22. package/dist/debugTool/index.js +18 -0
  23. package/dist/defaultModules/BuiltInConverters.d.ts +13 -0
  24. package/dist/defaultModules/BuiltInConverters.js +72 -0
  25. package/dist/defaultModules/CommandHandler.d.ts +11 -0
  26. package/dist/defaultModules/CommandHandler.js +178 -0
  27. package/dist/defaultModules/index.d.ts +2 -0
  28. package/dist/defaultModules/index.js +14 -0
  29. package/dist/error/CheckFailedError.d.ts +5 -0
  30. package/dist/error/CheckFailedError.js +10 -0
  31. package/dist/error/Permissions.d.ts +36 -0
  32. package/dist/error/Permissions.js +55 -0
  33. package/dist/listener/ListenerManager.d.ts +25 -0
  34. package/dist/listener/ListenerManager.js +52 -0
  35. package/dist/slashCommand/SlashCommandManager.d.ts +33 -0
  36. package/dist/slashCommand/SlashCommandManager.js +138 -0
  37. package/dist/structures/Context.d.ts +9 -0
  38. package/dist/structures/Context.js +13 -0
  39. package/dist/structures/Registry.js +2 -2
  40. package/dist/types/index.d.ts +101 -0
  41. package/dist/types/index.js +2 -0
  42. package/package.json +2 -2
  43. package/src/structures/Registry.ts +2 -2
  44. package/test/modules/dev.ts +25 -0
@@ -0,0 +1,72 @@
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.BuiltInConverters = void 0;
13
+ const __1 = require("..");
14
+ const discord_js_1 = require("discord.js");
15
+ /**
16
+ * Built-In module which is enabled by default.
17
+ */
18
+ class BuiltInConverters extends __1.Module {
19
+ constructor(client) {
20
+ super(__filename);
21
+ this.client = client;
22
+ }
23
+ getUserIDByMention(mention) {
24
+ if (!mention)
25
+ return;
26
+ if (mention.startsWith('<@') && mention.endsWith('>')) {
27
+ mention = mention.slice(2, -1);
28
+ if (mention.startsWith('!')) {
29
+ mention = mention.slice(1);
30
+ }
31
+ return mention;
32
+ }
33
+ }
34
+ user(value) {
35
+ const id = this.getUserIDByMention(value);
36
+ if (!id)
37
+ return null;
38
+ const user = this.client.users.cache.get(id);
39
+ return user || null;
40
+ }
41
+ member(value, msg) {
42
+ var _a;
43
+ const id = this.getUserIDByMention(value);
44
+ if (!id)
45
+ return null;
46
+ const user = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.members.cache.get(id);
47
+ return user || null;
48
+ }
49
+ number(value) {
50
+ const n = Number(value);
51
+ return isNaN(n) ? null : n;
52
+ }
53
+ }
54
+ __decorate([
55
+ __1.argConverter(discord_js_1.User),
56
+ __metadata("design:type", Function),
57
+ __metadata("design:paramtypes", [String]),
58
+ __metadata("design:returntype", Object)
59
+ ], BuiltInConverters.prototype, "user", null);
60
+ __decorate([
61
+ __1.argConverter(discord_js_1.GuildMember),
62
+ __metadata("design:type", Function),
63
+ __metadata("design:paramtypes", [String, discord_js_1.Message]),
64
+ __metadata("design:returntype", Object)
65
+ ], BuiltInConverters.prototype, "member", null);
66
+ __decorate([
67
+ __1.argConverter(Number),
68
+ __metadata("design:type", Function),
69
+ __metadata("design:paramtypes", [String]),
70
+ __metadata("design:returntype", void 0)
71
+ ], BuiltInConverters.prototype, "number", null);
72
+ exports.BuiltInConverters = BuiltInConverters;
@@ -0,0 +1,11 @@
1
+ import { Interaction, Message } from 'discord.js';
2
+ import { CommandClient, Module } from '../structures';
3
+ /**
4
+ * Built-In module which is enabled by default.
5
+ */
6
+ export declare class CommandHandler extends Module {
7
+ private client;
8
+ constructor(client: CommandClient);
9
+ onMessage(msg: Message): Promise<boolean | undefined>;
10
+ interaction(i: Interaction): Promise<boolean | undefined>;
11
+ }
@@ -0,0 +1,178 @@
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 discord_js_1 = require("discord.js");
23
+ const structures_1 = require("../structures");
24
+ const listener_1 = require("../listener");
25
+ const error_1 = require("../error");
26
+ /**
27
+ * Built-In module which is enabled by default.
28
+ */
29
+ class CommandHandler extends structures_1.Module {
30
+ constructor(client) {
31
+ super(__filename);
32
+ this.client = client;
33
+ }
34
+ onMessage(msg) {
35
+ var _a, _b, _c;
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (!this.client.commandOptions.commands.allowSelf &&
38
+ msg.author.id === this.client.user.id)
39
+ return;
40
+ if (!this.client.commandOptions.commands.allowBots && msg.author.bot)
41
+ return;
42
+ const prefixFunction = this.client.commandOptions.prefix;
43
+ const prefix = typeof prefixFunction === 'function'
44
+ ? yield prefixFunction(msg)
45
+ : prefixFunction;
46
+ const { content } = msg;
47
+ if (!content.startsWith(prefix))
48
+ return;
49
+ const args = content.slice(prefix.length).split(' ');
50
+ const command = args.shift();
51
+ if (!command)
52
+ return;
53
+ const cmd = this.client.registry.commandManager.commandList.find((x) => x.name.toLowerCase() === command.toLowerCase() ||
54
+ x.aliases.map((r) => r.toLowerCase()).includes(command));
55
+ if (!cmd)
56
+ return;
57
+ if (cmd.ownerOnly) {
58
+ if (!this.client.owners.includes(msg.author.id))
59
+ return this.client.emit('commandError', new error_1.OwnerOnlyCommand(cmd, msg), msg, cmd);
60
+ }
61
+ if (!((_b = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.me) === null || _b === void 0 ? void 0 : _b.permissionsIn(msg.channel.id).has(cmd.clientPermissions))) {
62
+ return this.client.emit('commandError', new error_1.MissingClientPermissions(cmd, cmd.clientPermissions, msg), msg, cmd);
63
+ }
64
+ if (!((_c = msg.member) === null || _c === void 0 ? void 0 : _c.permissionsIn(msg.channel.id).has(cmd.clientPermissions))) {
65
+ return this.client.emit('commandError', new error_1.MissingUserPermissions(cmd, cmd.clientPermissions, msg), msg, cmd);
66
+ }
67
+ const checks = cmd.checks;
68
+ for (const check of checks) {
69
+ try {
70
+ if (!(yield check(msg))) {
71
+ return this.client.emit('commandError', new error_1.CheckFailedError(cmd), msg, cmd);
72
+ }
73
+ }
74
+ catch (_d) {
75
+ return;
76
+ }
77
+ }
78
+ const commandArgs = cmd.args;
79
+ const parsedArgs = [];
80
+ for (const i in commandArgs) {
81
+ const v = args.shift();
82
+ const arg = commandArgs[i];
83
+ if (arg.rest) {
84
+ parsedArgs.push([v, ...args].join(' '));
85
+ break;
86
+ }
87
+ if (!arg.optional && !v) {
88
+ return this.client.emit('commandError', new Error(`An argument is required but not provided.`), msg, cmd);
89
+ }
90
+ if (arg.optional && !v) {
91
+ break;
92
+ }
93
+ if (arg.type === String) {
94
+ parsedArgs[i] = v;
95
+ continue;
96
+ }
97
+ const converter = this.client.registry.commandManager.argConverterList.find((x) => x.type === arg.type);
98
+ if (converter) {
99
+ try {
100
+ parsedArgs[i] = yield converter.convert.apply(converter.module, [
101
+ v,
102
+ msg,
103
+ ]);
104
+ if (!parsedArgs[i]) {
105
+ return this.client.emit('commandError', new Error('Argument converter returned no result.'), msg, cmd);
106
+ }
107
+ }
108
+ catch (e) {
109
+ return this.client.emit('commandError', e, msg, cmd);
110
+ }
111
+ }
112
+ else {
113
+ return this.client.emit('commandError', new Error(`No converter found for type ${arg.type.constructor.name}.`), msg, cmd);
114
+ }
115
+ }
116
+ const executeArgs = [];
117
+ if (cmd.usesCtx) {
118
+ executeArgs[0] = new structures_1.Context(msg, prefix);
119
+ }
120
+ else {
121
+ executeArgs[0] = msg;
122
+ }
123
+ executeArgs.push(...parsedArgs);
124
+ try {
125
+ cmd.execute.apply(cmd.module, executeArgs);
126
+ }
127
+ catch (e) {
128
+ this.client.emit('commandError', e, msg, cmd);
129
+ }
130
+ });
131
+ }
132
+ interaction(i) {
133
+ var _a, _b, _c;
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ if (this.client.commandOptions.slashCommands.guild &&
136
+ typeof this.client.commandOptions.slashCommands.guild ===
137
+ 'string'
138
+ ? this.client.commandOptions.slashCommands.guild !== i.guildId
139
+ : !this.client.commandOptions.slashCommands.guild.includes(i.guildId))
140
+ return;
141
+ if (!i.isCommand())
142
+ return;
143
+ const cmd = i.command;
144
+ const command = this.client.registry.slashCommandManager.commandList.find((x) => x.name === cmd.name);
145
+ if (!command)
146
+ return;
147
+ if (!((_b = (_a = i.guild) === null || _a === void 0 ? void 0 : _a.me) === null || _b === void 0 ? void 0 : _b.permissionsIn(i.channel.id).has(command.clientPermissions))) {
148
+ return this.client.emit('slashCommandError', new error_1.MissingSlashClientPermissions(command, command.clientPermissions, i), i, cmd);
149
+ }
150
+ if (!((_c = i.member) === null || _c === void 0 ? void 0 : _c.permissionsIn(i.channel.id).has(command.clientPermissions))) {
151
+ return this.client.emit('slashCommandError', new error_1.MissingSlashUserPermissions(command, command.clientPermissions, i), i, cmd);
152
+ }
153
+ if (command.ownerOnly) {
154
+ if (!this.client.owners.includes(i.user.id))
155
+ return this.client.emit('slashCommandError', new error_1.OwnerOnlySlashCommand(command, i), i, cmd);
156
+ }
157
+ try {
158
+ yield command.execute.apply(command.module, [i, i.options]);
159
+ }
160
+ catch (e) {
161
+ return this.client.emit('slashCommandError', e, i, cmd);
162
+ }
163
+ });
164
+ }
165
+ }
166
+ __decorate([
167
+ listener_1.listener('messageCreate'),
168
+ __metadata("design:type", Function),
169
+ __metadata("design:paramtypes", [discord_js_1.Message]),
170
+ __metadata("design:returntype", Promise)
171
+ ], CommandHandler.prototype, "onMessage", null);
172
+ __decorate([
173
+ listener_1.listener('interactionCreate'),
174
+ __metadata("design:type", Function),
175
+ __metadata("design:paramtypes", [discord_js_1.Interaction]),
176
+ __metadata("design:returntype", Promise)
177
+ ], CommandHandler.prototype, "interaction", null);
178
+ exports.CommandHandler = CommandHandler;
@@ -0,0 +1,2 @@
1
+ export * from './CommandHandler';
2
+ export * from './BuiltInConverters';
@@ -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("./BuiltInConverters"), exports);
@@ -0,0 +1,5 @@
1
+ import { Command } from '../types';
2
+ export declare class CheckFailedError extends Error {
3
+ command: Command;
4
+ constructor(command: Command);
5
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckFailedError = void 0;
4
+ class CheckFailedError extends Error {
5
+ constructor(command) {
6
+ super();
7
+ this.command = command;
8
+ }
9
+ }
10
+ exports.CheckFailedError = CheckFailedError;
@@ -0,0 +1,36 @@
1
+ import { Command, SlashCommand } from '../types';
2
+ import { CommandInteraction, Message, PermissionResolvable } from 'discord.js';
3
+ export declare class MissingUserPermissions extends Error {
4
+ command: Command;
5
+ missingPermissions: PermissionResolvable;
6
+ msg: Message;
7
+ constructor(command: Command, missingPermissions: PermissionResolvable, msg: Message);
8
+ }
9
+ export declare class MissingClientPermissions extends Error {
10
+ command: Command;
11
+ missingPermissions: PermissionResolvable;
12
+ msg: Message;
13
+ constructor(command: Command, missingPermissions: PermissionResolvable, msg: Message);
14
+ }
15
+ export declare class MissingSlashUserPermissions extends Error {
16
+ command: SlashCommand;
17
+ missingPermissions: PermissionResolvable;
18
+ interaction: CommandInteraction;
19
+ constructor(command: SlashCommand, missingPermissions: PermissionResolvable, interaction: CommandInteraction);
20
+ }
21
+ export declare class MissingSlashClientPermissions extends Error {
22
+ command: SlashCommand;
23
+ missingPermissions: PermissionResolvable;
24
+ interaction: CommandInteraction;
25
+ constructor(command: SlashCommand, missingPermissions: PermissionResolvable, interaction: CommandInteraction);
26
+ }
27
+ export declare class OwnerOnlyCommand extends Error {
28
+ command: Command;
29
+ msg: Message;
30
+ constructor(command: Command, msg: Message);
31
+ }
32
+ export declare class OwnerOnlySlashCommand extends Error {
33
+ command: SlashCommand;
34
+ interaction: CommandInteraction;
35
+ constructor(command: SlashCommand, interaction: CommandInteraction);
36
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OwnerOnlySlashCommand = exports.OwnerOnlyCommand = exports.MissingSlashClientPermissions = exports.MissingSlashUserPermissions = exports.MissingClientPermissions = exports.MissingUserPermissions = void 0;
4
+ class MissingUserPermissions extends Error {
5
+ constructor(command, missingPermissions, msg) {
6
+ super();
7
+ this.command = command;
8
+ this.missingPermissions = missingPermissions;
9
+ this.msg = msg;
10
+ }
11
+ }
12
+ exports.MissingUserPermissions = MissingUserPermissions;
13
+ class MissingClientPermissions extends Error {
14
+ constructor(command, missingPermissions, msg) {
15
+ super();
16
+ this.command = command;
17
+ this.missingPermissions = missingPermissions;
18
+ this.msg = msg;
19
+ }
20
+ }
21
+ exports.MissingClientPermissions = MissingClientPermissions;
22
+ class MissingSlashUserPermissions extends Error {
23
+ constructor(command, missingPermissions, interaction) {
24
+ super();
25
+ this.command = command;
26
+ this.missingPermissions = missingPermissions;
27
+ this.interaction = interaction;
28
+ }
29
+ }
30
+ exports.MissingSlashUserPermissions = MissingSlashUserPermissions;
31
+ class MissingSlashClientPermissions extends Error {
32
+ constructor(command, missingPermissions, interaction) {
33
+ super();
34
+ this.command = command;
35
+ this.missingPermissions = missingPermissions;
36
+ this.interaction = interaction;
37
+ }
38
+ }
39
+ exports.MissingSlashClientPermissions = MissingSlashClientPermissions;
40
+ class OwnerOnlyCommand extends Error {
41
+ constructor(command, msg) {
42
+ super();
43
+ this.command = command;
44
+ this.msg = msg;
45
+ }
46
+ }
47
+ exports.OwnerOnlyCommand = OwnerOnlyCommand;
48
+ class OwnerOnlySlashCommand extends Error {
49
+ constructor(command, interaction) {
50
+ super();
51
+ this.command = command;
52
+ this.interaction = interaction;
53
+ }
54
+ }
55
+ exports.OwnerOnlySlashCommand = OwnerOnlySlashCommand;
@@ -0,0 +1,25 @@
1
+ import { Collection } from 'discord.js';
2
+ import { Module } from '../structures';
3
+ import { Listener } from '../types';
4
+ import { CommandClient } from '../structures';
5
+ /**
6
+ * Listener handler
7
+ */
8
+ export declare class ListenerManager {
9
+ private client;
10
+ /**
11
+ * Collection of listeners.
12
+ */
13
+ listeners: Collection<Module, Listener[]>;
14
+ constructor(client: CommandClient);
15
+ /**
16
+ * This method is run by Registry. You don't have to run it manually.
17
+ * @param module
18
+ */
19
+ register(module: Module): void;
20
+ /**
21
+ * This method is run by Registry. You don't have to run it manually.
22
+ * @param module
23
+ */
24
+ unregister(module: Module): void;
25
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListenerManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const constants_1 = require("../constants");
6
+ /**
7
+ * Listener handler
8
+ */
9
+ class ListenerManager {
10
+ constructor(client) {
11
+ this.client = client;
12
+ /**
13
+ * Collection of listeners.
14
+ */
15
+ this.listeners = new discord_js_1.Collection();
16
+ }
17
+ /**
18
+ * This method is run by Registry. You don't have to run it manually.
19
+ * @param module
20
+ */
21
+ register(module) {
22
+ const meta = Reflect.getMetadata(constants_1.LISTENERS_KEY, module);
23
+ if (!meta)
24
+ return;
25
+ const listenersList = [];
26
+ this.listeners.forEach((value) => listenersList.push(...value.map((x) => x.id)));
27
+ if (meta.find((x) => listenersList.find((y) => y === x.id)))
28
+ throw new Error('해당 ID의 리스너가 이미 존재합니다.');
29
+ const listeners = meta.map((x) => ({
30
+ id: x.id,
31
+ module,
32
+ event: x.event,
33
+ wrapper: (...args) => Reflect.get(module, x.key).apply(module, args),
34
+ }));
35
+ listeners.forEach((listener) => this.client.on(listener.event, listener.wrapper));
36
+ this.listeners.set(module, listeners);
37
+ }
38
+ /**
39
+ * This method is run by Registry. You don't have to run it manually.
40
+ * @param module
41
+ */
42
+ unregister(module) {
43
+ const listeners = this.listeners.get(module);
44
+ if (!listeners)
45
+ return;
46
+ for (const listener of listeners) {
47
+ this.client.removeListener(listener.event, listener.wrapper);
48
+ }
49
+ this.listeners.delete(module);
50
+ }
51
+ }
52
+ exports.ListenerManager = ListenerManager;
@@ -0,0 +1,33 @@
1
+ import { Module, Registry } from '../structures';
2
+ import { Collection } from 'discord.js';
3
+ import { SlashCommand } from '../types';
4
+ /**
5
+ * Slash Command Manager.
6
+ */
7
+ export declare class SlashCommandManager {
8
+ private registry;
9
+ constructor(registry: Registry);
10
+ /**
11
+ * Collection of slash commands
12
+ */
13
+ commands: Collection<Module, SlashCommand[]>;
14
+ /**
15
+ * Get List of slash commands
16
+ */
17
+ get commandList(): SlashCommand[];
18
+ /**
19
+ * Auto-Refresh slash command list if `autoRegister` config enabled on client
20
+ */
21
+ refreshCommands(): Promise<void>;
22
+ private registerCommands;
23
+ /**
24
+ * This method is run by Registry. You don't have to run it manually.
25
+ * @param module
26
+ */
27
+ register(module: Module): void;
28
+ /**
29
+ * This method is run by Registry. You don't have to run it manually.
30
+ * @param module
31
+ */
32
+ unregister(module: Module): void;
33
+ }
@@ -0,0 +1,138 @@
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.SlashCommandManager = void 0;
13
+ const discord_js_1 = require("discord.js");
14
+ const constants_1 = require("../constants");
15
+ /**
16
+ * Slash Command Manager.
17
+ */
18
+ class SlashCommandManager {
19
+ constructor(registry) {
20
+ this.registry = registry;
21
+ /**
22
+ * Collection of slash commands
23
+ */
24
+ this.commands = new discord_js_1.Collection();
25
+ }
26
+ /**
27
+ * Get List of slash commands
28
+ */
29
+ get commandList() {
30
+ const result = [];
31
+ this.commands.forEach((x) => result.push(...x));
32
+ return result;
33
+ }
34
+ /**
35
+ * Auto-Refresh slash command list if `autoRegister` config enabled on client
36
+ */
37
+ refreshCommands() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const c = this.registry.client;
40
+ const app = c.application;
41
+ if (c.commandOptions.slashCommands.autoRegister) {
42
+ console.log('[command.ts] Updating commands...');
43
+ if ('guild' in c.commandOptions.slashCommands) {
44
+ const processForGuild = (guildID) => __awaiter(this, void 0, void 0, function* () {
45
+ console.log(`[command.ts] Target Guild ID: ${guildID}`);
46
+ const guild = c.guilds.cache.get(guildID);
47
+ if (!guild)
48
+ return console.log(`[command.ts] ${guildID} Command creation cancelled.`);
49
+ yield guild.commands.set(this.commandList.map((x) => ({
50
+ name: x.name,
51
+ description: x.description,
52
+ options: x.options,
53
+ defaultPermission: !x.ownerOnly,
54
+ })));
55
+ for (const [, command] of guild.commands.cache.filter((x) => {
56
+ var _a;
57
+ return ((_a = this.commandList.find((y) => x.name === y.name)) === null || _a === void 0 ? void 0 : _a.ownerOnly) ||
58
+ false;
59
+ })) {
60
+ yield command.permissions.set({
61
+ permissions: this.registry.client.owners.map((x) => ({
62
+ type: 'USER',
63
+ id: x,
64
+ permission: true,
65
+ })),
66
+ });
67
+ }
68
+ });
69
+ const g = c.commandOptions.slashCommands.guild;
70
+ if (typeof g === 'string') {
71
+ yield processForGuild(g);
72
+ }
73
+ else {
74
+ yield Promise.all(g.map((x) => processForGuild(x)));
75
+ }
76
+ }
77
+ else {
78
+ console.log(`[command.ts] Target: Global`);
79
+ yield app.commands.set(this.commandList.map((x) => ({
80
+ name: x.name,
81
+ description: x.description,
82
+ options: x.options,
83
+ defaultPermission: !x.ownerOnly,
84
+ })));
85
+ for (const [, command] of app.commands.cache.filter((x) => { var _a; return ((_a = this.commandList.find((y) => x.name === y.name)) === null || _a === void 0 ? void 0 : _a.ownerOnly) || false; })) {
86
+ yield command.permissions.set({
87
+ permissions: this.registry.client.owners.map((x) => ({
88
+ type: 'USER',
89
+ id: x,
90
+ permission: true,
91
+ })),
92
+ guild: this.registry.client.commandOptions.slashCommands
93
+ .ownerCommandGuild,
94
+ });
95
+ }
96
+ }
97
+ }
98
+ });
99
+ }
100
+ registerCommands(module) {
101
+ const decorators = Reflect.getMetadata(constants_1.SLASH_COMMANDS_KEY, module);
102
+ if (!decorators)
103
+ return;
104
+ const ownerOnlyKeys = Reflect.getMetadata(constants_1.COMMANDS_OWNER_ONLY_KEY, module) || new Set();
105
+ const commands = decorators.map((v) => {
106
+ const checks = Reflect.getMetadata(constants_1.COMMANDS_CHECK_KEY, module, v.key) || [];
107
+ const userPerms = Reflect.getMetadata(constants_1.COMMANDS_USER_PERMISSIONS_KEY, module, v.key) || { permissions: [] };
108
+ const clientPerms = Reflect.getMetadata(constants_1.COMMANDS_CLIENT_PERMISSIONS_KEY, module, v.key) || { permissions: [] };
109
+ return {
110
+ module: module,
111
+ name: v.name,
112
+ execute: Reflect.get(module, v.key),
113
+ description: v.description,
114
+ options: v.options,
115
+ userPermissions: userPerms.permissions,
116
+ clientPermissions: clientPerms.permissions,
117
+ checks,
118
+ ownerOnly: ownerOnlyKeys.has(v.key),
119
+ };
120
+ });
121
+ this.commands.set(module, commands);
122
+ }
123
+ /**
124
+ * This method is run by Registry. You don't have to run it manually.
125
+ * @param module
126
+ */
127
+ register(module) {
128
+ this.registerCommands(module);
129
+ }
130
+ /**
131
+ * This method is run by Registry. You don't have to run it manually.
132
+ * @param module
133
+ */
134
+ unregister(module) {
135
+ this.commands.delete(module);
136
+ }
137
+ }
138
+ exports.SlashCommandManager = SlashCommandManager;
@@ -0,0 +1,9 @@
1
+ import { Message } from 'discord.js';
2
+ /**
3
+ * Command Context class
4
+ */
5
+ export declare class Context {
6
+ msg: Message;
7
+ prefix: string;
8
+ constructor(msg: Message, prefix: string);
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Context = void 0;
4
+ /**
5
+ * Command Context class
6
+ */
7
+ class Context {
8
+ constructor(msg, prefix) {
9
+ this.msg = msg;
10
+ this.prefix = prefix;
11
+ }
12
+ }
13
+ exports.Context = Context;