fix: unaliased modules would throw error

This commit is contained in:
Jacob Nguyen
2023-05-10 15:09:26 -05:00
parent 8a537d670b
commit 7ff8917a26
4 changed files with 15 additions and 29 deletions

View File

@@ -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,

View File

@@ -75,27 +75,18 @@ export function createMessageHandler(
* @returns A unique string ID based on the type and properties of the interaction object.
*/
function createId<T extends Interaction>(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;
}

View File

@@ -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<T extends Processed<Module>>(
function registerModule<T extends Processed<AnyModule>>(
manager: ModuleManager,
module: T,
): Result<void, void> {
@@ -47,8 +43,6 @@ function registerModule<T extends Processed<Module>>(
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));

View File

@@ -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';