mirror of
https://github.com/sern-handler/handler
synced 2026-06-22 07:42:14 +00:00
once on eventModules
This commit is contained in:
@@ -6,7 +6,7 @@ import * as Id from './id'
|
||||
import { Module } from '../types/core-modules';
|
||||
|
||||
export const parseCallsite = (site: string) => {
|
||||
const pathobj = path.posix.parse(site.replace(/file:\\?/, "")
|
||||
const pathobj = path.parse(site.replace(/file:\\?/, "")
|
||||
.split(path.sep)
|
||||
.join(path.posix.sep))
|
||||
return { name: pathobj.name,
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Interaction, Message, BaseInteraction } from 'discord.js';
|
||||
import {
|
||||
EMPTY, type Observable, concatMap, filter,
|
||||
throwError, fromEvent, map, type OperatorFunction,
|
||||
catchError, finalize, pipe, from,
|
||||
catchError, finalize, pipe, from, take,
|
||||
} from 'rxjs';
|
||||
import * as Id from '../core/id'
|
||||
import type { Emitter } from '../core/interfaces';
|
||||
@@ -43,10 +43,15 @@ export function eventDispatcher(deps: Dependencies, module: Module, source: unkn
|
||||
concatMap(async args => {
|
||||
if(args) return Reflect.apply(module.execute, null, args);
|
||||
});
|
||||
|
||||
//@ts-ignore
|
||||
return fromEvent(source, module.name!)
|
||||
.pipe(intoPayload(module, deps),
|
||||
execute);
|
||||
let ev = fromEvent(source ,module.name!);
|
||||
//@ts-ignore
|
||||
if(module['once']) {
|
||||
ev = ev.pipe(take(1))
|
||||
}
|
||||
return ev.pipe(intoPayload(module, deps),
|
||||
execute);
|
||||
}
|
||||
|
||||
interface DispatchPayload {
|
||||
@@ -108,8 +113,7 @@ export function createInteractionHandler<T extends Interaction>(
|
||||
const possibleIds = Id.reconstruct(event);
|
||||
let modules = possibleIds
|
||||
.map(({ id, params }) => ({ module: mg.get(id), params }))
|
||||
.filter((id) => id !== undefined);
|
||||
|
||||
.filter(({ module }) => module !== undefined);
|
||||
if(modules.length == 0) {
|
||||
return Err.EMPTY;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ function (deps: UnpackedDependencies, defaultPrefix?: string) {
|
||||
return msgCommands$.pipe(
|
||||
filterTap(e => emitter.emit('warning', resultPayload(PayloadType.Warning, undefined, e))),
|
||||
concatMap(intoTask(module => {
|
||||
const result = resultPayload(PayloadType.Failure, module, SernError.PluginFailure);
|
||||
const result = resultPayload('failure', module, SernError.PluginFailure);
|
||||
emitter.emit('module.activate', result);
|
||||
})),
|
||||
mergeMap(payload => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as Files from '../core/module-loading'
|
||||
import { once } from 'node:events';
|
||||
import { resultPayload } from '../core/functions';
|
||||
import { PayloadType } from '..';
|
||||
import { CommandType } from '../core/structures/enums';
|
||||
import { Module } from '../types/core-modules';
|
||||
import { UnpackedDependencies } from '../types/utility';
|
||||
|
||||
@@ -193,7 +193,7 @@ type CommandModuleNoPlugins = {
|
||||
[T in CommandType]: Omit<CommandModuleDefs[T], 'plugins' | 'onEvent' | 'meta'>;
|
||||
};
|
||||
type EventModulesNoPlugins = {
|
||||
[T in EventType]: Omit<EventModuleDefs[T], 'plugins' | 'onEvent' | 'meta'>;
|
||||
[T in EventType]: Omit<EventModuleDefs[T], 'plugins' | 'onEvent' | 'meta'> & { once?: boolean };
|
||||
};
|
||||
|
||||
export type InputEvent = {
|
||||
|
||||
@@ -18,7 +18,7 @@ import type {
|
||||
SDT,
|
||||
} from './core-modules';
|
||||
import type { Awaitable } from './utility';
|
||||
import type { CommandType, EventType, PluginType } from '../core/structures/enums'
|
||||
import type { CommandType, PluginType } from '../core/structures/enums'
|
||||
import type { Context } from '../core/structures/context'
|
||||
import type {
|
||||
ButtonInteraction,
|
||||
|
||||
Reference in New Issue
Block a user