mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
Refactor and update types and handlers
- README changes: removed 'as const' annotation and note. - Connector changes: dispatched event for commands in gateway. - Updated processor type guard for command handlers. - Removed readonly from CommandHandler types in handler definitions. - Test adjustments: updated demo tests to reliable command registration.
This commit is contained in:
@@ -204,14 +204,16 @@ export class Gateway {
|
||||
this.client.messages.set(message.id, message);
|
||||
// Generate context
|
||||
const context = new Context(this.client, this.api, { message });
|
||||
// Dispatch event for the command
|
||||
this.bus.emit(`command:${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}`);
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ export class Processor {
|
||||
has: (event: string) => this.handlers[HandlerType.Interactions].has(event) ?? this.handlers[HandlerType.Interactions].get(event)?.length! > 0
|
||||
};
|
||||
|
||||
static isCommandHandler = (handler: Handler): handler is CommandHandler<readonly ApplicationCommandOption[]> => {
|
||||
static isCommandHandler = (handler: Handler): handler is CommandHandler<ApplicationCommandOption[]> => {
|
||||
if (typeof handler === 'object') {
|
||||
return 'args' in handler && Trait.execute in handler && handler instanceof CommandHandler;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user