@pikokr/command.ts 3.0.4 → 3.0.6-dev.33d39ce

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 (63) hide show
  1. package/dist/builtinModules/BuiltinCommandConverters.d.ts +3 -3
  2. package/dist/builtinModules/BuiltinCommandConverters.js +6 -6
  3. package/dist/builtinModules/CommandHandler.js +5 -2
  4. package/dist/command/decorator.js +28 -4
  5. package/dist/error/checks/DMOnlyCommand.d.ts +3 -0
  6. package/dist/error/checks/DMOnlyCommand.js +9 -0
  7. package/dist/error/checks/GuildOnlyCommand.d.ts +3 -0
  8. package/dist/error/checks/GuildOnlyCommand.js +9 -0
  9. package/dist/error/checks/OwnerOnlyCommand.d.ts +3 -0
  10. package/dist/error/checks/OwnerOnlyCommand.js +9 -0
  11. package/dist/error/checks/index.d.ts +3 -0
  12. package/dist/{defaultModules → error/checks}/index.js +3 -2
  13. package/dist/error/index.d.ts +1 -0
  14. package/dist/error/index.js +1 -0
  15. package/package.json +2 -2
  16. package/src/builtinModules/BuiltinCommandConverters.ts +3 -3
  17. package/src/builtinModules/CommandHandler.ts +6 -2
  18. package/src/command/cooldown/adapter.ts +1 -1
  19. package/src/command/decorator.ts +26 -8
  20. package/src/error/checks/DMOnlyCommand.ts +5 -0
  21. package/src/error/checks/GuildOnlyCommand.ts +5 -0
  22. package/src/error/checks/OwnerOnlyCommand.ts +5 -0
  23. package/src/error/checks/index.ts +3 -0
  24. package/src/error/index.ts +1 -0
  25. package/dist/argumentConverter/decorator.d.ts +0 -5
  26. package/dist/argumentConverter/decorator.js +0 -24
  27. package/dist/argumentConverter/index.d.ts +0 -1
  28. package/dist/argumentConverter/index.js +0 -13
  29. package/dist/command/CommandManager.d.ts +0 -16
  30. package/dist/command/CommandManager.js +0 -69
  31. package/dist/debugTool/DebugModule.d.ts +0 -7
  32. package/dist/debugTool/DebugModule.js +0 -56
  33. package/dist/debugTool/commands/default.d.ts +0 -7
  34. package/dist/debugTool/commands/default.js +0 -17
  35. package/dist/debugTool/commands/eval.d.ts +0 -9
  36. package/dist/debugTool/commands/eval.js +0 -103
  37. package/dist/debugTool/commands/index.d.ts +0 -6
  38. package/dist/debugTool/commands/index.js +0 -21
  39. package/dist/debugTool/commands/load.d.ts +0 -9
  40. package/dist/debugTool/commands/load.js +0 -36
  41. package/dist/debugTool/commands/reload.d.ts +0 -9
  42. package/dist/debugTool/commands/reload.js +0 -54
  43. package/dist/debugTool/commands/unload.d.ts +0 -9
  44. package/dist/debugTool/commands/unload.js +0 -54
  45. package/dist/debugTool/index.d.ts +0 -20
  46. package/dist/debugTool/index.js +0 -18
  47. package/dist/defaultModules/BuiltInConverters.d.ts +0 -13
  48. package/dist/defaultModules/BuiltInConverters.js +0 -72
  49. package/dist/defaultModules/CommandHandler.d.ts +0 -11
  50. package/dist/defaultModules/CommandHandler.js +0 -178
  51. package/dist/defaultModules/index.d.ts +0 -2
  52. package/dist/error/CheckFailedError.d.ts +0 -5
  53. package/dist/error/CheckFailedError.js +0 -10
  54. package/dist/error/Permissions.d.ts +0 -36
  55. package/dist/error/Permissions.js +0 -55
  56. package/dist/listener/ListenerManager.d.ts +0 -25
  57. package/dist/listener/ListenerManager.js +0 -52
  58. package/dist/slashCommand/SlashCommandManager.d.ts +0 -33
  59. package/dist/slashCommand/SlashCommandManager.js +0 -138
  60. package/dist/structures/Context.d.ts +0 -9
  61. package/dist/structures/Context.js +0 -13
  62. package/dist/types/index.d.ts +0 -101
  63. package/dist/types/index.js +0 -2
@@ -8,7 +8,7 @@ export declare class BuiltinCommandConverters extends BuiltInModule {
8
8
  message(msg: Message): Message;
9
9
  string(msg: Message, arg: string): string;
10
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;
11
+ user(msg: Message, value: string): User | null;
12
+ member(msg: Message, value: string): GuildMember | undefined;
13
+ number(msg: Message, value: string): number | undefined;
14
14
  }
@@ -36,14 +36,14 @@ class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
36
36
  return mention;
37
37
  }
38
38
  }
39
- user(value) {
39
+ user(msg, value) {
40
40
  const id = this.getUserIDByMention(value);
41
41
  if (!id)
42
42
  return null;
43
43
  const user = this.client.users.cache.get(id);
44
44
  return user || null;
45
45
  }
46
- member(value, msg) {
46
+ member(msg, value) {
47
47
  var _a;
48
48
  const id = this.getUserIDByMention(value);
49
49
  if (!id)
@@ -51,7 +51,7 @@ class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
51
51
  const user = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.members.cache.get(id);
52
52
  return user || undefined;
53
53
  }
54
- number(value) {
54
+ number(msg, value) {
55
55
  const n = Number(value);
56
56
  return isNaN(n) ? undefined : n;
57
57
  }
@@ -71,19 +71,19 @@ __decorate([
71
71
  __decorate([
72
72
  command_1.argumentConverter(discord_js_1.User),
73
73
  __metadata("design:type", Function),
74
- __metadata("design:paramtypes", [String]),
74
+ __metadata("design:paramtypes", [discord_js_1.Message, String]),
75
75
  __metadata("design:returntype", Object)
76
76
  ], BuiltinCommandConverters.prototype, "user", null);
77
77
  __decorate([
78
78
  command_1.argumentConverter(discord_js_1.GuildMember),
79
79
  __metadata("design:type", Function),
80
- __metadata("design:paramtypes", [String, discord_js_1.Message]),
80
+ __metadata("design:paramtypes", [discord_js_1.Message, String]),
81
81
  __metadata("design:returntype", Object)
82
82
  ], BuiltinCommandConverters.prototype, "member", null);
83
83
  __decorate([
84
84
  command_1.argumentConverter(Number),
85
85
  __metadata("design:type", Function),
86
- __metadata("design:paramtypes", [String]),
86
+ __metadata("design:paramtypes", [discord_js_1.Message, String]),
87
87
  __metadata("design:returntype", void 0)
88
88
  ], BuiltinCommandConverters.prototype, "number", null);
89
89
  exports.BuiltinCommandConverters = BuiltinCommandConverters;
@@ -95,8 +95,11 @@ class CommandHandler extends BuiltInModule_1.BuiltInModule {
95
95
  }
96
96
  if (!converter)
97
97
  return error(new error_1.ArgumentConverterNotFound(argType, msg));
98
+ const converterModule = this.registry.modules.find((x) => x.argumentConverters.includes(converter));
99
+ if (!converterModule)
100
+ return error(new error_1.ArgumentConverterNotFound(argType, msg));
98
101
  if (converter.withoutParameter) {
99
- argList.push(yield converter.execute(module, msg));
102
+ argList.push(yield converter.execute(converterModule, msg));
100
103
  continue;
101
104
  }
102
105
  const arg = args.shift();
@@ -106,7 +109,7 @@ class CommandHandler extends BuiltInModule_1.BuiltInModule {
106
109
  if (!arg) {
107
110
  return error(new error_1.ArgumentNotProvided(i, cmd, msg));
108
111
  }
109
- const executed = yield converter.execute(module, msg, arg);
112
+ const executed = yield converter.execute(converterModule, msg, arg);
110
113
  if (!executed === undefined) {
111
114
  return error(new error_1.ArgumentNotProvided(i, cmd, msg));
112
115
  }
@@ -75,9 +75,33 @@ const rest = (target, propertyKey, parameterIndex) => {
75
75
  Reflect.defineMetadata(constants_1.KRest, parameterIndex, target, propertyKey);
76
76
  };
77
77
  exports.rest = rest;
78
- exports.ownerOnly = utils_2.createCheckDecorator((msg) => msg.data.cts.owners.includes(msg.author.id), (i) => i.data.cts.owners.includes(i.user.id));
79
- exports.guildOnly = utils_2.createCheckDecorator((msg) => !!msg.guild, (i) => !!i.guildId);
80
- exports.dmOnly = utils_2.createCheckDecorator((msg) => !msg.guild, (i) => !i.guildId);
78
+ exports.ownerOnly = utils_2.createCheckDecorator((msg) => {
79
+ if (msg.data.cts.owners.includes(msg.author.id))
80
+ return true;
81
+ throw new error_1.OwnerOnlyCommandError();
82
+ }, (i) => {
83
+ if (i.data.cts.owners.includes(i.user.id))
84
+ return true;
85
+ throw new error_1.OwnerOnlyCommandError();
86
+ });
87
+ exports.guildOnly = utils_2.createCheckDecorator((msg) => {
88
+ if (!!msg.guild)
89
+ return true;
90
+ throw new error_1.GuildOnlyCommandError();
91
+ }, (i) => {
92
+ if (!!i.guildId)
93
+ return true;
94
+ throw new error_1.GuildOnlyCommandError();
95
+ });
96
+ exports.dmOnly = utils_2.createCheckDecorator((msg) => {
97
+ if (!msg.guild)
98
+ return true;
99
+ throw new error_1.DMOnlyCommandError();
100
+ }, (i) => {
101
+ if (!i.guildId)
102
+ return true;
103
+ throw new error_1.DMOnlyCommandError();
104
+ });
81
105
  const requireUserPermissions = (permission) => utils_2.createCheckDecorator((msg) => {
82
106
  if (!msg.guild || !msg.member)
83
107
  throw new Error('This command must be used in guild.');
@@ -87,7 +111,7 @@ const requireUserPermissions = (permission) => utils_2.createCheckDecorator((msg
87
111
  throw new error_1.UserPermissionRequired(msg.member, new discord_js_1.Permissions(permission));
88
112
  }, (i) => {
89
113
  if (!i.guild || !i.member)
90
- throw new Error('This command must be used in serer.');
114
+ throw new Error('This command must be used in guild.');
91
115
  if (!(i.member instanceof discord_js_1.GuildMember) || i.member.permissionsIn(i.channel).has(permission)) {
92
116
  return true;
93
117
  }
@@ -0,0 +1,3 @@
1
+ export declare class DMOnlyCommandError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DMOnlyCommandError = void 0;
4
+ class DMOnlyCommandError extends Error {
5
+ constructor() {
6
+ super();
7
+ }
8
+ }
9
+ exports.DMOnlyCommandError = DMOnlyCommandError;
@@ -0,0 +1,3 @@
1
+ export declare class GuildOnlyCommandError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildOnlyCommandError = void 0;
4
+ class GuildOnlyCommandError extends Error {
5
+ constructor() {
6
+ super();
7
+ }
8
+ }
9
+ exports.GuildOnlyCommandError = GuildOnlyCommandError;
@@ -0,0 +1,3 @@
1
+ export declare class OwnerOnlyCommandError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OwnerOnlyCommandError = void 0;
4
+ class OwnerOnlyCommandError extends Error {
5
+ constructor() {
6
+ super();
7
+ }
8
+ }
9
+ exports.OwnerOnlyCommandError = OwnerOnlyCommandError;
@@ -0,0 +1,3 @@
1
+ export * from './OwnerOnlyCommand';
2
+ export * from './GuildOnlyCommand';
3
+ export * from './DMOnlyCommand';
@@ -10,5 +10,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./CommandHandler"), exports);
14
- __exportStar(require("./BuiltInConverters"), exports);
13
+ __exportStar(require("./OwnerOnlyCommand"), exports);
14
+ __exportStar(require("./GuildOnlyCommand"), exports);
15
+ __exportStar(require("./DMOnlyCommand"), exports);
@@ -4,3 +4,4 @@ export * from './ArgumentNotProvided';
4
4
  export * from './ArgumentConverterNotFound';
5
5
  export * from './CommandCheckFailed';
6
6
  export * from './PermissionRequired';
7
+ export * from './checks';
@@ -16,3 +16,4 @@ __exportStar(require("./ArgumentNotProvided"), exports);
16
16
  __exportStar(require("./ArgumentConverterNotFound"), exports);
17
17
  __exportStar(require("./CommandCheckFailed"), exports);
18
18
  __exportStar(require("./PermissionRequired"), exports);
19
+ __exportStar(require("./checks"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikokr/command.ts",
3
3
  "description": "Discord.js command framework for typescript.",
4
- "version": "3.0.4",
4
+ "version": "3.0.6-dev.33d39ce",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -31,4 +31,4 @@
31
31
  "docs:dev": "typedoc",
32
32
  "docs:build": "typedoc"
33
33
  }
34
- }
34
+ }
@@ -33,7 +33,7 @@ export class BuiltinCommandConverters extends BuiltInModule {
33
33
  }
34
34
 
35
35
  @argumentConverter(User)
36
- user(value: string): User | null {
36
+ user(msg: Message, value: string): User | null {
37
37
  const id = this.getUserIDByMention(value)
38
38
  if (!id) return null
39
39
  const user = this.client.users.cache.get(id)
@@ -41,7 +41,7 @@ export class BuiltinCommandConverters extends BuiltInModule {
41
41
  }
42
42
 
43
43
  @argumentConverter(GuildMember)
44
- member(value: string, msg: Message): GuildMember | undefined {
44
+ member(msg: Message, value: string): GuildMember | undefined {
45
45
  const id = this.getUserIDByMention(value)
46
46
  if (!id) return
47
47
  const user = msg.guild?.members.cache.get(id)
@@ -49,7 +49,7 @@ export class BuiltinCommandConverters extends BuiltInModule {
49
49
  }
50
50
 
51
51
  @argumentConverter(Number)
52
- number(value: string) {
52
+ number(msg: Message, value: string) {
53
53
  const n = Number(value)
54
54
  return isNaN(n) ? undefined : n
55
55
  }
@@ -90,8 +90,12 @@ export class CommandHandler extends BuiltInModule {
90
90
 
91
91
  if (!converter) return error(new ArgumentConverterNotFound(argType, msg))
92
92
 
93
+ const converterModule = this.registry.modules.find((x) => x.argumentConverters.includes(converter))
94
+
95
+ if (!converterModule) return error(new ArgumentConverterNotFound(argType, msg))
96
+
93
97
  if (converter.withoutParameter) {
94
- argList.push(await converter.execute(module, msg))
98
+ argList.push(await converter.execute(converterModule, msg))
95
99
  continue
96
100
  }
97
101
  const arg = args.shift()
@@ -101,7 +105,7 @@ export class CommandHandler extends BuiltInModule {
101
105
  if (!arg) {
102
106
  return error(new ArgumentNotProvided(i, cmd, msg))
103
107
  }
104
- const executed = await converter.execute(module, msg, arg)
108
+ const executed = await converter.execute(converterModule, msg, arg)
105
109
  if (!executed === undefined) {
106
110
  return error(new ArgumentNotProvided(i, cmd, msg))
107
111
  }
@@ -1,4 +1,4 @@
1
- import { Collection, Guild, GuildChannel, GuildMember, Message, Role, TextChannel, ThreadChannel, User } from 'discord.js'
1
+ import { Collection } from 'discord.js'
2
2
 
3
3
  export interface CoolDownAdapter {
4
4
  get(id: string): Promise<number | undefined>
@@ -5,7 +5,7 @@ import { ArgumentConverter, SlashArgumentConverter } 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'
8
- import { ClientPermissionRequired, UserPermissionRequired } from '../error'
8
+ import { ClientPermissionRequired, DMOnlyCommandError, GuildOnlyCommandError, OwnerOnlyCommandError, UserPermissionRequired } from '../error'
9
9
 
10
10
  type CommandOptions = {
11
11
  name: string
@@ -111,18 +111,36 @@ export const rest: ParameterDecorator = (target, propertyKey, parameterIndex) =>
111
111
  }
112
112
 
113
113
  export const ownerOnly = createCheckDecorator(
114
- (msg) => msg.data.cts.owners.includes(msg.author.id),
115
- (i) => i.data.cts.owners.includes(i.user.id),
114
+ (msg) => {
115
+ if (msg.data.cts.owners.includes(msg.author.id)) return true
116
+ throw new OwnerOnlyCommandError()
117
+ },
118
+ (i) => {
119
+ if (i.data.cts.owners.includes(i.user.id)) return true
120
+ throw new OwnerOnlyCommandError()
121
+ },
116
122
  )
117
123
 
118
124
  export const guildOnly = createCheckDecorator(
119
- (msg) => !!msg.guild,
120
- (i) => !!i.guildId,
125
+ (msg) => {
126
+ if (!!msg.guild) return true
127
+ throw new GuildOnlyCommandError()
128
+ },
129
+ (i) => {
130
+ if (!!i.guildId) return true
131
+ throw new GuildOnlyCommandError()
132
+ },
121
133
  )
122
134
 
123
135
  export const dmOnly = createCheckDecorator(
124
- (msg) => !msg.guild,
125
- (i) => !i.guildId,
136
+ (msg) => {
137
+ if (!msg.guild) return true
138
+ throw new DMOnlyCommandError()
139
+ },
140
+ (i) => {
141
+ if (!i.guildId) return true
142
+ throw new DMOnlyCommandError()
143
+ },
126
144
  )
127
145
 
128
146
  export const requireUserPermissions = (permission: PermissionResolvable) =>
@@ -135,7 +153,7 @@ export const requireUserPermissions = (permission: PermissionResolvable) =>
135
153
  throw new UserPermissionRequired(msg.member, new Permissions(permission))
136
154
  },
137
155
  (i) => {
138
- if (!i.guild || !i.member) throw new Error('This command must be used in serer.')
156
+ if (!i.guild || !i.member) throw new Error('This command must be used in guild.')
139
157
  if (!(i.member instanceof GuildMember) || i.member.permissionsIn(i.channel as TextChannel).has(permission)) {
140
158
  return true
141
159
  }
@@ -0,0 +1,5 @@
1
+ export class DMOnlyCommandError extends Error {
2
+ constructor() {
3
+ super()
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ export class GuildOnlyCommandError extends Error {
2
+ constructor() {
3
+ super()
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ export class OwnerOnlyCommandError extends Error {
2
+ constructor() {
3
+ super()
4
+ }
5
+ }
@@ -0,0 +1,3 @@
1
+ export * from './OwnerOnlyCommand'
2
+ export * from './GuildOnlyCommand'
3
+ export * from './DMOnlyCommand'
@@ -4,3 +4,4 @@ export * from './ArgumentNotProvided'
4
4
  export * from './ArgumentConverterNotFound'
5
5
  export * from './CommandCheckFailed'
6
6
  export * from './PermissionRequired'
7
+ export * from './checks'
@@ -1,5 +0,0 @@
1
- /**
2
- * Argument Converter decorator
3
- * @param type
4
- */
5
- export declare function argConverter(type: Function): MethodDecorator;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.argConverter = void 0;
4
- const structures_1 = require("../structures");
5
- const constants_1 = require("../constants");
6
- /**
7
- * Argument Converter decorator
8
- * @param type
9
- */
10
- function argConverter(type) {
11
- return (target, propertyKey) => {
12
- if (!(target instanceof structures_1.Module)) {
13
- throw new TypeError('Class does not extend `Module` class.');
14
- }
15
- const meta = {
16
- type,
17
- key: propertyKey,
18
- };
19
- const metas = Reflect.getMetadata(constants_1.ARG_CONVERTER_KEY, target) || [];
20
- metas.push(meta);
21
- Reflect.defineMetadata(constants_1.ARG_CONVERTER_KEY, metas, target);
22
- };
23
- }
24
- exports.argConverter = argConverter;
@@ -1 +0,0 @@
1
- export * from './decorator';
@@ -1,13 +0,0 @@
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);
@@ -1,16 +0,0 @@
1
- import { Module } from '../structures';
2
- import { Collection } from 'discord.js';
3
- import { ArgConverter, Command } from '../types';
4
- /**
5
- * Command Manager
6
- */
7
- export declare class CommandManager {
8
- commands: Collection<Module, Command[]>;
9
- argumentConverters: Collection<Module, ArgConverter[]>;
10
- get commandList(): Command[];
11
- get argConverterList(): ArgConverter[];
12
- private registerCommands;
13
- registerArgConverter(module: Module): void;
14
- register(module: Module): void;
15
- unregister(module: Module): void;
16
- }
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandManager = void 0;
4
- const discord_js_1 = require("discord.js");
5
- const constants_1 = require("../constants");
6
- /**
7
- * Command Manager
8
- */
9
- class CommandManager {
10
- constructor() {
11
- this.commands = new discord_js_1.Collection();
12
- this.argumentConverters = new discord_js_1.Collection();
13
- }
14
- get commandList() {
15
- const result = [];
16
- this.commands.forEach((x) => result.push(...x));
17
- return result;
18
- }
19
- get argConverterList() {
20
- const result = [];
21
- this.argumentConverters.forEach((x) => result.push(...x));
22
- return result;
23
- }
24
- registerCommands(module) {
25
- const decorators = Reflect.getMetadata(constants_1.COMMANDS_KEY, module);
26
- const ownerOnlyKeys = Reflect.getMetadata(constants_1.COMMANDS_OWNER_ONLY_KEY, module) || new Set();
27
- if (!decorators)
28
- return;
29
- const commands = decorators.map((v) => {
30
- const checks = Reflect.getMetadata(constants_1.COMMANDS_CHECK_KEY, module, v.key) || [];
31
- const userPerms = Reflect.getMetadata(constants_1.COMMANDS_USER_PERMISSIONS_KEY, module, v.key) || { permissions: [] };
32
- const clientPerms = Reflect.getMetadata(constants_1.COMMANDS_CLIENT_PERMISSIONS_KEY, module, v.key) || { permissions: [] };
33
- return {
34
- usesCtx: v.usesCtx,
35
- args: v.args,
36
- brief: v.brief,
37
- description: v.description,
38
- module: module,
39
- name: v.name,
40
- execute: Reflect.get(module, v.key),
41
- aliases: v.aliases,
42
- ownerOnly: ownerOnlyKeys.has(v.key),
43
- checks,
44
- userPermissions: userPerms.permissions,
45
- clientPermissions: clientPerms.permissions,
46
- };
47
- });
48
- this.commands.set(module, commands);
49
- }
50
- registerArgConverter(module) {
51
- const decorators = Reflect.getMetadata(constants_1.ARG_CONVERTER_KEY, module);
52
- if (!decorators)
53
- return;
54
- const converters = decorators.map((v) => ({
55
- convert: Reflect.get(module, v.key),
56
- type: v.type,
57
- module: module,
58
- }));
59
- this.argumentConverters.set(module, converters);
60
- }
61
- register(module) {
62
- this.registerArgConverter(module);
63
- this.registerCommands(module);
64
- }
65
- unregister(module) {
66
- this.commands.delete(module);
67
- }
68
- }
69
- exports.CommandManager = CommandManager;
@@ -1,7 +0,0 @@
1
- import { Context } from '../index';
2
- /**
3
- * Debug Module
4
- */
5
- export declare class DebugModule {
6
- static run(ctx: Context): Promise<void>;
7
- }
@@ -1,56 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.DebugModule = void 0;
32
- const commands_1 = __importStar(require("./commands"));
33
- /**
34
- * Debug Module
35
- */
36
- class DebugModule {
37
- static run(ctx) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const args = ctx.msg.content.slice(ctx.prefix.length).split(' ');
40
- args.shift();
41
- const commandName = args.shift();
42
- const command = commands_1.default.find((x) => x.name === commandName);
43
- if (!commandName || !command) {
44
- yield commands_1.Default.execute(ctx.msg);
45
- return;
46
- }
47
- try {
48
- yield command.execute(ctx.msg, args);
49
- }
50
- catch (_a) {
51
- yield ctx.msg.reply('Command failed.');
52
- }
53
- });
54
- }
55
- }
56
- exports.DebugModule = DebugModule;
@@ -1,7 +0,0 @@
1
- import { Message } from 'discord.js';
2
- /**
3
- * Show available commands in debug module
4
- */
5
- export declare const Default: {
6
- execute: (msg: Message) => Promise<Message>;
7
- };
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Default = void 0;
7
- const index_1 = __importDefault(require("./index"));
8
- /**
9
- * Show available commands in debug module
10
- */
11
- exports.Default = {
12
- execute: (msg) => {
13
- let str = 'Available commands: ' +
14
- index_1.default.map((x) => '`' + x.name + '`').join(', ');
15
- return msg.reply(str);
16
- },
17
- };
@@ -1,9 +0,0 @@
1
- import { Message } from 'discord.js';
2
- declare const _default: {
3
- name: string;
4
- execute: (msg: Message, args: string[]) => Promise<void>;
5
- };
6
- /**
7
- * Evaluate javascript/typescript code
8
- */
9
- export default _default;