@pikokr/command.ts 3.2.4 → 4.0.0-dev.fddc66b
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/applicationCommand/AppCommand.js +25 -0
- package/dist/applicationCommand/AppCommand.js.map +1 -0
- package/dist/applicationCommand/decorator.d.ts +10 -0
- package/dist/{slashCommand → applicationCommand}/decorator.js +12 -8
- package/dist/applicationCommand/decorator.js.map +1 -0
- package/dist/applicationCommand/index.d.ts +2 -0
- package/dist/{slashCommand → applicationCommand}/index.js +4 -1
- package/dist/applicationCommand/index.js.map +1 -0
- package/dist/builtinModules/BuiltInModule.js +3 -0
- package/dist/builtinModules/BuiltInModule.js.map +1 -1
- package/dist/builtinModules/BuiltinApplicationCommandConverters.d.ts +8 -0
- package/dist/builtinModules/BuiltinApplicationCommandConverters.js +16 -0
- package/dist/builtinModules/BuiltinApplicationCommandConverters.js.map +1 -0
- package/dist/builtinModules/BuiltinCommandConverters.d.ts +1 -1
- package/dist/builtinModules/BuiltinCommandConverters.js +3 -0
- package/dist/builtinModules/BuiltinCommandConverters.js.map +1 -1
- package/dist/builtinModules/CommandHandler.d.ts +4 -1
- package/dist/builtinModules/CommandHandler.js +149 -19
- package/dist/builtinModules/CommandHandler.js.map +1 -1
- package/dist/builtinModules/index.d.ts +1 -1
- package/dist/builtinModules/index.js +4 -1
- package/dist/builtinModules/index.js.map +1 -1
- package/dist/command/ArgumentConverter.d.ts +3 -3
- package/dist/command/ArgumentConverter.js +6 -3
- package/dist/command/ArgumentConverter.js.map +1 -1
- package/dist/command/Command.d.ts +2 -2
- package/dist/command/Command.js +3 -0
- package/dist/command/Command.js.map +1 -1
- package/dist/command/cooldown/adapter.js +3 -0
- package/dist/command/cooldown/adapter.js.map +1 -1
- package/dist/command/cooldown/decorator.js +3 -0
- package/dist/command/cooldown/decorator.js.map +1 -1
- package/dist/command/cooldown/error.js +3 -0
- package/dist/command/cooldown/error.js.map +1 -1
- package/dist/command/cooldown/index.js +3 -0
- package/dist/command/cooldown/index.js.map +1 -1
- package/dist/command/cooldown/type.js +3 -0
- package/dist/command/cooldown/type.js.map +1 -1
- package/dist/command/decorator.d.ts +2 -1
- package/dist/command/decorator.js +9 -5
- package/dist/command/decorator.js.map +1 -1
- package/dist/command/index.js +3 -0
- package/dist/command/index.js.map +1 -1
- package/dist/command/utils.d.ts +2 -2
- package/dist/command/utils.js +9 -6
- package/dist/command/utils.js.map +1 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +7 -3
- package/dist/constants.js.map +1 -1
- package/dist/error/ArgumentConverterNotFound.d.ts +6 -6
- package/dist/error/ArgumentConverterNotFound.js +6 -3
- package/dist/error/ArgumentConverterNotFound.js.map +1 -1
- package/dist/error/ArgumentNotProvided.js +3 -0
- package/dist/error/ArgumentNotProvided.js.map +1 -1
- package/dist/error/CommandCheckFailed.d.ts +6 -6
- package/dist/error/CommandCheckFailed.js +6 -3
- package/dist/error/CommandCheckFailed.js.map +1 -1
- package/dist/error/CommandNotFound.js +3 -0
- package/dist/error/CommandNotFound.js.map +1 -1
- package/dist/error/InvalidTargetError.js +3 -0
- package/dist/error/InvalidTargetError.js.map +1 -1
- package/dist/error/ModuleError.js +3 -0
- package/dist/error/ModuleError.js.map +1 -1
- package/dist/error/PermissionRequired.js +3 -0
- package/dist/error/PermissionRequired.js.map +1 -1
- package/dist/error/checks/DMOnlyCommand.js +3 -0
- package/dist/error/checks/DMOnlyCommand.js.map +1 -1
- package/dist/error/checks/GuildOnlyCommand.js +3 -0
- package/dist/error/checks/GuildOnlyCommand.js.map +1 -1
- package/dist/error/checks/OwnerOnlyCommand.js +3 -0
- package/dist/error/checks/OwnerOnlyCommand.js.map +1 -1
- package/dist/error/checks/SlashCommandGlobalCheckError.d.ts +5 -0
- package/dist/error/checks/SlashCommandGlobalCheckError.js +14 -0
- package/dist/error/checks/SlashCommandGlobalCheckError.js.map +1 -0
- package/dist/error/checks/index.js +3 -0
- package/dist/error/checks/index.js.map +1 -1
- package/dist/error/index.js +3 -0
- package/dist/error/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/interface/index.js +3 -1
- package/dist/interface/index.js.map +1 -1
- package/dist/listener/Listener.js +3 -0
- package/dist/listener/Listener.js.map +1 -1
- package/dist/listener/decorator.js +3 -0
- package/dist/listener/decorator.js.map +1 -1
- package/dist/listener/index.js +3 -0
- package/dist/listener/index.js.map +1 -1
- package/dist/messageComponents/base.d.ts +10 -0
- package/dist/messageComponents/base.js +18 -0
- package/dist/messageComponents/base.js.map +1 -0
- package/dist/messageComponents/button.d.ts +5 -0
- package/dist/messageComponents/button.js +31 -0
- package/dist/messageComponents/button.js.map +1 -0
- package/dist/messageComponents/index.d.ts +2 -0
- package/dist/messageComponents/index.js +18 -0
- package/dist/messageComponents/index.js.map +1 -0
- package/dist/messageComponents/selectMenu.d.ts +5 -0
- package/dist/messageComponents/selectMenu.js +31 -0
- package/dist/messageComponents/selectMenu.js.map +1 -0
- package/dist/structures/CommandClient.d.ts +8 -3
- package/dist/structures/CommandClient.js +11 -8
- package/dist/structures/CommandClient.js.map +1 -1
- package/dist/structures/Module.d.ts +6 -4
- package/dist/structures/Module.js +9 -3
- package/dist/structures/Module.js.map +1 -1
- package/dist/structures/Registry.d.ts +6 -4
- package/dist/structures/Registry.js +21 -15
- package/dist/structures/Registry.js.map +1 -1
- package/dist/structures/index.js +3 -0
- package/dist/structures/index.js.map +1 -1
- package/dist/typings.d.ts +14 -2
- package/dist/typings.js +3 -0
- package/dist/typings.js.map +1 -1
- package/dist/utils.js +3 -0
- package/dist/utils.js.map +1 -1
- package/package.json +3 -5
- package/publish-version.js +7 -3
- package/src/applicationCommand/AppCommand.ts +32 -0
- package/src/{slashCommand → applicationCommand}/decorator.ts +14 -10
- package/src/applicationCommand/index.ts +6 -0
- package/src/builtinModules/BuiltInModule.ts +4 -0
- package/src/builtinModules/BuiltinApplicationCommandConverters.ts +16 -0
- package/src/builtinModules/BuiltinCommandConverters.ts +4 -0
- package/src/builtinModules/CommandHandler.ts +178 -22
- package/src/builtinModules/index.ts +5 -1
- package/src/command/ArgumentConverter.ts +7 -3
- package/src/command/Command.ts +6 -2
- package/src/command/cooldown/adapter.ts +4 -0
- package/src/command/cooldown/decorator.ts +4 -0
- package/src/command/cooldown/error.ts +4 -0
- package/src/command/cooldown/index.ts +4 -0
- package/src/command/cooldown/type.ts +4 -0
- package/src/command/decorator.ts +10 -5
- package/src/command/index.ts +4 -0
- package/src/command/utils.ts +13 -9
- package/src/constants.ts +8 -2
- package/src/error/ArgumentConverterNotFound.ts +8 -4
- package/src/error/ArgumentNotProvided.ts +4 -0
- package/src/error/CommandCheckFailed.ts +8 -4
- package/src/error/CommandNotFound.ts +4 -0
- package/src/error/InvalidTargetError.ts +4 -0
- package/src/error/ModuleError.ts +4 -0
- package/src/error/PermissionRequired.ts +4 -0
- package/src/error/checks/DMOnlyCommand.ts +4 -0
- package/src/error/checks/GuildOnlyCommand.ts +4 -0
- package/src/error/checks/OwnerOnlyCommand.ts +4 -0
- package/src/error/checks/SlashCommandGlobalCheckError.ts +11 -0
- package/src/error/checks/index.ts +4 -0
- package/src/error/index.ts +4 -0
- package/src/index.ts +6 -1
- package/src/interface/index.ts +4 -0
- package/src/listener/Listener.ts +4 -0
- package/src/listener/decorator.ts +4 -0
- package/src/listener/index.ts +4 -0
- package/src/messageComponents/base.ts +16 -0
- package/src/messageComponents/button.ts +30 -0
- package/src/messageComponents/index.ts +6 -0
- package/src/messageComponents/selectMenu.ts +30 -0
- package/src/structures/CommandClient.ts +22 -10
- package/src/structures/Module.ts +15 -6
- package/src/structures/Registry.ts +29 -19
- package/src/structures/index.ts +4 -0
- package/src/typings.ts +18 -2
- package/src/utils.ts +4 -0
- package/test/index.ts +6 -2
- package/test/modules/dev.ts +13 -5
- package/test/modules/test.ts +92 -15
- package/dist/builtinModules/BuiltinSlashCommandConverters.d.ts +0 -10
- package/dist/builtinModules/BuiltinSlashCommandConverters.js +0 -42
- package/dist/builtinModules/BuiltinSlashCommandConverters.js.map +0 -1
- package/dist/slashCommand/SlashCommand.d.ts +0 -19
- package/dist/slashCommand/SlashCommand.js +0 -22
- 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/builtinModules/BuiltinSlashCommandConverters.ts +0 -23
- package/src/slashCommand/SlashCommand.ts +0 -29
- package/src/slashCommand/index.ts +0 -2
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
|
|
2
6
|
import { Command } from '../command'
|
|
3
|
-
import {
|
|
7
|
+
import { AppCommand } from '../applicationCommand'
|
|
4
8
|
|
|
5
9
|
export class CommandCheckFailed extends Error {
|
|
6
10
|
constructor(public msg: Message, public command: Command) {
|
|
@@ -8,8 +12,8 @@ export class CommandCheckFailed extends Error {
|
|
|
8
12
|
}
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
export class
|
|
12
|
-
constructor(public interaction: CommandInteraction, public command:
|
|
15
|
+
export class ApplicationCommandCheckFailed extends Error {
|
|
16
|
+
constructor(public interaction: CommandInteraction | MessageComponentInteraction | ContextMenuInteraction, public command: AppCommand) {
|
|
13
17
|
super()
|
|
14
18
|
}
|
|
15
19
|
}
|
package/src/error/ModuleError.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/error/index.ts
CHANGED
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 './
|
|
14
|
+
export * from './applicationCommand'
|
|
15
|
+
export * from './messageComponents'
|
package/src/interface/index.ts
CHANGED
package/src/listener/Listener.ts
CHANGED
package/src/listener/index.ts
CHANGED
|
@@ -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,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,31 +1,42 @@
|
|
|
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,
|
|
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 {
|
|
10
13
|
prefix: string | ((msg: any) => string | Promise<string | string[]> | string[]) | string[]
|
|
11
14
|
check: (msg: Message) => boolean | Promise<boolean>
|
|
15
|
+
globalAliases: (cmd: string, msg: Message) => string[] | Promise<string[]>
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export interface SlashCommandOptions {
|
|
19
|
+
check: (i: CommandInteraction) => boolean | Promise<boolean>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ApplicationCommandOptions {
|
|
15
23
|
guild?: Snowflake | Snowflake[]
|
|
16
24
|
autoSync: boolean
|
|
25
|
+
beforeRunCheck: (i: Interaction) => void | Promise<void>
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
export interface CommandClientOptions {
|
|
20
29
|
command: CommandOptions
|
|
21
30
|
owners: 'auto' | Snowflake[]
|
|
22
31
|
slashCommands: SlashCommandOptions
|
|
32
|
+
applicationCommands: ApplicationCommandOptions
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
export interface CommandClientOptionsParam {
|
|
26
36
|
command: Partial<CommandOptions>
|
|
27
37
|
owners: 'auto' | string[]
|
|
28
38
|
slashCommands: Partial<SlashCommandOptions>
|
|
39
|
+
applicationCommands: Partial<ApplicationCommandOptions>
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
export class CommandClient {
|
|
@@ -34,9 +45,6 @@ export class CommandClient {
|
|
|
34
45
|
registry = new Registry(this)
|
|
35
46
|
client: Client
|
|
36
47
|
coolDownAdapter: CoolDownAdapter
|
|
37
|
-
rest = new REST({
|
|
38
|
-
version: '9',
|
|
39
|
-
})
|
|
40
48
|
logger: Logger
|
|
41
49
|
|
|
42
50
|
private _isReady = false
|
|
@@ -51,13 +59,12 @@ export class CommandClient {
|
|
|
51
59
|
|
|
52
60
|
async ready() {
|
|
53
61
|
if (this._isReady) return
|
|
54
|
-
this.rest.setToken(this.client.token!)
|
|
55
62
|
this._isReady = true
|
|
56
63
|
if (this.options.owners === 'auto') {
|
|
57
64
|
const owners = await this.fetchOwners()
|
|
58
65
|
this.owners.push(...owners)
|
|
59
66
|
}
|
|
60
|
-
if (this.options.
|
|
67
|
+
if (this.options.applicationCommands.autoSync) {
|
|
61
68
|
await this.registry.syncCommands()
|
|
62
69
|
}
|
|
63
70
|
}
|
|
@@ -70,10 +77,15 @@ export class CommandClient {
|
|
|
70
77
|
command: {
|
|
71
78
|
prefix: '!',
|
|
72
79
|
check: () => true,
|
|
80
|
+
globalAliases: () => [],
|
|
73
81
|
},
|
|
74
82
|
owners: 'auto',
|
|
75
83
|
slashCommands: {
|
|
76
|
-
|
|
84
|
+
check: () => true,
|
|
85
|
+
},
|
|
86
|
+
applicationCommands: {
|
|
87
|
+
autoSync: false,
|
|
88
|
+
beforeRunCheck: () => {},
|
|
77
89
|
},
|
|
78
90
|
},
|
|
79
91
|
options,
|
|
@@ -88,6 +100,6 @@ export class CommandClient {
|
|
|
88
100
|
this.client.once('ready', () => this.ready())
|
|
89
101
|
this.registry.registerModule(new CommandHandler(this.registry))
|
|
90
102
|
this.registry.registerModule(new BuiltinCommandConverters(this))
|
|
91
|
-
this.registry.registerModule(new
|
|
103
|
+
this.registry.registerModule(new BuiltinApplicationCommandConverters(this))
|
|
92
104
|
}
|
|
93
105
|
}
|
package/src/structures/Module.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
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,
|
|
5
|
-
import {
|
|
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
|
|
34
|
+
get applicationCommandArgumentConverters(): ApplicationCommandArgumentConverter[] {
|
|
30
35
|
return Reflect.getMetadata(KSlashArgumentConverters, this) || []
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
get
|
|
34
|
-
return Reflect.getMetadata(
|
|
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,
|
|
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 {
|
|
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
|
|
51
|
-
const result:
|
|
54
|
+
get applicationCommandArgumentConverters(): ApplicationCommandArgumentConverter[] {
|
|
55
|
+
const result: ApplicationCommandArgumentConverter[] = []
|
|
52
56
|
|
|
53
57
|
for (const [, module] of this.modules) {
|
|
54
|
-
result.push(...module.
|
|
58
|
+
result.push(...module.applicationCommandArgumentConverters)
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
return result
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
get
|
|
61
|
-
const result:
|
|
64
|
+
get applicationCommands(): AppCommand[] {
|
|
65
|
+
const result: AppCommand[] = []
|
|
62
66
|
|
|
63
67
|
for (const [, module] of this.modules) {
|
|
64
|
-
result.push(...module.
|
|
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.
|
|
132
|
-
const guild = this.client.options.
|
|
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.
|
|
138
|
-
...this.
|
|
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
|
|
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.
|
|
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
|
}
|
package/src/structures/index.ts
CHANGED
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 {
|
|
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:
|
|
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
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
|
-
|
|
20
|
+
applicationCommands: {
|
|
17
21
|
autoSync: true,
|
|
18
22
|
guild: '832938554438844438',
|
|
19
23
|
},
|
package/test/modules/dev.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
22
|
-
|
|
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) {
|