mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
Added workflow and fixed bug with command handling
This commit is contained in:
@@ -5,6 +5,7 @@ const EventBus = new EventEmitter() as Emitter;
|
||||
|
||||
export type Emitter = EventEmitter & {
|
||||
emit: (event_name: string, context: Context | null, ...args: any[]) => boolean
|
||||
on: (event_name: string, listener: Function) => Emitter
|
||||
}
|
||||
|
||||
export { EventBus };
|
||||
@@ -205,15 +205,15 @@ export class Gateway {
|
||||
// Generate context
|
||||
const context = new Context(this.client, this.api, { message });
|
||||
// Dispatch event for the command
|
||||
this.bus.emit(`command:${command}`, context, args);
|
||||
// this.bus.emit(`${HandlerType.ChatCommands}:${command}`, context, args);
|
||||
// // Check if command exists
|
||||
// if (this.processor[HandlerType.ChatCommands].has(command)) {
|
||||
// // Execute the handler
|
||||
// this.processor[HandlerType.ChatCommands].execute(command, context, args);
|
||||
// } else {
|
||||
// // TODO: Custom unknown command handler
|
||||
// context.reply(`Unknown command: ${command}`);
|
||||
// }
|
||||
if (this.processor[HandlerType.ChatCommands].has(command)) {
|
||||
// Execute the handler
|
||||
this.processor[HandlerType.ChatCommands].execute(command, context, args);
|
||||
} else {
|
||||
// TODO: Custom unknown command handler
|
||||
// context.reply(`Unknown command: ${command}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -64,6 +64,9 @@ export class Processor {
|
||||
throw new Error('Event handlers cannot be a CommandHandler');
|
||||
}
|
||||
// Validate and resolve the args
|
||||
// TODO: There's no reason this can't use the hydrator system
|
||||
// Hydrator should have a more genric subcomponent that can be used anywhere and is more dumb.
|
||||
// Basically a function that accepts id's and returns values.
|
||||
const resolvedArgs = await this.validateAndResolveArgs(argsOrPayload, handler.args);
|
||||
// Execute the handler
|
||||
await Promise.resolve(handler[Trait.execute](context!, resolvedArgs));
|
||||
|
||||
Reference in New Issue
Block a user