@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
@@ -1,36 +0,0 @@
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
- }
@@ -1,55 +0,0 @@
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;
@@ -1,25 +0,0 @@
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
- }
@@ -1,52 +0,0 @@
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;
@@ -1,33 +0,0 @@
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
- }
@@ -1,138 +0,0 @@
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;
@@ -1,9 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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;
@@ -1,101 +0,0 @@
1
- import { Module } from '../structures';
2
- import { ApplicationCommandOptionData, Message, PermissionResolvable, Snowflake } from 'discord.js';
3
- export declare type CommandClientOptions = {
4
- owners: Snowflake[] | 'auto';
5
- prefix: string | ((msg: Message) => string | Promise<string>);
6
- slashCommands: {
7
- autoRegister: boolean;
8
- } & ({
9
- guild: Snowflake | Snowflake[];
10
- } | {
11
- ownerCommandGuild: Snowflake;
12
- });
13
- commands: {
14
- allowSelf: boolean;
15
- allowBots: boolean;
16
- };
17
- };
18
- export interface ICommandDecoratorOptions {
19
- aliases: string[];
20
- brief?: string;
21
- description?: string;
22
- name: string;
23
- }
24
- export interface ICommandArgument {
25
- type: Function;
26
- optional: boolean;
27
- rest: boolean;
28
- }
29
- export interface ICommandDecoratorMetadata {
30
- args: ICommandArgument[];
31
- usesCtx: boolean;
32
- key: string;
33
- }
34
- export interface ISlashCommandDecoratorMetadata {
35
- options: ApplicationCommandOptionData[];
36
- key: string;
37
- }
38
- export interface ISlashCommandArgument {
39
- type: Function;
40
- }
41
- export interface ICommandArgument {
42
- type: Function;
43
- optional: boolean;
44
- rest: boolean;
45
- }
46
- export interface ISlashCommandDecoratorOptions {
47
- name: string;
48
- options: ApplicationCommandOptionData[];
49
- description: string;
50
- }
51
- export declare type ISlashCommandDecorator = ISlashCommandDecoratorMetadata & ISlashCommandDecoratorOptions;
52
- export declare type ICommandDecorator = ICommandDecoratorOptions & ICommandDecoratorMetadata;
53
- export interface Command {
54
- execute: Function;
55
- args: ICommandArgument[];
56
- name: string;
57
- aliases: string[];
58
- description?: string;
59
- brief?: string;
60
- usesCtx: boolean;
61
- module: Module;
62
- ownerOnly: boolean;
63
- checks: CheckFunction[];
64
- userPermissions?: PermissionResolvable;
65
- clientPermissions?: PermissionResolvable;
66
- }
67
- export interface SlashCommand {
68
- execute: Function;
69
- name: string;
70
- description: string;
71
- module: Module;
72
- options: ApplicationCommandOptionData[];
73
- ownerOnly: boolean;
74
- checks: CheckFunction[];
75
- userPermissions?: PermissionResolvable;
76
- clientPermissions?: PermissionResolvable;
77
- }
78
- export interface IListener {
79
- event: string;
80
- id: string;
81
- }
82
- export declare type ListenerDecorator = IListener & {
83
- key: string;
84
- };
85
- export declare type Listener = IListener & {
86
- wrapper: (...args: any[]) => any;
87
- module: Module;
88
- };
89
- export interface IArgConverterDecorator {
90
- type: Function;
91
- key: string;
92
- }
93
- export interface ArgConverter {
94
- type: Function;
95
- convert: (arg: string, msg: Message) => any;
96
- module: Module;
97
- }
98
- export declare type CheckFunction = (msg: Message) => boolean | Promise<boolean>;
99
- export declare type RequiredPermissions = {
100
- permissions: PermissionResolvable;
101
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });