From dad3042a644b0e47d01319f48eefe01632678cc3 Mon Sep 17 00:00:00 2001 From: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com> Date: Wed, 16 Feb 2022 22:57:40 +0300 Subject: [PATCH] feat: Improved TypeScript experince --- src/handler/sern.ts | 8 +++++++- src/handler/utilities/messageHelpers.ts | 1 + src/handler/utilities/preprocessors/args.ts | 1 + src/handler/utilities/readFile.ts | 6 ++---- src/types/handler.ts | 3 +-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 1d65856..11eb5c2 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -1,7 +1,12 @@ import * as Files from './utilities/readFile'; import type * as Utils from './utilities/preprocessors/args'; -import type { Arg, Context, Visibility, possibleOutput } from '../types/handler'; +import type { + possibleOutput, + Visibility, + Context, + Arg +} from '../types/handler'; import type { ApplicationCommandOptionData, @@ -23,6 +28,7 @@ export class Handler { private wrapper: Wrapper; /** + * * @constructor * @param {Wrapper} wrapper The data that is required to run sern handler */ diff --git a/src/handler/utilities/messageHelpers.ts b/src/handler/utilities/messageHelpers.ts index 8fb4132..05e9075 100644 --- a/src/handler/utilities/messageHelpers.ts +++ b/src/handler/utilities/messageHelpers.ts @@ -1,4 +1,5 @@ import type { Message } from 'discord.js'; + /** * Checks if the author of message is a bot or not * @param message The message to check diff --git a/src/handler/utilities/preprocessors/args.ts b/src/handler/utilities/preprocessors/args.ts index 722baba..d293609 100644 --- a/src/handler/utilities/preprocessors/args.ts +++ b/src/handler/utilities/preprocessors/args.ts @@ -21,6 +21,7 @@ export function parseInt(arg: string, onFailure: possibleOutput): ArgType; options: ApplicationCommandOptionData[]; @@ -14,7 +12,6 @@ export type CommandVal = { export const Commands = new Map(); export const Alias = new Map(); -// Courtesy of Townsy#0001 on Discord async function readPath(dir: string, arrayOfFiles: string[] = []): Promise { try { const files = readdirSync(dir); @@ -32,6 +29,7 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise n.substring(0, n.length - 3); /** + * * @param {Sern.Handler} handler an instance of Sern.Handler * @returns {Promise<{ name: string; mod: Sern.Module; absPath: string; }[]>} data from command files */ diff --git a/src/types/handler.ts b/src/types/handler.ts index ccd818a..07fca97 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -11,18 +11,17 @@ import type { import type * as Sern from '../handler/sern'; export type Visibility = 'private' | 'public'; + // Anything that can be sent in a `#send` or `#reply` export type possibleOutput = T | (MessagePayload & MessageOptions); export type Nullable = T | null; export type execute = Sern.Module['execute']; -// Thanks @cursorsdottsx export type ParseType = { [K in keyof T]: T[K] extends unknown ? [k: K, args: T[K]] : never; }[keyof T]; // A Sern.Module['delegate'] will carry a Context Parameter - export type Context = { message: Option; interaction: Option;