@pikokr/command.ts 3.2.4-dev.434c22e → 4.0.0-dev.7a5eecc

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 (182) hide show
  1. package/dist/index.d.ts +310 -9
  2. package/dist/index.js +1 -21
  3. package/dist/index.js.map +1 -1
  4. package/package.json +5 -4
  5. package/publish-version.js +7 -3
  6. package/src/applicationCommand/AppCommand.ts +32 -0
  7. package/src/{slashCommand → applicationCommand}/decorator.ts +14 -10
  8. package/src/applicationCommand/index.ts +6 -0
  9. package/src/builtinModules/BuiltInModule.ts +4 -0
  10. package/src/builtinModules/BuiltinApplicationCommandConverters.ts +16 -0
  11. package/src/builtinModules/BuiltinCommandConverters.ts +4 -0
  12. package/src/builtinModules/CommandHandler.ts +172 -20
  13. package/src/builtinModules/index.ts +5 -1
  14. package/src/command/ArgumentConverter.ts +7 -3
  15. package/src/command/Command.ts +6 -2
  16. package/src/command/cooldown/adapter.ts +4 -0
  17. package/src/command/cooldown/decorator.ts +4 -0
  18. package/src/command/cooldown/error.ts +4 -0
  19. package/src/command/cooldown/index.ts +4 -0
  20. package/src/command/cooldown/type.ts +4 -0
  21. package/src/command/decorator.ts +10 -5
  22. package/src/command/index.ts +4 -0
  23. package/src/command/utils.ts +13 -9
  24. package/src/constants.ts +8 -2
  25. package/src/error/ArgumentConverterNotFound.ts +8 -4
  26. package/src/error/ArgumentNotProvided.ts +4 -0
  27. package/src/error/CommandCheckFailed.ts +8 -4
  28. package/src/error/CommandNotFound.ts +4 -0
  29. package/src/error/InvalidTargetError.ts +4 -0
  30. package/src/error/ModuleError.ts +4 -0
  31. package/src/error/PermissionRequired.ts +4 -0
  32. package/src/error/checks/DMOnlyCommand.ts +4 -0
  33. package/src/error/checks/GuildOnlyCommand.ts +4 -0
  34. package/src/error/checks/OwnerOnlyCommand.ts +4 -0
  35. package/src/error/checks/SlashCommandGlobalCheckError.ts +11 -0
  36. package/src/error/checks/index.ts +4 -0
  37. package/src/error/index.ts +4 -0
  38. package/src/index.ts +6 -1
  39. package/src/interface/index.ts +4 -0
  40. package/src/listener/Listener.ts +4 -0
  41. package/src/listener/decorator.ts +4 -0
  42. package/src/listener/index.ts +4 -0
  43. package/src/messageComponents/base.ts +16 -0
  44. package/src/messageComponents/button.ts +30 -0
  45. package/src/messageComponents/index.ts +6 -0
  46. package/src/messageComponents/selectMenu.ts +30 -0
  47. package/src/structures/CommandClient.ts +20 -10
  48. package/src/structures/Module.ts +15 -6
  49. package/src/structures/Registry.ts +29 -19
  50. package/src/structures/index.ts +4 -0
  51. package/src/typings.ts +18 -2
  52. package/src/utils.ts +4 -0
  53. package/test/index.ts +6 -2
  54. package/test/modules/dev.ts +13 -5
  55. package/test/modules/test.ts +92 -15
  56. package/tsup.config.ts +14 -0
  57. package/dist/builtinModules/BuiltInModule.d.ts +0 -4
  58. package/dist/builtinModules/BuiltInModule.js +0 -13
  59. package/dist/builtinModules/BuiltInModule.js.map +0 -1
  60. package/dist/builtinModules/BuiltinCommandConverters.d.ts +0 -16
  61. package/dist/builtinModules/BuiltinCommandConverters.js +0 -127
  62. package/dist/builtinModules/BuiltinCommandConverters.js.map +0 -1
  63. package/dist/builtinModules/BuiltinSlashCommandConverters.d.ts +0 -10
  64. package/dist/builtinModules/BuiltinSlashCommandConverters.js +0 -42
  65. package/dist/builtinModules/BuiltinSlashCommandConverters.js.map +0 -1
  66. package/dist/builtinModules/CommandHandler.d.ts +0 -11
  67. package/dist/builtinModules/CommandHandler.js +0 -233
  68. package/dist/builtinModules/CommandHandler.js.map +0 -1
  69. package/dist/builtinModules/index.d.ts +0 -3
  70. package/dist/builtinModules/index.js +0 -16
  71. package/dist/builtinModules/index.js.map +0 -1
  72. package/dist/command/ArgumentConverter.d.ts +0 -15
  73. package/dist/command/ArgumentConverter.js +0 -25
  74. package/dist/command/ArgumentConverter.js.map +0 -1
  75. package/dist/command/Command.d.ts +0 -20
  76. package/dist/command/Command.js +0 -22
  77. package/dist/command/Command.js.map +0 -1
  78. package/dist/command/cooldown/adapter.d.ts +0 -10
  79. package/dist/command/cooldown/adapter.js +0 -31
  80. package/dist/command/cooldown/adapter.js.map +0 -1
  81. package/dist/command/cooldown/decorator.d.ts +0 -2
  82. package/dist/command/cooldown/decorator.js +0 -73
  83. package/dist/command/cooldown/decorator.js.map +0 -1
  84. package/dist/command/cooldown/error.d.ts +0 -4
  85. package/dist/command/cooldown/error.js +0 -11
  86. package/dist/command/cooldown/error.js.map +0 -1
  87. package/dist/command/cooldown/index.d.ts +0 -5
  88. package/dist/command/cooldown/index.js +0 -18
  89. package/dist/command/cooldown/index.js.map +0 -1
  90. package/dist/command/cooldown/type.d.ts +0 -8
  91. package/dist/command/cooldown/type.js +0 -13
  92. package/dist/command/cooldown/type.js.map +0 -1
  93. package/dist/command/decorator.d.ts +0 -16
  94. package/dist/command/decorator.js +0 -137
  95. package/dist/command/decorator.js.map +0 -1
  96. package/dist/command/index.d.ts +0 -5
  97. package/dist/command/index.js +0 -18
  98. package/dist/command/index.js.map +0 -1
  99. package/dist/command/utils.d.ts +0 -2
  100. package/dist/command/utils.js +0 -30
  101. package/dist/command/utils.js.map +0 -1
  102. package/dist/constants.d.ts +0 -13
  103. package/dist/constants.js +0 -17
  104. package/dist/constants.js.map +0 -1
  105. package/dist/error/ArgumentConverterNotFound.d.ts +0 -13
  106. package/dist/error/ArgumentConverterNotFound.js +0 -20
  107. package/dist/error/ArgumentConverterNotFound.js.map +0 -1
  108. package/dist/error/ArgumentNotProvided.d.ts +0 -8
  109. package/dist/error/ArgumentNotProvided.js +0 -13
  110. package/dist/error/ArgumentNotProvided.js.map +0 -1
  111. package/dist/error/CommandCheckFailed.d.ts +0 -13
  112. package/dist/error/CommandCheckFailed.js +0 -20
  113. package/dist/error/CommandCheckFailed.js.map +0 -1
  114. package/dist/error/CommandNotFound.d.ts +0 -7
  115. package/dist/error/CommandNotFound.js +0 -13
  116. package/dist/error/CommandNotFound.js.map +0 -1
  117. package/dist/error/InvalidTargetError.d.ts +0 -3
  118. package/dist/error/InvalidTargetError.js +0 -10
  119. package/dist/error/InvalidTargetError.js.map +0 -1
  120. package/dist/error/ModuleError.d.ts +0 -6
  121. package/dist/error/ModuleError.js +0 -14
  122. package/dist/error/ModuleError.js.map +0 -1
  123. package/dist/error/PermissionRequired.d.ts +0 -10
  124. package/dist/error/PermissionRequired.js +0 -19
  125. package/dist/error/PermissionRequired.js.map +0 -1
  126. package/dist/error/checks/DMOnlyCommand.d.ts +0 -3
  127. package/dist/error/checks/DMOnlyCommand.js +0 -10
  128. package/dist/error/checks/DMOnlyCommand.js.map +0 -1
  129. package/dist/error/checks/GuildOnlyCommand.d.ts +0 -3
  130. package/dist/error/checks/GuildOnlyCommand.js +0 -10
  131. package/dist/error/checks/GuildOnlyCommand.js.map +0 -1
  132. package/dist/error/checks/OwnerOnlyCommand.d.ts +0 -3
  133. package/dist/error/checks/OwnerOnlyCommand.js +0 -10
  134. package/dist/error/checks/OwnerOnlyCommand.js.map +0 -1
  135. package/dist/error/checks/index.d.ts +0 -3
  136. package/dist/error/checks/index.js +0 -16
  137. package/dist/error/checks/index.js.map +0 -1
  138. package/dist/error/index.d.ts +0 -7
  139. package/dist/error/index.js +0 -20
  140. package/dist/error/index.js.map +0 -1
  141. package/dist/interface/index.d.ts +0 -1
  142. package/dist/interface/index.js +0 -4
  143. package/dist/interface/index.js.map +0 -1
  144. package/dist/listener/Listener.d.ts +0 -5
  145. package/dist/listener/Listener.js +0 -11
  146. package/dist/listener/Listener.js.map +0 -1
  147. package/dist/listener/decorator.d.ts +0 -2
  148. package/dist/listener/decorator.js +0 -22
  149. package/dist/listener/decorator.js.map +0 -1
  150. package/dist/listener/index.d.ts +0 -2
  151. package/dist/listener/index.js +0 -15
  152. package/dist/listener/index.js.map +0 -1
  153. package/dist/slashCommand/SlashCommand.d.ts +0 -19
  154. package/dist/slashCommand/SlashCommand.js +0 -22
  155. package/dist/slashCommand/SlashCommand.js.map +0 -1
  156. package/dist/slashCommand/decorator.d.ts +0 -10
  157. package/dist/slashCommand/decorator.js +0 -38
  158. package/dist/slashCommand/decorator.js.map +0 -1
  159. package/dist/slashCommand/index.d.ts +0 -2
  160. package/dist/slashCommand/index.js +0 -15
  161. package/dist/slashCommand/index.js.map +0 -1
  162. package/dist/structures/CommandClient.d.ts +0 -41
  163. package/dist/structures/CommandClient.js +0 -95
  164. package/dist/structures/CommandClient.js.map +0 -1
  165. package/dist/structures/Module.d.ts +0 -19
  166. package/dist/structures/Module.js +0 -35
  167. package/dist/structures/Module.js.map +0 -1
  168. package/dist/structures/Registry.d.ts +0 -28
  169. package/dist/structures/Registry.js +0 -223
  170. package/dist/structures/Registry.js.map +0 -1
  171. package/dist/structures/index.d.ts +0 -3
  172. package/dist/structures/index.js +0 -16
  173. package/dist/structures/index.js.map +0 -1
  174. package/dist/typings.d.ts +0 -18
  175. package/dist/typings.js +0 -3
  176. package/dist/typings.js.map +0 -1
  177. package/dist/utils.d.ts +0 -1
  178. package/dist/utils.js +0 -11
  179. package/dist/utils.js.map +0 -1
  180. package/src/builtinModules/BuiltinSlashCommandConverters.ts +0 -23
  181. package/src/slashCommand/SlashCommand.ts +0 -29
  182. package/src/slashCommand/index.ts +0 -2
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Message } from 'discord.js'
2
6
 
3
7
  export class CommandNotFound extends Error {
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class InvalidTargetError extends Error {
2
6
  constructor() {
3
7
  super('Class does not extend "Module" class.')
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class ModuleLoadError extends Error {
2
6
  constructor(file: string, public error: Error) {
3
7
  super('Failed to load module ' + file)
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { GuildMember, Permissions } from 'discord.js'
2
6
 
3
7
  export class UserPermissionRequired extends Error {
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class DMOnlyCommandError extends Error {
2
6
  constructor() {
3
7
  super()
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class GuildOnlyCommandError extends Error {
2
6
  constructor() {
3
7
  super()
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class OwnerOnlyCommandError extends Error {
2
6
  constructor() {
3
7
  super()
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { CommandInteraction } from 'discord.js'
6
+
7
+ export class SlashCommandGlobalCheckError extends Error {
8
+ constructor(public i: CommandInteraction) {
9
+ super('Slash command before-run check failed.')
10
+ }
11
+ }
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './OwnerOnlyCommand'
2
6
  export * from './GuildOnlyCommand'
3
7
  export * from './DMOnlyCommand'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './InvalidTargetError'
2
6
  export * from './ModuleError'
3
7
  export * from './ArgumentNotProvided'
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import 'reflect-metadata'
2
6
  import './typings'
3
7
 
@@ -7,4 +11,5 @@ export * from './error'
7
11
  export * from './command'
8
12
  export * from './listener'
9
13
  export * from './builtinModules/BuiltInModule'
10
- export * from './slashCommand'
14
+ export * from './applicationCommand'
15
+ export * from './messageComponents'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  // export type { HandlerAdapter } from './HandlerAdapter'
2
6
 
3
7
  export {}
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class Listener {
2
6
  constructor(public name: string, public execute: Function) {}
3
7
  }
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { checkTarget } from '../utils'
2
6
  import { KListeners } from '../constants'
3
7
  import { Listener } from './Listener'
@@ -1,2 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './Listener'
2
6
  export * from './decorator'
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { MessageComponentInteraction, MessageComponentType } from 'discord.js'
6
+ import { Module } from '../structures'
7
+
8
+ export type MessageComponentExecutor = (i: MessageComponentInteraction) => void | Promise<void>
9
+
10
+ export class MessageComponentHandler {
11
+ constructor(public componentId: string, public componentType: Exclude<MessageComponentType, 'ACTION_ROW'>, public execute: MessageComponentExecutor) {}
12
+
13
+ run(module: Module, i: MessageComponentInteraction) {
14
+ return this.execute.apply(module, [i])
15
+ }
16
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { MessageComponentExecutor, MessageComponentHandler } from './base'
6
+ import { checkTarget } from '../utils'
7
+ import { KMessageComponentHandlers } from '../constants'
8
+
9
+ export class ButtonInteractionHandler extends MessageComponentHandler {
10
+ constructor(id: string, execute: MessageComponentExecutor) {
11
+ super(id, 'BUTTON', execute)
12
+ }
13
+ }
14
+
15
+ export const messageButton = (id: string): MethodDecorator => {
16
+ return (target, propertyKey) => {
17
+ checkTarget(target)
18
+
19
+ const handler = new ButtonInteractionHandler(id, Reflect.get(target, propertyKey))
20
+
21
+ let properties: MessageComponentHandler[] = Reflect.getMetadata(KMessageComponentHandlers, target)
22
+
23
+ if (properties) {
24
+ properties.push(handler)
25
+ } else {
26
+ properties = [handler]
27
+ Reflect.defineMetadata(KMessageComponentHandlers, properties, target)
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ export * from './button'
6
+ export * from './selectMenu'
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { MessageComponentExecutor, MessageComponentHandler } from './base'
6
+ import { checkTarget } from '../utils'
7
+ import { KMessageComponentHandlers } from '../constants'
8
+
9
+ export class SelectMenuInteractionHandler extends MessageComponentHandler {
10
+ constructor(id: string, execute: MessageComponentExecutor) {
11
+ super(id, 'SELECT_MENU', execute)
12
+ }
13
+ }
14
+
15
+ export const messageSelectMenu = (id: string): MethodDecorator => {
16
+ return (target, propertyKey) => {
17
+ checkTarget(target)
18
+
19
+ const handler = new SelectMenuInteractionHandler(id, Reflect.get(target, propertyKey))
20
+
21
+ let properties: MessageComponentHandler[] = Reflect.getMetadata(KMessageComponentHandlers, target)
22
+
23
+ if (properties) {
24
+ properties.push(handler)
25
+ } else {
26
+ properties = [handler]
27
+ Reflect.defineMetadata(KMessageComponentHandlers, properties, target)
28
+ }
29
+ }
30
+ }
@@ -1,9 +1,12 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import _ from 'lodash'
2
6
  import { Registry } from './Registry'
3
- import { Client, Message, Snowflake, User } from 'discord.js'
4
- import { BuiltinCommandConverters, BuiltinSlashCommandConverters, CommandHandler } from '../builtinModules'
7
+ import { Client, CommandInteraction, Interaction, Message, Snowflake, User } from 'discord.js'
8
+ import { BuiltinCommandConverters, BuiltinApplicationCommandConverters, CommandHandler } from '../builtinModules'
5
9
  import { CoolDownAdapter, DefaultCoolDownAdapter } from '../command'
6
- import { REST } from '@discordjs/rest'
7
10
  import { Logger } from 'tslog'
8
11
 
9
12
  export interface CommandOptions {
@@ -13,20 +16,27 @@ export interface CommandOptions {
13
16
  }
14
17
 
15
18
  export interface SlashCommandOptions {
19
+ check: (i: CommandInteraction) => boolean | Promise<boolean>
20
+ }
21
+
22
+ export interface ApplicationCommandOptions {
16
23
  guild?: Snowflake | Snowflake[]
17
24
  autoSync: boolean
25
+ beforeRunCheck: (i: Interaction) => void | Promise<void>
18
26
  }
19
27
 
20
28
  export interface CommandClientOptions {
21
29
  command: CommandOptions
22
30
  owners: 'auto' | Snowflake[]
23
31
  slashCommands: SlashCommandOptions
32
+ applicationCommands: ApplicationCommandOptions
24
33
  }
25
34
 
26
35
  export interface CommandClientOptionsParam {
27
36
  command: Partial<CommandOptions>
28
37
  owners: 'auto' | string[]
29
38
  slashCommands: Partial<SlashCommandOptions>
39
+ applicationCommands: Partial<ApplicationCommandOptions>
30
40
  }
31
41
 
32
42
  export class CommandClient {
@@ -35,9 +45,6 @@ export class CommandClient {
35
45
  registry = new Registry(this)
36
46
  client: Client
37
47
  coolDownAdapter: CoolDownAdapter
38
- rest = new REST({
39
- version: '9',
40
- })
41
48
  logger: Logger
42
49
 
43
50
  private _isReady = false
@@ -52,13 +59,12 @@ export class CommandClient {
52
59
 
53
60
  async ready() {
54
61
  if (this._isReady) return
55
- this.rest.setToken(this.client.token!)
56
62
  this._isReady = true
57
63
  if (this.options.owners === 'auto') {
58
64
  const owners = await this.fetchOwners()
59
65
  this.owners.push(...owners)
60
66
  }
61
- if (this.options.slashCommands.autoSync) {
67
+ if (this.options.applicationCommands.autoSync) {
62
68
  await this.registry.syncCommands()
63
69
  }
64
70
  }
@@ -75,7 +81,11 @@ export class CommandClient {
75
81
  },
76
82
  owners: 'auto',
77
83
  slashCommands: {
78
- autoSync: true,
84
+ check: () => true,
85
+ },
86
+ applicationCommands: {
87
+ autoSync: false,
88
+ beforeRunCheck: () => {},
79
89
  },
80
90
  },
81
91
  options,
@@ -90,6 +100,6 @@ export class CommandClient {
90
100
  this.client.once('ready', () => this.ready())
91
101
  this.registry.registerModule(new CommandHandler(this.registry))
92
102
  this.registry.registerModule(new BuiltinCommandConverters(this))
93
- this.registry.registerModule(new BuiltinSlashCommandConverters(this))
103
+ this.registry.registerModule(new BuiltinApplicationCommandConverters(this))
94
104
  }
95
105
  }
@@ -1,9 +1,14 @@
1
- import { KArgumentConverters, KCommands, KListeners, KModulePath, KSlashArgumentConverters, KSlashCommands } from '../constants'
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { KArgumentConverters, KCommands, KListeners, KMessageComponentHandlers, KModulePath, KSlashArgumentConverters, KApplicationCommands } from '../constants'
2
6
  import type { Command } from '../command'
3
7
  import { Listener } from '../listener'
4
- import { ArgumentConverter, SlashArgumentConverter } from '../command'
5
- import { SlashCommand } from '../slashCommand'
8
+ import { ArgumentConverter, ApplicationCommandArgumentConverter } from '../command'
9
+ import { AppCommand } from '../applicationCommand'
6
10
  import { CommandClient } from './CommandClient'
11
+ import { MessageComponentHandler } from '../messageComponents/base'
7
12
 
8
13
  export abstract class Module {
9
14
  commandClient!: CommandClient
@@ -26,12 +31,16 @@ export abstract class Module {
26
31
  return Reflect.getMetadata(KArgumentConverters, this) || []
27
32
  }
28
33
 
29
- get slashArgumentConverters(): SlashArgumentConverter[] {
34
+ get applicationCommandArgumentConverters(): ApplicationCommandArgumentConverter[] {
30
35
  return Reflect.getMetadata(KSlashArgumentConverters, this) || []
31
36
  }
32
37
 
33
- get slashCommands(): SlashCommand[] {
34
- return Reflect.getMetadata(KSlashCommands, this) || []
38
+ get applicationCommands(): AppCommand[] {
39
+ return Reflect.getMetadata(KApplicationCommands, this) || []
40
+ }
41
+
42
+ get messageComponentHandlers(): MessageComponentHandler[] {
43
+ return Reflect.getMetadata(KMessageComponentHandlers, this) || []
35
44
  }
36
45
 
37
46
  get path(): string | undefined {
@@ -1,15 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { CommandClient } from './CommandClient'
2
6
  import { Module } from './Module'
3
- import { Command, SlashArgumentConverter } from '../command'
7
+ import { Command, ApplicationCommandArgumentConverter } from '../command'
4
8
  import { KBuiltInModule, KListenerExecuteCache, KModulePath } from '../constants'
5
9
  import path from 'path'
6
10
  import { InvalidModuleError, InvalidTargetError, ModuleLoadError } from '../error'
7
11
  import { Collection, Guild } from 'discord.js'
8
12
  import walkSync from 'walk-sync'
9
13
  import { ArgumentConverter } from '../command'
10
- import { SlashCommand } from '../slashCommand'
11
- import { Routes } from 'discord-api-types/v9'
14
+ import { AppCommand } from '../applicationCommand'
12
15
  import * as fs from 'fs'
16
+ import { MessageComponentHandler } from '../messageComponents/base'
13
17
 
14
18
  type ListenerExecutor = {
15
19
  event: string
@@ -47,21 +51,31 @@ export class Registry {
47
51
  return result
48
52
  }
49
53
 
50
- get slashArgumentConverters(): SlashArgumentConverter[] {
51
- const result: SlashArgumentConverter[] = []
54
+ get applicationCommandArgumentConverters(): ApplicationCommandArgumentConverter[] {
55
+ const result: ApplicationCommandArgumentConverter[] = []
52
56
 
53
57
  for (const [, module] of this.modules) {
54
- result.push(...module.slashArgumentConverters)
58
+ result.push(...module.applicationCommandArgumentConverters)
55
59
  }
56
60
 
57
61
  return result
58
62
  }
59
63
 
60
- get slashCommands(): SlashCommand[] {
61
- const result: SlashCommand[] = []
64
+ get applicationCommands(): AppCommand[] {
65
+ const result: AppCommand[] = []
62
66
 
63
67
  for (const [, module] of this.modules) {
64
- result.push(...module.slashCommands)
68
+ result.push(...module.applicationCommands)
69
+ }
70
+
71
+ return result
72
+ }
73
+
74
+ get messageComponentHandlers(): MessageComponentHandler[] {
75
+ const result: MessageComponentHandler[] = []
76
+
77
+ for (const [, module] of this.modules) {
78
+ result.push(...module.messageComponentHandlers)
65
79
  }
66
80
 
67
81
  return result
@@ -128,19 +142,17 @@ export class Registry {
128
142
 
129
143
  async syncCommands() {
130
144
  this.logger.debug(`Syncing commands...`)
131
- const commands = this.slashCommands.filter((x) => !x.guild)
132
- const guild = this.client.options.slashCommands.guild
145
+ const commands = this.applicationCommands.filter((x) => !x.guild)
146
+ const guild = this.client.options.applicationCommands.guild
133
147
  if (guild) {
134
148
  const syncForGuild = async (g: Guild) => {
135
149
  this.logger.debug(`Syncing for guild ${g.name}(${g.id})`)
136
150
  const commandsToRegister = [
137
- ...commands.map((x) => x.commandBuilder),
138
- ...this.slashCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false).map((x) => x.commandBuilder),
151
+ ...commands.map((x) => x.command),
152
+ ...this.applicationCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false).map((x) => x.command),
139
153
  ]
140
154
  this.logger.debug(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`)
141
- await this.client.rest.put(Routes.applicationGuildCommands(this.client.client.application!.id, g.id) as any, {
142
- body: commandsToRegister.map((x) => x.toJSON()),
143
- })
155
+ await g.commands.set(commandsToRegister)
144
156
  }
145
157
 
146
158
  if (typeof guild === 'string') {
@@ -152,9 +164,7 @@ export class Registry {
152
164
  }
153
165
  } else {
154
166
  this.logger.debug('Syncing global...')
155
- await this.client.rest.put(Routes.applicationCommands(this.client.client.application!.id) as any, {
156
- body: commands.map((x) => x.commandBuilder.toJSON()),
157
- })
167
+ await this.client.client.application?.commands.set(commands.map((x) => x.command))
158
168
  }
159
169
  this.logger.debug('Syncing ended.')
160
170
  }
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './Module'
2
6
  export * from './CommandClient'
3
7
  export * from './Registry'
package/src/typings.ts CHANGED
@@ -1,6 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import type { Command } from './command'
2
6
  import { CommandClient } from './structures'
3
- import { SlashCommand } from './slashCommand'
7
+ import { AppCommand } from './applicationCommand'
4
8
 
5
9
  declare module 'discord.js' {
6
10
  interface Message {
@@ -12,7 +16,19 @@ declare module 'discord.js' {
12
16
  }
13
17
  interface CommandInteraction {
14
18
  data: {
15
- command: SlashCommand
19
+ command: AppCommand
20
+ cts: CommandClient
21
+ }
22
+ }
23
+ interface MessageComponentInteraction {
24
+ data: {
25
+ command: AppCommand
26
+ cts: CommandClient
27
+ }
28
+ }
29
+ interface ContextMenuInteraction {
30
+ data: {
31
+ command: AppCommand
16
32
  cts: CommandClient
17
33
  }
18
34
  }
package/src/utils.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Module } from './structures'
2
6
  import { InvalidTargetError } from './error'
3
7
 
package/test/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Client, Intents, IntentsString } from 'discord.js'
2
6
  import { CommandClient } from '../src'
3
7
 
@@ -8,12 +12,12 @@ const client = new Client({
8
12
  })
9
13
 
10
14
  const cts = new CommandClient({
11
- owners: [],
15
+ owners: 'auto',
12
16
  client,
13
17
  command: {
14
18
  prefix: '!',
15
19
  },
16
- slashCommands: {
20
+ applicationCommands: {
17
21
  autoSync: true,
18
22
  guild: '832938554438844438',
19
23
  },
@@ -1,6 +1,9 @@
1
- import { BuiltInModule, CommandClient, ownerOnly, slashCommand, listener, SlashCommandCheckFailed } from '../../src'
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { BuiltInModule, CommandClient, ownerOnly, applicationCommand, listener, ApplicationCommandCheckFailed } from '../../src'
2
6
  import { CommandInteraction } from 'discord.js'
3
- import { SlashCommandBuilder } from '@discordjs/builders'
4
7
 
5
8
  export class Dev extends BuiltInModule {
6
9
  constructor(private cts: CommandClient) {
@@ -9,7 +12,7 @@ export class Dev extends BuiltInModule {
9
12
 
10
13
  @listener('slashCommandError')
11
14
  slashError(e: Error, i: CommandInteraction) {
12
- if (e instanceof SlashCommandCheckFailed) {
15
+ if (e instanceof ApplicationCommandCheckFailed) {
13
16
  return i.reply({
14
17
  content: 'Command before-run check failed',
15
18
  ephemeral: true,
@@ -18,8 +21,13 @@ export class Dev extends BuiltInModule {
18
21
  console.error(e.message)
19
22
  }
20
23
 
21
- @slashCommand({
22
- command: new SlashCommandBuilder().setName('reload').setDescription('리로드 커맨드'),
24
+ // new SlashCommandBuilder().setName('reload').setDescription('리로드 커맨드')
25
+ @applicationCommand({
26
+ command: {
27
+ name: 'reload',
28
+ type: 'CHAT_INPUT',
29
+ description: '리로드 커맨드',
30
+ },
23
31
  })
24
32
  @ownerOnly
25
33
  async reload(i: CommandInteraction) {