feat(decorators): stablize props and remove after loading
This commit is contained in:
parent
f2e906987c
commit
659080f341
3 changed files with 21 additions and 12 deletions
|
@ -11,6 +11,7 @@ import { ClientPresence } from '../structures/presence.ts'
|
|||
import { EmojisManager } from '../managers/emojis.ts'
|
||||
import { ActivityGame, ClientActivity } from '../types/presence.ts'
|
||||
import { ClientEvents } from '../gateway/handlers/index.ts'
|
||||
import { Extension } from './extensions.ts'
|
||||
|
||||
/** Some Client Options to modify behaviour */
|
||||
export interface ClientOptions {
|
||||
|
@ -181,7 +182,7 @@ export class Client extends EventEmitter {
|
|||
}
|
||||
|
||||
export function event(name?: string) {
|
||||
return function (client: Client, prop: string) {
|
||||
return function (client: Client | Extension, prop: string) {
|
||||
const listener = ((client as unknown) as {
|
||||
[name: string]: (...args: any[]) => any
|
||||
})[prop]
|
||||
|
|
|
@ -98,6 +98,7 @@ export class CommandClient extends Client implements CommandClientOptions {
|
|||
Object.values(this._decoratedCommands).forEach((entry) => {
|
||||
this.commands.add(entry)
|
||||
})
|
||||
this._decoratedCommands = undefined
|
||||
}
|
||||
|
||||
this.on(
|
||||
|
@ -361,13 +362,7 @@ export function command(options?: CommandOptions) {
|
|||
|
||||
if (options !== undefined) Object.assign(command, options)
|
||||
|
||||
if (target instanceof CommandClient) {
|
||||
if (target._decoratedCommands === undefined)
|
||||
target._decoratedCommands = {}
|
||||
if (target._decoratedCommands === undefined) target._decoratedCommands = {}
|
||||
target._decoratedCommands[command.name] = command
|
||||
} else {
|
||||
if (target._decorated === undefined) target._decorated = {}
|
||||
target._decorated[command.name] = command
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,14 +69,27 @@ export class Extension {
|
|||
commands: ExtensionCommands = new ExtensionCommands(this)
|
||||
/** Events registered by this Extension */
|
||||
events: { [name: string]: (...args: any[]) => {} } = {}
|
||||
_decorated?: { [name: string]: Command }
|
||||
|
||||
_decoratedCommands?: { [name: string]: Command }
|
||||
_decoratedEvents?: { [name: string]: (...args: any[]) => any }
|
||||
|
||||
constructor(client: CommandClient) {
|
||||
this.client = client
|
||||
if (this._decorated !== undefined) {
|
||||
Object.entries(this._decorated).forEach((entry) => {
|
||||
if (this._decoratedCommands !== undefined) {
|
||||
Object.entries(this._decoratedCommands).forEach((entry) => {
|
||||
this.commands.add(entry[1])
|
||||
})
|
||||
this._decoratedCommands = undefined
|
||||
}
|
||||
|
||||
if (
|
||||
this._decoratedEvents !== undefined &&
|
||||
Object.keys(this._decoratedEvents).length !== 0
|
||||
) {
|
||||
Object.entries(this._decoratedEvents).forEach((entry) => {
|
||||
this.listen(entry[0], entry[1])
|
||||
})
|
||||
this._decoratedEvents = undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue