fix many things fr

This commit is contained in:
DjDeveloperr 2021-01-25 00:06:19 +05:30
parent 2dcce6e2bb
commit 04c4e7760b
7 changed files with 22 additions and 20 deletions

View file

@ -116,11 +116,11 @@ export interface VoiceServerUpdateData {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type ClientEvents = {
/** When Client has successfully connected to Discord */
ready: []
ready: [shard: number]
/** When a successful reconnect has been made */
reconnect: []
reconnect: [shard: number]
/** When a successful session resume has been done */
resumed: []
resumed: [shard: number]
/**
* When a new Channel is created
* @param channel New Channel object

View file

@ -20,5 +20,5 @@ export const ready: GatewayEventHandler = async (
gateway.client.guilds.set(guild.id, guild)
})
gateway.client.emit('ready')
gateway.client.emit('ready', gateway.shards?.[0] ?? 0)
}

View file

@ -8,11 +8,11 @@ export const resume: GatewayEventHandler = async (
d: Resume
) => {
gateway.debug(`Session Resumed!`)
gateway.client.emit('resumed')
gateway.client.emit('resumed', gateway.shards?.[0] ?? 0)
if (gateway.client.user === undefined)
gateway.client.user = new User(
gateway.client,
await gateway.client.rest.get(CLIENT_USER())
)
gateway.client.emit('ready')
gateway.client.emit('ready', gateway.shards?.[0] ?? 0)
}

View file

@ -179,7 +179,7 @@ export class Client extends HarmonyEventEmitter<ClientEvents> {
Object.keys(this._decoratedEvents).length !== 0
) {
Object.entries(this._decoratedEvents).forEach((entry) => {
this.on(entry[0] as keyof ClientEvents, entry[1])
this.on(entry[0] as keyof ClientEvents, entry[1].bind(this))
})
this._decoratedEvents = undefined
}
@ -196,12 +196,6 @@ export class Client extends HarmonyEventEmitter<ClientEvents> {
if (options.shard !== undefined) this.shard = options.shard
if (options.shardCount !== undefined) this.shardCount = options.shardCount
this.slash = new SlashClient({
id: () => this.getEstimatedID(),
client: this,
enabled: options.enableSlash
})
this.fetchGatewayInfo = options.fetchGatewayInfo ?? true
if (this.token === undefined) {
@ -224,6 +218,12 @@ export class Client extends HarmonyEventEmitter<ClientEvents> {
if (options.restOptions !== undefined)
Object.assign(restOptions, options.restOptions)
this.rest = new RESTManager(restOptions)
this.slash = new SlashClient({
id: () => this.getEstimatedID(),
client: this,
enabled: options.enableSlash
})
}
/**
@ -425,7 +425,7 @@ export function event(name?: keyof ClientEvents) {
) {
const listener = ((client as unknown) as {
[name in keyof ClientEvents]: (...args: ClientEvents[name]) => any
})[name ?? ((prop as unknown) as keyof ClientEvents)]
})[(prop as unknown) as keyof ClientEvents]
if (typeof listener !== 'function')
throw new Error('@event decorator requires a function')
if (client._decoratedEvents === undefined) client._decoratedEvents = {}

View file

@ -91,7 +91,7 @@ export class Extension {
Object.keys(this._decoratedEvents).length !== 0
) {
Object.entries(this._decoratedEvents).forEach((entry) => {
this.listen(entry[0] as keyof ClientEvents, entry[1])
this.listen(entry[0] as keyof ClientEvents, entry[1].bind(this))
})
this._decoratedEvents = undefined
}

View file

@ -201,13 +201,11 @@ export class SlashBuilder {
export class SlashCommandsManager {
slash: SlashClient
get rest(): RESTManager {
return this.slash.rest
}
rest: RESTManager
constructor(client: SlashClient) {
this.slash = client
this.rest = client.rest
}
/** Get all Global Slash Commands */
@ -378,7 +376,6 @@ export class SlashClient {
this.id = id
this.client = options.client
this.token = options.token
this.commands = new SlashCommandsManager(this)
this.publicKey = options.publicKey
if (options !== undefined) {
@ -387,12 +384,14 @@ export class SlashClient {
if (this.client?._decoratedSlash !== undefined) {
this.client._decoratedSlash.forEach((e) => {
e.handler = e.handler.bind(this.client)
this.handlers.push(e)
})
}
if (this._decoratedSlash !== undefined) {
this._decoratedSlash.forEach((e) => {
e.handler = e.handler.bind(this.client)
this.handlers.push(e)
})
}
@ -409,6 +408,8 @@ export class SlashClient {
this.client?.on('interactionCreate', (interaction) =>
this._process(interaction)
)
this.commands = new SlashCommandsManager(this)
}
getID(): string {

View file

@ -7,6 +7,7 @@ export class MyClient extends Client {
@event()
ready(): void {
console.log(`Logged in as ${this.user?.tag}!`)
this.slash.commands.bulkEdit([{ name: 'send', description: 'idk' }])
}
@event('debug')