From 7087f39d5a89ff9442cc7e5132e70396dcfe67f0 Mon Sep 17 00:00:00 2001 From: 0x000011b <0x000011b@waifu.club> Date: Wed, 21 Dec 2022 20:05:01 -0300 Subject: [PATCH] fix: cai dumper crashing if chat had no messages --- extras/characterai-dumper/README.md | 2 ++ .../characterai-dumper.user.js | 34 ++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/extras/characterai-dumper/README.md b/extras/characterai-dumper/README.md index dd56103..3fee4f0 100644 --- a/extras/characterai-dumper/README.md +++ b/extras/characterai-dumper/README.md @@ -35,6 +35,8 @@ And you'll reach the page that should show the `Download` link. ## Changelog +- **v1.4:** + - Fixed a bug where the `Download` link wouldn't show up for a given bot if you had a conversation with it where all of the messages were deleted. - **v1.3:** - Implemented support for downloading a character's definitions from the Character Editor page. - Fixed a bug where the `Download` link was not showing up on some bots that had trailing whitespace in their names (e.g. `2B `). diff --git a/extras/characterai-dumper/characterai-dumper.user.js b/extras/characterai-dumper/characterai-dumper.user.js index eded9ab..6234f70 100644 --- a/extras/characterai-dumper/characterai-dumper.user.js +++ b/extras/characterai-dumper/characterai-dumper.user.js @@ -3,7 +3,7 @@ // @namespace Violentmonkey Scripts // @match https://beta.character.ai/* // @grant none -// @version 1.3 +// @version 1.4 // @author 0x000011b // @description Allows downloading saved chat messages and character definitions from CharacterAI. // @downloadURL https://git.fuwafuwa.moe/waifu-collective/toolbox/raw/branch/master/extras/characterai-dumper/characterai-dumper.user.js @@ -11,9 +11,9 @@ // ==/UserScript== const log = (firstArg, ...remainingArgs) => - console.log(`[CharacterAI Dumper v1.3] ${firstArg}`, ...remainingArgs); + console.log(`[CharacterAI Dumper v1.4] ${firstArg}`, ...remainingArgs); log.error = (firstArg, ...remainingArgs) => - console.error(`[CharacterAI Dumper v1.3] ${firstArg}`, ...remainingArgs); + console.error(`[CharacterAI Dumper v1.4] ${firstArg}`, ...remainingArgs); // Endpoints to intercept. const CHARACTER_INFO_URL = "https://beta.character.ai/chat/character/info/"; @@ -145,20 +145,22 @@ const anonymizeHistories = (histories) => { // _and_ bot messages, we might've seen more names to redact, so let's go // back to the first message and attempt to redact it again just in case we // have new names. - namesToReplace.forEach((nameToReplace) => { - if (!nameToReplace) { - return; - } + if (history.msgs.length) { + namesToReplace.forEach((nameToReplace) => { + if (!nameToReplace) { + return; + } - const replacementRegex = new RegExp( - "\\b" + escapeStringForRegExp(nameToReplace) + "\\b", - "g" - ); - history.msgs[0].text = history.msgs[0].text.replace( - replacementRegex, - "[NAME_IN_MESSAGE_REDACTED]" - ); - }); + const replacementRegex = new RegExp( + "\\b" + escapeStringForRegExp(nameToReplace) + "\\b", + "g" + ); + history.msgs[0].text = history.msgs[0].text.replace( + replacementRegex, + "[NAME_IN_MESSAGE_REDACTED]" + ); + }); + } } // This was modified in-place, but we return it here for simplicity at the