From 92dc63abee5a22d93c24daf7e124f6f419436ecc Mon Sep 17 00:00:00 2001 From: jacoobes Date: Thu, 10 Feb 2022 10:43:33 -0600 Subject: [PATCH] remove ctxHandler class in favor of functions --- src/handler/sern.ts | 8 ++++---- src/handler/utils/{ctxHandler.ts => messageHelpers.ts} | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) rename src/handler/utils/{ctxHandler.ts => messageHelpers.ts} (58%) diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 584e2d5..4c23a1b 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -4,7 +4,7 @@ import type { ApplicationCommandOptionData, Awaitable, Client, CommandInteracti import type { possibleOutput } from "../types/handler" import { Ok, Result, None, Some } from "ts-results"; import type * as Utils from "./utils/preprocessors/args"; -import { CtxHandler } from "./utils/ctxHandler"; +import { isBot, hasPrefix, fmt } from "./utils/messageHelpers"; /** @@ -26,14 +26,14 @@ export class Handler { .on("ready", async () => { Files.buildData(this) .then(this.registerModules); - if (this.wrapper.init !== undefined) this.wrapper.init(this); + if (wrapper.init !== undefined) wrapper.init(this); }) .on("messageCreate", async message => { - if (CtxHandler.isBot(message) || !CtxHandler.hasPrefix(message, this.prefix)) return; + if (isBot(message) || !hasPrefix(message, this.prefix)) return; if(message.channel.type === "DM") return; - const tryFmt = CtxHandler.fmt(message, this.prefix) + const tryFmt = fmt(message, this.prefix) const commandName = tryFmt.shift()!; const module = Files.Commands.get(commandName) ?? Files.Alias.get(commandName) if (module === undefined) { diff --git a/src/handler/utils/ctxHandler.ts b/src/handler/utils/messageHelpers.ts similarity index 58% rename from src/handler/utils/ctxHandler.ts rename to src/handler/utils/messageHelpers.ts index 53bc617..de63956 100644 --- a/src/handler/utils/ctxHandler.ts +++ b/src/handler/utils/messageHelpers.ts @@ -1,16 +1,14 @@ import type { Message } from "discord.js"; -export class CtxHandler { - static isBot(message: Message) { + export function isBot(message: Message) { return message.author.bot; } - static hasPrefix(message: Message, prefix: string) { + export function hasPrefix(message: Message, prefix: string) { return (message.content.slice(0, prefix.length).toLowerCase().trim()) === prefix; } - static fmt(msg: Message, prefix: string): string[] { + export function fmt(msg: Message, prefix: string): string[] { return msg.content.slice(prefix.length).trim().split(/\s+/g) - } -} \ No newline at end of file + } \ No newline at end of file