refactor: decouple system events from command dispatch and add explicit system event handlers and improve gateway handling

This commit is contained in:
2026-05-17 22:27:25 -05:00
parent 8b1eecd823
commit ce45eacb3b
11 changed files with 313 additions and 84 deletions
+13 -3
View File
@@ -1,7 +1,8 @@
import { EventEmitter } from 'node:events';
import type { Unicord } from '.';
import type { UnicordCommandContext } from './context';
import type { UnicordCommandOptions, UnicordEventContext, UnicordHandler } from './types/common';
import type { UnicordCommandOptions, UnicordEventHandler, UnicordHandler } from './types/common';
import { UnicordEventType } from './types/common';
export class UnicordEventProcessor extends EventEmitter {
constructor(private readonly self: Unicord) {
@@ -16,7 +17,16 @@ export class UnicordEventProcessor extends EventEmitter {
return super.off(event, handler);
}
emit(event: string, context: UnicordCommandContext | UnicordEventContext, args: any[]): boolean {
return super.emit(event, context, args);
emitCommand(
type: UnicordEventType.ChatCommands | UnicordEventType.ApplicationCommands,
event: string,
context: UnicordCommandContext,
args: any[],
): boolean {
return super.emit(`${type}:${event}`, context, args);
}
emitSystem(event: string, payload: Parameters<UnicordEventHandler>[0]): boolean {
return super.emit(`${UnicordEventType.SystemEvent}:${event}`, payload);
}
}