diff --git a/src/handler/structures/commands/command-creator.ts b/src/handler/structures/commands/command-creator.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/handler/structures/commands/command.ts b/src/handler/structures/commands/command.ts new file mode 100644 index 0000000..068f4ed --- /dev/null +++ b/src/handler/structures/commands/command.ts @@ -0,0 +1,26 @@ +import type { Awaitable } from "discord.js"; +import type { possibleOutput, Arg } from "../../../types/handler"; +import Context from "../context"; +import type * as Utils from '../../utilities/preprocessors/args'; +import { None, Ok } from "ts-results"; +import type { CommandType } from "../../sern"; + + +export abstract class Command { + + protected name : string | undefined; + protected _ctx : Context = new Context( None, None ); + protected commandType : CommandType; + + protected constructor ( + name : string | undefined, + commandType : CommandType + ) { + this.name = name; + this.commandType = commandType; + } + + abstract execute ( args: Ok ) : Awaitable; + abstract parse? (args: Arg) : Utils.ArgType; + private set ctx ( context: Context ) { this._ctx = context; } +} diff --git a/src/handler/utilities/readFile.ts b/src/handler/utilities/readFile.ts index 8bc6553..4e11be1 100644 --- a/src/handler/utilities/readFile.ts +++ b/src/handler/utilities/readFile.ts @@ -2,15 +2,16 @@ import type { ApplicationCommandOptionData } from 'discord.js'; import type Module from '../structures/module'; import { readdirSync, statSync } from 'fs'; -import { basename, join } from 'path'; +import { join } from 'path'; +import type { Command } from '../structures/commands/command'; export type CommandVal = { - mod: Module & { name : string }; + mod: Command; options: ApplicationCommandOptionData[]; }; export const Commands = new Map(); -export const Alias = new Map(); +export const Alias = new Map>(); // Courtesy @Townsy45 function readPath(dir: string, arrayOfFiles: string[] = []): string[] { @@ -31,20 +32,19 @@ export const fmtFileName = (n: string) => n.substring(0, n.length - 3); /** * - * @param {Sern.Handler} handler an instance of Sern.Handler - * @returns {Promise<{ name: string; mod: Module; absPath: string; }[]>} data from command files + * @param {commandsDir} Relative path to commands directory + * @returns {Promise<{ mod: Command; absPath: string; }[]>} data from command files */ export async function buildData(commandDir: string ): Promise< { - name: string; - mod: Module; + mod: Command; absPath: string; }[] > { return Promise.all( getCommands(commandDir).map( async (absPath) => { - return { name: basename(absPath), mod: (await import(absPath)).default as Module, absPath }; + return { mod: (await import(absPath)).default as Command, absPath }; }), ); }