@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
1 lines • 2.3 kB
Source Map (JSON)
{"version":3,"file":"contexts.mjs","names":["type: InteractionContextType"],"sources":["../../../../../../src/lib/utils/application-commands/compute-differences/contexts.ts"],"sourcesContent":["import type { InteractionContextType } from 'discord.js';\nimport type { CommandDifference } from './_shared';\n\nexport function* checkInteractionContextTypes(\n\texistingContexts?: InteractionContextType[],\n\tnewContexts?: InteractionContextType[]\n): Generator<CommandDifference> {\n\t// 0. No existing contexts and now we have contexts\n\tif (!existingContexts && newContexts?.length) {\n\t\tyield {\n\t\t\tkey: 'contexts',\n\t\t\toriginal: 'no contexts present',\n\t\t\texpected: 'contexts present'\n\t\t};\n\t}\n\t// 1. Existing contexts and now we have no contexts\n\telse if (existingContexts?.length && !newContexts?.length) {\n\t\tyield {\n\t\t\tkey: 'contexts',\n\t\t\toriginal: 'contexts present',\n\t\t\texpected: 'no contexts present'\n\t\t};\n\t}\n\t// 2. Maybe changes in order or additions, log\n\telse if (newContexts?.length) {\n\t\tlet index = 0;\n\n\t\tfor (const newContext of newContexts) {\n\t\t\tconst currentIndex = index++;\n\n\t\t\tif (existingContexts![currentIndex] !== newContext) {\n\t\t\t\tyield {\n\t\t\t\t\tkey: `contexts[${currentIndex}]`,\n\t\t\t\t\toriginal: `contexts type ${existingContexts?.[currentIndex]}`,\n\t\t\t\t\texpected: `contexts type ${newContext}`\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif (index < existingContexts!.length) {\n\t\t\tlet type: InteractionContextType;\n\n\t\t\twhile ((type = existingContexts![index]) !== undefined) {\n\t\t\t\tyield {\n\t\t\t\t\tkey: `contexts[${index}]`,\n\t\t\t\t\toriginal: `context ${type} present`,\n\t\t\t\t\texpected: `no context present`\n\t\t\t\t};\n\n\t\t\t\tindex++;\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";AAGA,UAAiB,6BAChB,kBACA,aAC+B;AAE/B,KAAI,CAAC,oBAAoB,aAAa,OACrC,OAAM;EACL,KAAK;EACL,UAAU;EACV,UAAU;EACV;UAGO,kBAAkB,UAAU,CAAC,aAAa,OAClD,OAAM;EACL,KAAK;EACL,UAAU;EACV,UAAU;EACV;UAGO,aAAa,QAAQ;EAC7B,IAAI,QAAQ;AAEZ,OAAK,MAAM,cAAc,aAAa;GACrC,MAAM,eAAe;AAErB,OAAI,iBAAkB,kBAAkB,WACvC,OAAM;IACL,KAAK,YAAY,aAAa;IAC9B,UAAU,iBAAiB,mBAAmB;IAC9C,UAAU,iBAAiB;IAC3B;;AAIH,MAAI,QAAQ,iBAAkB,QAAQ;GACrC,IAAIA;AAEJ,WAAQ,OAAO,iBAAkB,YAAY,QAAW;AACvD,UAAM;KACL,KAAK,YAAY,MAAM;KACvB,UAAU,WAAW,KAAK;KAC1B,UAAU;KACV;AAED"}