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

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 (98) hide show
  1. package/dist/applicationCommand/AppCommand.d.ts +18 -0
  2. package/dist/applicationCommand/AppCommand.js +22 -0
  3. package/dist/applicationCommand/AppCommand.js.map +1 -0
  4. package/dist/applicationCommand/decorator.d.ts +10 -0
  5. package/dist/applicationCommand/decorator.js +39 -0
  6. package/dist/applicationCommand/decorator.js.map +1 -0
  7. package/dist/applicationCommand/index.d.ts +2 -0
  8. package/dist/applicationCommand/index.js +15 -0
  9. package/dist/applicationCommand/index.js.map +1 -0
  10. package/dist/builtinModules/BuiltinApplicationCommandConverters.d.ts +8 -0
  11. package/dist/builtinModules/BuiltinApplicationCommandConverters.js +13 -0
  12. package/dist/builtinModules/BuiltinApplicationCommandConverters.js.map +1 -0
  13. package/dist/builtinModules/CommandHandler.d.ts +4 -1
  14. package/dist/builtinModules/CommandHandler.js +141 -17
  15. package/dist/builtinModules/CommandHandler.js.map +1 -1
  16. package/dist/builtinModules/index.d.ts +1 -1
  17. package/dist/builtinModules/index.js +1 -1
  18. package/dist/builtinModules/index.js.map +1 -1
  19. package/dist/command/ArgumentConverter.d.ts +3 -3
  20. package/dist/command/ArgumentConverter.js +3 -3
  21. package/dist/command/ArgumentConverter.js.map +1 -1
  22. package/dist/command/Command.d.ts +2 -2
  23. package/dist/command/decorator.d.ts +2 -1
  24. package/dist/command/decorator.js +6 -5
  25. package/dist/command/decorator.js.map +1 -1
  26. package/dist/command/utils.d.ts +2 -2
  27. package/dist/command/utils.js +6 -6
  28. package/dist/command/utils.js.map +1 -1
  29. package/dist/constants.d.ts +3 -2
  30. package/dist/constants.js +4 -3
  31. package/dist/constants.js.map +1 -1
  32. package/dist/error/ArgumentConverterNotFound.d.ts +6 -6
  33. package/dist/error/ArgumentConverterNotFound.js +3 -3
  34. package/dist/error/ArgumentConverterNotFound.js.map +1 -1
  35. package/dist/error/CommandCheckFailed.d.ts +6 -6
  36. package/dist/error/CommandCheckFailed.js +3 -3
  37. package/dist/error/CommandCheckFailed.js.map +1 -1
  38. package/dist/error/checks/SlashCommandGlobalCheckError.d.ts +5 -0
  39. package/dist/error/checks/SlashCommandGlobalCheckError.js +11 -0
  40. package/dist/error/checks/SlashCommandGlobalCheckError.js.map +1 -0
  41. package/dist/index.d.ts +2 -1
  42. package/dist/index.js +2 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/messageComponents/base.d.ts +10 -0
  45. package/dist/messageComponents/base.js +15 -0
  46. package/dist/messageComponents/base.js.map +1 -0
  47. package/dist/messageComponents/button.d.ts +5 -0
  48. package/dist/messageComponents/button.js +28 -0
  49. package/dist/messageComponents/button.js.map +1 -0
  50. package/dist/messageComponents/index.d.ts +2 -0
  51. package/dist/messageComponents/index.js +15 -0
  52. package/dist/messageComponents/index.js.map +1 -0
  53. package/dist/messageComponents/selectMenu.d.ts +5 -0
  54. package/dist/messageComponents/selectMenu.js +28 -0
  55. package/dist/messageComponents/selectMenu.js.map +1 -0
  56. package/dist/slashCommand/decorator.d.ts +1 -0
  57. package/dist/slashCommand/decorator.js +2 -1
  58. package/dist/slashCommand/decorator.js.map +1 -1
  59. package/dist/structures/CommandClient.d.ts +7 -3
  60. package/dist/structures/CommandClient.js +7 -8
  61. package/dist/structures/CommandClient.js.map +1 -1
  62. package/dist/structures/Module.d.ts +6 -4
  63. package/dist/structures/Module.js +6 -3
  64. package/dist/structures/Module.js.map +1 -1
  65. package/dist/structures/Registry.d.ts +6 -4
  66. package/dist/structures/Registry.js +18 -15
  67. package/dist/structures/Registry.js.map +1 -1
  68. package/dist/typings.d.ts +14 -2
  69. package/package.json +2 -4
  70. package/src/applicationCommand/AppCommand.ts +28 -0
  71. package/src/{slashCommand → applicationCommand}/decorator.ts +10 -10
  72. package/src/applicationCommand/index.ts +2 -0
  73. package/src/builtinModules/BuiltinApplicationCommandConverters.ts +12 -0
  74. package/src/builtinModules/CommandHandler.ts +168 -20
  75. package/src/builtinModules/index.ts +1 -1
  76. package/src/command/ArgumentConverter.ts +3 -3
  77. package/src/command/Command.ts +2 -2
  78. package/src/command/decorator.ts +6 -5
  79. package/src/command/utils.ts +9 -9
  80. package/src/constants.ts +4 -2
  81. package/src/error/ArgumentConverterNotFound.ts +4 -4
  82. package/src/error/CommandCheckFailed.ts +4 -4
  83. package/src/error/checks/SlashCommandGlobalCheckError.ts +7 -0
  84. package/src/index.ts +2 -1
  85. package/src/messageComponents/base.ts +12 -0
  86. package/src/messageComponents/button.ts +26 -0
  87. package/src/messageComponents/index.ts +2 -0
  88. package/src/messageComponents/selectMenu.ts +26 -0
  89. package/src/structures/CommandClient.ts +16 -10
  90. package/src/structures/Module.ts +11 -6
  91. package/src/structures/Registry.ts +25 -19
  92. package/src/typings.ts +14 -2
  93. package/test/index.ts +2 -2
  94. package/test/modules/dev.ts +9 -5
  95. package/test/modules/test.ts +88 -15
  96. package/src/builtinModules/BuiltinSlashCommandConverters.ts +0 -23
  97. package/src/slashCommand/SlashCommand.ts +0 -29
  98. package/src/slashCommand/index.ts +0 -2
@@ -1,6 +1,6 @@
1
- import { CommandInteraction, Message } from 'discord.js'
1
+ import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
2
2
  import { Command } from '../command'
3
- import { SlashCommand } from '../slashCommand'
3
+ import { AppCommand } from '../applicationCommand'
4
4
 
5
5
  export class CommandCheckFailed extends Error {
6
6
  constructor(public msg: Message, public command: Command) {
@@ -8,8 +8,8 @@ export class CommandCheckFailed extends Error {
8
8
  }
9
9
  }
10
10
 
11
- export class SlashCommandCheckFailed extends Error {
12
- constructor(public interaction: CommandInteraction, public command: SlashCommand) {
11
+ export class ApplicationCommandCheckFailed extends Error {
12
+ constructor(public interaction: CommandInteraction | MessageComponentInteraction | ContextMenuInteraction, public command: AppCommand) {
13
13
  super()
14
14
  }
15
15
  }
@@ -0,0 +1,7 @@
1
+ import { CommandInteraction } from 'discord.js'
2
+
3
+ export class SlashCommandGlobalCheckError extends Error {
4
+ constructor(public i: CommandInteraction) {
5
+ super('Slash command before-run check failed.')
6
+ }
7
+ }
package/src/index.ts CHANGED
@@ -7,4 +7,5 @@ export * from './error'
7
7
  export * from './command'
8
8
  export * from './listener'
9
9
  export * from './builtinModules/BuiltInModule'
10
- export * from './slashCommand'
10
+ export * from './applicationCommand'
11
+ export * from './messageComponents'
@@ -0,0 +1,12 @@
1
+ import { MessageComponentInteraction, MessageComponentType } from 'discord.js'
2
+ import { Module } from '../structures'
3
+
4
+ export type MessageComponentExecutor = (i: MessageComponentInteraction) => void | Promise<void>
5
+
6
+ export class MessageComponentHandler {
7
+ constructor(public componentId: string, public componentType: Exclude<MessageComponentType, 'ACTION_ROW'>, public execute: MessageComponentExecutor) {}
8
+
9
+ run(module: Module, i: MessageComponentInteraction) {
10
+ return this.execute.apply(module, [i])
11
+ }
12
+ }
@@ -0,0 +1,26 @@
1
+ import { MessageComponentExecutor, MessageComponentHandler } from './base'
2
+ import { checkTarget } from '../utils'
3
+ import { KMessageComponentHandlers } from '../constants'
4
+
5
+ export class ButtonInteractionHandler extends MessageComponentHandler {
6
+ constructor(id: string, execute: MessageComponentExecutor) {
7
+ super(id, 'BUTTON', execute)
8
+ }
9
+ }
10
+
11
+ export const messageButton = (id: string): MethodDecorator => {
12
+ return (target, propertyKey) => {
13
+ checkTarget(target)
14
+
15
+ const handler = new ButtonInteractionHandler(id, Reflect.get(target, propertyKey))
16
+
17
+ let properties: MessageComponentHandler[] = Reflect.getMetadata(KMessageComponentHandlers, target)
18
+
19
+ if (properties) {
20
+ properties.push(handler)
21
+ } else {
22
+ properties = [handler]
23
+ Reflect.defineMetadata(KMessageComponentHandlers, properties, target)
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ export * from './button'
2
+ export * from './selectMenu'
@@ -0,0 +1,26 @@
1
+ import { MessageComponentExecutor, MessageComponentHandler } from './base'
2
+ import { checkTarget } from '../utils'
3
+ import { KMessageComponentHandlers } from '../constants'
4
+
5
+ export class SelectMenuInteractionHandler extends MessageComponentHandler {
6
+ constructor(id: string, execute: MessageComponentExecutor) {
7
+ super(id, 'SELECT_MENU', execute)
8
+ }
9
+ }
10
+
11
+ export const messageSelectMenu = (id: string): MethodDecorator => {
12
+ return (target, propertyKey) => {
13
+ checkTarget(target)
14
+
15
+ const handler = new SelectMenuInteractionHandler(id, Reflect.get(target, propertyKey))
16
+
17
+ let properties: MessageComponentHandler[] = Reflect.getMetadata(KMessageComponentHandlers, target)
18
+
19
+ if (properties) {
20
+ properties.push(handler)
21
+ } else {
22
+ properties = [handler]
23
+ Reflect.defineMetadata(KMessageComponentHandlers, properties, target)
24
+ }
25
+ }
26
+ }
@@ -1,9 +1,8 @@
1
1
  import _ from 'lodash'
2
2
  import { Registry } from './Registry'
3
- import { Client, Message, Snowflake, User } from 'discord.js'
4
- import { BuiltinCommandConverters, BuiltinSlashCommandConverters, CommandHandler } from '../builtinModules'
3
+ import { Client, CommandInteraction, Interaction, Message, Snowflake, User } from 'discord.js'
4
+ import { BuiltinCommandConverters, BuiltinApplicationCommandConverters, CommandHandler } from '../builtinModules'
5
5
  import { CoolDownAdapter, DefaultCoolDownAdapter } from '../command'
6
- import { REST } from '@discordjs/rest'
7
6
  import { Logger } from 'tslog'
8
7
 
9
8
  export interface CommandOptions {
@@ -13,20 +12,27 @@ export interface CommandOptions {
13
12
  }
14
13
 
15
14
  export interface SlashCommandOptions {
15
+ check: (i: CommandInteraction) => boolean | Promise<boolean>
16
+ }
17
+
18
+ export interface ApplicationCommandOptions {
16
19
  guild?: Snowflake | Snowflake[]
17
20
  autoSync: boolean
21
+ beforeRunCheck: (i: Interaction) => void | Promise<void>
18
22
  }
19
23
 
20
24
  export interface CommandClientOptions {
21
25
  command: CommandOptions
22
26
  owners: 'auto' | Snowflake[]
23
27
  slashCommands: SlashCommandOptions
28
+ applicationCommands: ApplicationCommandOptions
24
29
  }
25
30
 
26
31
  export interface CommandClientOptionsParam {
27
32
  command: Partial<CommandOptions>
28
33
  owners: 'auto' | string[]
29
34
  slashCommands: Partial<SlashCommandOptions>
35
+ applicationCommands: Partial<ApplicationCommandOptions>
30
36
  }
31
37
 
32
38
  export class CommandClient {
@@ -35,9 +41,6 @@ export class CommandClient {
35
41
  registry = new Registry(this)
36
42
  client: Client
37
43
  coolDownAdapter: CoolDownAdapter
38
- rest = new REST({
39
- version: '9',
40
- })
41
44
  logger: Logger
42
45
 
43
46
  private _isReady = false
@@ -52,13 +55,12 @@ export class CommandClient {
52
55
 
53
56
  async ready() {
54
57
  if (this._isReady) return
55
- this.rest.setToken(this.client.token!)
56
58
  this._isReady = true
57
59
  if (this.options.owners === 'auto') {
58
60
  const owners = await this.fetchOwners()
59
61
  this.owners.push(...owners)
60
62
  }
61
- if (this.options.slashCommands.autoSync) {
63
+ if (this.options.applicationCommands.autoSync) {
62
64
  await this.registry.syncCommands()
63
65
  }
64
66
  }
@@ -75,7 +77,11 @@ export class CommandClient {
75
77
  },
76
78
  owners: 'auto',
77
79
  slashCommands: {
78
- autoSync: true,
80
+ check: () => true,
81
+ },
82
+ applicationCommands: {
83
+ autoSync: false,
84
+ beforeRunCheck: () => {},
79
85
  },
80
86
  },
81
87
  options,
@@ -90,6 +96,6 @@ export class CommandClient {
90
96
  this.client.once('ready', () => this.ready())
91
97
  this.registry.registerModule(new CommandHandler(this.registry))
92
98
  this.registry.registerModule(new BuiltinCommandConverters(this))
93
- this.registry.registerModule(new BuiltinSlashCommandConverters(this))
99
+ this.registry.registerModule(new BuiltinApplicationCommandConverters(this))
94
100
  }
95
101
  }
@@ -1,9 +1,10 @@
1
- import { KArgumentConverters, KCommands, KListeners, KModulePath, KSlashArgumentConverters, KSlashCommands } from '../constants'
1
+ import { KArgumentConverters, KCommands, KListeners, KMessageComponentHandlers, KModulePath, KSlashArgumentConverters, KApplicationCommands } from '../constants'
2
2
  import type { Command } from '../command'
3
3
  import { Listener } from '../listener'
4
- import { ArgumentConverter, SlashArgumentConverter } from '../command'
5
- import { SlashCommand } from '../slashCommand'
4
+ import { ArgumentConverter, ApplicationCommandArgumentConverter } from '../command'
5
+ import { AppCommand } from '../applicationCommand'
6
6
  import { CommandClient } from './CommandClient'
7
+ import { MessageComponentHandler } from '../messageComponents/base'
7
8
 
8
9
  export abstract class Module {
9
10
  commandClient!: CommandClient
@@ -26,12 +27,16 @@ export abstract class Module {
26
27
  return Reflect.getMetadata(KArgumentConverters, this) || []
27
28
  }
28
29
 
29
- get slashArgumentConverters(): SlashArgumentConverter[] {
30
+ get applicationCommandArgumentConverters(): ApplicationCommandArgumentConverter[] {
30
31
  return Reflect.getMetadata(KSlashArgumentConverters, this) || []
31
32
  }
32
33
 
33
- get slashCommands(): SlashCommand[] {
34
- return Reflect.getMetadata(KSlashCommands, this) || []
34
+ get applicationCommands(): AppCommand[] {
35
+ return Reflect.getMetadata(KApplicationCommands, this) || []
36
+ }
37
+
38
+ get messageComponentHandlers(): MessageComponentHandler[] {
39
+ return Reflect.getMetadata(KMessageComponentHandlers, this) || []
35
40
  }
36
41
 
37
42
  get path(): string | undefined {
@@ -1,15 +1,15 @@
1
1
  import { CommandClient } from './CommandClient'
2
2
  import { Module } from './Module'
3
- import { Command, SlashArgumentConverter } from '../command'
3
+ import { Command, ApplicationCommandArgumentConverter } from '../command'
4
4
  import { KBuiltInModule, KListenerExecuteCache, KModulePath } from '../constants'
5
5
  import path from 'path'
6
6
  import { InvalidModuleError, InvalidTargetError, ModuleLoadError } from '../error'
7
7
  import { Collection, Guild } from 'discord.js'
8
8
  import walkSync from 'walk-sync'
9
9
  import { ArgumentConverter } from '../command'
10
- import { SlashCommand } from '../slashCommand'
11
- import { Routes } from 'discord-api-types/v9'
10
+ import { AppCommand } from '../applicationCommand'
12
11
  import * as fs from 'fs'
12
+ import { MessageComponentHandler } from '../messageComponents/base'
13
13
 
14
14
  type ListenerExecutor = {
15
15
  event: string
@@ -47,21 +47,31 @@ export class Registry {
47
47
  return result
48
48
  }
49
49
 
50
- get slashArgumentConverters(): SlashArgumentConverter[] {
51
- const result: SlashArgumentConverter[] = []
50
+ get applicationCommandArgumentConverters(): ApplicationCommandArgumentConverter[] {
51
+ const result: ApplicationCommandArgumentConverter[] = []
52
52
 
53
53
  for (const [, module] of this.modules) {
54
- result.push(...module.slashArgumentConverters)
54
+ result.push(...module.applicationCommandArgumentConverters)
55
55
  }
56
56
 
57
57
  return result
58
58
  }
59
59
 
60
- get slashCommands(): SlashCommand[] {
61
- const result: SlashCommand[] = []
60
+ get applicationCommands(): AppCommand[] {
61
+ const result: AppCommand[] = []
62
62
 
63
63
  for (const [, module] of this.modules) {
64
- result.push(...module.slashCommands)
64
+ result.push(...module.applicationCommands)
65
+ }
66
+
67
+ return result
68
+ }
69
+
70
+ get messageComponentHandlers(): MessageComponentHandler[] {
71
+ const result: MessageComponentHandler[] = []
72
+
73
+ for (const [, module] of this.modules) {
74
+ result.push(...module.messageComponentHandlers)
65
75
  }
66
76
 
67
77
  return result
@@ -128,19 +138,17 @@ export class Registry {
128
138
 
129
139
  async syncCommands() {
130
140
  this.logger.debug(`Syncing commands...`)
131
- const commands = this.slashCommands.filter((x) => !x.guild)
132
- const guild = this.client.options.slashCommands.guild
141
+ const commands = this.applicationCommands.filter((x) => !x.guild)
142
+ const guild = this.client.options.applicationCommands.guild
133
143
  if (guild) {
134
144
  const syncForGuild = async (g: Guild) => {
135
145
  this.logger.debug(`Syncing for guild ${g.name}(${g.id})`)
136
146
  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),
147
+ ...commands.map((x) => x.command),
148
+ ...this.applicationCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false).map((x) => x.command),
139
149
  ]
140
150
  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
- })
151
+ await g.commands.set(commandsToRegister)
144
152
  }
145
153
 
146
154
  if (typeof guild === 'string') {
@@ -152,9 +160,7 @@ export class Registry {
152
160
  }
153
161
  } else {
154
162
  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
- })
163
+ await this.client.client.application?.commands.set(commands.map((x) => x.command))
158
164
  }
159
165
  this.logger.debug('Syncing ended.')
160
166
  }
package/src/typings.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Command } from './command'
2
2
  import { CommandClient } from './structures'
3
- import { SlashCommand } from './slashCommand'
3
+ import { AppCommand } from './applicationCommand'
4
4
 
5
5
  declare module 'discord.js' {
6
6
  interface Message {
@@ -12,7 +12,19 @@ declare module 'discord.js' {
12
12
  }
13
13
  interface CommandInteraction {
14
14
  data: {
15
- command: SlashCommand
15
+ command: AppCommand
16
+ cts: CommandClient
17
+ }
18
+ }
19
+ interface MessageComponentInteraction {
20
+ data: {
21
+ command: AppCommand
22
+ cts: CommandClient
23
+ }
24
+ }
25
+ interface ContextMenuInteraction {
26
+ data: {
27
+ command: AppCommand
16
28
  cts: CommandClient
17
29
  }
18
30
  }
package/test/index.ts CHANGED
@@ -8,12 +8,12 @@ const client = new Client({
8
8
  })
9
9
 
10
10
  const cts = new CommandClient({
11
- owners: [],
11
+ owners: 'auto',
12
12
  client,
13
13
  command: {
14
14
  prefix: '!',
15
15
  },
16
- slashCommands: {
16
+ applicationCommands: {
17
17
  autoSync: true,
18
18
  guild: '832938554438844438',
19
19
  },
@@ -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,23 +0,0 @@
1
- import { BuiltInModule } from './BuiltInModule'
2
- import { slashArgumentConverter } from '../command'
3
- import { Client, CommandInteraction, CommandInteractionOptionResolver } from 'discord.js'
4
- import { CommandClient } from '../structures'
5
-
6
- export class BuiltinSlashCommandConverters extends BuiltInModule {
7
- client: Client
8
-
9
- constructor(private cts: CommandClient) {
10
- super()
11
- this.client = cts.client
12
- }
13
-
14
- @slashArgumentConverter(CommandInteraction)
15
- message(interaction: CommandInteraction) {
16
- return interaction
17
- }
18
-
19
- @slashArgumentConverter(CommandInteractionOptionResolver)
20
- optionResolver(interaction: CommandInteraction): CommandInteractionOptionResolver {
21
- return interaction.options as CommandInteractionOptionResolver
22
- }
23
- }
@@ -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'