mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
refactor: remove cast
This commit is contained in:
@@ -54,7 +54,7 @@ export interface SernEventCommand<T extends keyof SernEventsMapping = keyof Sern
|
||||
}
|
||||
export interface ExternalEventCommand extends Module {
|
||||
name?: string;
|
||||
emitter: string;
|
||||
emitter: keyof Dependencies;
|
||||
type: EventType.External;
|
||||
execute(...args: unknown[]): Awaitable<unknown>;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@ import {
|
||||
throwError,
|
||||
tap,
|
||||
MonoTypeOperatorFunction,
|
||||
catchError,
|
||||
finalize,
|
||||
} from 'rxjs';
|
||||
import { ModuleManager } from '../../core';
|
||||
import { ErrorHandling, Logging, ModuleManager, useContainerRaw } from '../../core';
|
||||
import { SernError } from '../../core/structures/errors';
|
||||
import { callPlugin, everyPluginOk, filterMap, filterMapTo } from '../../core/operators';
|
||||
import { callPlugin, everyPluginOk, filterMap, filterMapTo, handleError } from '../../core/operators';
|
||||
import { defaultModuleLoader } from '../../core/module-loading';
|
||||
import { CommandModule, Module, AnyModule } from '../../core/types/modules';
|
||||
import { contextArgs, createDispatcher, dispatchMessage } from './dispatchers';
|
||||
@@ -214,3 +216,17 @@ export function makeModuleExecutor<
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function handleCrash(
|
||||
errorHandler: ErrorHandling,
|
||||
logger?: Logging,
|
||||
) {
|
||||
return pipe(
|
||||
catchError(handleError(errorHandler, logger)),
|
||||
finalize(() => {
|
||||
logger?.info({ message: 'A stream closed or reached end of lifetime' });
|
||||
useContainerRaw()?.disposeAll()
|
||||
.then(() => logger?.info({ message: 'Cleaning container and crashing' }));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { buildModules, callInitPlugins } from './generic';
|
||||
import { handleError } from '../../core/operators';
|
||||
import { Service, useContainerRaw } from '../../core/ioc';
|
||||
import { DependencyList, Processed } from '../types';
|
||||
import { Dependencies } from '../../core/ioc/types';
|
||||
|
||||
export function makeEventsHandler(
|
||||
[emitter, err, log, moduleManager, client]: DependencyList,
|
||||
@@ -22,7 +21,7 @@ export function makeEventsHandler(
|
||||
case EventType.Discord:
|
||||
return eventDispatcher(e, client);
|
||||
case EventType.External:
|
||||
return eventDispatcher(e, Service(e.emitter as keyof Dependencies));
|
||||
return eventDispatcher(e, Service(e.emitter));
|
||||
default:
|
||||
return err.crash(
|
||||
Error(SernError.InvalidModuleType + ' while creating event handler'),
|
||||
|
||||
Reference in New Issue
Block a user