UNPKG

@sapphire/plugin-pattern-commands

Version:

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

1 lines 3.17 kB
{"version":3,"sources":["../../../../src/lib/structures/PatternCommand.ts"],"names":["Command"],"mappings":";;;;;;;;AAGO,IAAe,eAAA,GAAf,MAAe,eAAA,SAAuBA,iBAAsC,CAAA;AAAA,EAI3E,WAAA,CAAY,SAAuC,OAAiC,EAAA;AAC1F,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAJvB,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAChB,IAAgB,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AAGf,IAAK,IAAA,CAAA,MAAA,GAAS,QAAQ,MAAU,IAAA,GAAA;AAChC,IAAA,IAAI,QAAQ,MAAQ,EAAA;AACnB,MAAI,IAAA,OAAA,CAAQ,SAAS,CAAG,EAAA;AACvB,QAAA,IAAA,CAAK,MAAS,GAAA,CAAA;AAAA,OACf,MAAA,IAAW,OAAQ,CAAA,MAAA,GAAS,EAAI,EAAA;AAC/B,QAAA,IAAA,CAAK,MAAS,GAAA,EAAA;AAAA,OACR,MAAA;AACN,QAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA;AAAA;AACvB,KACM,MAAA;AACN,MAAA,IAAA,CAAK,MAAS,GAAA,CAAA;AAAA;AAEf,IAAK,IAAA,CAAA,aAAA,GAAgB,QAAQ,aAAiB,IAAA,KAAA;AAAA;AAQhD,CAAA;AA1BmF,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAA5E,IAAe,cAAf,GAAA","file":"PatternCommand.cjs","sourcesContent":["import { Args, Command, type MessageCommand } from '@sapphire/framework';\nimport type { Awaitable, Message } from 'discord.js';\n\nexport abstract class PatternCommand extends Command<Args, PatternCommand.Options> {\n\tpublic readonly chance: number;\n\tpublic readonly weight: number;\n\tpublic readonly matchFullName: boolean;\n\tpublic constructor(context: PatternCommand.LoaderContext, options: PatternCommand.Options) {\n\t\tsuper(context, options);\n\t\tthis.chance = options.chance ?? 100;\n\t\tif (options.weight) {\n\t\t\tif (options.weight < 0) {\n\t\t\t\tthis.weight = 0;\n\t\t\t} else if (options.weight > 10) {\n\t\t\t\tthis.weight = 10;\n\t\t\t} else {\n\t\t\t\tthis.weight = options.weight;\n\t\t\t}\n\t\t} else {\n\t\t\tthis.weight = 5;\n\t\t}\n\t\tthis.matchFullName = options.matchFullName ?? false;\n\t}\n\n\t/**\n\t * Executes the pattern command's logic.\n\t * @param message The message that triggered the pattern command.\n\t */\n\tpublic abstract override messageRun(message: Message): Awaitable<unknown>;\n}\n\nexport interface PatternCommandOptions extends MessageCommand.Options {\n\t/**\n\t * The chance that the pattern command is triggered.\n\t * @default 100\n\t */\n\tchance?: number;\n\t/**\n\t * The matching weight of the command.\n\t * @default 5\n\t */\n\tweight?: number;\n\t/**\n\t * If true it will only trigger on full matches (for example, explore won't trigger lore)\n\t * Note: It will only change the behavior of the command's name and not for the command's aliasses\n\t * @default false\n\t */\n\tmatchFullName?: boolean;\n}\n\nexport namespace PatternCommand {\n\t/**\n\t * Re-export of {@link MessageCommand.LoaderContext}\n\t * @deprecated Use {@linkcode LoaderContext} instead.\n\t */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = MessageCommand.LoaderContext;\n\n\t/** Re-export of {@link MessageCommand.RunContext} */\n\texport type RunContext = MessageCommand.RunContext;\n\n\t/** Re-export of {@link MessageCommand.JSON} */\n\texport type JSON = MessageCommand.JSON;\n\n\t/** Re-export of {@link MessageCommand.RunInTypes} */\n\texport type RunInTypes = MessageCommand.RunInTypes;\n\n\t/**\n\t * The PatternCommand Options\n\t */\n\texport type Options = PatternCommandOptions;\n}\n"]}