From 49483e2e21f4189c482301f5ad0453efebcab3bd Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Sun, 7 Jan 2024 11:36:44 +0000 Subject: [PATCH 1/3] add optional arguments to /world command - deactivate a single world - toggle a world - suppress toast messages --- public/scripts/world-info.js | 44 +++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 67ed6a9ee..d0fc83f05 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -2265,25 +2265,53 @@ export async function importEmbeddedWorldInfo(skipPopup = false) { setWorldInfoButtonClass(chid, true); } -function onWorldInfoChange(_, text) { - if (_ !== '__notSlashCommand__') { // if it's a slash command +function onWorldInfoChange(args, text) { + if (args !== '__notSlashCommand__') { // if it's a slash command + const silent = args.silent == 'true'; if (text.trim() !== '') { // and args are provided const slashInputSplitText = text.trim().toLowerCase().split(','); slashInputSplitText.forEach((worldName) => { const wiElement = getWIElement(worldName); if (wiElement.length > 0) { - selected_world_info.push(wiElement.text()); - wiElement.prop('selected', true); - toastr.success(`Activated world: ${wiElement.text()}`); + const name = wiElement.text(); + switch (args.state) { + case 'off': { + if (selected_world_info.includes(name)) { + selected_world_info.splice(selected_world_info.indexOf(name), 1); + wiElement.prop('selected', false); + if (!silent) toastr.success(`Deactivated world: ${name}`); + } else { + if (!silent) toastr.error(`World was not active: ${name}`); + } + break; + } + case 'toggle': { + if (selected_world_info.includes(name)) { + selected_world_info.splice(selected_world_info.indexOf(name), 1); + wiElement.prop('selected', false); + if (!silent) toastr.success(`Activated world: ${name}`); + } else { + selected_world_info.push(name); + wiElement.prop('selected', true); + if (!silent) toastr.success(`Deactivated world: ${name}`); + } + break; + } + default: { + selected_world_info.push(name); + wiElement.prop('selected', true); + if (!silent) toastr.success(`Activated world: ${name}`); + } + } } else { - toastr.error(`No world found named: ${worldName}`); + if (!silent) toastr.error(`No world found named: ${worldName}`); } }); $('#world_info').trigger('change'); } else { // if no args, unset all worlds toastr.success('Deactivated all worlds'); - selected_world_info = []; + if (!silent) selected_world_info = []; $('#world_info').val(null).trigger('change'); } } else { //if it's a pointer selection @@ -2414,7 +2442,7 @@ function assignLorebookToChat() { jQuery(() => { $(document).ready(function () { - registerSlashCommand('world', onWorldInfoChange, [], '(optional name) – sets active World, or unsets if no args provided', true, true); + registerSlashCommand('world', onWorldInfoChange, [], '[optional state=off|toggle] [optional silent=true] (optional name) – sets active World, or unsets if no args provided, use state=off and state=toggle to deactivate or toggle a World, use silent=true to suppress toast messages', true, true); }); From 247048ebfab5e27081c9cd800098aaf3cc7a66ca Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 7 Jan 2024 18:58:30 +0200 Subject: [PATCH 2/3] Use boolean selector --- public/scripts/world-info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index d0fc83f05..abb552391 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -2267,7 +2267,7 @@ export async function importEmbeddedWorldInfo(skipPopup = false) { function onWorldInfoChange(args, text) { if (args !== '__notSlashCommand__') { // if it's a slash command - const silent = args.silent == 'true'; + const silent = isTrueBoolean(args.silent); if (text.trim() !== '') { // and args are provided const slashInputSplitText = text.trim().toLowerCase().split(','); From c54746b21c8c84530ce43851f63bfb82cd7d4cf3 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 7 Jan 2024 19:00:16 +0200 Subject: [PATCH 3/3] Fix world unset --- public/scripts/world-info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index abb552391..79aabc100 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -2310,8 +2310,8 @@ function onWorldInfoChange(args, text) { }); $('#world_info').trigger('change'); } else { // if no args, unset all worlds - toastr.success('Deactivated all worlds'); - if (!silent) selected_world_info = []; + if (!silent) toastr.success('Deactivated all worlds'); + selected_world_info = []; $('#world_info').val(null).trigger('change'); } } else { //if it's a pointer selection