Update hide / unhide commands to accept range

This commit is contained in:
Cohee 2023-11-14 21:37:37 +02:00
parent c6ac4459a3
commit abb8b0f0cc
3 changed files with 33 additions and 16 deletions

View File

@ -4685,7 +4685,7 @@ async function renamePastChats(newAvatar, newValue) {
}
}
function saveChatDebounced() {
export function saveChatDebounced() {
const chid = this_chid;
const selectedGroup = selected_group;

View File

@ -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() {

View File

@ -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, [], '<span class="monospace">(prompt)</sp
parser.addCommand('delname', deleteMessagesByNameCallback, ['cancel'], '<span class="monospace">(name)</span> deletes all messages attributed to a specified name', true, true);
parser.addCommand('send', sendUserMessageCallback, ['add'], '<span class="monospace">(text)</span> adds a user message to the chat log without triggering a generation', true, true);
parser.addCommand('trigger', triggerGroupMessageCallback, [], '<span class="monospace">(member index or name)</span> triggers a message generation for the specified group member', true, true);
parser.addCommand('hide', hideMessageCallback, [], '<span class="monospace">(message index)</span> hides a chat message from the prompt', true, true);
parser.addCommand('unhide', unhideMessageCallback, [], '<span class="monospace">(message index)</span> unhides a message from the prompt', true, true);
parser.addCommand('hide', hideMessageCallback, [], '<span class="monospace">(message index or range)</span> hides a chat message from the prompt', true, true);
parser.addCommand('unhide', unhideMessageCallback, [], '<span class="monospace">(message index or range)</span> unhides a message from the prompt', true, true);
const NARRATOR_NAME_KEY = 'narrator_name';
const NARRATOR_NAME_DEFAULT = 'System';
@ -240,7 +241,14 @@ async function hideMessageCallback(_, arg) {
return;
}
const messageId = Number(arg);
const range = stringToRange(arg, 0, chat.length - 1);
if (!range) {
console.warn(`WARN: Invalid range provided for /hide command: ${arg}`);
return;
}
for (let messageId = range.start; messageId <= range.end; messageId++) {
const messageBlock = $(`.mes[mesid="${messageId}"]`);
if (!messageBlock.length) {
@ -250,6 +258,7 @@ async function hideMessageCallback(_, arg) {
await hideChatMessage(messageId, messageBlock);
}
}
async function unhideMessageCallback(_, arg) {
if (!arg) {
@ -257,7 +266,14 @@ async function unhideMessageCallback(_, arg) {
return;
}
const messageId = Number(arg);
const range = stringToRange(arg, 0, chat.length - 1);
if (!range) {
console.warn(`WARN: Invalid range provided for /unhide command: ${arg}`);
return;
}
for (let messageId = range.start; messageId <= range.end; messageId++) {
const messageBlock = $(`.mes[mesid="${messageId}"]`);
if (!messageBlock.length) {
@ -267,6 +283,7 @@ async function unhideMessageCallback(_, arg) {
await unhideChatMessage(messageId, messageBlock);
}
}
async function triggerGroupMessageCallback(_, arg) {
if (!selected_group) {