diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index e4875c5..dd4ef4f 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -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, diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index 21c3f0a..6b47c3d 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -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( 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; } diff --git a/src/handlers/message.ts b/src/handlers/message.ts index 8eb8abf..125889f 100644 --- a/src/handlers/message.ts +++ b/src/handlers/message.ts @@ -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 => { diff --git a/src/handlers/ready.ts b/src/handlers/ready.ts index 9ac1006..662b1bd 100644 --- a/src/handlers/ready.ts +++ b/src/handlers/ready.ts @@ -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'; diff --git a/src/types/core-modules.ts b/src/types/core-modules.ts index 911e582..aeb102d 100644 --- a/src/types/core-modules.ts +++ b/src/types/core-modules.ts @@ -193,7 +193,7 @@ type CommandModuleNoPlugins = { [T in CommandType]: Omit; }; type EventModulesNoPlugins = { - [T in EventType]: Omit; + [T in EventType]: Omit & { once?: boolean }; }; export type InputEvent = { diff --git a/src/types/core-plugin.ts b/src/types/core-plugin.ts index d082bae..60c0b03 100644 --- a/src/types/core-plugin.ts +++ b/src/types/core-plugin.ts @@ -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,