UNPKG

@sapphire/plugin-pattern-commands

Version:

Plugin for @sapphire/framework that adds support for pattern commands.

188 lines (177 loc) • 7.8 kB
import { AliasStore } from '@sapphire/pieces'; import { MessageCommand, Command, Args, Listener, Events } from '@sapphire/framework'; import { Message, Awaitable } from 'discord.js'; interface PatternCommandOptions extends MessageCommand.Options { /** * The chance that the pattern command is triggered. * @default 100 */ chance?: number; /** * The matching weight of the command. * @default 5 */ weight?: number; /** * If true it will only trigger on full matches (for example, explore won't trigger lore) * Note: It will only change the behavior of the command's name and not for the command's aliasses * @default false */ matchFullName?: boolean; } declare abstract class PatternCommand extends Command<Args, PatternCommand.Options> { readonly chance: number; readonly weight: number; readonly matchFullName: boolean; constructor(context: PatternCommand.LoaderContext, options: PatternCommand.Options); /** * Executes the pattern command's logic. * @param message The message that triggered the pattern command. */ abstract messageRun(message: Message): Awaitable<unknown>; } declare namespace PatternCommand { /** * Re-export of {@link MessageCommand.LoaderContext} * @deprecated Use {@linkcode LoaderContext} instead. */ type Context = LoaderContext; type LoaderContext = MessageCommand.LoaderContext; /** Re-export of {@link MessageCommand.RunContext} */ type RunContext = MessageCommand.RunContext; /** Re-export of {@link MessageCommand.JSON} */ type JSON = MessageCommand.JSON; /** Re-export of {@link MessageCommand.RunInTypes} */ type RunInTypes = MessageCommand.RunInTypes; /** * The PatternCommand Options */ type Options = PatternCommandOptions; } declare class PatternCommandStore extends AliasStore<PatternCommand> { constructor(); } /** * Events emitted during the parsing and command run. * You can use these events for debugging and logging purposes. */ declare enum PatternCommandEvents { /** * Event that is emitted when the RNG doesn't love the command * @param message The message where the command was triggered * @param command The command's piece * @param alias The alias that triggered the command */ CommandNoLuck = "patternCommandNoLuck", /** * Event that is emitted when an alias triggered the command but before parsing the preconditions * @param payload PatternCommandRunPayload which contains message, command and alias */ PreCommandRun = "patternCommandPreRun", /** * Event that is emitted after the preconditions if none of them denied the command * @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias */ CommandAccepted = "patternCommandAccepted", /** * Event that is emitted after the preconditions if at least one of them denied the command * @param error The error of the precondition which denied the command * @param payload PatternCommandDeniedPayload which contains parameters, context, message, command and alias */ CommandDenied = "patternCommandDenied", /** * Event that is emitted just before the command is ran * @param message The message where the command was triggered * @param command The command's piece * @param alias The alias that triggered the command */ CommandRun = "patternCommandRun", /** * Event that is emitted if there's no error while running the command * @param result The result of command's run * @param command The command's piece * @param alias The alias that triggered the command * @param duration The duration which indicates how long it took the command to run */ CommandSuccess = "patternCommandSuccess", /** * Event that is emitted if there's an error while running the command * @param error The error message which happened while the command was running * @param command The command's piece * @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias */ CommandError = "patternCommandError", /** * Event that is emitted if the command has finished, regardless of whether an error occurred or not * @param command The command's piece * @param duration The duration which indicates how long it took the command to run * @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias */ CommandFinished = "patternCommandFinished" } interface PatternCommandPrePayload { message: Message; possibleCommands: PossiblePatternCommand[]; } interface PatternCommandPayload { /** The message that triggered this PatternCommand */ message: Message; /** The command that is triggered by this PatternCommand */ command: PatternCommand; /** The alias of this pattern command */ alias: string; } interface PatternPreCommandRunPayload extends PatternCommandDeniedPayload { } interface PatternCommandDeniedPayload extends PatternCommandPayload { parameters: string; context: PatternCommand.RunContext; } interface PatternCommandAcceptedPayload extends PatternCommandPayload { parameters: string; context: PatternCommand.RunContext; } interface PatternCommandSuccessPayload extends PatternCommandFinishedPayload { result: unknown; } interface PatternCommandFinishedPayload extends PatternCommandAcceptedPayload { duration: number; success: boolean; } interface PatternCommandErrorPayload extends PatternCommandFinishedPayload { } interface PatternCommandNoLuckPayload extends PatternCommandAcceptedPayload { } interface PossiblePatternCommand { command: PatternCommand; alias: string; weight: number; } declare class PluginListener$2 extends Listener<typeof PatternCommandEvents.CommandAccepted> { constructor(context: Listener.LoaderContext); run(payload: PatternCommandAcceptedPayload): Promise<void>; } declare class PluginListener$1 extends Listener<typeof Events.PreMessageParsed> { private readonly requiredPermissions; constructor(context: Listener.LoaderContext); run(message: Message): Promise<void>; private canRunInChannel; } declare class PluginListener extends Listener<typeof PatternCommandEvents.PreCommandRun> { constructor(context: Listener.LoaderContext); run(payload: PatternCommandPrePayload): Promise<void>; } declare function loadListeners(): void; declare module '@sapphire/pieces' { interface StoreRegistryEntries { 'pattern-commands': PatternCommandStore; } } /** * The [@sapphire/plugin-pattern-commands](https://github.com/sapphiredev/plugins/blob/main/packages/pattern-commands) version that you are currently using. * An example use of this is showing it of in a bot information command. * * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild */ declare const version: string; export { PatternCommand, type PatternCommandAcceptedPayload, type PatternCommandDeniedPayload, type PatternCommandErrorPayload, PatternCommandEvents, type PatternCommandFinishedPayload, type PatternCommandNoLuckPayload, type PatternCommandOptions, type PatternCommandPayload, type PatternCommandPrePayload, PatternCommandStore, type PatternCommandSuccessPayload, type PatternPreCommandRunPayload, PluginListener$2 as PluginPatternCommandsCommandAcceptedListener, PluginListener$1 as PluginPatternCommandsMessageParseListener, PluginListener as PluginPatternCommandsPreCommandRunListener, type PossiblePatternCommand, loadListeners, version };