diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index 33ae374..bacf73b 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -27,7 +27,6 @@ export async function defaultModuleLoader(absPath: string): Mo module = module.getInstance(); } //todo readd class modules - assert.ok(module.type > 0 && module.type < 1<<10, 'Found a module that does not have a valid type'); return Ok({ module, absPath }); } diff --git a/src/core/structures/module-store.ts b/src/core/structures/module-store.ts index f2a60fc..e8cb7ee 100644 --- a/src/core/structures/module-store.ts +++ b/src/core/structures/module-store.ts @@ -1,10 +1,12 @@ import { CoreModuleStore } from '../contracts'; +import { Module, CommandMeta } from '../types/modules'; /* * @internal * Version 4.0.0 will internalize this api. Please refrain from using ModuleStore! - * For interacting with ModuleStore, use CoreModuleStore contract. + * For interacting with modules, use the ModuleManager instead. */ export class ModuleStore implements CoreModuleStore { + metadata = new WeakMap(); commands = new Map(); } diff --git a/src/handler/commands.ts b/src/handler/commands.ts index 2f388c2..d645b50 100644 --- a/src/handler/commands.ts +++ b/src/handler/commands.ts @@ -1,6 +1,6 @@ import { ClientEvents } from 'discord.js'; import { CommandType, EventType, PluginType } from '../core/structures'; -import { AnyCommandPlugin, AnyEventPlugin, CommandArgs, EventArgs } from '../core/types/plugins'; +import { AnyCommandPlugin, AnyEventPlugin, CommandArgs, ControlPlugin, EventArgs } from '../core/types/plugins'; import { CommandModule, EventModule, InputCommand, InputEvent } from '../core/types/modules'; import { partitionPlugins } from '../core/functions'; import { Awaitable } from '../shared'; @@ -62,13 +62,20 @@ export function discordEvent(mod: { export abstract class CommandExecutable { abstract type: Type; plugins?: AnyCommandPlugin[]; + onEvent?: ControlPlugin[] private static _instance : CommandModule; static readonly [clazz] = true; + constructor() { - const [onEvent, plugins] = partitionPlugins(this.plugins); - this.plugins = plugins as AnyCommandPlugin[]; - Reflect.set(this, 'onEvent', onEvent); + if(this.onEvent) { + console.warn('Put control plugins in `onEvent` into the `plugins` field, as it\'s automatically handled in v3.'); + } else { + const [onEvent, plugins] = partitionPlugins(this.plugins); + this.plugins = plugins as AnyCommandPlugin[]; + Reflect.set(this, 'onEvent', onEvent); + } } + static getInstance() { if (!CommandExecutable._instance) { //@ts-ignore @@ -76,6 +83,7 @@ export abstract class CommandExecutable { } return CommandExecutable._instance; } + abstract execute(...args: CommandArgs) : Awaitable } @@ -88,11 +96,16 @@ export abstract class EventExecutable { abstract type: Type; plugins?: AnyEventPlugin[]; static readonly [clazz] = true; + onEvent?: ControlPlugin[] private static _instance : EventModule; constructor() { - const [onEvent, plugins] = partitionPlugins(this.plugins); - this.plugins = plugins as AnyEventPlugin[]; - Reflect.set(this, 'onEvent', onEvent); + if(this.onEvent) { + console.warn('Put control plugins in `onEvent` into the `plugins` field, as it\'s automatically handled in v3.'); + } else { + const [onEvent, plugins] = partitionPlugins(this.plugins); + this.plugins = plugins as AnyEventPlugin[]; + Reflect.set(this, 'onEvent', onEvent); + } } static getInstance() { if (!EventExecutable._instance) { diff --git a/src/handler/events/ready.ts b/src/handler/events/ready.ts index 5e476f0..969bbc9 100644 --- a/src/handler/events/ready.ts +++ b/src/handler/events/ready.ts @@ -7,6 +7,7 @@ import { SernEmitter } from '../../core'; import { Processed, DependencyList } from '../types'; import { buildModules, callInitPlugins } from './generic'; import { AnyModule } from '../../core/types/modules'; +import * as assert from 'node:assert'; export function startReadyEvent( [sEmitter,,, moduleManager, client]: DependencyList, @@ -41,6 +42,7 @@ function registerModule>( const { id, fullPath } = manager.getMetadata(module); + assert.ok(module.type > 0 && module.type < 1<<10, `Found ${module}, which does not have a valid type`); if (module.type === CommandType.Both || module.type === CommandType.Text ) { diff --git a/src/handler/sern.ts b/src/handler/sern.ts index ab3752d..7ffe9bc 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -18,9 +18,6 @@ import { Wrapper } from '../shared'; * Sern.init({ * commands: 'dist/commands', * events: 'dist/events', - * containerConfig : { - * get: useContainer - * } * }) * ``` */ @@ -32,7 +29,7 @@ export function init(wrapper: Wrapper) { const dependencies = useDependencies(); const logger = dependencies[2]; const errorHandler = dependencies[1]; - const mode = debugModuleLoading(process.env.MODE); + const mode = debugModuleLoading(wrapper.mode ?? process.env.MODE); if (wrapper.events !== undefined) { makeEventsHandler(