@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
1 lines • 6.84 kB
Source Map (JSON)
{"version":3,"file":"computeDifferences.cjs","names":["ApplicationCommandType","contextMenuTypes","casted","checkName","checkDMPermission","checkDefaultMemberPermissions","originalLocalizedNames","expectedLocalizedNames","checkLocalizations","checkIntegrationTypes","checkInteractionContextTypes","checkDescription","checkOptions"],"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,SAASA,6CAAuB,aAAa,gBAAgB,MAAM;AAEtF,MAAIC,oFAAiB,SAAS,gBAAgB,QAAQD,6CAAuB,UAAU,EAAE;GACxF,MAAME,WAAS;AAGf,UAAOC,0EAAU;IAAE,SAAS,gBAAgB;IAAM,SAASD,SAAO;IAAM,CAAC;AAGzE,OAAI,CAAC,aACJ,QAAOE,2FAAkB,gBAAgB,eAAeF,SAAO,cAAc;AAI9E,UAAOG,oHAA8B,gBAAgB,4BAA4BH,SAAO,2BAA2B;GAGnH,MAAMI,2BAAyB,gBAAgB;GAC/C,MAAMC,2BAAyBL,SAAO;AAEtC,UAAOM,4FAAmB;IACzB,eAAe;IACf,sBAAsB;IACtB,sBAAsB;IAC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