UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 4.32 kB
{"version":3,"file":"RunIn.mjs","names":[],"sources":["../../../src/preconditions/RunIn.ts"],"sourcesContent":["import { container } from '@sapphire/pieces';\nimport type { ChatInputCommandInteraction, ContextMenuCommandInteraction, Message } from 'discord.js';\nimport { Identifiers } from '../lib/errors/Identifiers';\nimport { Command } from '../lib/structures/Command';\nimport { AllFlowsPrecondition, type Preconditions } from '../lib/structures/Precondition';\nimport type { ChatInputCommand, ContextMenuCommand, MessageCommand } from '../lib/types/CommandTypes';\n\nexport interface RunInPreconditionContext extends AllFlowsPrecondition.Context {\n\ttypes?: Preconditions['RunIn']['types'];\n}\n\nexport class CorePrecondition extends AllFlowsPrecondition {\n\tpublic override messageRun(message: Message<boolean>, _: MessageCommand, context: RunInPreconditionContext): AllFlowsPrecondition.Result {\n\t\tconst commandType = 'message';\n\t\tif (!context.types) return this.ok();\n\n\t\tconst channelType = message.channel.type;\n\n\t\tif (Command.runInTypeIsSpecificsObject(context.types)) {\n\t\t\treturn context.types.messageRun.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType);\n\t\t}\n\n\t\treturn context.types.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType);\n\t}\n\n\tpublic override async chatInputRun(\n\t\tinteraction: ChatInputCommandInteraction,\n\t\t_: ChatInputCommand,\n\t\tcontext: RunInPreconditionContext\n\t): AllFlowsPrecondition.AsyncResult {\n\t\tconst commandType = 'chat input';\n\t\tif (!context.types) return this.ok();\n\n\t\tconst channelType = (await this.fetchChannelFromInteraction(interaction)).type;\n\n\t\tif (Command.runInTypeIsSpecificsObject(context.types)) {\n\t\t\treturn context.types.chatInputRun.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType);\n\t\t}\n\n\t\treturn context.types.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType);\n\t}\n\n\tpublic override async contextMenuRun(\n\t\tinteraction: ContextMenuCommandInteraction,\n\t\t_: ContextMenuCommand,\n\t\tcontext: RunInPreconditionContext\n\t): AllFlowsPrecondition.AsyncResult {\n\t\tconst commandType = 'context menu';\n\t\tif (!context.types) return this.ok();\n\n\t\tconst channelType = (await this.fetchChannelFromInteraction(interaction)).type;\n\n\t\tif (Command.runInTypeIsSpecificsObject(context.types)) {\n\t\t\treturn context.types.contextMenuRun.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType);\n\t\t}\n\n\t\treturn context.types.includes(channelType) ? this.ok() : this.makeSharedError(context, commandType);\n\t}\n\n\tprivate makeSharedError(context: RunInPreconditionContext, commandType: string): AllFlowsPrecondition.Result {\n\t\treturn this.error({\n\t\t\tidentifier: Identifiers.PreconditionRunIn,\n\t\t\tmessage: `You cannot run this ${commandType} command in this type of channel.`,\n\t\t\tcontext: { types: context.types }\n\t\t});\n\t}\n}\n\nvoid container.stores.loadPiece({\n\tname: 'RunIn',\n\tpiece: CorePrecondition,\n\tstore: 'preconditions'\n});\n"],"mappings":";;;;;;AAWA,IAAa,mBAAb,cAAsC,qBAAqB;CAC1D,AAAgB,WAAW,SAA2B,GAAmB,SAAgE;EACxI,MAAM,cAAc;AACpB,MAAI,CAAC,QAAQ,MAAO,QAAO,KAAK,IAAI;EAEpC,MAAM,cAAc,QAAQ,QAAQ;AAEpC,MAAI,QAAQ,2BAA2B,QAAQ,MAAM,CACpD,QAAO,QAAQ,MAAM,WAAW,SAAS,YAAY,GAAG,KAAK,IAAI,GAAG,KAAK,gBAAgB,SAAS,YAAY;AAG/G,SAAO,QAAQ,MAAM,SAAS,YAAY,GAAG,KAAK,IAAI,GAAG,KAAK,gBAAgB,SAAS,YAAY;;CAGpG,MAAsB,aACrB,aACA,GACA,SACmC;EACnC,MAAM,cAAc;AACpB,MAAI,CAAC,QAAQ,MAAO,QAAO,KAAK,IAAI;EAEpC,MAAM,eAAe,MAAM,KAAK,4BAA4B,YAAY,EAAE;AAE1E,MAAI,QAAQ,2BAA2B,QAAQ,MAAM,CACpD,QAAO,QAAQ,MAAM,aAA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