fix: collectors

This commit is contained in:
MARCROCK22 2024-08-03 23:59:52 +00:00
parent c3ea1a394a
commit f3ba75155d
4 changed files with 12 additions and 7 deletions

View File

@ -141,7 +141,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
protected async onPacket(shardId: number, packet: GatewayDispatchPayload) {
Promise.allSettled([
this.events?.runEvent('RAW', this, packet, shardId, false),
this.collectors.run('RAW', packet),
this.collectors.run('RAW', packet, this),
]); //ignore promise
switch (packet.t) {
//// Cases where we must obtain the old data before updating

View File

@ -2,6 +2,8 @@ import { randomUUID } from 'node:crypto';
import type { Awaitable, CamelCase } from '../common';
import type { CallbackEventHandler, CustomEventsKeys, GatewayEvents } from '../events';
import { error } from 'node:console';
import * as RawEvents from '../events/hooks';
import type { UsingClient } from '../commands';
export type AllClientEvents = CustomEventsKeys | GatewayEvents;
export type ParseClientEventName<T extends AllClientEvents> = T extends CustomEventsKeys ? T : CamelCase<T>;
@ -98,11 +100,14 @@ export class Collectors {
/**@internal */
async run<T extends AllClientEvents>(
name: T,
data: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>,
raw: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>,
client: UsingClient,
) {
const collectors = this.values.get(name);
if (!collectors) return;
const data = RawEvents[name]?.(client, raw as never) ?? raw;
for (const i of collectors) {
if (await i.options.filter(data as never)) {
i.idle?.refresh();

View File

@ -357,7 +357,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
protected async onPacket(packet: GatewayDispatchPayload, shardId: number) {
Promise.allSettled([
this.events?.runEvent('RAW', this, packet, shardId, false),
this.collectors.run('RAW', packet),
this.collectors.run('RAW', packet, this),
]); //ignore promise
switch (packet.t) {
//// Cases where we must obtain the old data before updating

View File

@ -111,7 +111,7 @@ export class EventHandler extends BaseHandler {
await Promise.all([
this.runEvent(args[0].t as never, args[1], args[0].d, args[2]),
this.client.collectors.run(args[0].t as never, args[0].d as never),
this.client.collectors.run(args[0].t as never, args[0].d as never, this.client),
]);
}
@ -150,15 +150,15 @@ export class EventHandler extends BaseHandler {
async runCustom<T extends CustomEventsKeys>(name: T, ...args: Parameters<CustomEvents[T]>) {
const Event = this.values[name];
if (!Event) {
return this.client.collectors.run(name, args as never);
return this.client.collectors.run(name, args as never, this.client);
}
try {
if (Event.data.once && Event.fired) {
return this.client.collectors.run(name, args as never);
return this.client.collectors.run(name, args as never, this.client);
}
Event.fired = true;
this.logger.debug(`executed a custom event [${name}]`, Event.data.once ? 'once' : '');
await Promise.all([Event.run(args, this.client), this.client.collectors.run(name, args as never)]);
await Promise.all([Event.run(args, this.client), this.client.collectors.run(name, args as never, this.client)]);
} catch (e) {
await this.onFail(name, e);
}