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 { EmojisManager } from '../managers/emojis.ts'
|
||||||
import { ActivityGame, ClientActivity } from '../types/presence.ts'
|
import { ActivityGame, ClientActivity } from '../types/presence.ts'
|
||||||
import { ClientEvents } from '../gateway/handlers/index.ts'
|
import { ClientEvents } from '../gateway/handlers/index.ts'
|
||||||
|
import { Extension } from './extensions.ts'
|
||||||
|
|
||||||
/** Some Client Options to modify behaviour */
|
/** Some Client Options to modify behaviour */
|
||||||
export interface ClientOptions {
|
export interface ClientOptions {
|
||||||
|
@ -181,7 +182,7 @@ export class Client extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function event(name?: string) {
|
export function event(name?: string) {
|
||||||
return function (client: Client, prop: string) {
|
return function (client: Client | Extension, prop: string) {
|
||||||
const listener = ((client as unknown) as {
|
const listener = ((client as unknown) as {
|
||||||
[name: string]: (...args: any[]) => any
|
[name: string]: (...args: any[]) => any
|
||||||
})[prop]
|
})[prop]
|
||||||
|
|
|
@ -98,6 +98,7 @@ export class CommandClient extends Client implements CommandClientOptions {
|
||||||
Object.values(this._decoratedCommands).forEach((entry) => {
|
Object.values(this._decoratedCommands).forEach((entry) => {
|
||||||
this.commands.add(entry)
|
this.commands.add(entry)
|
||||||
})
|
})
|
||||||
|
this._decoratedCommands = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on(
|
this.on(
|
||||||
|
@ -361,13 +362,7 @@ export function command(options?: CommandOptions) {
|
||||||
|
|
||||||
if (options !== undefined) Object.assign(command, options)
|
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
|
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)
|
commands: ExtensionCommands = new ExtensionCommands(this)
|
||||||
/** Events registered by this Extension */
|
/** Events registered by this Extension */
|
||||||
events: { [name: string]: (...args: any[]) => {} } = {}
|
events: { [name: string]: (...args: any[]) => {} } = {}
|
||||||
_decorated?: { [name: string]: Command }
|
|
||||||
|
_decoratedCommands?: { [name: string]: Command }
|
||||||
|
_decoratedEvents?: { [name: string]: (...args: any[]) => any }
|
||||||
|
|
||||||
constructor(client: CommandClient) {
|
constructor(client: CommandClient) {
|
||||||
this.client = client
|
this.client = client
|
||||||
if (this._decorated !== undefined) {
|
if (this._decoratedCommands !== undefined) {
|
||||||
Object.entries(this._decorated).forEach((entry) => {
|
Object.entries(this._decoratedCommands).forEach((entry) => {
|
||||||
this.commands.add(entry[1])
|
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