remove ctxHandler class in favor of functions

This commit is contained in:
jacoobes
2022-02-10 10:43:33 -06:00
parent 35d6c27893
commit 92dc63abee
2 changed files with 8 additions and 10 deletions

View File

@@ -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) {

View File

@@ -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)
}
}
}