embarassing ass typo

This commit is contained in:
2024-11-16 12:50:19 -06:00
parent 119ddfefd1
commit 7848ea0082
7 changed files with 124 additions and 122 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ import { Gateway } from './connectors/gateway';
import { Processor } from './processor';
import { Expectation, fromDiscord, Intent, type ClientConfig } from '../types/common';
import { exists, isNil } from '../utils/index';
import type { Handler } from '../types/hander';
import type { Handler } from '../types/handler';
import { type DiscordMessage, Message } from '../types/message';
import { Guilds } from './caches/guilds';
import { Messages } from './caches/messages';
+18 -5
View File
@@ -1,8 +1,9 @@
import type { Client } from "./client";
import type { Context } from "../types/context";
import { HandlerType, type EventPayload } from "../types/common";
import { BaseHandler, type Handler } from "../types/hander";
import { HandlerType, Trait, type EventPayload } from "../types/common";
import { type CommandHandler, type Handler } from "../types/handler";
import type { API } from "./api";
import type { ApplicationCommandOption } from "../types/applicationCommand";
export class Processor {
private handlers = {
@@ -55,11 +56,15 @@ export class Processor {
if (handlers) {
for (const handler of handlers) {
if (handler instanceof BaseHandler) {
await Promise.resolve(handler.execute(context, argsOrPayload));
if (isCommandHandler(handler)) {
if (type === HandlerType.Events) {
throw new Error('Event handlers cannot be a CommandHandler');
}
await Promise.resolve(handler[Trait.execute](context!, argsOrPayload));
} else {
// TODO: Fix ts error
await Promise.resolve(handler(context, argsOrPayload))
await Promise.resolve(handler(context, argsOrPayload));
}
}
}
@@ -93,3 +98,11 @@ export class Processor {
has: (event: string) => this.handlers[HandlerType.Interactions].has(event) ?? this.handlers[HandlerType.Interactions].get(event)?.length! > 0
};
}
const isCommandHandler = (handler: Handler): handler is CommandHandler<readonly ApplicationCommandOption[]> => {
if (typeof handler === 'object') {
return 'args' in handler && Trait.execute in handler;
} else {
return false;
}
}