This commit is contained in:
DjDeveloperr 2021-04-23 11:22:37 +05:30
commit 9d88c5d113
5 changed files with 51 additions and 62 deletions

2
mod.ts
View File

@ -180,7 +180,7 @@ export * from './src/cache/redis.ts'
export { ColorUtil } from './src/utils/colorutil.ts' export { ColorUtil } from './src/utils/colorutil.ts'
export type { Colors } from './src/utils/colorutil.ts' export type { Colors } from './src/utils/colorutil.ts'
export { StoreChannel } from './src/structures/guildStoreChannel.ts' export { StoreChannel } from './src/structures/guildStoreChannel.ts'
export { StageVoiceChannel } from './src/structures/guildStageVoiceChannel.ts' export { StageVoiceChannel } from './src/structures/guildVoiceStageChannel.ts'
export { export {
isCategoryChannel, isCategoryChannel,
isDMChannel, isDMChannel,

View File

@ -70,8 +70,6 @@ export class CommandClient extends Client implements CommandClientOptions {
commands: CommandsManager = new CommandsManager(this) commands: CommandsManager = new CommandsManager(this)
categories: CategoriesManager = new CategoriesManager(this) categories: CategoriesManager = new CategoriesManager(this)
_decoratedCommands?: { [name: string]: Command }
constructor(options: CommandClientOptions) { constructor(options: CommandClientOptions) {
super(options) super(options)
this.prefix = options.prefix this.prefix = options.prefix
@ -116,11 +114,12 @@ export class CommandClient extends Client implements CommandClientOptions {
this.caseSensitive = this.caseSensitive =
options.caseSensitive === undefined ? false : options.caseSensitive options.caseSensitive === undefined ? false : options.caseSensitive
if (this._decoratedCommands !== undefined) { const self = this as any
Object.values(this._decoratedCommands).forEach((entry) => { if (self._decoratedCommands !== undefined) {
Object.values(self._decoratedCommands).forEach((entry: any) => {
this.commands.add(entry) this.commands.add(entry)
}) })
this._decoratedCommands = undefined self._decoratedCommands = undefined
} }
this.on( this.on(
@ -382,11 +381,11 @@ export class CommandClient extends Client implements CommandClientOptions {
*/ */
export function command(options?: CommandOptions) { export function command(options?: CommandOptions) {
return function (target: CommandClient | Extension, name: string) { return function (target: CommandClient | Extension, name: string) {
if (target._decoratedCommands === undefined) target._decoratedCommands = {} // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const c = target as any
if (c._decoratedCommands === undefined) c._decoratedCommands = {}
const prop = ((target as unknown) as { const prop = c[name]
[name: string]: (ctx: CommandContext) => any
})[name]
if (typeof prop !== 'function') if (typeof prop !== 'function')
throw new Error('@command decorator can only be used on class methods') throw new Error('@command decorator can only be used on class methods')
@ -400,6 +399,6 @@ export function command(options?: CommandOptions) {
if (target instanceof Extension) command.extension = target if (target instanceof Extension) command.extension = target
target._decoratedCommands[command.name] = command c._decoratedCommands[command.name] = command
} }
} }

View File

@ -57,14 +57,6 @@ export class SlashClient extends HarmonyEventEmitter<SlashClientEvents> {
modules: SlashModule[] = [] modules: SlashModule[] = []
publicKey?: string publicKey?: string
_decoratedSlash?: Array<{
name: string
guild?: string
parent?: string
group?: string
handler: (interaction: Interaction) => any
}>
constructor(options: SlashOptions) { constructor(options: SlashOptions) {
super() super()
let id = options.id let id = options.id
@ -87,10 +79,11 @@ export class SlashClient extends HarmonyEventEmitter<SlashClientEvents> {
}) })
} }
if (this._decoratedSlash !== undefined) { const self = this as any
this._decoratedSlash.forEach((e) => { if (self._decoratedSlash !== undefined) {
self._decoratedSlash.forEach((e: any) => {
e.handler = e.handler.bind(this.client) e.handler = e.handler.bind(this.client)
this.handlers.push(e) self.handlers.push(e)
}) })
} }

View File

@ -0,0 +1,3 @@
import { VoiceChannel } from './guildVoiceChannel.ts'
export class StageVoiceChannel extends VoiceChannel { }

View File

@ -1,48 +1,42 @@
import { import { Client, Intents, event, slash } from '../mod.ts'
Client, import { Interaction } from '../src/structures/slash.ts'
Intents,
event,
slash,
SlashCommandOptionType as Type
} from '../../mod.ts'
import { Interaction } from '../structures/slash.ts'
import { TOKEN } from './config.ts' import { TOKEN } from './config.ts'
export class MyClient extends Client { export class MyClient extends Client {
@event() ready(): void { @event() ready(): void {
console.log(`Logged in as ${this.user?.tag}!`) console.log(`Logged in as ${this.user?.tag}!`)
this.slash.commands.bulkEdit( // this.slash.commands.bulkEdit(
[ // [
{ // {
name: 'test', // name: 'test',
description: 'Test command.', // description: 'Test command.',
options: [ // options: [
{ // {
name: 'user', // name: 'user',
type: Type.USER, // type: Type.USER,
description: 'User' // description: 'User'
}, // },
{ // {
name: 'role', // name: 'role',
type: Type.ROLE, // type: Type.ROLE,
description: 'Role' // description: 'Role'
}, // },
{ // {
name: 'channel', // name: 'channel',
type: Type.CHANNEL, // type: Type.CHANNEL,
description: 'Channel' // description: 'Channel'
}, // },
{ // {
name: 'string', // name: 'string',
type: Type.STRING, // type: Type.STRING,
description: 'String' // description: 'String'
} // }
] // ]
} // }
], // ],
'807935370556866560' // '807935370556866560'
) // )
this.slash.commands.bulkEdit([]) // this.slash.commands.bulkEdit([])
} }
@slash() test(d: Interaction): void { @slash() test(d: Interaction): void {