From 34e09bbbb526f529c64fca29935ae6d3276b55d9 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Sun, 13 Feb 2022 22:04:10 -0600 Subject: [PATCH] console.clear, modularize name -> map --- src/handler/logger.ts | 6 ++++-- src/handler/sern.ts | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/handler/logger.ts b/src/handler/logger.ts index 5ead7f0..b5343dd 100644 --- a/src/handler/logger.ts +++ b/src/handler/logger.ts @@ -2,7 +2,7 @@ import dayJS from 'dayjs'; import Timezone from 'dayjs/plugin/timezone'; import UTC from 'dayjs/plugin/timezone'; -enum sEvent { +enum sEvent { GLOBAL_SLASH, LOCAL_SLASH, DM, @@ -11,7 +11,9 @@ enum sEvent { } export default class Logger { - + + public clear() { console.clear() } + public log(e : T, message: string) { dayJS.extend(UTC); dayJS.extend(Timezone); diff --git a/src/handler/sern.ts b/src/handler/sern.ts index ebf0a46..028a8fa 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -16,9 +16,8 @@ import type { Message } from 'discord.js'; -import { Ok, Result, None, Some } from 'ts-results'; +import { Ok, Result, None, Some, Option } from 'ts-results'; import { isBot, hasPrefix, fmt } from './utilities/messageHelpers'; -import Logger from './logger'; /** * @class @@ -47,16 +46,14 @@ export class Handler { Files.buildData(this) .then(data => this.registerModules(data)) if (wrapper.init !== undefined) wrapper.init(this); - new Logger().tableRam() }) .on('messageCreate', async (message: Message) => { if (isBot(message) || !hasPrefix(message, this.prefix)) return; if (message.channel.type === 'DM') return; // TODO: Handle dms - const tryFmt = fmt(message, this.prefix) - const commandName = tryFmt.shift()!; - const module = Files.Commands.get(commandName) ?? Files.Alias.get(commandName) + const tryFmt = fmt(message, this.prefix); + const module = this.findCommand(tryFmt.shift()!); if (module === undefined) { message.channel.send('Unknown legacy command') return; @@ -89,9 +86,8 @@ export class Handler { interaction: CommandInteraction): Promise { if (module === undefined) return 'Unknown slash command!'; - const name = Array.from(Files.Commands.keys()).find(it => it === interaction.commandName); - if (name === undefined) return `Could not find ${interaction.commandName} command!`; - + const name = this.findCommand(interaction.commandName); + if (name === undefined) `${interaction.commandName} is not a valid command!`; if (module.mod.type < CommandType.SLASH) return 'This is not a slash command'; const context = { message: None, interaction: Some(interaction) } @@ -177,6 +173,14 @@ export class Handler { } } } + /** + * + * @param {string} name name of possible command + * @returns {Files.CommandVal | undefined} + */ + private findCommand(name : string) : Files.CommandVal | undefined { + return Files.Commands.get(name) ?? Files.Alias.get(name); + } /** *