@pikokr/command.ts 3.2.4-dev.434c22e → 3.2.4-dev.535de3c
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/dist/applicationCommand/AppCommand.d.ts +18 -0
- package/dist/{slashCommand/SlashCommand.js → applicationCommand/AppCommand.js} +7 -7
- package/dist/applicationCommand/AppCommand.js.map +1 -0
- package/dist/applicationCommand/decorator.d.ts +10 -0
- package/dist/{slashCommand → applicationCommand}/decorator.js +9 -8
- package/dist/applicationCommand/decorator.js.map +1 -0
- package/dist/applicationCommand/index.d.ts +2 -0
- package/dist/{slashCommand → applicationCommand}/index.js +1 -1
- package/dist/applicationCommand/index.js.map +1 -0
- package/dist/builtinModules/CommandHandler.d.ts +4 -1
- package/dist/builtinModules/CommandHandler.js +107 -15
- package/dist/builtinModules/CommandHandler.js.map +1 -1
- package/dist/command/Command.d.ts +2 -2
- package/dist/command/decorator.d.ts +1 -0
- package/dist/command/decorator.js +2 -1
- package/dist/command/decorator.js.map +1 -1
- package/dist/command/utils.d.ts +2 -2
- package/dist/command/utils.js +6 -6
- package/dist/command/utils.js.map +1 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +4 -3
- package/dist/constants.js.map +1 -1
- package/dist/error/ArgumentConverterNotFound.d.ts +1 -1
- package/dist/error/CommandCheckFailed.d.ts +6 -6
- package/dist/error/CommandCheckFailed.js +3 -3
- package/dist/error/CommandCheckFailed.js.map +1 -1
- package/dist/error/checks/SlashCommandGlobalCheckError.d.ts +5 -0
- package/dist/error/checks/SlashCommandGlobalCheckError.js +11 -0
- package/dist/error/checks/SlashCommandGlobalCheckError.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/messageComponents/base.d.ts +10 -0
- package/dist/messageComponents/base.js +15 -0
- package/dist/messageComponents/base.js.map +1 -0
- package/dist/messageComponents/button.d.ts +5 -0
- package/dist/messageComponents/button.js +28 -0
- package/dist/messageComponents/button.js.map +1 -0
- package/dist/messageComponents/index.d.ts +2 -0
- package/dist/messageComponents/index.js +15 -0
- package/dist/messageComponents/index.js.map +1 -0
- package/dist/messageComponents/selectMenu.d.ts +5 -0
- package/dist/messageComponents/selectMenu.js +28 -0
- package/dist/messageComponents/selectMenu.js.map +1 -0
- package/dist/structures/CommandClient.d.ts +7 -3
- package/dist/structures/CommandClient.js +6 -7
- package/dist/structures/CommandClient.js.map +1 -1
- package/dist/structures/Module.d.ts +4 -2
- package/dist/structures/Module.js +5 -2
- package/dist/structures/Module.js.map +1 -1
- package/dist/structures/Registry.d.ts +4 -2
- package/dist/structures/Registry.js +16 -13
- package/dist/structures/Registry.js.map +1 -1
- package/dist/typings.d.ts +14 -2
- package/package.json +1 -3
- package/src/applicationCommand/AppCommand.ts +28 -0
- package/src/{slashCommand → applicationCommand}/decorator.ts +10 -10
- package/src/applicationCommand/index.ts +2 -0
- package/src/builtinModules/CommandHandler.ts +123 -18
- package/src/command/Command.ts +2 -2
- package/src/command/decorator.ts +2 -1
- package/src/command/utils.ts +9 -9
- package/src/constants.ts +4 -2
- package/src/error/ArgumentConverterNotFound.ts +1 -1
- package/src/error/CommandCheckFailed.ts +4 -4
- package/src/error/checks/SlashCommandGlobalCheckError.ts +7 -0
- package/src/index.ts +2 -1
- package/src/messageComponents/base.ts +12 -0
- package/src/messageComponents/button.ts +26 -0
- package/src/messageComponents/index.ts +2 -0
- package/src/messageComponents/selectMenu.ts +26 -0
- package/src/structures/CommandClient.ts +14 -8
- package/src/structures/Module.ts +9 -4
- package/src/structures/Registry.ts +21 -15
- package/src/typings.ts +14 -2
- package/test/index.ts +2 -2
- package/test/modules/dev.ts +9 -5
- package/test/modules/test.ts +88 -15
- package/dist/slashCommand/SlashCommand.d.ts +0 -19
- package/dist/slashCommand/SlashCommand.js.map +0 -1
- package/dist/slashCommand/decorator.d.ts +0 -10
- package/dist/slashCommand/decorator.js.map +0 -1
- package/dist/slashCommand/index.d.ts +0 -2
- package/dist/slashCommand/index.js.map +0 -1
- package/src/slashCommand/SlashCommand.ts +0 -29
- package/src/slashCommand/index.ts +0 -2
package/test/modules/test.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { command, CommandClient, coolDown, CoolDownError, CoolDownType, listener, Module, option, rest,
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { command, CommandClient, coolDown, CoolDownError, CoolDownType, listener, messageButton, messageSelectMenu, Module, option, rest, applicationCommand } from '../../src'
|
|
2
|
+
import {
|
|
3
|
+
ButtonInteraction,
|
|
4
|
+
CommandInteraction,
|
|
5
|
+
ContextMenuInteraction,
|
|
6
|
+
Message,
|
|
7
|
+
MessageActionRow,
|
|
8
|
+
MessageButton,
|
|
9
|
+
MessageContextMenuInteraction,
|
|
10
|
+
MessageSelectMenu,
|
|
11
|
+
SelectMenuInteraction,
|
|
12
|
+
UserContextMenuInteraction,
|
|
13
|
+
} from 'discord.js'
|
|
4
14
|
|
|
5
15
|
class Test extends Module {
|
|
6
16
|
constructor(private client: CommandClient) {
|
|
7
17
|
super()
|
|
8
18
|
}
|
|
9
19
|
|
|
20
|
+
// region lifetime method
|
|
10
21
|
load() {
|
|
11
22
|
console.log('load')
|
|
12
23
|
}
|
|
@@ -22,6 +33,7 @@ class Test extends Module {
|
|
|
22
33
|
afterReload() {
|
|
23
34
|
console.log('after reload')
|
|
24
35
|
}
|
|
36
|
+
// endregion
|
|
25
37
|
|
|
26
38
|
@listener('ready')
|
|
27
39
|
ready() {
|
|
@@ -35,8 +47,8 @@ class Test extends Module {
|
|
|
35
47
|
}
|
|
36
48
|
console.error(err)
|
|
37
49
|
}
|
|
38
|
-
@listener('
|
|
39
|
-
slashCommandError(err: Error, msg: CommandInteraction) {
|
|
50
|
+
@listener('applicationCommandError')
|
|
51
|
+
slashCommandError(err: Error, msg: CommandInteraction | ContextMenuInteraction) {
|
|
40
52
|
if (err instanceof CoolDownError) {
|
|
41
53
|
return msg.reply({
|
|
42
54
|
content: `쿨다운: <t:${(err.endsAt.getTime() / 1000).toFixed(0)}:R>`,
|
|
@@ -46,22 +58,83 @@ class Test extends Module {
|
|
|
46
58
|
console.error(err)
|
|
47
59
|
}
|
|
48
60
|
|
|
49
|
-
@
|
|
61
|
+
@applicationCommand({
|
|
62
|
+
command: {
|
|
63
|
+
type: 'CHAT_INPUT',
|
|
64
|
+
name: 'test',
|
|
65
|
+
description: 'test',
|
|
66
|
+
options: [
|
|
67
|
+
{
|
|
68
|
+
type: 'STRING',
|
|
69
|
+
name: 'asdf',
|
|
70
|
+
description: 'test',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
})
|
|
50
75
|
@coolDown(CoolDownType.USER, 10)
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
coolDownSlash(i: CommandInteraction, @option('asdf') asdf: string = 'wa sans') {
|
|
77
|
+
i.reply({
|
|
78
|
+
content: asdf,
|
|
79
|
+
components: [
|
|
80
|
+
new MessageActionRow().addComponents(new MessageButton().setLabel('test').setCustomId('testButton').setStyle('PRIMARY')),
|
|
81
|
+
new MessageActionRow().addComponents(
|
|
82
|
+
new MessageSelectMenu()
|
|
83
|
+
.setCustomId('testSelectMenu')
|
|
84
|
+
.setPlaceholder('test')
|
|
85
|
+
.setMinValues(1)
|
|
86
|
+
.setOptions(
|
|
87
|
+
new Array(10).fill(1).map((_, i) => ({
|
|
88
|
+
label: `${i}`,
|
|
89
|
+
value: `${i}`,
|
|
90
|
+
})),
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
],
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@applicationCommand({
|
|
98
|
+
command: {
|
|
99
|
+
type: 'MESSAGE',
|
|
100
|
+
name: 'contextMenuTest',
|
|
101
|
+
defaultPermission: true,
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
@coolDown(CoolDownType.USER, 10)
|
|
105
|
+
async contextMenuMessage(i: MessageContextMenuInteraction) {
|
|
106
|
+
return i.reply({
|
|
107
|
+
content: `message id: ${i.targetMessage.id}`,
|
|
108
|
+
})
|
|
53
109
|
}
|
|
54
110
|
|
|
55
|
-
@
|
|
56
|
-
command:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
111
|
+
@applicationCommand({
|
|
112
|
+
command: {
|
|
113
|
+
type: 'USER',
|
|
114
|
+
name: 'contextMenuTest',
|
|
115
|
+
defaultPermission: true,
|
|
116
|
+
},
|
|
60
117
|
})
|
|
61
118
|
@coolDown(CoolDownType.USER, 10)
|
|
62
|
-
async
|
|
119
|
+
async contextMenuUser(i: UserContextMenuInteraction) {
|
|
63
120
|
return i.reply({
|
|
64
|
-
content:
|
|
121
|
+
content: `user id: ${i.targetUser.id}`,
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@messageButton('testButton')
|
|
126
|
+
async testButton(i: ButtonInteraction) {
|
|
127
|
+
await i.update({
|
|
128
|
+
content: 'test',
|
|
129
|
+
components: [],
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@messageSelectMenu('testSelectMenu')
|
|
134
|
+
async testSelectMenu(i: SelectMenuInteraction) {
|
|
135
|
+
await i.update({
|
|
136
|
+
content: i.values.join(', '),
|
|
137
|
+
components: [],
|
|
65
138
|
})
|
|
66
139
|
}
|
|
67
140
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SlashCommandBuilder } from '@discordjs/builders';
|
|
2
|
-
import { Module } from '../structures';
|
|
3
|
-
import { Snowflake } from 'discord.js';
|
|
4
|
-
import { SlashCheckFunction } from '../command';
|
|
5
|
-
export declare type SlashArgument = {
|
|
6
|
-
type: any;
|
|
7
|
-
name?: string;
|
|
8
|
-
};
|
|
9
|
-
export declare class SlashCommand {
|
|
10
|
-
commandBuilder: SlashCommandBuilder | Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
|
11
|
-
private run;
|
|
12
|
-
module: Module;
|
|
13
|
-
params: SlashArgument[];
|
|
14
|
-
guild: Snowflake | Snowflake[] | undefined;
|
|
15
|
-
private key;
|
|
16
|
-
get checks(): SlashCheckFunction[];
|
|
17
|
-
execute(module: Module, args: any[]): any;
|
|
18
|
-
constructor(commandBuilder: SlashCommandBuilder | Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>, run: Function, module: Module, params: SlashArgument[], guild: Snowflake | Snowflake[] | undefined, key: string | symbol);
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SlashCommand.js","sourceRoot":"","sources":["../../src/slashCommand/SlashCommand.ts"],"names":[],"mappings":";;;AAGA,4CAAkD;AAQlD,MAAa,YAAY;IASvB,YACS,cAAuG,EACtG,GAAa,EACd,MAAc,EACd,MAAuB,EACvB,KAA0C,EACzC,GAAoB;QALrB,mBAAc,GAAd,cAAc,CAAyF;QACtG,QAAG,GAAH,GAAG,CAAU;QACd,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAiB;QACvB,UAAK,GAAL,KAAK,CAAqC;QACzC,QAAG,GAAH,GAAG,CAAiB;IAC3B,CAAC;IAfJ,IAAI,MAAM;QACR,OAAO,OAAO,CAAC,WAAW,CAAC,+BAAmB,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IAC9E,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,IAAW;QACjC,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACrC,CAAC;CAUF;AAjBD,oCAiBC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Snowflake } from 'discord.js';
|
|
2
|
-
import { SlashCommandBuilder } from '@discordjs/builders';
|
|
3
|
-
declare type SlashOptions = {
|
|
4
|
-
guild: Snowflake | Snowflake[];
|
|
5
|
-
};
|
|
6
|
-
export declare const slashCommand: (opt: Partial<SlashOptions> & {
|
|
7
|
-
command: SlashCommandBuilder | Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
|
8
|
-
}) => (target: Object, propertyKey: string) => void;
|
|
9
|
-
export declare const option: (key: string) => ParameterDecorator;
|
|
10
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/slashCommand/decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAClD,oCAAsC;AACtC,4CAAmE;AAEnE,iDAA6C;AAOtC,MAAM,YAAY,GAAG,CAAC,GAAiI,EAAE,EAAE;IAChK,OAAO,CACL,MAAc,EACd,WAAmB,EAEnB,EAAE;QACF,mBAAW,CAAC,MAAM,CAAC,CAAA;QAEnB,IAAI,UAAU,GAAmB,OAAO,CAAC,WAAW,CAAC,0BAAc,EAAE,MAAM,CAAC,CAAA;QAE5E,MAAM,MAAM,GAAU,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;QAEnF,MAAM,OAAO,GAA+B,OAAO,CAAC,WAAW,CAAC,gCAAoB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI,uBAAU,EAAkB,CAAA;QAE9I,MAAM,OAAO,GAAG,IAAI,2BAAY,CAC9B,GAAG,CAAC,OAAO,EACX,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EAChC,MAAgB,EAChB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACpB,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;SACrB,CAAC,CAAC,EACH,GAAG,CAAC,KAAK,EACT,WAAW,CACZ,CAAA;QAED,IAAI,UAAU,EAAE;YACd,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACzB;aAAM;YACL,UAAU,GAAG,CAAC,OAAO,CAAC,CAAA;YACtB,OAAO,CAAC,cAAc,CAAC,0BAAc,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;SAC3D;IACH,CAAC,CAAA;AACH,CAAC,CAAA;AAjCY,QAAA,YAAY,gBAiCxB;AAEM,MAAM,MAAM,GAAG,CAAC,GAAW,EAAsB,EAAE,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;IACjG,mBAAW,CAAC,MAAM,CAAC,CAAA;IAEnB,IAAI,UAAU,GAA+B,OAAO,CAAC,WAAW,CAAC,gCAAoB,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;IAE3G,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,IAAI,uBAAU,EAAkB,CAAA;QAC7C,OAAO,CAAC,cAAc,CAAC,gCAAoB,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;KAC9E;IAED,UAAU,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;AACrC,CAAC,CAAA;AAXY,QAAA,MAAM,UAWlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/slashCommand/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA2B;AAC3B,iDAA8B"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { SlashCommandBuilder } from '@discordjs/builders'
|
|
2
|
-
import { Module } from '../structures'
|
|
3
|
-
import { Snowflake } from 'discord.js'
|
|
4
|
-
import { KSlashCommandChecks } from '../constants'
|
|
5
|
-
import { SlashCheckFunction } from '../command'
|
|
6
|
-
|
|
7
|
-
export type SlashArgument = {
|
|
8
|
-
type: any
|
|
9
|
-
name?: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class SlashCommand {
|
|
13
|
-
get checks(): SlashCheckFunction[] {
|
|
14
|
-
return Reflect.getMetadata(KSlashCommandChecks, this.module, this.key) || []
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
execute(module: Module, args: any[]) {
|
|
18
|
-
return this.run.apply(module, args)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
public commandBuilder: SlashCommandBuilder | Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>,
|
|
23
|
-
private run: Function,
|
|
24
|
-
public module: Module,
|
|
25
|
-
public params: SlashArgument[],
|
|
26
|
-
public guild: Snowflake | Snowflake[] | undefined,
|
|
27
|
-
private key: string | symbol,
|
|
28
|
-
) {}
|
|
29
|
-
}
|