From 2e5942cb11092c4a8f5a2c590029005c5fea1066 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Mon, 31 Jan 2022 23:06:02 -0600 Subject: [PATCH] adding slash command map --- src/handler/sern/sern.ts | 12 ++++++++++-- src/handler/utils/readFile.ts | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/handler/sern/sern.ts b/src/handler/sern/sern.ts index c102e97..f44409f 100644 --- a/src/handler/sern/sern.ts +++ b/src/handler/sern/sern.ts @@ -20,7 +20,9 @@ export namespace Sern { this.wrapper.client .on("ready", async () => { if (this.wrapper.init !== undefined) this.wrapper.init(); - Files.registerModules(this) + await Files.registerModules(this); + + }) .on("messageCreate", async message => { @@ -36,10 +38,16 @@ export namespace Sern { .on("interactionCreate", async interaction => { if (!interaction.isCommand()) return; - const module = Files.Commands.get(interaction.commandName); + const module = Files.Slash.get(interaction.commandName); + await this.interactionResult(module); + }) } + private async interactionResult(module: Sern.Module | undefined) { + + } + private async commandResult(module: Sern.Module | undefined, message: Message) : Promise { if (module === undefined) return "Unknown Command"; if (module.visibility === "private" && message.guildId !== this.privateServerId) { diff --git a/src/handler/utils/readFile.ts b/src/handler/utils/readFile.ts index cc3488a..eb6a410 100644 --- a/src/handler/utils/readFile.ts +++ b/src/handler/utils/readFile.ts @@ -3,8 +3,9 @@ import { basename, join } from "path"; import type { Sern } from "../sern/sern"; export namespace Files { - export const Commands = new Map >() - export const Alias = new Map>() + export const Slash = new Map>(); + export const Commands = new Map>(); + export const Alias = new Map>(); //courtesy of Townsy#0001 on Discord async function readPath(dir: string, arrayOfFiles: string[] = []): Promise { @@ -31,7 +32,16 @@ export namespace Files { return { name : basename(absPath), mod: ( await import(absPath)).default as Sern.Module } })).then( modArr => { for ( const { name, mod } of modArr) { - Commands.set(name.substring(0, name.length-3), mod); + switch (mod.type) { + case 2 : Commands.set(name.substring(0, name.length-3), mod); break; + case 4 : Slash.set(name.substring(0, name.length - 3), mod); break; + case 6 : { + Commands.set(name.substring(0, name.length-3), mod); + Slash.set(name.substring(0, name.length - 3), mod); + } break; + default : throw Error(`${name}.js is not a valid module type.`); + } + if(mod.alias.length > 0) { for( const alias of mod.alias) { Alias.set(alias, mod)