diff --git a/src/handler/sern/sern.ts b/src/handler/sern.ts similarity index 86% rename from src/handler/sern/sern.ts rename to src/handler/sern.ts index 0a4d9d6..3068e71 100644 --- a/src/handler/sern/sern.ts +++ b/src/handler/sern.ts @@ -1,10 +1,10 @@ -import type { Arg, Context, MessagePackage, Nullable, ParseType, Visibility } from "../../types/handler/handler"; -import { CommandType } from "../../types/handler/handler"; -import { Files } from "../utils/readFile" +import type { Arg, Context, Nullable, ParseType, Visibility } from "../types/handler/handler"; +import { Files } from "./utils/readFile" import type { ApplicationCommandOptionData, Awaitable, Client, CommandInteraction, CommandInteractionOptionResolver, Message} from "discord.js"; -import type { possibleOutput } from "../../types/handler/handler" +import type { possibleOutput } from "../types/handler/handler" import { Err, Ok, Result, Option, None, Some } from "ts-results"; -import type { Utils } from "../utils/preprocessors/args"; +import type { Utils } from "./utils/preprocessors/args"; +import { CtxHandler } from "./utils/ctxHandler"; @@ -18,7 +18,7 @@ export namespace Sern { this.wrapper = wrapper; this.wrapper.client .on("ready", async () => { - if (this.wrapper.init !== undefined) this.wrapper.init(); + if (this.wrapper.init !== undefined) this.wrapper.init(this); await Files.registerModules(this); @@ -116,13 +116,10 @@ export namespace Sern { readonly client : Client, readonly prefix: string, readonly commands : string - init? : () => void, + init? : (handler : Sern.Handler) => void, readonly privateServerId : string } - - - - export interface Module { + export interface Module { alias: string[], desc : string, visibility : Visibility, @@ -131,20 +128,10 @@ export namespace Sern { parse? : (ctx: Context, args: ParseType ) => Utils.ArgType } + export enum CommandType { + TEXT = 2, + SLASH = 4, + } } -class CtxHandler { - - static isBot(message: Message) { - return message.author.bot; - } - - static hasPrefix(message: Message, prefix: string) { - return (message.content.slice(0, prefix.length).toLowerCase().trim()) === prefix; - } - - static fmt(msg: Message, prefix: string) : string[] { - return msg.content.slice(prefix.length).trim().split(/\s+/g) - } -} \ No newline at end of file diff --git a/src/handler/utils/ctxHandler.ts b/src/handler/utils/ctxHandler.ts new file mode 100644 index 0000000..0fc67c8 --- /dev/null +++ b/src/handler/utils/ctxHandler.ts @@ -0,0 +1,16 @@ +import type { Message } from "discord.js"; + +export class CtxHandler { + + static isBot(message: Message) { + return message.author.bot; + } + + static hasPrefix(message: Message, prefix: string) { + return (message.content.slice(0, prefix.length).toLowerCase().trim()) === prefix; + } + + static fmt(msg: Message, prefix: string) : string[] { + return msg.content.slice(prefix.length).trim().split(/\s+/g) + } +} \ No newline at end of file diff --git a/src/handler/utils/readFile.ts b/src/handler/utils/readFile.ts index 7ba1633..2d874f8 100644 --- a/src/handler/utils/readFile.ts +++ b/src/handler/utils/readFile.ts @@ -1,7 +1,7 @@ import type { ApplicationCommandOptionData, CommandInteractionOption } from "discord.js"; import { readdirSync, statSync } from "fs"; import { basename, join } from "path"; -import type { Sern } from "../sern/sern"; +import type { Sern } from "../sern"; export namespace Files { export const Commands = new Map, options: ApplicationCommandOptionData[] }>(); @@ -26,8 +26,7 @@ export namespace Files { } export async function registerModules(handler : Sern.Handler) : Promise { - const commandDir = handler.commandDir, - client = handler.client; + const commandDir = handler.commandDir; Promise.all((await getCommands(commandDir)).map(async absPath => { return { name : basename(absPath), mod: ( await import(absPath)).default as Sern.Module, absPath } })).then( async modArr => { diff --git a/src/index.ts b/src/index.ts index 7f95b3c..d6edaee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ -import { Sern } from "./handler/sern/sern"; +import { Sern } from "./handler/sern"; import { Utils } from "./handler/utils/preprocessors/args" - -module.exports = { Sern, Utils }; -export { Sern, Utils }; \ No newline at end of file +import * as Types from "./types/handler/handler" +module.exports = { Sern, Utils, Types }; +export { Sern, Utils, Types }; \ No newline at end of file diff --git a/src/types/handler/handler.ts b/src/types/handler/handler.d.ts similarity index 60% rename from src/types/handler/handler.ts rename to src/types/handler/handler.d.ts index 1881df3..a547dee 100644 --- a/src/types/handler/handler.ts +++ b/src/types/handler/handler.d.ts @@ -1,24 +1,14 @@ -import type { Ok, Result, Option } from 'ts-results'; -import type { Awaitable, Client, CommandInteraction, CommandInteractionOptionResolver, Message, MessagePayload} from 'discord.js'; +import type { Option } from 'ts-results'; +import type { CommandInteraction, CommandInteractionOptionResolver, Message, MessagePayload} from 'discord.js'; import type { MessageOptions } from 'child_process'; -import type { Sern } from '../../handler/sern/sern'; +import type { Sern } from '../../handler/sern'; export type Visibility = "private" | "public" export type possibleOutput = string | MessagePayload & MessageOptions export type Nullable = T | null; -export type MessagePackage = { - message : Option, - interaction : Option, - prefix : string -} - export type delegate = Sern.Module["delegate"] -export enum CommandType { - TEXT = 2, - SLASH = 4, -} /// Thanks @cursorsdottsx export type ParseType = {