Add format selector to /listinjects

f5873aec259a65a0822f353cb9d732713737d172

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +32 -4Showing whitespace changes
public/scripts/slash-commands.js+32 -4
@@ -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}
17451760
1746function listInjectsCallback() {1761async 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 }
17511767
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));
17631779
1780 switch (type) {
1781 case 'none':
1782 break;
1783 case 'chat':
1764 sendSystemMessage(system_message_types.GENERIC, htmlMessage);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}
17661794
1767/**1795/**