diff --git a/public/scripts/extensions.js b/public/scripts/extensions.js index c99255713..6c72c78e6 100644 --- a/public/scripts/extensions.js +++ b/public/scripts/extensions.js @@ -1056,7 +1056,7 @@ export async function openThirdPartyExtensionMenu(suggestUrl = '') { function getExtensionActionCallback(action) { return async (args, extensionName) => { if (args?.reload instanceof SlashCommandClosure) throw new Error('\'reload\' argument cannot be a closure.'); - if (typeof extensionName !== 'string') throw new Error('Extension name does only support string. Closures or arrays are not allowed.'); + if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.'); if (!extensionName) { toastr.warning(`Extension name must be provided as an argument to ${action} this extension.`); return ''; @@ -1184,7 +1184,7 @@ function registerExtensionSlashCommands() { name: 'extension-toggle', callback: async (args, extensionName) => { if (args?.state instanceof SlashCommandClosure) throw new Error('\'state\' argument cannot be a closure.'); - if (typeof extensionName !== 'string') throw new Error('Extension name does only support string. Closures or arrays are not allowed.'); + if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.'); const action = isTrueBoolean(args?.state) ? 'enable' : isFalseBoolean(args?.state) ? 'disable' : @@ -1238,6 +1238,73 @@ function registerExtensionSlashCommands() { `, })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'extension-state', + callback: async (_, extensionName) => { + if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.'); + const internalExtensionName = extensionNames.find(x => equalsIgnoreCaseAndAccents(x, extensionName)); + if (!internalExtensionName) { + toastr.warning(`Extension ${extensionName} does not exist.`); + return ''; + } + + const isEnabled = !extension_settings.disabledExtensions.includes(internalExtensionName); + return String(isEnabled); + }, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'Extension name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)), + forceEnum: true, + }), + ], + helpString: ` +
+ Returns the state of a specified extension (true if enabled, false if disabled). +
+
+ Example: + +
+ `, + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'extension-exists', + aliases: ['extension-installed'], + callback: async (_, extensionName) => { + if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.'); + const exists = extensionNames.find(x => equalsIgnoreCaseAndAccents(x, extensionName)) !== undefined; + return exists ? 'true' : 'false'; + }, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'Extension name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)), + forceEnum: true, + }), + ], + helpString: ` +
+ Checks if a specified extension exists. +
+
+ Example: + +
+ `, + })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'reload-page',