Skip to content

Commit

Permalink
plugin system loking better, tbd type
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed May 20, 2024
1 parent 0beeb4c commit 735a9e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/core/structures/default-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class DefaultErrorHandling implements ErrorHandling {
* Version 4.0.0 will internalize this api. Please refrain from using ModuleStore!
*/
export class DefaultLogging implements Logging {
private date = () => new Date();
private date() { return new Date() }
debug(payload: LogPayload): void {
console.debug(`DEBUG: ${this.date().toISOString()} -> ${payload.message}`);
}
Expand Down
5 changes: 2 additions & 3 deletions src/handlers/event-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export function eventDispatcher(deps: Dependencies, module: Module, source: unkn
`${source} cannot be constructed into an event listener`);
const execute: OperatorFunction<unknown[]|undefined, unknown> =
concatMap(async args => {
if(args)
return module.execute.apply(null, args);
if(args) return module.execute.apply(null, args);
});
//@ts-ignore
return fromEvent(source, module.name!)
Expand Down Expand Up @@ -240,7 +239,7 @@ async function callPlugins({ args, module, deps }: ExecutePayload) {
export function intoTask(onStop: (m: Module) => unknown) {
const onNext = ({ args, module, deps }: ExecutePayload, state: Record<string, unknown>) => ({
module,
args: [...args, { state }],
args: [...args, { state, deps }],
deps
});
return createResultResolver({ onStop, onNext })
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ function hasPrefix(prefix: string, content: string) {
return (prefixInContent.localeCompare(prefix, undefined, { sensitivity: 'accent' }) === 0);
}

export default function message(
export default function (
deps: UnpackedDependencies,
defaultPrefix: string | undefined
defaultPrefix?: string
) {
const {"@sern/emitter": emitter,
'@sern/logger': log,
'@sern/client': client } = deps
'@sern/client': client} = deps

if (!defaultPrefix) {
log?.debug({ message: 'No prefix found. message handler shutting down' });
Expand Down
13 changes: 7 additions & 6 deletions src/types/core-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { AnyCommandPlugin, AnyEventPlugin, ControlPlugin, InitPlugin } from './c
import { Awaitable, SernEventsMapping } from './utility';

type ToBeDecided = {
result: Record<string,unknown>;
state: Record<string,unknown>;
deps: Dependencies
}
export type Processed<T> = T & { name: string; description: string };

Expand Down Expand Up @@ -62,12 +63,12 @@ export interface CronEventCommand extends Module {

export interface ContextMenuUser extends Module {
type: CommandType.CtxUser;
execute: (ctx: UserContextMenuCommandInteraction) => Awaitable<unknown>;
execute: (ctx: UserContextMenuCommandInteraction, tbd: ToBeDecided) => Awaitable<unknown>;
}

export interface ContextMenuMsg extends Module {
type: CommandType.CtxMsg;
execute: (ctx: MessageContextMenuCommandInteraction) => Awaitable<unknown>;
execute: (ctx: MessageContextMenuCommandInteraction, tbd: ToBeDecided) => Awaitable<unknown>;
}

export interface ButtonCommand extends Module {
Expand Down Expand Up @@ -118,21 +119,21 @@ export interface DiscordEventCommand<T extends keyof ClientEvents = keyof Client
}
export interface TextCommand extends Module {
type: CommandType.Text;
execute: (ctx: Context) => Awaitable<unknown>;
execute: (ctx: Context, tbd: ToBeDecided) => Awaitable<unknown>;
}

export interface SlashCommand extends Module {
type: CommandType.Slash;
description: string;
options?: SernOptionsData[];
execute: (ctx: Context) => Awaitable<unknown>;
execute: (ctx: Context, tbd: ToBeDecided) => Awaitable<unknown>;
}

export interface BothCommand extends Module {
type: CommandType.Both;
description: string;
options?: SernOptionsData[];
execute: (ctx: Context) => Awaitable<unknown>;
execute: (ctx: Context, tbd: ToBeDecided) => Awaitable<unknown>;
}

export type EventModule = DiscordEventCommand | SernEventCommand | ExternalEventCommand | CronEventCommand;
Expand Down

0 comments on commit 735a9e3

Please sign in to comment.