mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: Improved TypeScript experince
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,6 +21,7 @@ export function parseInt(arg: string, onFailure: possibleOutput): ArgType<number
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} arg - command arguments
|
||||
* @param {possibleOutput} onFailure - If cannot parse `arg` into boolean.
|
||||
* @param { {yesRegex: RegExp, noRegex: RegExp} } regexes - default regexes: yes : `/^(?:y(?:es)?|👍)$/i`, no : /^(?:n(?:o)?|👎)$/i
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import type { ApplicationCommandOptionData } from 'discord.js';
|
||||
import type * as Sern from '../sern';
|
||||
|
||||
import { readdirSync, statSync } from 'fs';
|
||||
|
||||
import { basename, join } from 'path';
|
||||
|
||||
import type * as Sern from '../sern';
|
||||
|
||||
export type CommandVal = {
|
||||
mod: Sern.Module<unknown>;
|
||||
options: ApplicationCommandOptionData[];
|
||||
@@ -14,7 +12,6 @@ export type CommandVal = {
|
||||
export const Commands = new Map<string, CommandVal>();
|
||||
export const Alias = new Map<string, CommandVal>();
|
||||
|
||||
// Courtesy of Townsy#0001 on Discord
|
||||
async function readPath(dir: string, arrayOfFiles: string[] = []): Promise<string[]> {
|
||||
try {
|
||||
const files = readdirSync(dir);
|
||||
@@ -32,6 +29,7 @@ async function readPath(dir: string, arrayOfFiles: string[] = []): Promise<strin
|
||||
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: Sern.Module<unknown>; absPath: string; }[]>} data from command files
|
||||
*/
|
||||
|
||||
@@ -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 `<TextChannel>#send` or `<CommandInteraction>#reply`
|
||||
export type possibleOutput<T = string> = T | (MessagePayload & MessageOptions);
|
||||
export type Nullable<T> = T | null;
|
||||
export type execute = Sern.Module<unknown>['execute'];
|
||||
|
||||
// Thanks @cursorsdottsx
|
||||
export type ParseType<T> = {
|
||||
[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<Message>;
|
||||
interaction: Option<CommandInteraction>;
|
||||
|
||||
Reference in New Issue
Block a user