mirror of
https://github.com/sern-handler/handler
synced 2026-06-21 07:12:15 +00:00
Rnamed some directories & format code
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Err, Ok, Result } from 'ts-results';
|
||||
import type { possibleOutput } from '../../../types/handler';
|
||||
import type { possibleOutput } from '../../../Types/Handler';
|
||||
|
||||
/**
|
||||
* Wrapper type taking `Ok(T)` or `Err(possibleOutput)` e.g `Result<T, possibleOutput`
|
||||
@@ -21,7 +21,6 @@ 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
|
||||
@@ -41,6 +40,7 @@ export function parseBool(
|
||||
): ArgType<boolean> {
|
||||
if (arg.match(regexes.yesRegex)) return Ok(true);
|
||||
if (arg.match(regexes.noRegex)) return Ok(false);
|
||||
|
||||
return Err(onFailure);
|
||||
}
|
||||
|
||||
@@ -73,5 +73,5 @@ export function toPositiveInt(arg: string, onFailure: possibleOutput): ArgType<n
|
||||
* @returns {ArgType<number>}
|
||||
*/
|
||||
export function toNegativeInt(arg: string, onFailure: possibleOutput): ArgType<number> {
|
||||
return parseInt(arg, onFailure).andThen(num => Ok(num > 0 ? -num : num))
|
||||
return parseInt(arg, onFailure).andThen(num => Ok(num > 0 ? -num : num));
|
||||
}
|
||||
@@ -23,15 +23,15 @@ 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);
|
||||
for (const file of files) {
|
||||
if (statSync(dir + '/' + file).isDirectory())
|
||||
await readPath(dir + '/' + file, arrayOfFiles)
|
||||
else
|
||||
arrayOfFiles.push(join(dir, '/', file));
|
||||
const files = readdirSync(dir);
|
||||
for (const file of files) {
|
||||
if (statSync(dir + '/' + file).isDirectory())
|
||||
await readPath(dir + '/' + file, arrayOfFiles)
|
||||
else
|
||||
arrayOfFiles.push(join(dir, '/', file));
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
throw err;
|
||||
}
|
||||
|
||||
return arrayOfFiles;
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as Files from './utils/readFile'
|
||||
import type * as Utils from './utils/preprocessors/args';
|
||||
import * as Files from './Utilities/readFile';
|
||||
import type * as Utils from './Utilities/Preprocessors/args';
|
||||
|
||||
import type {
|
||||
Arg,
|
||||
Context,
|
||||
Visibility,
|
||||
possibleOutput
|
||||
} from '../types/handler';
|
||||
Arg,
|
||||
Context,
|
||||
Visibility,
|
||||
possibleOutput
|
||||
} from '../Types/Handler';
|
||||
|
||||
import type {
|
||||
ApplicationCommandOptionData,
|
||||
@@ -17,7 +17,7 @@ import type {
|
||||
} from 'discord.js';
|
||||
|
||||
import { Ok, Result, None, Some } from 'ts-results';
|
||||
import { isBot, hasPrefix, fmt } from './utils/messageHelpers';
|
||||
import { isBot, hasPrefix, fmt } from './Utilities/messageHelpers';
|
||||
|
||||
|
||||
/**
|
||||
@@ -29,14 +29,13 @@ export class Handler {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Wrapper} wrapper Some data that is required to run sern handler
|
||||
* @param {Wrapper} wrapper The data that is required to run sern handler
|
||||
*/
|
||||
|
||||
constructor(
|
||||
wrapper: Wrapper,
|
||||
) {
|
||||
this.wrapper = wrapper;
|
||||
|
||||
this.client
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as Sern from './handler/sern';
|
||||
import * as Utils from './handler/utils/preprocessors/args';
|
||||
import * as Types from './types/handler';
|
||||
import * as Sern from './Handler/sern';
|
||||
import * as Utils from './Handler/Utilities/Preprocessors/args';
|
||||
import * as Types from './Types/Handler';
|
||||
|
||||
module.exports = { Sern, Utils, Types };
|
||||
export { Sern, Utils, Types };
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
MessageOptions
|
||||
} from 'discord.js';
|
||||
|
||||
import type * as Sern from '../handler/sern';
|
||||
import type * as Sern from '../Handler/sern';
|
||||
|
||||
export type Visibility = 'private' | 'public';
|
||||
|
||||
@@ -19,15 +19,17 @@ export type delegate = Sern.Module<unknown>['delegate'];
|
||||
|
||||
// Thanks @cursorsdottsx
|
||||
export type ParseType<T> = {
|
||||
[K in keyof T]: T[K] extends unknown ? [k: K, args: T[K]] : never;
|
||||
[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>
|
||||
}
|
||||
export type Arg = ParseType<{text : string, slash : SlashOptions}>
|
||||
|
||||
export type Arg = ParseType<{ text: string, slash: SlashOptions }>;
|
||||
|
||||
// TypeAlias for interaction.options
|
||||
export type SlashOptions = Omit<CommandInteractionOptionResolver, 'getMessage' | 'getFocused'>;
|
||||
|
||||
Reference in New Issue
Block a user