mirror of
https://github.com/sern-handler/handler
synced 2026-06-05 17:06:53 +00:00
* some wip code Co-authored-by: Jacob Nguyen <jacoobes@users.noreply.github.com> * general idea * style * making shrimple truly optional * got optional localizer working * proposing api notation? * prepare for localization map * add localsFor * merge some internals * boss call * add test for init functionality * add documentation * inline and cleanup * feat: logging for experimental json loading * loosen typings * dev workflow and cleaning up comments * cleaning up a bit more * rename Localizer -> Localization * more documentation, change dir for default localizer * some tests * " * move stuff, refactor, deprecate * yarnb * Update index.ts --------- Co-authored-by: Jacob Nguyen <jacoobes@users.noreply.github.com> Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Co-authored-by: jacob <jacoobes@sern.dev>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { Interaction } from 'discord.js';
|
|
import { mergeMap, merge } from 'rxjs';
|
|
import { PayloadType } from '../core';
|
|
import {
|
|
isAutocomplete,
|
|
isCommand,
|
|
isMessageComponent,
|
|
isModal,
|
|
sharedEventStream,
|
|
SernError,
|
|
filterTap,
|
|
resultPayload,
|
|
} from '../core/_internal';
|
|
import { createInteractionHandler, executeModule, makeModuleExecutor } from './_internal';
|
|
import type { DependencyList } from '../types/ioc';
|
|
|
|
export function interactionHandler([emitter, err, log, modules, client]: DependencyList) {
|
|
const interactionStream$ = sharedEventStream<Interaction>(client, 'interactionCreate');
|
|
const handle = createInteractionHandler(interactionStream$, modules);
|
|
|
|
const interactionHandler$ = merge(
|
|
handle(isMessageComponent),
|
|
handle(isAutocomplete),
|
|
handle(isCommand),
|
|
handle(isModal),
|
|
);
|
|
return interactionHandler$
|
|
.pipe(
|
|
filterTap(e => emitter.emit('warning', resultPayload(PayloadType.Warning, undefined, e))),
|
|
makeModuleExecutor(module =>
|
|
emitter.emit('module.activate', resultPayload(PayloadType.Failure, module, SernError.PluginFailure))),
|
|
mergeMap(payload => executeModule(emitter, log, err, payload)));
|
|
}
|