mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
fix: typings for options- have access to all properties now
This commit is contained in:
@@ -22,7 +22,6 @@ export type {
|
||||
ExternalEventCommand,
|
||||
CommandModuleDefs,
|
||||
EventModuleDefs,
|
||||
BaseOptions,
|
||||
SernAutocompleteData,
|
||||
SernOptionsData,
|
||||
} from './types/modules';
|
||||
|
||||
@@ -54,26 +54,39 @@ export function filename(path: string) {
|
||||
return fmtFileName(basename(path));
|
||||
}
|
||||
|
||||
function createSkipCondition(base: string) {
|
||||
const validExtensions = ['.js', '.cjs', '.mts', '.mjs', 'cts'];
|
||||
return ( type: 'file' | 'directory') => {
|
||||
if(type === 'file') {
|
||||
return fmtFileName(base)[0] === '!'
|
||||
|| !validExtensions.includes(extname(base));
|
||||
}
|
||||
return base[0] === '!';
|
||||
}
|
||||
}
|
||||
async function deriveFileInfo(dir: string, file: string) {
|
||||
const fullPath = join(dir, file);
|
||||
return {
|
||||
fullPath,
|
||||
fileStats: await stat(fullPath),
|
||||
base: basename(file)
|
||||
}
|
||||
}
|
||||
async function* readPaths(dir: string, shouldDebug: boolean): AsyncGenerator<string> {
|
||||
try {
|
||||
const files = await readdir(dir);
|
||||
for (const file of files) {
|
||||
const fullPath = join(dir, file);
|
||||
const fileStats = await stat(fullPath);
|
||||
const base = basename(file);
|
||||
const { fullPath, fileStats, base } = await deriveFileInfo(dir, file);
|
||||
const isSkippable = createSkipCondition(base);
|
||||
if (fileStats.isDirectory()) {
|
||||
//Todo: refactor so that i dont repeat myself for files (line 71)
|
||||
if (base.endsWith('-ignore!')) {
|
||||
if (isSkippable('directory')) {
|
||||
if (shouldDebug) console.info(`ignored directory: ${fullPath}`);
|
||||
} else {
|
||||
yield* readPaths(fullPath, shouldDebug);
|
||||
}
|
||||
} else {
|
||||
const isSkippable =
|
||||
fmtFileName(base).endsWith('-ignore!') ||
|
||||
!['.js', '.cjs', '.mts', '.mjs'].includes(extname(base));
|
||||
|
||||
if (isSkippable) {
|
||||
if (isSkippable('file')) {
|
||||
if (shouldDebug) console.info(`ignored: ${fullPath}`);
|
||||
} else {
|
||||
/// #if MODE === 'esm'
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type {
|
||||
APIApplicationCommandBasicOption,
|
||||
APIApplicationCommandOptionBase,
|
||||
APIApplicationCommandOptionChoice,
|
||||
APIApplicationCommandRoleOption,
|
||||
ApplicationCommandAttachmentOption,
|
||||
ApplicationCommandChannelOptionData,
|
||||
ApplicationCommandChoicesData,
|
||||
@@ -9,6 +13,7 @@ import type {
|
||||
ApplicationCommandSubCommandData,
|
||||
ApplicationCommandSubGroupData,
|
||||
BaseApplicationCommandOptionsData,
|
||||
CommandOptionNonChoiceResolvableType,
|
||||
} from 'discord.js';
|
||||
import {
|
||||
AutocompleteInteraction,
|
||||
@@ -202,32 +207,22 @@ export type InputCommand = {
|
||||
[T in CommandType]: CommandModuleNoPlugins[T] & { plugins?: AnyCommandPlugin[] };
|
||||
}[CommandType];
|
||||
|
||||
|
||||
/**
|
||||
* Type that replaces autocomplete with {@link SernAutocompleteData}
|
||||
*/
|
||||
export type BaseOptions =
|
||||
| ApplicationCommandChoicesData
|
||||
| ApplicationCommandNonOptionsData
|
||||
| ApplicationCommandChannelOptionData
|
||||
| ApplicationCommandNumericOptionData
|
||||
| ApplicationCommandAttachmentOption
|
||||
export type SernOptionsData =
|
||||
| SernSubCommandData
|
||||
| SernSubCommandGroupData
|
||||
| APIApplicationCommandBasicOption
|
||||
| SernAutocompleteData;
|
||||
|
||||
export interface SernSubCommandData extends BaseApplicationCommandOptionsData {
|
||||
export interface SernSubCommandData extends APIApplicationCommandOptionBase<ApplicationCommandOptionType.Subcommand> {
|
||||
type: ApplicationCommandOptionType.Subcommand;
|
||||
required?: never;
|
||||
options?: BaseOptions[];
|
||||
options?: SernOptionsData[];
|
||||
}
|
||||
|
||||
export interface SernSubCommandGroupData extends BaseApplicationCommandOptionsData {
|
||||
type: ApplicationCommandOptionType.SubcommandGroup;
|
||||
required?: never;
|
||||
options?: SernSubCommandData[];
|
||||
}
|
||||
|
||||
export type SernOptionsData<U extends ApplicationCommandOptionData = ApplicationCommandOptionData> =
|
||||
U extends ApplicationCommandSubCommandData
|
||||
? SernSubCommandData
|
||||
: U extends ApplicationCommandSubGroupData
|
||||
? SernSubCommandGroupData
|
||||
: BaseOptions;
|
||||
|
||||
Reference in New Issue
Block a user