mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
remove ctxHandler class in favor of functions
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user