@pikokr/command.ts 4.0.6 → 5.0.0-dev.84d717c
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/.github/workflows/codeql-analysis.yml +70 -0
- package/.github/workflows/publish.stable.yml +1 -1
- package/.github/workflows/publish.yml +1 -1
- package/.vscode/settings.json +10 -0
- package/.vscode/templates/ts.lict +5 -0
- package/dist/index.d.ts +41 -307
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +13 -10
- package/publish-version.js +10 -0
- package/scripts/docs.ts +8 -4
- package/src/applicationCommand/ApplicationCommand.ts +17 -0
- package/src/applicationCommand/ApplicationCommandOption.ts +9 -0
- package/src/applicationCommand/index.ts +2 -6
- package/src/core/components/BaseComponent.ts +32 -0
- package/src/core/components/ComponentArgument.ts +7 -0
- package/src/core/components/ComponentArgumentDecorator.ts +17 -0
- package/src/core/components/decoratorCreator.ts +68 -0
- package/src/core/components/index.ts +3 -0
- package/src/core/hooks/index.ts +1 -0
- package/src/core/hooks/moduleHook.ts +31 -0
- package/src/core/index.ts +3 -0
- package/src/core/structures/Registry.ts +30 -0
- package/src/core/structures/index.ts +1 -0
- package/src/core/symbols.ts +3 -0
- package/src/index.ts +10 -16
- package/test/index.ts +46 -23
- package/tsconfig.json +1 -1
- package/tsconfig.prod.json +4 -0
- package/tsup.config.ts +8 -4
- package/src/applicationCommand/AppCommand.ts +0 -32
- package/src/applicationCommand/decorator.ts +0 -62
- package/src/builtinModules/BuiltInModule.ts +0 -13
- package/src/builtinModules/BuiltinApplicationCommandConverters.ts +0 -16
- package/src/builtinModules/BuiltinCommandConverters.ts +0 -87
- package/src/builtinModules/CommandHandler.ts +0 -363
- package/src/builtinModules/index.ts +0 -7
- package/src/command/ArgumentConverter.ts +0 -22
- package/src/command/Command.ts +0 -35
- package/src/command/cooldown/adapter.ts +0 -22
- package/src/command/cooldown/decorator.ts +0 -67
- package/src/command/cooldown/error.ts +0 -9
- package/src/command/cooldown/index.ts +0 -9
- package/src/command/cooldown/type.ts +0 -12
- package/src/command/decorator.ts +0 -185
- package/src/command/index.ts +0 -9
- package/src/command/utils.ts +0 -33
- package/src/constants.ts +0 -31
- package/src/error/ArgumentConverterNotFound.ts +0 -18
- package/src/error/ArgumentNotProvided.ts +0 -12
- package/src/error/CommandCheckFailed.ts +0 -19
- package/src/error/CommandNotFound.ts +0 -11
- package/src/error/InvalidTargetError.ts +0 -9
- package/src/error/ModuleError.ts +0 -11
- package/src/error/PermissionRequired.ts +0 -17
- package/src/error/checks/DMOnlyCommand.ts +0 -9
- package/src/error/checks/GuildOnlyCommand.ts +0 -9
- package/src/error/checks/OwnerOnlyCommand.ts +0 -9
- package/src/error/checks/SlashCommandGlobalCheckError.ts +0 -11
- package/src/error/checks/index.ts +0 -8
- package/src/error/index.ts +0 -12
- package/src/interface/index.ts +0 -7
- package/src/listener/Listener.ts +0 -7
- package/src/listener/decorator.ts +0 -29
- package/src/listener/index.ts +0 -6
- package/src/messageComponents/base.ts +0 -16
- package/src/messageComponents/button.ts +0 -30
- package/src/messageComponents/index.ts +0 -6
- package/src/messageComponents/selectMenu.ts +0 -30
- package/src/structures/CommandClient.ts +0 -103
- package/src/structures/Module.ts +0 -54
- package/src/structures/Registry.ts +0 -253
- package/src/structures/index.ts +0 -7
- package/src/typings.ts +0 -35
- package/src/utils.ts +0 -10
- package/test/config.example.json +0 -3
- package/test/modules/dev.ts +0 -45
- package/test/modules/test.ts +0 -148
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Module } from '../structures'
|
|
6
|
-
import { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'
|
|
7
|
-
|
|
8
|
-
export class ArgumentConverter {
|
|
9
|
-
execute(module: Module, msg: Message, arg?: string) {
|
|
10
|
-
return this.run.apply(module, [msg, arg])
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
constructor(public type: object, private run: Function, public withoutParameter: boolean) {}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class ApplicationCommandArgumentConverter {
|
|
17
|
-
execute(module: Module, interaction: CommandInteraction | ContextMenuInteraction) {
|
|
18
|
-
return this.run.apply(module, [interaction])
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
constructor(public type: object, private run: Function) {}
|
|
22
|
-
}
|
package/src/command/Command.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Module } from '../structures'
|
|
6
|
-
import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
|
|
7
|
-
import { KCommandChecks } from '../constants'
|
|
8
|
-
|
|
9
|
-
export type Argument = {
|
|
10
|
-
optional: boolean
|
|
11
|
-
type: any
|
|
12
|
-
rest: boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type CheckFunction = (msg: Message) => boolean | Promise<boolean>
|
|
16
|
-
export type ApplicationCommandCheckFunction = (i: CommandInteraction | MessageComponentInteraction | ContextMenuInteraction) => boolean | Promise<boolean>
|
|
17
|
-
|
|
18
|
-
export class Command {
|
|
19
|
-
execute(module: Module, args: any[]) {
|
|
20
|
-
return this.run.apply(module, args)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get checks(): CheckFunction[] {
|
|
24
|
-
return Reflect.getMetadata(KCommandChecks, this.module, this.key) || []
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
private run: Function,
|
|
29
|
-
public argTypes: Argument[],
|
|
30
|
-
public name: string,
|
|
31
|
-
public aliases: string[] | ((msg: Message) => string[] | Promise<string[]>),
|
|
32
|
-
public module: Module,
|
|
33
|
-
public key: symbol | string,
|
|
34
|
-
) {}
|
|
35
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Collection } from 'discord.js'
|
|
6
|
-
|
|
7
|
-
export interface CoolDownAdapter {
|
|
8
|
-
get(id: string): Promise<number | undefined>
|
|
9
|
-
set(id: string, value: number): Promise<void>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class DefaultCoolDownAdapter implements CoolDownAdapter {
|
|
13
|
-
map = new Collection<string, number>()
|
|
14
|
-
async get(id: string): Promise<number | undefined> {
|
|
15
|
-
return this.map.get(id)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async set(id: string, value: number) {
|
|
19
|
-
this.map.set(id, value)
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createCheckDecorator } from '../utils'
|
|
6
|
-
import { CoolDownType } from './type'
|
|
7
|
-
import { DMChannel, GuildMember, TextChannel } from 'discord.js'
|
|
8
|
-
import { CoolDownError } from './error'
|
|
9
|
-
|
|
10
|
-
export const coolDown = (type: CoolDownType, seconds: number) =>
|
|
11
|
-
createCheckDecorator(
|
|
12
|
-
async (msg) => {
|
|
13
|
-
const a = msg.data.cts.coolDownAdapter
|
|
14
|
-
const getKey = (): string => {
|
|
15
|
-
switch (type) {
|
|
16
|
-
case CoolDownType.USER:
|
|
17
|
-
return msg.author.id
|
|
18
|
-
case CoolDownType.GUILD:
|
|
19
|
-
return (msg.guild || msg.author).id
|
|
20
|
-
case CoolDownType.CHANNEL:
|
|
21
|
-
return msg.channel.id
|
|
22
|
-
case CoolDownType.MEMBER:
|
|
23
|
-
return `${msg.guild?.id}.${msg.author.id}`
|
|
24
|
-
case CoolDownType.ROLE:
|
|
25
|
-
return (msg.channel instanceof DMChannel ? msg.channel : msg.member!.roles.highest).id
|
|
26
|
-
case CoolDownType.CATEGORY:
|
|
27
|
-
return ((msg.channel as TextChannel).parent || msg.channel).id
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const key = getKey() + '-command-' + msg.data.command?.name
|
|
31
|
-
const data = await a.get(key)
|
|
32
|
-
const now = Date.now()
|
|
33
|
-
if (!data || !(now - data < seconds * 1000)) {
|
|
34
|
-
await a.set(key, now)
|
|
35
|
-
return true
|
|
36
|
-
}
|
|
37
|
-
throw new CoolDownError(new Date(data + seconds * 1000))
|
|
38
|
-
},
|
|
39
|
-
async (i) => {
|
|
40
|
-
if (i.isMessageComponent()) return true
|
|
41
|
-
const a = i.data.cts.coolDownAdapter
|
|
42
|
-
const getKey = (): string => {
|
|
43
|
-
switch (type) {
|
|
44
|
-
case CoolDownType.USER:
|
|
45
|
-
return i.user.id + '.user'
|
|
46
|
-
case CoolDownType.GUILD:
|
|
47
|
-
return (i.guild || i.user).id + '.guild'
|
|
48
|
-
case CoolDownType.CHANNEL:
|
|
49
|
-
return i.channel!.id + '.channel'
|
|
50
|
-
case CoolDownType.MEMBER:
|
|
51
|
-
return `${i.guild?.id}.${i.user.id}`
|
|
52
|
-
case CoolDownType.ROLE:
|
|
53
|
-
return (i.channel instanceof DMChannel ? i.channel : (i.member as GuildMember)!.roles.highest).id + '.role'
|
|
54
|
-
case CoolDownType.CATEGORY:
|
|
55
|
-
return ((i.channel as TextChannel).parent || i.channel!).id + '.category'
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const key = getKey() + '-appCommand-' + i.commandName
|
|
59
|
-
const data = await a.get(key)
|
|
60
|
-
const now = Date.now()
|
|
61
|
-
if (!data || !(now - data < seconds * 1000)) {
|
|
62
|
-
await a.set(key, now)
|
|
63
|
-
return true
|
|
64
|
-
}
|
|
65
|
-
throw new CoolDownError(new Date(data + seconds * 1000))
|
|
66
|
-
},
|
|
67
|
-
)
|
package/src/command/decorator.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { KArgumentConverters, KCommands, KOptionals, KRest, KSlashArgumentConverters } from '../constants'
|
|
6
|
-
import { Command } from './Command'
|
|
7
|
-
import { checkTarget } from '../utils'
|
|
8
|
-
import { ArgumentConverter, ApplicationCommandArgumentConverter } from './ArgumentConverter'
|
|
9
|
-
import { Module } from '../structures'
|
|
10
|
-
import { createCheckDecorator } from './utils'
|
|
11
|
-
import { GuildMember, Message, PermissionResolvable, Permissions, TextChannel } from 'discord.js'
|
|
12
|
-
import { ClientPermissionRequired, DMOnlyCommandError, GuildOnlyCommandError, OwnerOnlyCommandError, UserPermissionRequired } from '../error'
|
|
13
|
-
|
|
14
|
-
type CommandOptions = {
|
|
15
|
-
name: string
|
|
16
|
-
aliases: string[] | ((msg: Message) => string[])
|
|
17
|
-
optionTypes?: any[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const command = (options: Partial<CommandOptions> = {}) => {
|
|
21
|
-
return (
|
|
22
|
-
target: Object,
|
|
23
|
-
propertyKey: string,
|
|
24
|
-
// descriptor: TypedPropertyDescriptor<any>,
|
|
25
|
-
) => {
|
|
26
|
-
checkTarget(target)
|
|
27
|
-
|
|
28
|
-
let properties: Command[] = Reflect.getMetadata(KCommands, target)
|
|
29
|
-
|
|
30
|
-
const params: any[] = options.optionTypes ?? Reflect.getMetadata('design:paramtypes', target, propertyKey)
|
|
31
|
-
|
|
32
|
-
const optionals: number = Reflect.getMetadata(KOptionals, target, propertyKey) || -1
|
|
33
|
-
|
|
34
|
-
const rest = Reflect.getMetadata(KRest, target, propertyKey) || -1
|
|
35
|
-
|
|
36
|
-
const command = new Command(
|
|
37
|
-
Reflect.get(target, propertyKey),
|
|
38
|
-
params.map((x, i) => ({
|
|
39
|
-
type: x,
|
|
40
|
-
optional: optionals === -1 ? false : optionals <= i,
|
|
41
|
-
rest: rest === -1 ? false : rest === i,
|
|
42
|
-
})),
|
|
43
|
-
options.name || propertyKey,
|
|
44
|
-
options.aliases || [],
|
|
45
|
-
target as Module,
|
|
46
|
-
propertyKey,
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
if (properties) {
|
|
50
|
-
properties.push(command)
|
|
51
|
-
} else {
|
|
52
|
-
properties = [command]
|
|
53
|
-
Reflect.defineMetadata(KCommands, properties, target)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const argumentConverter = (type: object, requireParameter = true) => {
|
|
59
|
-
return (
|
|
60
|
-
target: Object,
|
|
61
|
-
propertyKey: string,
|
|
62
|
-
// descriptor: TypedPropertyDescriptor<any>,
|
|
63
|
-
) => {
|
|
64
|
-
checkTarget(target)
|
|
65
|
-
|
|
66
|
-
let properties: ArgumentConverter[] = Reflect.getMetadata(KArgumentConverters, target)
|
|
67
|
-
|
|
68
|
-
const converter = new ArgumentConverter(type, Reflect.get(target, propertyKey), !requireParameter)
|
|
69
|
-
|
|
70
|
-
if (properties) {
|
|
71
|
-
properties.push(converter)
|
|
72
|
-
} else {
|
|
73
|
-
properties = [converter]
|
|
74
|
-
Reflect.defineMetadata(KArgumentConverters, properties, target)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const applicationCommandArgumentConverter = (type: object) => {
|
|
80
|
-
return (
|
|
81
|
-
target: Object,
|
|
82
|
-
propertyKey: string,
|
|
83
|
-
// descriptor: TypedPropertyDescriptor<any>,
|
|
84
|
-
) => {
|
|
85
|
-
checkTarget(target)
|
|
86
|
-
|
|
87
|
-
let properties: ApplicationCommandArgumentConverter[] = Reflect.getMetadata(KSlashArgumentConverters, target)
|
|
88
|
-
|
|
89
|
-
const converter = new ApplicationCommandArgumentConverter(type, Reflect.get(target, propertyKey))
|
|
90
|
-
|
|
91
|
-
if (properties) {
|
|
92
|
-
properties.push(converter)
|
|
93
|
-
} else {
|
|
94
|
-
properties = [converter]
|
|
95
|
-
Reflect.defineMetadata(KSlashArgumentConverters, properties, target)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export const optional: ParameterDecorator = (target, propertyKey, parameterIndex) => {
|
|
101
|
-
checkTarget(target)
|
|
102
|
-
|
|
103
|
-
Reflect.defineMetadata(KOptionals, parameterIndex, target, propertyKey)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const rest: ParameterDecorator = (target, propertyKey, parameterIndex) => {
|
|
107
|
-
checkTarget(target)
|
|
108
|
-
|
|
109
|
-
const params: any[] = Reflect.getMetadata('design:paramtypes', target, propertyKey)
|
|
110
|
-
|
|
111
|
-
if (params.length - 1 !== parameterIndex) throw new Error('Rest decorator must be used at last argument.')
|
|
112
|
-
|
|
113
|
-
if (params[parameterIndex] !== String) throw new Error('Rest argument type must be "String"')
|
|
114
|
-
|
|
115
|
-
Reflect.defineMetadata(KRest, parameterIndex, target, propertyKey)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export const ownerOnly = createCheckDecorator(
|
|
119
|
-
(msg) => {
|
|
120
|
-
if (msg.data.cts.owners.includes(msg.author.id)) return true
|
|
121
|
-
throw new OwnerOnlyCommandError()
|
|
122
|
-
},
|
|
123
|
-
(i) => {
|
|
124
|
-
if (i.data.cts.owners.includes(i.user.id)) return true
|
|
125
|
-
throw new OwnerOnlyCommandError()
|
|
126
|
-
},
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
export const guildOnly = createCheckDecorator(
|
|
130
|
-
(msg) => {
|
|
131
|
-
if (!!msg.guild) return true
|
|
132
|
-
throw new GuildOnlyCommandError()
|
|
133
|
-
},
|
|
134
|
-
(i) => {
|
|
135
|
-
if (!!i.guildId) return true
|
|
136
|
-
throw new GuildOnlyCommandError()
|
|
137
|
-
},
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
export const dmOnly = createCheckDecorator(
|
|
141
|
-
(msg) => {
|
|
142
|
-
if (!msg.guild) return true
|
|
143
|
-
throw new DMOnlyCommandError()
|
|
144
|
-
},
|
|
145
|
-
(i) => {
|
|
146
|
-
if (!i.guildId) return true
|
|
147
|
-
throw new DMOnlyCommandError()
|
|
148
|
-
},
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
export const requireUserPermissions = (permission: PermissionResolvable) =>
|
|
152
|
-
createCheckDecorator(
|
|
153
|
-
(msg) => {
|
|
154
|
-
if (!msg.guild || !msg.member) throw new Error('This command must be used in guild.')
|
|
155
|
-
if (msg.member.permissionsIn(msg.channel as TextChannel).has(permission)) {
|
|
156
|
-
return true
|
|
157
|
-
}
|
|
158
|
-
throw new UserPermissionRequired(msg.member, new Permissions(permission))
|
|
159
|
-
},
|
|
160
|
-
(i) => {
|
|
161
|
-
if (!i.guild || !i.member) throw new Error('This command must be used in guild.')
|
|
162
|
-
if (!(i.member instanceof GuildMember) || i.member.permissionsIn(i.channel as TextChannel).has(permission)) {
|
|
163
|
-
return true
|
|
164
|
-
}
|
|
165
|
-
throw new UserPermissionRequired(i.member, new Permissions(permission))
|
|
166
|
-
},
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
export const requireClientPermissions = (permission: PermissionResolvable) =>
|
|
170
|
-
createCheckDecorator(
|
|
171
|
-
(msg) => {
|
|
172
|
-
if (!msg.guild) throw new Error('This command must be used in guild.')
|
|
173
|
-
if (msg.guild.me!.permissionsIn(msg.channel as TextChannel).has(permission)) {
|
|
174
|
-
return true
|
|
175
|
-
}
|
|
176
|
-
throw new ClientPermissionRequired(new Permissions(permission))
|
|
177
|
-
},
|
|
178
|
-
(i) => {
|
|
179
|
-
if (!i.guild) throw new Error('This command must be used in guild.')
|
|
180
|
-
if (i.guild.me!.permissionsIn(i.channel as TextChannel).has(permission)) {
|
|
181
|
-
return true
|
|
182
|
-
}
|
|
183
|
-
throw new ClientPermissionRequired(new Permissions(permission))
|
|
184
|
-
},
|
|
185
|
-
)
|
package/src/command/index.ts
DELETED
package/src/command/utils.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
|
|
6
|
-
import type { CheckFunction, ApplicationCommandCheckFunction } from './Command'
|
|
7
|
-
import { KCommandChecks, KApplicationCommandChecks } from '../constants'
|
|
8
|
-
|
|
9
|
-
export const createCheckDecorator = (
|
|
10
|
-
execute: ((msg: Message) => boolean | Promise<boolean>) | null,
|
|
11
|
-
executeApplicationCommand?: (i: CommandInteraction | MessageComponentInteraction | ContextMenuInteraction) => boolean | Promise<boolean>,
|
|
12
|
-
): MethodDecorator => {
|
|
13
|
-
return (target, propertyKey) => {
|
|
14
|
-
if (execute) {
|
|
15
|
-
let properties: CheckFunction[] = Reflect.getMetadata(KCommandChecks, target, propertyKey)
|
|
16
|
-
if (properties) {
|
|
17
|
-
properties.push(execute)
|
|
18
|
-
} else {
|
|
19
|
-
properties = [execute]
|
|
20
|
-
Reflect.defineMetadata(KCommandChecks, properties, target, propertyKey)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (executeApplicationCommand) {
|
|
24
|
-
let properties: ApplicationCommandCheckFunction[] = Reflect.getMetadata(KApplicationCommandChecks, target, propertyKey)
|
|
25
|
-
if (properties) {
|
|
26
|
-
properties.push(executeApplicationCommand)
|
|
27
|
-
} else {
|
|
28
|
-
properties = [executeApplicationCommand]
|
|
29
|
-
Reflect.defineMetadata(KApplicationCommandChecks, properties, target, propertyKey)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/constants.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export const KCommands = Symbol('Command.TS Commands')
|
|
6
|
-
|
|
7
|
-
export const KApplicationCommands = Symbol('Command.TS Slash Commands')
|
|
8
|
-
|
|
9
|
-
export const KSlashCommandOptions = Symbol('Command.TS Slash Command Options')
|
|
10
|
-
|
|
11
|
-
export const KListeners = Symbol('Command.TS Listeners')
|
|
12
|
-
|
|
13
|
-
export const KModulePath = Symbol('Command.TS Module Path')
|
|
14
|
-
|
|
15
|
-
export const KListenerExecuteCache = Symbol('Command.TS Module Identifier')
|
|
16
|
-
|
|
17
|
-
export const KBuiltInModule = Symbol('Command.TS Built-In Module')
|
|
18
|
-
|
|
19
|
-
export const KOptionals = Symbol('Command.TS Optional Parameters')
|
|
20
|
-
|
|
21
|
-
export const KRest = Symbol('Command.TS Rest Parameter')
|
|
22
|
-
|
|
23
|
-
export const KArgumentConverters = Symbol('Command.TS Argument Converter')
|
|
24
|
-
|
|
25
|
-
export const KSlashArgumentConverters = Symbol('Command.TS Slash Argument Converter')
|
|
26
|
-
|
|
27
|
-
export const KCommandChecks = Symbol('Command.TS Command Checks')
|
|
28
|
-
|
|
29
|
-
export const KApplicationCommandChecks = Symbol('Command.TS Slash Command Checks')
|
|
30
|
-
|
|
31
|
-
export const KMessageComponentHandlers = Symbol('Command.TS Message Component Handlers')
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'
|
|
6
|
-
import type { Argument } from '../command'
|
|
7
|
-
import type { AppCommandArgument } from '../applicationCommand'
|
|
8
|
-
|
|
9
|
-
export class ArgumentConverterNotFound extends Error {
|
|
10
|
-
constructor(public type: Argument, public msg: Message) {
|
|
11
|
-
super(`Argument converter ${type.type.name} not found.`)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class ApplicationCommandArgumentConverterNotFound extends Error {
|
|
15
|
-
constructor(public type: AppCommandArgument, public interaction: CommandInteraction | ContextMenuInteraction) {
|
|
16
|
-
super(`Argument converter ${type.type.name} not found.`)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Message } from 'discord.js'
|
|
6
|
-
import { Command } from '../command'
|
|
7
|
-
|
|
8
|
-
export class ArgumentNotProvided extends Error {
|
|
9
|
-
constructor(public index: number, public command: Command, public msg: Message) {
|
|
10
|
-
super(`Required argument #${index} not provided.`)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
|
|
6
|
-
import { Command } from '../command'
|
|
7
|
-
import { AppCommand } from '../applicationCommand'
|
|
8
|
-
|
|
9
|
-
export class CommandCheckFailed extends Error {
|
|
10
|
-
constructor(public msg: Message, public command: Command) {
|
|
11
|
-
super()
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class ApplicationCommandCheckFailed extends Error {
|
|
16
|
-
constructor(public interaction: CommandInteraction | MessageComponentInteraction | ContextMenuInteraction, public command: AppCommand) {
|
|
17
|
-
super()
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Message } from 'discord.js'
|
|
6
|
-
|
|
7
|
-
export class CommandNotFound extends Error {
|
|
8
|
-
constructor(public commandName: string, public msg: Message, public args: string[]) {
|
|
9
|
-
super(`Command ${commandName} not found.`)
|
|
10
|
-
}
|
|
11
|
-
}
|
package/src/error/ModuleError.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export class ModuleLoadError extends Error {
|
|
6
|
-
constructor(file: string, public error: Error) {
|
|
7
|
-
super('Failed to load module ' + file)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class InvalidModuleError extends Error {}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { GuildMember, Permissions } from 'discord.js'
|
|
6
|
-
|
|
7
|
-
export class UserPermissionRequired extends Error {
|
|
8
|
-
constructor(public user: GuildMember, public permissions: Permissions) {
|
|
9
|
-
super()
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class ClientPermissionRequired extends Error {
|
|
14
|
-
constructor(public permissions: Permissions) {
|
|
15
|
-
super()
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from './InvalidTargetError'
|
|
6
|
-
export * from './ModuleError'
|
|
7
|
-
export * from './ArgumentNotProvided'
|
|
8
|
-
export * from './ArgumentConverterNotFound'
|
|
9
|
-
export * from './CommandCheckFailed'
|
|
10
|
-
export * from './PermissionRequired'
|
|
11
|
-
export * from './checks'
|
|
12
|
-
export * from './CommandNotFound'
|
package/src/interface/index.ts
DELETED
package/src/listener/Listener.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022 pikokr. Licensed under the MIT license
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { checkTarget } from '../utils'
|
|
6
|
-
import { KListeners } from '../constants'
|
|
7
|
-
import { Listener } from './Listener'
|
|
8
|
-
import { Module } from '../structures'
|
|
9
|
-
|
|
10
|
-
export const listener = (event: string) => {
|
|
11
|
-
return (
|
|
12
|
-
target: Module,
|
|
13
|
-
propertyKey: string,
|
|
14
|
-
// descriptor: TypedPropertyDescriptor<any>,
|
|
15
|
-
) => {
|
|
16
|
-
checkTarget(target)
|
|
17
|
-
|
|
18
|
-
let properties: Listener[] = Reflect.getMetadata(KListeners, target)
|
|
19
|
-
|
|
20
|
-
const listener = new Listener(event, Reflect.get(target, propertyKey))
|
|
21
|
-
|
|
22
|
-
if (properties) {
|
|
23
|
-
properties.push(listener)
|
|
24
|
-
} else {
|
|
25
|
-
properties = [listener]
|
|
26
|
-
Reflect.defineMetadata(KListeners, properties, target)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|