2025-10-27 02:05:43 -05:00
|
|
|
import { EventEmitter } from 'node:events';
|
|
|
|
|
import type { Unicord } from '.';
|
|
|
|
|
import type { UnicordCommandContext } from './context';
|
2026-05-17 22:27:25 -05:00
|
|
|
import type { UnicordCommandOptions, UnicordEventHandler, UnicordHandler } from './types/common';
|
|
|
|
|
import { UnicordEventType } from './types/common';
|
2025-10-27 02:05:43 -05:00
|
|
|
|
|
|
|
|
export class UnicordEventProcessor extends EventEmitter {
|
|
|
|
|
constructor(private readonly self: Unicord) {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-27 02:38:45 -05:00
|
|
|
register<const Options extends UnicordCommandOptions>(event: string, handler: UnicordHandler<Options>) {
|
|
|
|
|
return super.on(event, handler);
|
2025-10-27 02:05:43 -05:00
|
|
|
}
|
|
|
|
|
|
2025-11-02 01:03:30 -06:00
|
|
|
unregister<const Options extends UnicordCommandOptions>(event: string, handler: UnicordHandler<Options>) {
|
|
|
|
|
return super.off(event, handler);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 22:27:25 -05:00
|
|
|
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);
|
2025-10-27 02:05:43 -05:00
|
|
|
}
|
|
|
|
|
}
|