@pikokr/command.ts 3.2.3 → 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.
Files changed (90) hide show
  1. package/dist/applicationCommand/AppCommand.d.ts +18 -0
  2. package/dist/{slashCommand/SlashCommand.js → applicationCommand/AppCommand.js} +7 -7
  3. package/dist/applicationCommand/AppCommand.js.map +1 -0
  4. package/dist/applicationCommand/decorator.d.ts +10 -0
  5. package/dist/{slashCommand → applicationCommand}/decorator.js +9 -8
  6. package/dist/applicationCommand/decorator.js.map +1 -0
  7. package/dist/applicationCommand/index.d.ts +2 -0
  8. package/dist/{slashCommand → applicationCommand}/index.js +1 -1
  9. package/dist/applicationCommand/index.js.map +1 -0
  10. package/dist/builtinModules/BuiltinCommandConverters.d.ts +1 -1
  11. package/dist/builtinModules/BuiltinSlashCommandConverters.d.ts +1 -1
  12. package/dist/builtinModules/BuiltinSlashCommandConverters.js.map +1 -1
  13. package/dist/builtinModules/CommandHandler.d.ts +4 -1
  14. package/dist/builtinModules/CommandHandler.js +114 -19
  15. package/dist/builtinModules/CommandHandler.js.map +1 -1
  16. package/dist/command/Command.d.ts +2 -2
  17. package/dist/command/decorator.d.ts +1 -0
  18. package/dist/command/decorator.js +2 -1
  19. package/dist/command/decorator.js.map +1 -1
  20. package/dist/command/utils.d.ts +2 -2
  21. package/dist/command/utils.js +6 -6
  22. package/dist/command/utils.js.map +1 -1
  23. package/dist/constants.d.ts +3 -2
  24. package/dist/constants.js +4 -3
  25. package/dist/constants.js.map +1 -1
  26. package/dist/error/ArgumentConverterNotFound.d.ts +1 -1
  27. package/dist/error/CommandCheckFailed.d.ts +6 -6
  28. package/dist/error/CommandCheckFailed.js +3 -3
  29. package/dist/error/CommandCheckFailed.js.map +1 -1
  30. package/dist/error/checks/SlashCommandGlobalCheckError.d.ts +5 -0
  31. package/dist/error/checks/SlashCommandGlobalCheckError.js +11 -0
  32. package/dist/error/checks/SlashCommandGlobalCheckError.js.map +1 -0
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.js +2 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/messageComponents/base.d.ts +10 -0
  37. package/dist/messageComponents/base.js +15 -0
  38. package/dist/messageComponents/base.js.map +1 -0
  39. package/dist/messageComponents/button.d.ts +5 -0
  40. package/dist/messageComponents/button.js +28 -0
  41. package/dist/messageComponents/button.js.map +1 -0
  42. package/dist/messageComponents/index.d.ts +2 -0
  43. package/dist/messageComponents/index.js +15 -0
  44. package/dist/messageComponents/index.js.map +1 -0
  45. package/dist/messageComponents/selectMenu.d.ts +5 -0
  46. package/dist/messageComponents/selectMenu.js +28 -0
  47. package/dist/messageComponents/selectMenu.js.map +1 -0
  48. package/dist/structures/CommandClient.d.ts +8 -3
  49. package/dist/structures/CommandClient.js +7 -7
  50. package/dist/structures/CommandClient.js.map +1 -1
  51. package/dist/structures/Module.d.ts +4 -2
  52. package/dist/structures/Module.js +5 -2
  53. package/dist/structures/Module.js.map +1 -1
  54. package/dist/structures/Registry.d.ts +4 -2
  55. package/dist/structures/Registry.js +16 -13
  56. package/dist/structures/Registry.js.map +1 -1
  57. package/dist/typings.d.ts +15 -3
  58. package/package.json +3 -5
  59. package/src/applicationCommand/AppCommand.ts +28 -0
  60. package/src/{slashCommand → applicationCommand}/decorator.ts +10 -10
  61. package/src/applicationCommand/index.ts +2 -0
  62. package/src/builtinModules/BuiltinSlashCommandConverters.ts +1 -1
  63. package/src/builtinModules/CommandHandler.ts +131 -22
  64. package/src/command/Command.ts +2 -2
  65. package/src/command/decorator.ts +2 -1
  66. package/src/command/utils.ts +9 -9
  67. package/src/constants.ts +4 -2
  68. package/src/error/ArgumentConverterNotFound.ts +1 -1
  69. package/src/error/CommandCheckFailed.ts +4 -4
  70. package/src/error/checks/SlashCommandGlobalCheckError.ts +7 -0
  71. package/src/index.ts +2 -1
  72. package/src/messageComponents/base.ts +12 -0
  73. package/src/messageComponents/button.ts +26 -0
  74. package/src/messageComponents/index.ts +2 -0
  75. package/src/messageComponents/selectMenu.ts +26 -0
  76. package/src/structures/CommandClient.ts +16 -8
  77. package/src/structures/Module.ts +9 -4
  78. package/src/structures/Registry.ts +21 -15
  79. package/src/typings.ts +15 -3
  80. package/test/index.ts +2 -2
  81. package/test/modules/dev.ts +9 -5
  82. package/test/modules/test.ts +88 -15
  83. package/dist/slashCommand/SlashCommand.d.ts +0 -19
  84. package/dist/slashCommand/SlashCommand.js.map +0 -1
  85. package/dist/slashCommand/decorator.d.ts +0 -10
  86. package/dist/slashCommand/decorator.js.map +0 -1
  87. package/dist/slashCommand/index.d.ts +0 -2
  88. package/dist/slashCommand/index.js.map +0 -1
  89. package/src/slashCommand/SlashCommand.ts +0 -29
  90. package/src/slashCommand/index.ts +0 -2
@@ -1,6 +1,5 @@
1
- import { BuiltInModule, CommandClient, ownerOnly, slashCommand, listener, SlashCommandCheckFailed } from '../../src'
1
+ import { BuiltInModule, CommandClient, ownerOnly, applicationCommand, listener, ApplicationCommandCheckFailed } from '../../src'
2
2
  import { CommandInteraction } from 'discord.js'
3
- import { SlashCommandBuilder } from '@discordjs/builders'
4
3
 
5
4
  export class Dev extends BuiltInModule {
6
5
  constructor(private cts: CommandClient) {
@@ -9,7 +8,7 @@ export class Dev extends BuiltInModule {
9
8
 
10
9
  @listener('slashCommandError')
11
10
  slashError(e: Error, i: CommandInteraction) {
12
- if (e instanceof SlashCommandCheckFailed) {
11
+ if (e instanceof ApplicationCommandCheckFailed) {
13
12
  return i.reply({
14
13
  content: 'Command before-run check failed',
15
14
  ephemeral: true,
@@ -18,8 +17,13 @@ export class Dev extends BuiltInModule {
18
17
  console.error(e.message)
19
18
  }
20
19
 
21
- @slashCommand({
22
- command: new SlashCommandBuilder().setName('reload').setDescription('리로드 커맨드'),
20
+ // new SlashCommandBuilder().setName('reload').setDescription('리로드 커맨드')
21
+ @applicationCommand({
22
+ command: {
23
+ name: 'reload',
24
+ type: 'CHAT_INPUT',
25
+ description: '리로드 커맨드',
26
+ },
23
27
  })
24
28
  @ownerOnly
25
29
  async reload(i: CommandInteraction) {
@@ -1,12 +1,23 @@
1
- import { command, CommandClient, coolDown, CoolDownError, CoolDownType, listener, Module, option, rest, slashCommand } from '../../src'
2
- import { CommandInteraction, Message } from 'discord.js'
3
- import { SlashCommandBuilder } from '@discordjs/builders'
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('slashCommandError')
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
- @command()
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
- test(msg: Message, @rest asdf: string = 'wa sans') {
52
- msg.reply(asdf)
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
- @slashCommand({
56
- command: new SlashCommandBuilder()
57
- .setName('test')
58
- .setDescription('test command')
59
- .addStringOption((builder) => builder.setName('test').setDescription('test option').setRequired(false)),
111
+ @applicationCommand({
112
+ command: {
113
+ type: 'USER',
114
+ name: 'contextMenuTest',
115
+ defaultPermission: true,
116
+ },
60
117
  })
61
118
  @coolDown(CoolDownType.USER, 10)
62
- async testSlash(i: CommandInteraction, @option('test') test: string = 'wa sans') {
119
+ async contextMenuUser(i: UserContextMenuInteraction) {
63
120
  return i.reply({
64
- content: test,
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,2 +0,0 @@
1
- export * from './decorator';
2
- export * from './SlashCommand';
@@ -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
- }
@@ -1,2 +0,0 @@
1
- export * from './decorator'
2
- export * from './SlashCommand'