From 161f7c89fc2ba3d9e422ebbc237156140085633f Mon Sep 17 00:00:00 2001 From: UndiedGamer Date: Tue, 9 Aug 2022 18:05:28 +0530 Subject: [PATCH] chore: init --- src/index.ts | 2 +- src/lib/parsers/ChatInputArgs.ts | 9 ++++ src/lib/parsers/{Args.ts => MessageArgs.ts} | 54 ++++++++++----------- src/lib/structures/Argument.ts | 10 ++-- src/lib/structures/Command.ts | 8 +-- 5 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 src/lib/parsers/ChatInputArgs.ts rename src/lib/parsers/{Args.ts => MessageArgs.ts} (91%) diff --git a/src/index.ts b/src/index.ts index 258120319..270c3b41a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,7 @@ export * from './lib/errors/ArgumentError'; export * from './lib/errors/Identifiers'; export * from './lib/errors/PreconditionError'; export * from './lib/errors/UserError'; -export * from './lib/parsers/Args'; +export * from './lib/parsers/MessageArgs'; export * from './lib/plugins/Plugin'; export * from './lib/plugins/PluginManager'; export * from './lib/plugins/symbols'; diff --git a/src/lib/parsers/ChatInputArgs.ts b/src/lib/parsers/ChatInputArgs.ts new file mode 100644 index 000000000..7ad1fe2cc --- /dev/null +++ b/src/lib/parsers/ChatInputArgs.ts @@ -0,0 +1,9 @@ +import type { CacheType, CommandInteractionOptionResolver } from 'discord.js'; + +export class ChatInputArgs { + public readonly options: Omit, 'getMessage' | 'getFocused'>; + + public constructor(options: Omit, 'getMessage' | 'getFocused'>) { + this.options = options; + } +} diff --git a/src/lib/parsers/Args.ts b/src/lib/parsers/MessageArgs.ts similarity index 91% rename from src/lib/parsers/Args.ts rename to src/lib/parsers/MessageArgs.ts index 0b5470e04..97b494745 100644 --- a/src/lib/parsers/Args.ts +++ b/src/lib/parsers/MessageArgs.ts @@ -27,7 +27,7 @@ import type { MessageCommand } from '../structures/Command'; /** * The argument parser to be used in {@link Command}. */ -export class Args { +export class MessageArgs { /** * The original message that triggered the command. */ @@ -50,8 +50,8 @@ export class Args { /** * The states stored in the args. - * @see Args#save - * @see Args#restore + * @see MessageArgs#save + * @see MessageArgs#restore */ private readonly states: ArgumentStream.State[] = []; @@ -65,7 +65,7 @@ export class Args { /** * Sets the parser to the first token. */ - public start(): Args { + public start(): MessageArgs { this.parser.reset(); return this; } @@ -128,7 +128,7 @@ export class Args { } /** - * Similar to {@link Args.pickResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.pickResult} but returns the value on success, throwing otherwise. * @param type The type of the argument. * @example * ```typescript @@ -146,7 +146,7 @@ export class Args { */ public async pick(type: IArgument, options?: ArgOptions): Promise; /** - * Similar to {@link Args.pickResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.pickResult} but returns the value on success, throwing otherwise. * @param type The type of the argument. * @example * ```typescript @@ -218,7 +218,7 @@ export class Args { } /** - * Similar to {@link Args.restResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.restResult} but returns the value on success, throwing otherwise. * @param type The type of the argument. * @example * ```typescript @@ -231,7 +231,7 @@ export class Args { */ public async rest(type: IArgument, options?: ArgOptions): Promise; /** - * Similar to {@link Args.restResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.restResult} but returns the value on success, throwing otherwise. * @param type The type of the argument. * @example * ```typescript @@ -312,7 +312,7 @@ export class Args { } /** - * Similar to {@link Args.repeatResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.repeatResult} but returns the value on success, throwing otherwise. * @param type The type of the argument. * @example * ```typescript @@ -325,7 +325,7 @@ export class Args { */ public async repeat(type: IArgument, options?: RepeatArgOptions): Promise; /** - * Similar to {@link Args.repeatResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.repeatResult} but returns the value on success, throwing otherwise. * @param type The type of the argument. * @example * ```typescript @@ -343,9 +343,9 @@ export class Args { /** * Peeks the following parameter(s) without advancing the parser's state. - * Passing a function as a parameter allows for returning {@link Args.pickResult}, {@link Args.repeatResult}, - * or {@link Args.restResult}; otherwise, passing the custom argument or the argument type with options - * will use {@link Args.pickResult} and only peek a single argument. + * Passing a function as a parameter allows for returning {@link MessageArgs.pickResult}, {@link MessageArgs.repeatResult}, + * or {@link MessageArgs.restResult}; otherwise, passing the custom argument or the argument type with options + * will use {@link MessageArgs.pickResult} and only peek a single argument. * @param type The function, custom argument, or argument name. * @example * ```typescript @@ -366,9 +366,9 @@ export class Args { public async peekResult(type: () => Argument.Result): Promise>; /** * Peeks the following parameter(s) without advancing the parser's state. - * Passing a function as a parameter allows for returning {@link Args.pickResult}, {@link Args.repeatResult}, - * or {@link Args.restResult}; otherwise, passing the custom argument or the argument type with options - * will use {@link Args.pickResult} and only peek a single argument. + * Passing a function as a parameter allows for returning {@link MessageArgs.pickResult}, {@link MessageArgs.repeatResult}, + * or {@link MessageArgs.restResult}; otherwise, passing the custom argument or the argument type with options + * will use {@link MessageArgs.pickResult} and only peek a single argument. * @param type The function, custom argument, or argument name. * @example * ```typescript @@ -385,9 +385,9 @@ export class Args { public async peekResult(type: IArgument, options?: ArgOptions): Promise>; /** * Peeks the following parameter(s) without advancing the parser's state. - * Passing a function as a parameter allows for returning {@link Args.pickResult}, {@link Args.repeatResult}, - * or {@link Args.restResult}; otherwise, passing the custom argument or the argument type with options - * will use {@link Args.pickResult} and only peek a single argument. + * Passing a function as a parameter allows for returning {@link MessageArgs.pickResult}, {@link MessageArgs.repeatResult}, + * or {@link MessageArgs.restResult}; otherwise, passing the custom argument or the argument type with options + * will use {@link MessageArgs.pickResult} and only peek a single argument. * @param type The function, custom argument, or argument name. * @example * ```typescript @@ -419,7 +419,7 @@ export class Args { } /** - * Similar to {@link Args.peekResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.peekResult} but returns the value on success, throwing otherwise. * @param type The function, custom argument, or argument name. * @example * ```typescript @@ -441,7 +441,7 @@ export class Args { */ public async peek(type: () => Argument.Result): Promise; /** - * Similar to {@link Args.peekResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.peekResult} but returns the value on success, throwing otherwise. * @param type The function, custom argument, or argument name. * @example * ```typescript @@ -464,7 +464,7 @@ export class Args { */ public async peek(type: IArgument, options?: ArgOptions): Promise; /** - * Similar to {@link Args.peekResult} but returns the value on success, throwing otherwise. + * Similar to {@link MessageArgs.peekResult} but returns the value on success, throwing otherwise. * @param type The function, custom argument, or argument name. * @example * ```typescript @@ -518,7 +518,7 @@ export class Args { } /** - * Similar to {@link Args.nextMaybe} but returns the value on success, null otherwise. + * Similar to {@link MessageArgs.nextMaybe} but returns the value on success, null otherwise. * @example * ```typescript * // !numbers 1 2 3 @@ -529,7 +529,7 @@ export class Args { */ public next(): string; /** - * Similar to {@link Args.nextMaybe} but returns the value on success, null otherwise. + * Similar to {@link MessageArgs.nextMaybe} but returns the value on success, null otherwise. * @typeparam T Output type of the {@link ArgsNextCallback callback}. * @param cb Gives an option of either the resulting value, or nothing if failed. * @example @@ -612,7 +612,7 @@ export class Args { /** * Saves the current state into the stack following a FILO strategy (first-in, last-out). - * @see Args#restore + * @see MessageArgs#restore */ public save() { this.states.push(this.parser.save()); @@ -620,7 +620,7 @@ export class Args { /** * Restores the previously saved state from the stack. - * @see Args#save + * @see MessageArgs#save */ public restore() { if (this.states.length !== 0) this.parser.restore(this.states.pop()!); @@ -729,7 +729,7 @@ export interface RepeatArgOptions extends ArgOptions { } /** - * The callback used for {@link Args.nextMaybe} and {@link Args.next}. + * The callback used for {@link MessageArgs.nextMaybe} and {@link MessageArgs.next}. */ export interface ArgsNextCallback { /** diff --git a/src/lib/structures/Argument.ts b/src/lib/structures/Argument.ts index a3aa04c74..77dd896d9 100644 --- a/src/lib/structures/Argument.ts +++ b/src/lib/structures/Argument.ts @@ -3,7 +3,7 @@ import type { Result } from '@sapphire/result'; import type { Awaitable } from '@sapphire/utilities'; import type { Message } from 'discord.js'; import type { ArgumentError } from '../errors/ArgumentError'; -import { Args } from '../parsers/Args'; +import { MessageArgs } from '../parsers/MessageArgs'; import type { MessageCommand } from './Command'; /** @@ -37,7 +37,7 @@ export interface IArgument { /** * The base argument class. This class is abstract and is to be extended by subclasses implementing the methods. In - * Sapphire's workflow, arguments are called when using {@link Args}'s methods (usually used inside {@link Command}s by default). + * Sapphire's workflow, arguments are called when using {@link MessageArgs}'s methods (usually used inside {@link Command}s by default). * * @example * ```typescript @@ -99,7 +99,7 @@ export abstract class Argument { - return Args.ok(value); + return MessageArgs.ok(value); } /** @@ -107,7 +107,7 @@ export abstract class Argument, 'argument'>): Argument.Result { - return Args.error({ argument: this, identifier: this.name, ...options }); + return MessageArgs.error({ argument: this, identifier: this.name, ...options }); } } @@ -115,7 +115,7 @@ export interface ArgumentOptions extends AliasPiece.Options {} export interface ArgumentContext extends Record { argument: IArgument; - args: Args; + args: MessageArgs; message: Message; command: MessageCommand; commandContext: MessageCommand.RunContext; diff --git a/src/lib/structures/Command.ts b/src/lib/structures/Command.ts index 0206697ff..97912931c 100644 --- a/src/lib/structures/Command.ts +++ b/src/lib/structures/Command.ts @@ -11,7 +11,7 @@ import { Permissions, Snowflake } from 'discord.js'; -import { Args } from '../parsers/Args'; +import { MessageArgs } from '../parsers/MessageArgs'; import { BucketScope, RegisterBehavior } from '../types/Enums'; import { acquire } from '../utils/application-commands/ApplicationCommandRegistries'; import type { ApplicationCommandRegistry } from '../utils/application-commands/ApplicationCommandRegistry'; @@ -20,7 +20,7 @@ import { getNeededRegistryParameters } from '../utils/application-commands/getNe import { PreconditionContainerArray, PreconditionEntryResolvable } from '../utils/preconditions/PreconditionContainerArray'; import { FlagStrategyOptions, FlagUnorderedStrategy } from '../utils/strategies/FlagUnorderedStrategy'; -export class Command extends AliasPiece { +export class Command extends AliasPiece { /** * A basic summary about the command * @since 1.0.0 @@ -126,7 +126,7 @@ export class Command { const parser = new Parser(this.strategy); const args = new ArgumentStream(parser.run(this.lexer.run(parameters))); - return new Args(message, this as any, args, context) as any; + return new MessageArgs(message, this as any, args, context) as any; } /** @@ -168,7 +168,7 @@ export class Command;