diff --git a/src/core/contracts/module-manager.ts b/src/core/contracts/module-manager.ts index 2b53512..e123ec0 100644 --- a/src/core/contracts/module-manager.ts +++ b/src/core/contracts/module-manager.ts @@ -1,13 +1,15 @@ -import { CommandMeta, CommandModule, Module } from '../types/modules'; +import { CommandType } from '../structures'; +import { CommandMeta, CommandModule, CommandModuleDefs, Module } from '../types/modules'; /** * @since 2.0.0 */ export interface ModuleManager { get(id: string): string | undefined; - getMetadata(m: Module): CommandMeta; + getMetadata(m: Module): CommandMeta|undefined; setMetadata(m: Module, c: CommandMeta): void; set(id: string, path: string): void; getPublishableCommands(): Promise; + getByNameCommandType(name: string, commandType: T): Promise|undefined; remove(id: string): boolean; } diff --git a/src/core/structures/services/module-manager.ts b/src/core/structures/services/module-manager.ts index 53dfcf2..099394a 100644 --- a/src/core/structures/services/module-manager.ts +++ b/src/core/structures/services/module-manager.ts @@ -1,6 +1,8 @@ +import { uniqueId } from '../../../handler/id'; import { CoreModuleStore, ModuleManager } from '../../contracts'; import { importModule } from '../../module-loading'; -import { CommandMeta, CommandModule, Module } from '../../types/modules'; +import { CommandMeta, CommandModule, CommandModuleDefs, Module } from '../../types/modules'; +import { CommandType } from '../enums'; /** * @internal * @since 2.0.0 @@ -8,6 +10,15 @@ import { CommandMeta, CommandModule, Module } from '../../types/modules'; */ export class DefaultModuleManager implements ModuleManager { constructor(private moduleStore: CoreModuleStore) {} + + getByNameCommandType(name: string, commandType: T) { + const id = this.get(`${name}_${uniqueId(commandType)}`); + if(!id) { + return undefined; + } + return importModule(id); + } + setMetadata(m: Module, c: CommandMeta): void { this.moduleStore.metadata.set(m, c); } diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 0fca62d..8295c48 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -38,7 +38,7 @@ export function init(wrapper: Wrapper) { startReadyEvent(dependencies, getFullPathTree(wrapper.commands, mode)) .add(() => { const time = ((performance.now() - startTime) / 1000).toFixed(2); - dependencies[0].emit('modulesLoaded'); + dependencies[0].emit('modulesLoaded' ); logger?.info({ message: `sern: registered all modules in ${time} s`, }); diff --git a/src/shared.ts b/src/shared.ts index be25896..67b23f8 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -21,7 +21,7 @@ export interface SernEventsMapping { 'module.activate': [Payload]; error: [Payload]; warning: [Payload]; - 'modulesLoaded' : []; + 'modulesLoaded': [never?]; } export type Awaitable = PromiseLike | T;