remove slashModule decorator

This commit is contained in:
DjDeveloperr 2021-01-01 14:22:15 +05:30
parent 33f103279d
commit b112b6ae36
3 changed files with 11 additions and 37 deletions

View File

@ -134,7 +134,6 @@ export class Client extends EventEmitter {
handler: (interaction: Interaction) => any
}>
_decoratedSlashModules?: string[]
_id?: string
/** Shard on which this Client is */
@ -362,12 +361,3 @@ export function groupslash(
})
}
}
/** Decorator to add a Slash Module to Client */
export function slashModule() {
return function (client: Client | SlashClient, prop: string) {
if (client._decoratedSlashModules === undefined)
client._decoratedSlashModules = []
client._decoratedSlashModules.push(prop)
}
}

View File

@ -353,8 +353,6 @@ export class SlashClient {
handler: (interaction: Interaction) => any
}>
_decoratedSlashModules?: string[]
constructor(options: SlashOptions) {
let id = options.id
if (options.token !== undefined) id = atob(options.token?.split('.')[0])
@ -376,36 +374,12 @@ export class SlashClient {
})
}
if (this.client?._decoratedSlashModules !== undefined) {
this.client._decoratedSlashModules.forEach((e) => {
const mod = ((this.client as unknown) as {
[name: string]: SlashModule
})[e]
if (!(mod instanceof SlashModule))
throw new Error(
'@slashModule can only be used on SlashModule instances'
)
this.modules.push(mod)
})
}
if (this._decoratedSlash !== undefined) {
this._decoratedSlash.forEach((e) => {
this.handlers.push(e)
})
}
if (this._decoratedSlashModules !== undefined) {
this._decoratedSlashModules.forEach((e) => {
const mod = ((this as unknown) as { [name: string]: SlashModule })[e]
if (!(mod instanceof SlashModule))
throw new Error(
'@slashModule can only be used on SlashModule instances'
)
this.modules.push(mod)
})
}
this.rest =
options.client === undefined
? options.rest === undefined

View File

@ -1,8 +1,18 @@
import { SlashClient } from '../models/slashClient.ts'
import { SlashCommandPartial } from '../types/slash.ts'
import { TOKEN } from './config.ts'
import { SlashModule, slashModule } from '../../mod.ts'
export const slash = new SlashClient({ token: TOKEN })
class MyMod extends SlashModule {}
class MySlashClient extends SlashClient {
@slashModule()
mod = new MyMod()
}
export const slash = new MySlashClient({ token: TOKEN })
console.log(slash.modules)
// Cmd objects come here
const commands: SlashCommandPartial[] = []