@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
1 lines • 3.73 kB
Source Map (JSON)
{"version":3,"file":"localizations.mjs","names":[],"sources":["../../../../../../src/lib/utils/application-commands/compute-differences/localizations.ts"],"sourcesContent":["import type { LocalizationMap } from 'discord-api-types/v10';\nimport type { CommandDifference } from './_shared';\n\nexport function* checkLocalizations({\n\tlocaleMapName,\n\tlocalePresentMessage,\n\tlocaleMissingMessage,\n\toriginalLocalizedDescriptions,\n\texpectedLocalizedDescriptions\n}: {\n\tlocaleMapName: string;\n\tlocalePresentMessage: string;\n\tlocaleMissingMessage: string;\n\toriginalLocalizedDescriptions?: LocalizationMap | null;\n\texpectedLocalizedDescriptions?: LocalizationMap | null;\n}) {\n\tif (!originalLocalizedDescriptions && expectedLocalizedDescriptions) {\n\t\tyield {\n\t\t\tkey: localeMapName,\n\t\t\toriginal: localeMissingMessage,\n\t\t\texpected: localePresentMessage\n\t\t};\n\t} else if (originalLocalizedDescriptions && !expectedLocalizedDescriptions) {\n\t\tyield {\n\t\t\tkey: localeMapName,\n\t\t\toriginal: localePresentMessage,\n\t\t\texpected: localeMissingMessage\n\t\t};\n\t} else if (originalLocalizedDescriptions && expectedLocalizedDescriptions) {\n\t\tyield* reportLocalizationMapDifferences(originalLocalizedDescriptions, expectedLocalizedDescriptions, localeMapName);\n\t}\n}\n\nfunction* reportLocalizationMapDifferences(\n\toriginalMap: LocalizationMap,\n\texpectedMap: LocalizationMap,\n\tmapName: string\n): Generator<CommandDifference> {\n\tconst originalLocalizations = new Map(Object.entries(originalMap));\n\n\tfor (const [key, value] of Object.entries(expectedMap)) {\n\t\tconst possiblyExistingEntry = originalLocalizations.get(key) as string | undefined;\n\t\toriginalLocalizations.delete(key);\n\n\t\tconst wasMissingBefore = typeof possiblyExistingEntry === 'undefined';\n\t\tconst isResetNow = value === null;\n\n\t\t// Was missing before and now is present\n\t\tif (wasMissingBefore && !isResetNow) {\n\t\t\tyield {\n\t\t\t\tkey: `${mapName}.${key}`,\n\t\t\t\toriginal: 'no localization present',\n\t\t\t\texpected: value\n\t\t\t};\n\t\t}\n\t\t// Was present before and now is reset\n\t\telse if (!wasMissingBefore && isResetNow) {\n\t\t\tyield {\n\t\t\t\tkey: `${mapName}.${key}`,\n\t\t\t\toriginal: possiblyExistingEntry,\n\t\t\t\texpected: 'no localization present'\n\t\t\t};\n\t\t}\n\t\t// Not equal\n\t\t// eslint-disable-next-line no-negated-condition\n\t\telse if (possiblyExistingEntry !== value) {\n\t\t\tyield {\n\t\t\t\tkey: `${mapName}.${key}`,\n\t\t\t\toriginal: String(possiblyExistingEntry),\n\t\t\t\texpected: String(value)\n\t\t\t};\n\t\t}\n\t}\n\n\t// Report any remaining localizations\n\tfor (const [key, value] of originalLocalizations) {\n\t\tif (value) {\n\t\t\tyield {\n\t\t\t\tkey: `${mapName}.${key}`,\n\t\t\t\toriginal: value,\n\t\t\t\texpected: 'no localization present'\n\t\t\t};\n\t\t}\n\t}\n}\n"],"mappings":";AAGA,UAAiB,mBAAmB,EACnC,eACA,sBACA,sBACA,+BACA,iCAOE;AACF,KAAI,CAAC,iCAAiC,8BACrC,OAAM;EACL,KAAK;EACL,UAAU;EACV,UAAU;EACV;UACS,iCAAiC,CAAC,8BAC5C,OAAM;EACL,KAAK;EACL,UAAU;EACV,UAAU;EACV;UACS,iCAAiC,8BAC3C,QAAO,iCAAiC,+BAA+B,+BAA+B,cAAc;;AAItH,UAAU,iCACT,aACA,aACA,SAC+B;CAC/B,MAAM,wBAAwB,IAAI,IAAI,OAAO,QAAQ,YAAY,CAAC;AAElE,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,YAAY,EAAE;EACvD,MAAM,wBAAwB,sBAAsB,IAAI,IAAI;AAC5D,wBAAsB,OAAO,IAAI;EAEjC,MAAM,mBAAmB,OAAO,0BAA0B;EAC1D,MAAM,aAAa,UAAU;AAG7B,MAAI,oBAAoB,CAAC,WACxB,OAAM;GACL,KAAK,GAAG,QAAQ,GAAG;GACnB,UAAU;GACV,UAAU;GACV;WAGO,CAAC,oBAAoB,WAC7B,OAAM;GACL,KAAK,GAAG,QAAQ,GAAG;GACnB,UAAU;GACV,UAAU;GACV;WAIO,0BAA0B,MAClC,OAAM;GACL,KAAK,GAAG,QAAQ,GAAG;GACnB,UAAU,OAAO,sBAAsB;GACvC,UAAU,OAAO,MAAM;GACvB;;AAKH,MAAK,MAAM,CAAC,KAAK,UAAU,sBAC1B,KAAI,MACH,OAAM;EACL,KAAK,GAAG,QAAQ,GAAG;EACnB,UAAU;EACV,UAAU;EACV"}