Add format selector to /listinjects

f5873aec259a65a0822f353cb9d732713737d172

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

1 files changed, +33 -5Ignore whitespace
public/scripts/slash-commands.js+33 -5
@@ -1485,7 +1485,22 @@ export function initDefaultSlashCommands() {
14851485 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
14861486 name: 'listinjects',
14871487 callback: listInjectsCallback,
14881488 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+ ],
14891504 }));
14901505 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
14911506 name: 'flushinject',
@@ -1743,10 +1758,11 @@ function injectCallback(args, value) {
17431758 return '';
17441759}
17451760
17461761async function listInjectsCallback(args) {
1762+ const type = String(args?.format).toLowerCase().trim();
17471763 if (!chat_metadata.script_injects || !Object.keys(chat_metadata.script_injects).length) {
17481764 type !== 'none' && toastr.info('No script injections for the current chat');
1749- return '';
1765+ return JSON.stringify({});
17501766 }
17511767
17521768 const injects = Object.entries(chat_metadata.script_injects)
@@ -1761,7 +1777,19 @@ function listInjectsCallback() {
17611777 const messageText = `### Script injections:\n${injects}`;
17621778 const htmlMessage = DOMPurify.sanitize(converter.makeHtml(messageText));
17631779
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);
17651793}
17661794
17671795/**