From 0bf6835de21a815b4d51c181d8272b437b10e9ff Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:40:34 +0200 Subject: [PATCH 1/2] Add "compact" argument to message sending commands. --- public/script.js | 7 +++++-- public/scripts/slash-commands.js | 17 ++++++++++++----- public/style.css | 5 +++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/public/script.js b/public/script.js index e56f4ec33..d223ef889 100644 --- a/public/script.js +++ b/public/script.js @@ -4178,9 +4178,10 @@ export function removeMacros(str) { * @param {string} messageText Message text. * @param {string} messageBias Message bias. * @param {number} [insertAt] Optional index to insert the message at. + * @params {boolean} [compact] Send as a compact display message. * @returns {Promise} A promise that resolves when the message is inserted. */ -export async function sendMessageAsUser(messageText, messageBias, insertAt = null) { +export async function sendMessageAsUser(messageText, messageBias, insertAt = null, compact = false) { messageText = getRegexedString(messageText, regex_placement.USER_INPUT); const message = { @@ -4189,7 +4190,9 @@ export async function sendMessageAsUser(messageText, messageBias, insertAt = nul is_system: false, send_date: getMessageTimeStamp(), mes: substituteParams(messageText), - extra: {}, + extra: { + isSmallSys: compact, + }, }; if (power_user.message_token_count_enabled) { diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index a6e0020ef..20f3e8666 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -204,10 +204,10 @@ parser.addCommand('name', setNameCallback, ['persona'], '(filename) – sets a background according to filename, partial names allowed', false, true); -parser.addCommand('sendas', sendMessageAs, [], ' – sends message as a specific character. Uses character avatar if it exists in the characters list. Example that will send "Hello, guys!" from "Chloe": /sendas name="Chloe" Hello, guys!', true, true); -parser.addCommand('sys', sendNarratorMessage, ['nar'], '(text) – sends message as a system narrator', false, true); +parser.addCommand('sendas', sendMessageAs, [], '[name=CharName compact=true/false (text)] – sends message as a specific character. Uses character avatar if it exists in the characters list. Example that will send "Hello, guys!" from "Chloe": /sendas name="Chloe" Hello, guys!. If "compact" is set to true, the message is sent using a compact layout.', true, true); +parser.addCommand('sys', sendNarratorMessage, ['nar'], '[compact=true/false (text)] – sends message as a system narrator. If "compact" is set to true, the message is sent using a compact layout.', false, true); parser.addCommand('sysname', setNarratorName, [], '(name) – sets a name for future system narrator messages in this chat (display only). Default: System. Leave empty to reset.', true, true); -parser.addCommand('comment', sendCommentMessage, [], '(text) – adds a note/comment message not part of the chat', false, true); +parser.addCommand('comment', sendCommentMessage, [], '[compact=true/false (text)] – adds a note/comment message not part of the chat. If "compact" is set to true, the message is sent using a compact layout.', false, true); parser.addCommand('single', setStoryModeCallback, ['story'], ' – sets the message style to single document mode without names or avatars visible', true, true); parser.addCommand('bubble', setBubbleModeCallback, ['bubbles'], ' – sets the message style to bubble chat mode', true, true); parser.addCommand('flat', setFlatModeCallback, ['default'], ' – sets the message style to flat chat mode', true, true); @@ -216,7 +216,7 @@ parser.addCommand('go', goToCharacterCallback, ['char'], '(prompt) – generates a system message using a specified prompt', true, true); parser.addCommand('ask', askCharacter, [], '(prompt) – asks a specified character card a prompt', true, true); parser.addCommand('delname', deleteMessagesByNameCallback, ['cancel'], '(name) – deletes all messages attributed to a specified name', true, true); -parser.addCommand('send', sendUserMessageCallback, [], '(text) – adds a user message to the chat log without triggering a generation', true, true); +parser.addCommand('send', sendUserMessageCallback, [], '[compact=true/false (text)] – adds a user message to the chat log without triggering a generation. If "compact" is set to true, the message is sent using a compact layout.', true, true); parser.addCommand('trigger', triggerGenerationCallback, [], ' await=true/false – triggers a message generation. If in group, can trigger a message for the specified group member index or name. If await=true named argument passed, the command will await for the triggered generation before continuing.', 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); @@ -1176,9 +1176,10 @@ async function sendUserMessageCallback(args, text) { } text = text.trim(); + const compact = isTrueBoolean(args?.compact); const bias = extractMessageBias(text); const insertAt = Number(resolveVariable(args?.at)); - await sendMessageAsUser(text, bias, insertAt); + await sendMessageAsUser(text, bias, insertAt, compact); return ''; } @@ -1391,6 +1392,7 @@ export async function sendMessageAs(args, text) { // Messages that do nothing but set bias will be hidden from the context const bias = extractMessageBias(mesText); const isSystem = bias && !removeMacros(mesText).length; + const compact = isTrueBoolean(args?.compact); const character = characters.find(x => x.name === name); let force_avatar, original_avatar; @@ -1415,6 +1417,7 @@ export async function sendMessageAs(args, text) { extra: { bias: bias.trim().length ? bias : null, gen_id: Date.now(), + isSmallSys: compact, }, }; @@ -1444,6 +1447,7 @@ export async function sendNarratorMessage(args, text) { // Messages that do nothing but set bias will be hidden from the context const bias = extractMessageBias(text); const isSystem = bias && !removeMacros(text).length; + const compact = isTrueBoolean(args?.compact); const message = { name: name, @@ -1456,6 +1460,7 @@ export async function sendNarratorMessage(args, text) { type: system_message_types.NARRATOR, bias: bias.trim().length ? bias : null, gen_id: Date.now(), + isSmallSys: compact, }, }; @@ -1520,6 +1525,7 @@ async function sendCommentMessage(args, text) { return; } + const compact = isTrueBoolean(args?.compact); const message = { name: COMMENT_NAME_DEFAULT, is_user: false, @@ -1530,6 +1536,7 @@ async function sendCommentMessage(args, text) { extra: { type: system_message_types.COMMENT, gen_id: Date.now(), + isSmallSys: compact, }, }; diff --git a/public/style.css b/public/style.css index 91932cb47..cacdc2679 100644 --- a/public/style.css +++ b/public/style.css @@ -382,6 +382,11 @@ small { text-align: center; } +.mes.smallSysMes .swipe_right, +.mes.smallSysMes .swipe_left { + display: none !important; +} + .mes.smallSysMes .mes_text { padding: 0 !important; text-align: center; From 45bd8c18ed9386091d832a15ca5d06b9d4796354 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:49:14 +0200 Subject: [PATCH 2/2] Remove last paragraph margin for compact layout --- public/style.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/style.css b/public/style.css index cacdc2679..3f54d5cec 100644 --- a/public/style.css +++ b/public/style.css @@ -382,6 +382,10 @@ small { text-align: center; } +.mes.smallSysMes .mes_text p:last-child { + margin: 0; +} + .mes.smallSysMes .swipe_right, .mes.smallSysMes .swipe_left { display: none !important;