UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 2.41 kB
{"version":3,"file":"GuildTextOnly.cjs","names":["AllFlowsPrecondition","ChannelType","Identifiers","container"],"sources":["../../../src/preconditions/GuildTextOnly.ts"],"sourcesContent":["import { container } from '@sapphire/pieces';\nimport { ChannelType, ChatInputCommandInteraction, ContextMenuCommandInteraction, Message, type TextBasedChannelTypes } from 'discord.js';\nimport { Identifiers } from '../lib/errors/Identifiers';\nimport { AllFlowsPrecondition } from '../lib/structures/Precondition';\n\nexport class CorePrecondition extends AllFlowsPrecondition {\n\tprivate readonly allowedTypes: TextBasedChannelTypes[] = [ChannelType.GuildText, ChannelType.PublicThread, ChannelType.PrivateThread];\n\n\tpublic messageRun(message: Message): AllFlowsPrecondition.Result {\n\t\treturn this.allowedTypes.includes(message.channel.type) ? this.ok() : this.makeSharedError();\n\t}\n\n\tpublic async chatInputRun(interaction: ChatInputCommandInteraction): AllFlowsPrecondition.AsyncResult {\n\t\tconst channel = await this.fetchChannelFromInteraction(interaction);\n\t\treturn this.allowedTypes.includes(channel.type) ? this.ok() : this.makeSharedError();\n\t}\n\n\tpublic async contextMenuRun(interaction: ContextMenuCommandInteraction): AllFlowsPrecondition.AsyncResult {\n\t\tconst channel = await this.fetchChannelFromInteraction(interaction);\n\t\treturn this.allowedTypes.includes(channel.type) ? this.ok() : this.makeSharedError();\n\t}\n\n\tprivate makeSharedError(): AllFlowsPrecondition.Result {\n\t\treturn this.error({\n\t\t\tidentifier: Identifiers.PreconditionGuildTextOnly,\n\t\t\tmessage: 'You can only run this command in server text channels.'\n\t\t});\n\t}\n}\n\nvoid container.stores.loadPiece({\n\tname: 'GuildTextOnly',\n\tpiece: CorePrecondition,\n\tstore: 'preconditions'\n});\n"],"mappings":";;;;;;;AAKA,IAAa,mBAAb,cAAsCA,yDAAqB;;;OACzC,eAAwC;GAACC,uBAAY;GAAWA,uBAAY;GAAcA,uBAAY;GAAc;;CAErI,AAAO,WAAW,SAA+C;AAChE,SAAO,KAAK,aAAa,SAAS,QAAQ,QAAQ,KAAK,GAAG,KAAK,IAAI,GAAG,KAAK,iBAAiB;;CAG7F,MAAa,aAAa,aAA4E;EACrG,MAAM,UAAU,MAAM,KAAK,4BAA4B,YAAY;AACnE,SAAO,KAAK,aAAa,SAAS,QAAQ,KAAK,GAAG,KAAK,IAAI,GAAG,KAAK,iBAAiB;;CAGrF,MAAa,eAAe,aAA8E;EACzG,MAAM,UAAU,MAAM,KAAK,4BAA4B,YAAY;AACnE,SAAO,KAAK,aAAa,SAAS,QAAQ,KAAK,GAAG,KAAK,IAAI,GAAG,KAAK,iBAAiB;;CAGrF,AAAQ,kBAA+C;AACtD,SAAO,KAAK,MAAM;GACjB,YAAYC,2CAAY;GACxB,SAAS;GACT,CAAC;;;AAICC,4BAAU,OAAO,UAAU;CAC/B,MAAM;CACN,OAAO;CACP,OAAO;CACP,CAAC"}