Add /extension-exists and /extension-state

1a6f0c0922b263dbdcac7904996cfe4fce47805a

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +69 -2Showing whitespace changes
public/scripts/extensions.js+69 -2
@@ -1056,7 +1056,7 @@ export async function openThirdPartyExtensionMenu(suggestUrl = '') {
1056function getExtensionActionCallback(action) {1056function getExtensionActionCallback(action) {
1057 return async (args, extensionName) => {1057 return async (args, extensionName) => {
1058 if (args?.reload instanceof SlashCommandClosure) throw new Error('\'reload\' argument cannot be a closure.');1058 if (args?.reload instanceof SlashCommandClosure) throw new Error('\'reload\' argument cannot be a closure.');
1059 if (typeof extensionName !== 'string') throw new Error('Extension name does only support string. Closures or arrays are not allowed.');1059 if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.');
1060 if (!extensionName) {1060 if (!extensionName) {
1061 toastr.warning(`Extension name must be provided as an argument to ${action} this extension.`);1061 toastr.warning(`Extension name must be provided as an argument to ${action} this extension.`);
1062 return '';1062 return '';
@@ -1184,7 +1184,7 @@ function registerExtensionSlashCommands() {
1184 name: 'extension-toggle',1184 name: 'extension-toggle',
1185 callback: async (args, extensionName) => {1185 callback: async (args, extensionName) => {
1186 if (args?.state instanceof SlashCommandClosure) throw new Error('\'state\' argument cannot be a closure.');1186 if (args?.state instanceof SlashCommandClosure) throw new Error('\'state\' argument cannot be a closure.');
1187 if (typeof extensionName !== 'string') throw new Error('Extension name does only support string. Closures or arrays are not allowed.');1187 if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.');
11881188
1189 const action = isTrueBoolean(args?.state) ? 'enable' :1189 const action = isTrueBoolean(args?.state) ? 'enable' :
1190 isFalseBoolean(args?.state) ? 'disable' :1190 isFalseBoolean(args?.state) ? 'disable' :
@@ -1238,6 +1238,73 @@ function registerExtensionSlashCommands() {
1238 </div>1238 </div>
1239 `,1239 `,
1240 }));1240 }));
1241 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
1242 name: 'extension-state',
1243 callback: async (_, extensionName) => {
1244 if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.');
1245 const internalExtensionName = extensionNames.find(x => equalsIgnoreCaseAndAccents(x, extensionName));
1246 if (!internalExtensionName) {
1247 toastr.warning(`Extension ${extensionName} does not exist.`);
1248 return '';
1249 }
1250
1251 const isEnabled = !extension_settings.disabledExtensions.includes(internalExtensionName);
1252 return String(isEnabled);
1253 },
1254 unnamedArgumentList: [
1255 SlashCommandArgument.fromProps({
1256 description: 'Extension name',
1257 typeList: [ARGUMENT_TYPE.STRING],
1258 isRequired: true,
1259 enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)),
1260 forceEnum: true,
1261 }),
1262 ],
1263 helpString: `
1264 <div>
1265 Returns the state of a specified extension (true if enabled, false if disabled).
1266 </div>
1267 <div>
1268 <strong>Example:</strong>
1269 <ul>
1270 <li>
1271 <pre><code class="language-stscript">/extension-state Summarize</code></pre>
1272 </li>
1273 </ul>
1274 </div>
1275 `,
1276 }));
1277 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
1278 name: 'extension-exists',
1279 aliases: ['extension-installed'],
1280 callback: async (_, extensionName) => {
1281 if (typeof extensionName !== 'string') throw new Error('Extension name must be a string. Closures or arrays are not allowed.');
1282 const exists = extensionNames.find(x => equalsIgnoreCaseAndAccents(x, extensionName)) !== undefined;
1283 return exists ? 'true' : 'false';
1284 },
1285 unnamedArgumentList: [
1286 SlashCommandArgument.fromProps({
1287 description: 'Extension name',
1288 typeList: [ARGUMENT_TYPE.STRING],
1289 isRequired: true,
1290 enumProvider: () => extensionNames.map(name => new SlashCommandEnumValue(name)),
1291 forceEnum: true,
1292 }),
1293 ],
1294 helpString: `
1295 <div>
1296 Checks if a specified extension exists.
1297 </div>
1298 <div>
1299 <strong>Example:</strong>
1300 <ul>
1301 <li>
1302 <pre><code class="language-stscript">/extension-exists LALib</code></pre>
1303 </li>
1304 </ul>
1305 </div>
1306 `,
1307 }));
12411308
1242 SlashCommandParser.addCommandObject(SlashCommand.fromProps({1309 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
1243 name: 'reload-page',1310 name: 'reload-page',