console.clear, modularize name -> map

This commit is contained in:
jacoobes
2022-02-13 22:04:10 -06:00
parent ce22f854a1
commit 34e09bbbb5
2 changed files with 17 additions and 11 deletions

View File

@@ -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<T extends sEvent>(e : T, message: string) {
dayJS.extend(UTC);
dayJS.extend(Timezone);

View File

@@ -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<possibleOutput | undefined> {
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);
}
/**
*