mirror of
https://github.com/sern-handler/handler
synced 2026-06-23 16:22:15 +00:00
still broken but progress
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "tsup --watch",
|
||||
"watch": "tsc --watch",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"format": "eslint src/**/*.ts --fix",
|
||||
"build:dev": "tsup --metafile",
|
||||
"build:dev": "tsc",
|
||||
"build:prod": "tsc",
|
||||
"prepare": "tsc",
|
||||
"pretty": "prettier --write .",
|
||||
|
||||
@@ -10,25 +10,22 @@ import {
|
||||
SernError,
|
||||
filterTap,
|
||||
resultPayload,
|
||||
type _Module,
|
||||
} from './core/_internal';
|
||||
import { createInteractionHandler, executeModule, makeModuleExecutor } from './handlers/event-utils';
|
||||
import type { DependencyList } from './types/ioc';
|
||||
import type { Emitter } from './core/interfaces'
|
||||
|
||||
|
||||
export function interactionHandler([emitter, err, log, modules, client]: DependencyList) {
|
||||
export function interactionHandler(client: Emitter, emitter: Emitter, modules: Map<string, _Module>) {
|
||||
const interactionStream$ = sharedEventStream<Interaction>(client, 'interactionCreate');
|
||||
const handle = createInteractionHandler(interactionStream$, modules);
|
||||
|
||||
const interactionHandler$ = merge(
|
||||
handle(isMessageComponent),
|
||||
handle(isAutocomplete),
|
||||
handle(isCommand),
|
||||
handle(isModal),
|
||||
);
|
||||
const interactionHandler$ = merge(handle(isMessageComponent),
|
||||
handle(isAutocomplete),
|
||||
handle(isCommand),
|
||||
handle(isModal));
|
||||
return interactionHandler$
|
||||
.pipe(
|
||||
filterTap(e => emitter.emit('warning', resultPayload(PayloadType.Warning, undefined, e))),
|
||||
concatMap(makeModuleExecutor(module =>
|
||||
.pipe(filterTap(e => emitter.emit('warning', resultPayload(PayloadType.Warning, undefined, e))),
|
||||
concatMap(makeModuleExecutor(module =>
|
||||
emitter.emit('module.activate', resultPayload(PayloadType.Failure, module, SernError.PluginFailure)))),
|
||||
mergeMap(payload => executeModule(emitter, log, err, payload)));
|
||||
mergeMap(payload => executeModule(emitter, log, err, payload)));
|
||||
}
|
||||
|
||||
@@ -140,8 +140,7 @@ function composeRoot(
|
||||
container.ready();
|
||||
}
|
||||
|
||||
export async function makeDependencies
|
||||
(conf: ValidDependencyConfig) {
|
||||
export async function makeDependencies (conf: ValidDependencyConfig) {
|
||||
containerSubject = new CoreContainer();
|
||||
if(typeof conf === 'function') {
|
||||
const excluded: string[] = [];
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
arrayifySource,
|
||||
isAutocomplete,
|
||||
treeSearch,
|
||||
_Module,
|
||||
} from '../core/_internal';
|
||||
import type { Emitter, ErrorHandling, Logging } from '../core/interfaces';
|
||||
import { PayloadType } from '../core/structures/enums'
|
||||
@@ -77,10 +78,7 @@ export function eventDispatcher(module: Processed<Module>, source: unknown) {
|
||||
execute);
|
||||
}
|
||||
|
||||
export function createDispatcher(payload: {
|
||||
module: Processed<CommandModule>;
|
||||
event: BaseInteraction;
|
||||
}) {
|
||||
export function createDispatcher(payload: { module: Processed<CommandModule>; event: BaseInteraction; }) {
|
||||
assert.ok(CommandType.Text !== payload.module.type,
|
||||
SernError.MismatchEvent + 'Found text command in interaction stream');
|
||||
switch (payload.module.type) {
|
||||
@@ -135,7 +133,7 @@ export function fmt(msg: string, prefix: string): string[] {
|
||||
*/
|
||||
export function createInteractionHandler<T extends Interaction>(
|
||||
source: Observable<Interaction>,
|
||||
mg: any, //TODO
|
||||
mg: Map<string, _Module>, //TODO
|
||||
) {
|
||||
return createGenericHandler<Interaction, T, Result<ReturnType<typeof createDispatcher>, void>>(
|
||||
source,
|
||||
@@ -143,12 +141,13 @@ export function createInteractionHandler<T extends Interaction>(
|
||||
const possibleIds = Id.reconstruct(event);
|
||||
let fullPaths= possibleIds
|
||||
.map(id => mg.get(id))
|
||||
.filter((id): id is Module => id !== undefined);
|
||||
.filter((id): id is _Module => id !== undefined);
|
||||
|
||||
if(fullPaths.length == 0) {
|
||||
return Err.EMPTY;
|
||||
}
|
||||
const [ path ] = fullPaths;
|
||||
//@ts-ignore TODO fixme
|
||||
return Ok(createDispatcher({ module: path as Processed<CommandModule>, event }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * as Sern from './sern';
|
||||
|
||||
export type {
|
||||
CommandModule,
|
||||
EventModule,
|
||||
|
||||
Reference in New Issue
Block a user