// A method to reformat command input text which contains a "#"
// Such that all "do", "say", "story" inputs perfectly match a regular "story" input for command parsing
// 😘
function giftFromLeahToRae(rawText) {
if (!rawText.includes("#")) {
return rawText;
}
let commandText = rawText;
if (commandText.startsWith("\n> ")) {
// Input text is either "do" or "say"
characterName = getCharacterName(commandText);
// Remove the leadning newline, ">", and single space
commandText = commandText.substring(3);
if (commandText.startsWith(characterName + " ")) {
// Remove the leading character name and the single space which follows
commandText = commandText.substring(characterName.length + 1);
}
if (commandText.startsWith("say")) {
// Input text is "say"
// Remove the leading "say"
commandText = commandText.substring(3);
if (commandText.startsWith("s ")) {
// Input text is 3rd-person perspective
// Remove the leading lonely "s"
commandText = commandText.substring(1);
}
if (commandText.startsWith(" \"")) {
// Remove the leading single space and quotation mark
commandText = commandText.substring(2);
}
if (commandText.endsWith("\"\n")) {
// Remove the trailing quotation mark and newline
commandText = commandText.substring(0, commandText.length - 2);
}
} else if (commandText.endsWith("\n")) {
// Input text is "do"
// Remove the trailing newline
commandText = commandText.substring(0, commandText.length - 1);
if (commandText.endsWith(".")) {
// Remove the trailing auto-generated period if it exists
commandText = commandText.substring(0, commandText.length - 1);
}
}
} else if (commandText.startsWith(" ")) {
// Input text is "story"
// Remove the leading single space
commandText = commandText.substring(1);
}
return commandText;
}
Credit to LewdLeah from the AI Dungeon discord: