mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 13:06:08 +00:00
feat: extraProps
This commit is contained in:
parent
db6134cf95
commit
f3b8e3b67d
@ -2,7 +2,14 @@ import { join } from 'node:path';
|
||||
import { ApiHandler, Router } from '../api';
|
||||
import type { Adapter } from '../cache';
|
||||
import { Cache, MemoryAdapter } from '../cache';
|
||||
import type { Command, CommandContext, OnOptionsReturnObject, RegisteredMiddlewares, UsingClient } from '../commands';
|
||||
import type {
|
||||
Command,
|
||||
CommandContext,
|
||||
ExtraProps,
|
||||
OnOptionsReturnObject,
|
||||
RegisteredMiddlewares,
|
||||
UsingClient,
|
||||
} from '../commands';
|
||||
import { IgnoreCommand, type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
|
||||
import { CommandHandler } from '../commands/handler';
|
||||
import {
|
||||
@ -384,6 +391,7 @@ export interface BaseClientOptions {
|
||||
onMiddlewaresError?: Command['onMiddlewaresError'];
|
||||
onOptionsError?: Command['onOptionsError'];
|
||||
onAfterRun?: Command['onAfterRun'];
|
||||
props?: ExtraProps;
|
||||
};
|
||||
};
|
||||
components?: {
|
||||
|
@ -24,6 +24,7 @@ import type { OptionResolver } from '../optionresolver';
|
||||
import type { CommandContext } from './chatcontext';
|
||||
import type {
|
||||
DefaultLocale,
|
||||
ExtraProps,
|
||||
IgnoreCommand,
|
||||
OKFunction,
|
||||
OnOptionsReturnObject,
|
||||
@ -138,6 +139,8 @@ export class BaseCommand {
|
||||
|
||||
aliases?: string[];
|
||||
|
||||
props: ExtraProps = {};
|
||||
|
||||
/** @internal */
|
||||
async __runOptions(
|
||||
ctx: CommandContext<{}, never>,
|
||||
|
@ -7,7 +7,7 @@ import type {
|
||||
import { magicImport, type PermissionStrings } from '../../common';
|
||||
import type { RegisteredMiddlewares } from '../decorators';
|
||||
import type { MenuCommandContext } from './menucontext';
|
||||
import type { UsingClient } from './shared';
|
||||
import type { ExtraProps, UsingClient } from './shared';
|
||||
|
||||
export abstract class ContextMenuCommand {
|
||||
middlewares: (keyof RegisteredMiddlewares)[] = [];
|
||||
@ -28,6 +28,8 @@ export abstract class ContextMenuCommand {
|
||||
name_localizations?: Partial<Record<LocaleString, string>>;
|
||||
description_localizations?: Partial<Record<LocaleString, string>>;
|
||||
|
||||
props: ExtraProps = {};
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
|
@ -13,6 +13,7 @@ export type InferWithPrefix = InternalOptions extends { withPrefix: infer P } ?
|
||||
export interface GlobalMetadata {}
|
||||
export interface DefaultLocale {}
|
||||
export interface ExtendContext {}
|
||||
export interface ExtraProps {}
|
||||
export interface UsingClient extends BaseClient {}
|
||||
export type ParseClient<T extends BaseClient> = T;
|
||||
export interface InternalOptions {}
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
} from 'discord-api-types/v10';
|
||||
import type { FlatObjectKeys, PermissionStrings } from '../common';
|
||||
import type { CommandOption, OptionsRecord, SubCommand } from './applications/chat';
|
||||
import type { DefaultLocale, IgnoreCommand, MiddlewareContext } from './applications/shared';
|
||||
import type { DefaultLocale, ExtraProps, IgnoreCommand, MiddlewareContext } from './applications/shared';
|
||||
|
||||
export interface RegisteredMiddlewares {}
|
||||
|
||||
@ -23,6 +23,7 @@ type DeclareOptions =
|
||||
contexts?: (keyof typeof InteractionContextType)[];
|
||||
ignore?: IgnoreCommand;
|
||||
aliases?: string[];
|
||||
props?: ExtraProps;
|
||||
}
|
||||
| (Omit<
|
||||
{
|
||||
@ -34,6 +35,7 @@ type DeclareOptions =
|
||||
nsfw?: boolean;
|
||||
integrationTypes?: (keyof typeof ApplicationIntegrationType)[];
|
||||
contexts?: (keyof typeof InteractionContextType)[];
|
||||
props?: ExtraProps;
|
||||
},
|
||||
'type' | 'description'
|
||||
> & {
|
||||
@ -157,6 +159,7 @@ export function Declare(declare: DeclareOptions) {
|
||||
class extends target {
|
||||
name = declare.name;
|
||||
nsfw = declare.nsfw;
|
||||
props = declare.props;
|
||||
contexts =
|
||||
declare.contexts?.map(i => InteractionContextType[i]) ??
|
||||
Object.values(InteractionContextType).filter(x => typeof x === 'number');
|
||||
|
@ -214,6 +214,8 @@ export class CommandHandler extends BaseHandler {
|
||||
commandInstance.onRunError ??= client.options?.commands?.defaults?.onRunError;
|
||||
commandInstance.__filePath = command.path;
|
||||
commandInstance.options ??= [] as NonNullable<Command['options']>;
|
||||
console.log(commandInstance, commandInstance.props);
|
||||
commandInstance.props ??= client.options.commands?.defaults?.props ?? {};
|
||||
if (commandInstance.__autoload) {
|
||||
//@AutoLoad
|
||||
const options = await this.getFiles(dirname(command.path));
|
||||
@ -239,35 +241,36 @@ export class CommandHandler extends BaseHandler {
|
||||
option.onMiddlewaresError =
|
||||
option.onMiddlewaresError?.bind(option) ??
|
||||
commandInstance.onMiddlewaresError?.bind(commandInstance) ??
|
||||
this.client.options?.commands?.defaults?.onMiddlewaresError;
|
||||
this.client.options.commands?.defaults?.onMiddlewaresError;
|
||||
option.onRunError =
|
||||
option.onRunError?.bind(option) ??
|
||||
commandInstance.onRunError?.bind(commandInstance) ??
|
||||
this.client.options?.commands?.defaults?.onRunError;
|
||||
this.client.options.commands?.defaults?.onRunError;
|
||||
option.onOptionsError =
|
||||
option.onOptionsError?.bind(option) ??
|
||||
commandInstance.onOptionsError?.bind(commandInstance) ??
|
||||
this.client.options?.commands?.defaults?.onOptionsError;
|
||||
this.client.options.commands?.defaults?.onOptionsError;
|
||||
option.onInternalError =
|
||||
option.onInternalError?.bind(option) ??
|
||||
commandInstance.onInternalError?.bind(commandInstance) ??
|
||||
this.client.options?.commands?.defaults?.onInternalError;
|
||||
this.client.options.commands?.defaults?.onInternalError;
|
||||
option.onAfterRun =
|
||||
option.onAfterRun?.bind(option) ??
|
||||
commandInstance.onAfterRun?.bind(commandInstance) ??
|
||||
this.client.options?.commands?.defaults?.onAfterRun;
|
||||
this.client.options.commands?.defaults?.onAfterRun;
|
||||
option.onBotPermissionsFail =
|
||||
option.onBotPermissionsFail?.bind(option) ??
|
||||
commandInstance.onBotPermissionsFail?.bind(commandInstance) ??
|
||||
this.client.options?.commands?.defaults?.onBotPermissionsFail;
|
||||
this.client.options.commands?.defaults?.onBotPermissionsFail;
|
||||
option.onPermissionsFail =
|
||||
option.onPermissionsFail?.bind(option) ??
|
||||
commandInstance.onPermissionsFail?.bind(commandInstance) ??
|
||||
this.client.options?.commands?.defaults?.onPermissionsFail;
|
||||
this.client.options.commands?.defaults?.onPermissionsFail;
|
||||
option.botPermissions ??= commandInstance.botPermissions;
|
||||
option.defaultMemberPermissions ??= commandInstance.defaultMemberPermissions;
|
||||
option.contexts ??= commandInstance.contexts;
|
||||
option.integrationTypes ??= commandInstance.integrationTypes;
|
||||
option.props ??= commandInstance.props;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ComponentType } from 'discord-api-types/v10';
|
||||
import type { ContextComponentCommandInteractionMap, ComponentContext } from './componentcontext';
|
||||
import type { RegisteredMiddlewares, UsingClient } from '../commands';
|
||||
import type { ExtraProps, RegisteredMiddlewares, UsingClient } from '../commands';
|
||||
|
||||
export const InteractionCommandType = {
|
||||
COMPONENT: 0,
|
||||
@ -17,6 +17,10 @@ export abstract class ComponentCommand {
|
||||
abstract filter(context: ComponentContext<typeof this.componentType>): Promise<boolean> | boolean;
|
||||
abstract run(context: ComponentContext<typeof this.componentType>): any;
|
||||
|
||||
middlewares: (keyof RegisteredMiddlewares)[] = [];
|
||||
|
||||
props: ExtraProps = {};
|
||||
|
||||
get cType(): number {
|
||||
return ComponentType[this.componentType];
|
||||
}
|
||||
@ -25,6 +29,4 @@ export abstract class ComponentCommand {
|
||||
onRunError?(context: ComponentContext, error: unknown): any;
|
||||
onMiddlewaresError?(context: ComponentContext, error: string): any;
|
||||
onInternalError?(client: UsingClient, error?: unknown): any;
|
||||
|
||||
middlewares: (keyof RegisteredMiddlewares)[] = [];
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ export class ComponentContext<
|
||||
super(client);
|
||||
}
|
||||
|
||||
command?: ComponentCommand;
|
||||
command!: ComponentCommand;
|
||||
metadata: CommandMetadata<UnionToTuple<M>> = {} as never;
|
||||
globalMetadata: GlobalMetadata = {};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { RegisteredMiddlewares, UsingClient } from '../commands';
|
||||
import type { ExtraProps, RegisteredMiddlewares, UsingClient } from '../commands';
|
||||
import { InteractionCommandType } from './componentcommand';
|
||||
import type { ModalContext } from './modalcontext';
|
||||
|
||||
@ -13,6 +13,8 @@ export abstract class ModalCommand {
|
||||
|
||||
middlewares: (keyof RegisteredMiddlewares)[] = [];
|
||||
|
||||
props: ExtraProps = {};
|
||||
|
||||
onAfterRun?(context: ModalContext, error: unknown | undefined): any;
|
||||
onRunError?(context: ModalContext, error: unknown): any;
|
||||
onMiddlewaresError?(context: ModalContext, error: string): any;
|
||||
|
@ -38,7 +38,7 @@ export class ModalContext<M extends keyof RegisteredMiddlewares = never> extends
|
||||
super(client);
|
||||
}
|
||||
|
||||
command?: ModalCommand;
|
||||
command!: ModalCommand;
|
||||
metadata: CommandMetadata<UnionToTuple<M>> = {} as never;
|
||||
globalMetadata: GlobalMetadata = {};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user