Add format selector to /listinjects
| @@ -1485,7 +1485,22 @@ export function initDefaultSlashCommands() { | |||
| 1485 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 1485 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 1486 | name: 'listinjects', | 1486 | name: 'listinjects', |
| 1487 | callback: listInjectsCallback, | 1487 | callback: listInjectsCallback, |
| 1488 | helpString: 'Lists all script injections for the current chat.', | 1488 | helpString: 'Lists all script injections for the current chat. Displays injects in a popup by default. Use the <code>format</code> argument to change the output format.', |
| 1489 | returns: 'JSON object of script injections', | ||
| 1490 | namedArgumentList: [ | ||
| 1491 | SlashCommandNamedArgument.fromProps({ | ||
| 1492 | name: 'format', | ||
| 1493 | description: 'output format', | ||
| 1494 | typeList: [ARGUMENT_TYPE.STRING], | ||
| 1495 | isRequired: true, | ||
| 1496 | forceEnum: true, | ||
| 1497 | enumList: [ | ||
| 1498 | new SlashCommandEnumValue('popup', 'Show injects in a popup.', enumTypes.enum, enumIcons.default), | ||
| 1499 | new SlashCommandEnumValue('chat', 'Post a system message to the chat.', enumTypes.enum, enumIcons.default), | ||
| 1500 | new SlashCommandEnumValue('none', 'Just return the injects as a JSON object.', enumTypes.enum, enumIcons.default), | ||
| 1501 | ], | ||
| 1502 | }), | ||
| 1503 | ], | ||
| 1489 | })); | 1504 | })); |
| 1490 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 1505 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 1491 | name: 'flushinject', | 1506 | name: 'flushinject', |
| @@ -1743,10 +1758,11 @@ function injectCallback(args, value) { | |||
| 1743 | return ''; | 1758 | return ''; |
| 1744 | } | 1759 | } |
| 1745 | 1760 | ||
| 1746 | function listInjectsCallback() { | 1761 | async function listInjectsCallback(args) { |
| 1762 | const type = String(args?.format).toLowerCase().trim(); | ||
| 1747 | if (!chat_metadata.script_injects || !Object.keys(chat_metadata.script_injects).length) { | 1763 | if (!chat_metadata.script_injects || !Object.keys(chat_metadata.script_injects).length) { |
| 1748 | toastr.info('No script injections for the current chat'); | 1764 | type !== 'none' && toastr.info('No script injections for the current chat'); |
| 1749 | return ''; | 1765 | return JSON.stringify({}); |
| 1750 | } | 1766 | } |
| 1751 | 1767 | ||
| 1752 | const injects = Object.entries(chat_metadata.script_injects) | 1768 | const injects = Object.entries(chat_metadata.script_injects) |
| @@ -1761,7 +1777,19 @@ function listInjectsCallback() { | |||
| 1761 | const messageText = `### Script injections:\n${injects}`; | 1777 | const messageText = `### Script injections:\n${injects}`; |
| 1762 | const htmlMessage = DOMPurify.sanitize(converter.makeHtml(messageText)); | 1778 | const htmlMessage = DOMPurify.sanitize(converter.makeHtml(messageText)); |
| 1763 | 1779 | ||
| 1764 | sendSystemMessage(system_message_types.GENERIC, htmlMessage); | 1780 | switch (type) { |
| 1781 | case 'none': | ||
| 1782 | break; | ||
| 1783 | case 'chat': | ||
| 1784 | sendSystemMessage(system_message_types.GENERIC, htmlMessage); | ||
| 1785 | break; | ||
| 1786 | case 'popup': | ||
| 1787 | default: | ||
| 1788 | await callGenericPopup(htmlMessage, POPUP_TYPE.TEXT); | ||
| 1789 | break; | ||
| 1790 | } | ||
| 1791 | |||
| 1792 | return JSON.stringify(chat_metadata.script_injects); | ||
| 1765 | } | 1793 | } |
| 1766 | 1794 | ||
| 1767 | /** | 1795 | /** |