From dfb34b99e325c98dbf0f701ba0fb51c39e175eaa Mon Sep 17 00:00:00 2001 From: jacoobes Date: Sun, 13 Feb 2022 01:17:33 -0600 Subject: [PATCH] testing cmds now have module prop, not on filename --- src/handler/sern.ts | 13 +++++++------ src/handler/utils/readFile.ts | 8 +------- src/types/handler.ts | 1 + 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/handler/sern.ts b/src/handler/sern.ts index eda48a4..c1551dd 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -64,7 +64,7 @@ export class Handler { const cmdResult = (await this.commandResult(module, message, tryFmt.join(' '))) if (cmdResult === undefined) return; - message.channel.send(cmdResult) + message.channel.send(cmdResult); }) @@ -116,7 +116,7 @@ export class Handler { if (module.mod.visibility === 'private') { const checkIsTestServer = this.privateServers.find(({ id }) => id === message.guildId!)?.test; if (checkIsTestServer === undefined) return 'This command has the private modifier but is not registered under Handler#privateServers'; - if (checkIsTestServer !== module.testOnly) { + if (checkIsTestServer !== module.mod.test) { const msg = `This command is only available on test servers.`; // TODO: Customizable private message return msg; @@ -144,13 +144,13 @@ export class Handler { }[] ) { for await (const { name, mod, absPath } of modArr) { - const { cmdName, testOnly } = Files.fmtFileName(name); + const cmdName = Files.fmtFileName(name); switch (mod.type) { - case 1: Files.Commands.set(cmdName, { mod, options: [], testOnly }); break; + case 1: Files.Commands.set(cmdName, { mod, options: [] }); break; case 2: case (1 | 2): { const options = ((await import(absPath)).options as ApplicationCommandOptionData[]) - Files.Commands.set(cmdName, { mod, options: options ?? [], testOnly }); + Files.Commands.set(cmdName, { mod, options: options ?? [] }); switch (mod.visibility) { case 'private': { // Loading guild slash commands only @@ -172,7 +172,7 @@ export class Handler { if (mod.alias.length > 0) { for (const alias of mod.alias) { - Files.Alias.set(alias, { mod, options: [], testOnly }) + Files.Alias.set(alias, { mod, options: [] }) } } } @@ -270,6 +270,7 @@ export interface Module { desc: string, visibility: Visibility, type: CommandType, + test : boolean, delegate: (eventParams: Context, args: Ok) => Awaitable | void> parse?: (ctx: Context, args: Arg) => Utils.ArgType } diff --git a/src/handler/utils/readFile.ts b/src/handler/utils/readFile.ts index fb8e611..7a5a468 100644 --- a/src/handler/utils/readFile.ts +++ b/src/handler/utils/readFile.ts @@ -15,7 +15,6 @@ import type * as Sern from '../sern'; export type CommandVal = { mod: Sern.Module, options: ApplicationCommandOptionData[], - testOnly: boolean } export const Commands = new Map(); export const Alias = new Map(); @@ -37,12 +36,7 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise { - const endsW = n.toLowerCase().endsWith('-test.js') || n.toLowerCase().endsWith('-test.ts'); - return endsW - ? { cmdName: n.substring(0, n.length - 8), testOnly: true } - : { cmdName: n.substring(0, n.length - 3), testOnly: false }; -}; +export const fmtFileName = (n: string) => n.substring(0, n.length - 3); /** * @param {Sern.Handler} handler an instance of Sern.Handler diff --git a/src/types/handler.ts b/src/types/handler.ts index 9bfa72f..7193500 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -27,6 +27,7 @@ export type Context = { message: Option, interaction: Option } +// `string` | `SlashOptions`, narrow down your type by checking `text` | `slash` export type Arg = ParseType<{text : string, slash : SlashOptions}> // TypeAlias for interaction.options