@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
1 lines • 5.96 kB
Source Map (JSON)
{"version":3,"file":"autocomplete.cjs","names":["checkLocalizations","choice: APIApplicationCommandOptionChoice"],"sources":["../../../../../../../src/lib/utils/application-commands/compute-differences/option/autocomplete.ts"],"sourcesContent":["import type { APIApplicationCommandOptionChoice } from 'discord-api-types/v10';\nimport type { APIApplicationCommandChoosableAndAutocompletableTypes, CommandDifference } from '../_shared';\nimport { checkLocalizations } from '../localizations';\n\nexport function* handleAutocomplete({\n\tcurrentIndex,\n\texistingOption,\n\texpectedOption,\n\tkeyPath\n}: {\n\tcurrentIndex: number;\n\tkeyPath: (index: number) => string;\n\texpectedOption: APIApplicationCommandChoosableAndAutocompletableTypes;\n\texistingOption: APIApplicationCommandChoosableAndAutocompletableTypes;\n}): Generator<CommandDifference> {\n\t// 0. No autocomplete and now it should autocomplete\n\tif (!existingOption.autocomplete && expectedOption.autocomplete) {\n\t\tyield {\n\t\t\tkey: `${keyPath(currentIndex)}.autocomplete`,\n\t\t\texpected: 'autocomplete enabled',\n\t\t\toriginal: 'autocomplete disabled'\n\t\t};\n\t}\n\t// 1. Have autocomplete and now it shouldn't\n\telse if (existingOption.autocomplete && !expectedOption.autocomplete) {\n\t\tyield {\n\t\t\tkey: `${keyPath(currentIndex)}.autocomplete`,\n\t\t\texpected: 'autocomplete disabled',\n\t\t\toriginal: 'autocomplete enabled'\n\t\t};\n\t}\n\n\tif (!expectedOption.autocomplete && !existingOption.autocomplete) {\n\t\t// 0. No choices and now we have choices\n\t\tif (!existingOption.choices?.length && expectedOption.choices?.length) {\n\t\t\tyield {\n\t\t\t\tkey: `${keyPath(currentIndex)}.choices`,\n\t\t\t\texpected: 'choices present',\n\t\t\t\toriginal: 'no choices present'\n\t\t\t};\n\t\t}\n\t\t// 1. Have choices and now we don't\n\t\telse if (existingOption.choices?.length && !expectedOption.choices?.length) {\n\t\t\tyield {\n\t\t\t\tkey: `${keyPath(currentIndex)}.choices`,\n\t\t\t\texpected: 'no choices present',\n\t\t\t\toriginal: 'choices present'\n\t\t\t};\n\t\t}\n\t\t// 2. Check every choice to see differences\n\t\telse if (expectedOption.choices?.length && existingOption.choices?.length) {\n\t\t\tlet index = 0;\n\t\t\tfor (const choice of expectedOption.choices) {\n\t\t\t\tconst currentChoiceIndex = index++;\n\t\t\t\tconst existingChoice = existingOption.choices[currentChoiceIndex];\n\n\t\t\t\t// If this choice never existed, return the difference\n\t\t\t\tif (existingChoice === undefined) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\tkey: `${keyPath(currentIndex)}.choices[${currentChoiceIndex}]`,\n\t\t\t\t\t\toriginal: 'no choice present',\n\t\t\t\t\t\texpected: 'choice present'\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\tif (choice.name !== existingChoice.name) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\tkey: `${keyPath(currentIndex)}.choices[${currentChoiceIndex}].name`,\n\t\t\t\t\t\t\toriginal: existingChoice.name,\n\t\t\t\t\t\t\texpected: choice.name\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check localized names\n\t\t\t\t\tconst originalLocalizedNames = existingChoice.name_localizations;\n\t\t\t\t\tconst expectedLocalizedNames = choice.name_localizations;\n\n\t\t\t\t\tyield* checkLocalizations({\n\t\t\t\t\t\tlocaleMapName: `${keyPath(currentIndex)}.choices[${currentChoiceIndex}].nameLocalizations`,\n\t\t\t\t\t\tlocalePresentMessage: 'localized names',\n\t\t\t\t\t\tlocaleMissingMessage: 'no localized names',\n\t\t\t\t\t\toriginalLocalizedDescriptions: originalLocalizedNames,\n\t\t\t\t\t\texpectedLocalizedDescriptions: expectedLocalizedNames\n\t\t\t\t\t});\n\n\t\t\t\t\tif (choice.value !== existingChoice.value) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\tkey: `${keyPath(currentIndex)}.choices[${currentChoiceIndex}].value`,\n\t\t\t\t\t\t\toriginal: String(existingChoice.value),\n\t\t\t\t\t\t\texpected: String(choice.value)\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If there are more choices than the expected ones, return the difference\n\t\t\tif (index < existingOption.choices.length) {\n\t\t\t\tlet choice: APIApplicationCommandOptionChoice;\n\t\t\t\twhile ((choice = existingOption.choices[index]) !== undefined) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\tkey: `existing choice at path ${keyPath(currentIndex)}.choices[${index}]`,\n\t\t\t\t\t\texpected: 'no choice present',\n\t\t\t\t\t\toriginal: `choice with name \"${choice.name}\" and value ${\n\t\t\t\t\t\t\ttypeof choice.value === 'number' ? choice.value : `\"${choice.value}\"`\n\t\t\t\t\t\t} present`\n\t\t\t\t\t};\n\n\t\t\t\t\tindex++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAIA,UAAiB,mBAAmB,EACnC,cACA,gBACA,gBACA,WAMgC;AAEhC,KAAI,CAAC,eAAe,gBAAgB,eAAe,aAClD,OAAM;EACL,KAAK,GAAG,QAAQ,aAAa,CAAC;EAC9B,UAAU;EACV,UAAU;EACV;UAGO,eAAe,gBAAgB,CAAC,eAAe,aACvD,OAAM;EACL,KAAK,GAAG,QAAQ,aAAa,CAAC;EAC9B,UAAU;EACV,UAAU;EACV;AAGF,KAAI,CAAC,eAAe,gBAAgB,CAAC,eAAe,cAEnD;MAAI,CAAC,eAAe,SAAS,UAAU,eAAe,SAAS,OAC9D,OAAM;GACL,KAAK,GAAG,QAAQ,aAAa,CAAC;GAC9B,UAAU;GACV,UAAU;GACV;WAGO,eAAe,SAAS,UAAU,CAAC,eAAe,SAAS,OACnE,OAAM;GACL,KAAK,GAAG,QAAQ,aAAa,CAAC;GAC9B,UAAU;GACV,UAAU;GACV;WAGO,eAAe,SAAS,UAAU,eAAe,SAAS,QAAQ;GAC1E,IAAI,QAAQ;AACZ,QAAK,MAAM,UAAU,eAAe,SAAS;IAC5C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