@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
1 lines • 6.6 kB
Source Map (JSON)
{"version":3,"file":"computeDifferences.mjs","names":["casted","originalLocalizedNames","expectedLocalizedNames"],"sources":["../../../../../src/lib/utils/application-commands/computeDifferences.ts"],"sourcesContent":["import {\n\tApplicationCommandType,\n\ttype RESTPostAPIApplicationCommandsJSONBody,\n\ttype RESTPostAPIChatInputApplicationCommandsJSONBody,\n\ttype RESTPostAPIContextMenuApplicationCommandsJSONBody\n} from 'discord-api-types/v10';\nimport type { InternalAPICall } from './ApplicationCommandRegistry';\nimport { contextMenuTypes, type CommandDifference } from './compute-differences/_shared';\nimport { checkDefaultMemberPermissions } from './compute-differences/default_member_permissions';\nimport { checkDescription } from './compute-differences/description';\nimport { checkDMPermission } from './compute-differences/dm_permission';\nimport { checkLocalizations } from './compute-differences/localizations';\nimport { checkName } from './compute-differences/name';\nimport { checkOptions } from './compute-differences/options';\nimport { checkIntegrationTypes } from './compute-differences/integration_types';\nimport { checkInteractionContextTypes } from './compute-differences/contexts';\n\n/**\n * @returns `true` if there are differences, `false` otherwise\n */\nexport function getCommandDifferencesFast(\n\texistingCommand: RESTPostAPIApplicationCommandsJSONBody,\n\tapiData: InternalAPICall['builtData'],\n\tguildCommand: boolean\n) {\n\tfor (const _ of getCommandDifferences(existingCommand, apiData, guildCommand)) {\n\t\t// Return immediately on first difference found (also means we skip all other checks)\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nexport function* getCommandDifferences(\n\texistingCommand: RESTPostAPIApplicationCommandsJSONBody,\n\tapiData: InternalAPICall['builtData'],\n\tguildCommand: boolean\n): Generator<CommandDifference> {\n\tif (existingCommand.type !== ApplicationCommandType.ChatInput && existingCommand.type) {\n\t\t// Check context menus\n\t\tif (contextMenuTypes.includes(existingCommand.type ?? ApplicationCommandType.ChatInput)) {\n\t\t\tconst casted = apiData as RESTPostAPIContextMenuApplicationCommandsJSONBody;\n\n\t\t\t// Check name\n\t\t\tyield* checkName({ oldName: existingCommand.name, newName: casted.name });\n\n\t\t\t// Check dmPermission only for non-guild commands\n\t\t\tif (!guildCommand) {\n\t\t\t\tyield* checkDMPermission(existingCommand.dm_permission, casted.dm_permission);\n\t\t\t}\n\n\t\t\t// Check defaultMemberPermissions\n\t\t\tyield* checkDefaultMemberPermissions(existingCommand.default_member_permissions, casted.default_member_permissions);\n\n\t\t\t// Check localized names\n\t\t\tconst originalLocalizedNames = existingCommand.name_localizations;\n\t\t\tconst expectedLocalizedNames = casted.name_localizations;\n\n\t\t\tyield* checkLocalizations({\n\t\t\t\tlocaleMapName: 'nameLocalizations',\n\t\t\t\tlocalePresentMessage: 'localized names',\n\t\t\t\tlocaleMissingMessage: 'no localized names',\n\t\t\t\toriginalLocalizedDescriptions: originalLocalizedNames,\n\t\t\t\texpectedLocalizedDescriptions: expectedLocalizedNames\n\t\t\t});\n\n\t\t\t// Check integration types\n\t\t\tyield* checkIntegrationTypes(existingCommand.integration_types, casted.integration_types);\n\n\t\t\t// Check contexts\n\t\t\tyield* checkInteractionContextTypes(existingCommand.contexts, casted.contexts);\n\t\t}\n\n\t\treturn;\n\t}\n\n\tconst casted = apiData as RESTPostAPIChatInputApplicationCommandsJSONBody;\n\n\t// Check name\n\tyield* checkName({ oldName: existingCommand.name.toLowerCase(), newName: casted.name.toLowerCase() });\n\n\t// Check localized names\n\tconst originalLocalizedNames = existingCommand.name_localizations;\n\tconst expectedLocalizedNames = casted.name_localizations;\n\n\tyield* checkLocalizations({\n\t\tlocaleMapName: 'nameLocalizations',\n\t\tlocalePresentMessage: 'localized names',\n\t\tlocaleMissingMessage: 'no localized names',\n\t\toriginalLocalizedDescriptions: originalLocalizedNames,\n\t\texpectedLocalizedDescriptions: expectedLocalizedNames\n\t});\n\n\t// Check dmPermission\n\tif (!guildCommand) {\n\t\tyield* checkDMPermission(existingCommand.dm_permission, casted.dm_permission);\n\t}\n\n\t// Check defaultMemberPermissions\n\tyield* checkDefaultMemberPermissions(existingCommand.default_member_permissions, casted.default_member_permissions);\n\n\t// Check description\n\tyield* checkDescription({ oldDescription: existingCommand.description, newDescription: casted.description });\n\n\t// Check localized descriptions\n\tconst originalLocalizedDescriptions = existingCommand.description_localizations;\n\tconst expectedLocalizedDescriptions = casted.description_localizations;\n\n\tyield* checkLocalizations({\n\t\tlocaleMapName: 'descriptionLocalizations',\n\t\tlocalePresentMessage: 'localized descriptions',\n\t\tlocaleMissingMessage: 'no localized descriptions',\n\t\toriginalLocalizedDescriptions,\n\t\texpectedLocalizedDescriptions\n\t});\n\n\t// Check integration types\n\tyield* checkIntegrationTypes(existingCommand.integration_types, casted.integration_types);\n\n\t// Check contexts\n\tyield* checkInteractionContextTypes(existingCommand.contexts, casted.contexts);\n\n\tyield* checkOptions(existingCommand.options, casted.options);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAgB,0BACf,iBACA,SACA,cACC;AACD,MAAK,MAAM,KAAK,sBAAsB,iBAAiB,SAAS,aAAa,CAE5E,QAAO;AAGR,QAAO;;AAGR,UAAiB,sBAChB,iBACA,SACA,cAC+B;AAC/B,KAAI,gBAAgB,SAAS,uBAAuB,aAAa,gBAAgB,MAAM;AAEtF,MAAI,iBAAiB,SAAS,gBAAgB,QAAQ,uBAAuB,UAAU,EAAE;GACxF,MAAMA,WAAS;AAGf,UAAO,UAAU;IAAE,SAAS,gBAAgB;IAAM,SAASA,SAAO;IAAM,CAAC;AAGzE,OAAI,CAAC,aACJ,QAAO,kBAAkB,gBAAgB,eAAeA,SAAO,cAAc;AAI9E,UAAO,8BAA8B,gBAAgB,4BAA4BA,SAAO,2BAA2B;GAGnH,MAAMC,2BAAyB,gBAAgB;GAC/C,MAAMC,2BAAyBF,SAAO;AAEtC,UAAO,mBAAmB;IACzB,eAAe;IACf,sBAAsB;IACtB,sBAAsB;IACtB,+BAA+BC;IAC/B,+BAA+BC;IAC/B,CAAC;AAGF,UAAO,sBAAsB,gBAAgB,mBAAmBF,SAAO,kBAAkB;AAGzF,UAAO,6BA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