diff --git a/public/script.js b/public/script.js index 825429ab3..3d0bca026 100644 --- a/public/script.js +++ b/public/script.js @@ -4685,7 +4685,7 @@ async function renamePastChats(newAvatar, newValue) { } } -function saveChatDebounced() { +export function saveChatDebounced() { const chid = this_chid; const selectedGroup = selected_group; diff --git a/public/scripts/chats.js b/public/scripts/chats.js index d716a968f..50a63beaa 100644 --- a/public/scripts/chats.js +++ b/public/scripts/chats.js @@ -4,7 +4,7 @@ import { chat, getCurrentChatId, hideSwipeButtons, - saveChatConditional, + saveChatDebounced, showSwipeButtons, } from "../script.js"; @@ -30,7 +30,7 @@ export async function hideChatMessage(messageId, messageBlock) { hideSwipeButtons(); showSwipeButtons(); - await saveChatConditional(); + saveChatDebounced(); } /** @@ -55,7 +55,7 @@ export async function unhideChatMessage(messageId, messageBlock) { hideSwipeButtons(); showSwipeButtons(); - await saveChatConditional(); + saveChatDebounced(); } jQuery(function() { diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index b1af99469..9fb31fbe9 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -32,6 +32,7 @@ import { chat_styles, power_user } from "./power-user.js"; import { autoSelectPersona } from "./personas.js"; import { getContext } from "./extensions.js"; import { hideChatMessage, unhideChatMessage } from "./chats.js"; +import { stringToRange } from "./utils.js"; export { executeSlashCommands, registerSlashCommand, @@ -145,8 +146,8 @@ parser.addCommand('ask', askCharacter, [], '(prompt)(name) – deletes all messages attributed to a specified name', true, true); parser.addCommand('send', sendUserMessageCallback, ['add'], '(text) – adds a user message to the chat log without triggering a generation', true, true); parser.addCommand('trigger', triggerGroupMessageCallback, [], '(member index or name) – triggers a message generation for the specified group member', true, true); -parser.addCommand('hide', hideMessageCallback, [], '(message index) – hides a chat message from the prompt', true, true); -parser.addCommand('unhide', unhideMessageCallback, [], '(message index) – unhides a message from the prompt', true, true); +parser.addCommand('hide', hideMessageCallback, [], '(message index or range) – hides a chat message from the prompt', true, true); +parser.addCommand('unhide', unhideMessageCallback, [], '(message index or range) – unhides a message from the prompt', true, true); const NARRATOR_NAME_KEY = 'narrator_name'; const NARRATOR_NAME_DEFAULT = 'System'; @@ -240,15 +241,23 @@ async function hideMessageCallback(_, arg) { return; } - const messageId = Number(arg); - const messageBlock = $(`.mes[mesid="${messageId}"]`); + const range = stringToRange(arg, 0, chat.length - 1); - if (!messageBlock.length) { - console.warn(`WARN: No message found with ID ${messageId}`); + if (!range) { + console.warn(`WARN: Invalid range provided for /hide command: ${arg}`); return; } - await hideChatMessage(messageId, messageBlock); + for (let messageId = range.start; messageId <= range.end; messageId++) { + const messageBlock = $(`.mes[mesid="${messageId}"]`); + + if (!messageBlock.length) { + console.warn(`WARN: No message found with ID ${messageId}`); + return; + } + + await hideChatMessage(messageId, messageBlock); + } } async function unhideMessageCallback(_, arg) { @@ -257,15 +266,23 @@ async function unhideMessageCallback(_, arg) { return; } - const messageId = Number(arg); - const messageBlock = $(`.mes[mesid="${messageId}"]`); + const range = stringToRange(arg, 0, chat.length - 1); - if (!messageBlock.length) { - console.warn(`WARN: No message found with ID ${messageId}`); + if (!range) { + console.warn(`WARN: Invalid range provided for /unhide command: ${arg}`); return; } - await unhideChatMessage(messageId, messageBlock); + for (let messageId = range.start; messageId <= range.end; messageId++) { + const messageBlock = $(`.mes[mesid="${messageId}"]`); + + if (!messageBlock.length) { + console.warn(`WARN: No message found with ID ${messageId}`); + return; + } + + await unhideChatMessage(messageId, messageBlock); + } } async function triggerGroupMessageCallback(_, arg) {