From 7ff8917a26a360bc053ffe440fbff93e6ce3fb60 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 10 May 2023 15:09:26 -0500 Subject: [PATCH] fix: unaliased modules would throw error --- src/handler/events/dispatchers.ts | 3 ++- src/handler/events/generic.ts | 27 +++++++++------------------ src/handler/events/ready.ts | 12 +++--------- src/handler/events/user-defined.ts | 2 +- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/handler/events/dispatchers.ts b/src/handler/events/dispatchers.ts index 261339d..611eeba 100644 --- a/src/handler/events/dispatchers.ts +++ b/src/handler/events/dispatchers.ts @@ -8,8 +8,9 @@ import { treeSearch } from '../../core/functions'; import { SernError } from '../../core/structures/errors'; import { CommandType, Context } from '../../core'; import { isAutocomplete } from '../../core/predicates'; -import { Args, Processed } from '../types'; +import { Processed } from '../types'; import { BothCommand, CommandModule, Module } from '../../core/types/modules'; +import { Args } from '../../shared'; export function dispatchInteraction< T extends CommandModule, diff --git a/src/handler/events/generic.ts b/src/handler/events/generic.ts index 3bed1bf..db1513d 100644 --- a/src/handler/events/generic.ts +++ b/src/handler/events/generic.ts @@ -75,27 +75,18 @@ export function createMessageHandler( * @returns A unique string ID based on the type and properties of the interaction object. */ function createId(event: T) { - let id: string; switch (event.type) { - case InteractionType.MessageComponent: - { - id = `${event.customId}__C${event.componentType}`; - } - break; + case InteractionType.MessageComponent: { + return `${event.customId}__C${event.componentType}`; + } case InteractionType.ApplicationCommand: - case InteractionType.ApplicationCommandAutocomplete: - { - id = `${event.commandName}__A${event.commandType}`; - console.log(id); - } - break; - case InteractionType.ModalSubmit: - { - id = `${event.customId}__C1`; - } - break; + case InteractionType.ApplicationCommandAutocomplete: { + return `${event.commandName}__A${event.commandType}`; + } + case InteractionType.ModalSubmit: { + return `${event.customId}__C1`; + } } - return id; } diff --git a/src/handler/events/ready.ts b/src/handler/events/ready.ts index fdab30a..6ccff7b 100644 --- a/src/handler/events/ready.ts +++ b/src/handler/events/ready.ts @@ -6,9 +6,8 @@ import { ModuleManager } from '../../core/contracts'; import { SernEmitter } from '../../core'; import { sernMeta } from '../commands'; import { Processed, DependencyList } from '../types'; -import * as assert from 'node:assert'; import { buildModules, callInitPlugins } from './generic'; -import { Module } from '../../core/types/modules'; +import { AnyModule } from '../../core/types/modules'; export function startReadyEvent( [sEmitter,,, moduleManager, client]: DependencyList, @@ -20,10 +19,7 @@ export function startReadyEvent( buildModules(allPaths, sEmitter), callInitPlugins({ onStop: module => { - sEmitter.emit( - 'module.register', - SernEmitter.failure(module, SernError.PluginFailure), - ); + sEmitter.emit('module.register', SernEmitter.failure(module, SernError.PluginFailure)); }, onNext: ({ module }) => { sEmitter.emit('module.register', SernEmitter.success(module)); @@ -39,7 +35,7 @@ export function startReadyEvent( }); } -function registerModule>( +function registerModule>( manager: ModuleManager, module: T, ): Result { @@ -47,8 +43,6 @@ function registerModule>( if (module.type === CommandType.Both || module.type === CommandType.Text ) { - assert.ok('alias' in module); - assert.ok(Array.isArray(module.alias)); module.alias?.forEach(a => manager.set(`${a}__A0`, fullPath)); } return Result.wrap(() => manager.set(id, fullPath)); diff --git a/src/handler/events/user-defined.ts b/src/handler/events/user-defined.ts index 55f3ed9..5892985 100644 --- a/src/handler/events/user-defined.ts +++ b/src/handler/events/user-defined.ts @@ -1,5 +1,5 @@ import { ObservableInput, catchError, finalize, map, mergeAll, of } from 'rxjs'; -import type { CommandModule, EventModule } from '../../types/module'; +import type { CommandModule, EventModule } from '../../core/types/modules'; import { SernEmitter } from '../../core'; import { EventType } from '../../core/structures'; import { SernError } from '../../core/structures/errors';