Fix role cbs and add isfirstmsg cbs
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { ArrowLeft, ArrowRight, PencilIcon, LanguagesIcon, RefreshCcwIcon, TrashIcon, CopyIcon, Volume2Icon, BotIcon, ArrowLeftRightIcon, UserIcon } from "lucide-svelte";
|
||||
import { ParseMarkdown, postTranslationParse, type simpleCharacterArgument } from "../../ts/parser";
|
||||
import { type CbsConditions, ParseMarkdown, postTranslationParse, type simpleCharacterArgument } from "../../ts/parser";
|
||||
import AutoresizeArea from "../UI/GUI/TextAreaResizable.svelte";
|
||||
import { alertConfirm, alertError, alertRequestData } from "../../ts/alert";
|
||||
import { language } from "../../lang";
|
||||
@@ -28,6 +28,7 @@
|
||||
export let onReroll = () => {}
|
||||
export let unReroll = () => {}
|
||||
export let character:simpleCharacterArgument|string|null = null
|
||||
export let firstMessage = false
|
||||
let translating = false
|
||||
try {
|
||||
translating = get(DataBase).autoTranslate
|
||||
@@ -73,8 +74,16 @@
|
||||
$CurrentChat.message = msg
|
||||
}
|
||||
|
||||
function getCbsCondition(){
|
||||
const cbsConditions:CbsConditions = {
|
||||
firstmsg: firstMessage ?? false,
|
||||
chatRole: $CurrentChat?.message?.[idx]?.role ?? null,
|
||||
}
|
||||
return cbsConditions
|
||||
}
|
||||
|
||||
function displaya(message:string){
|
||||
msgDisplay = risuChatParser(message, {chara: name, chatID: idx, rmVar: true, visualize: true})
|
||||
msgDisplay = risuChatParser(message, {chara: name, chatID: idx, rmVar: true, visualize: true, cbsConditions: getCbsCondition()})
|
||||
}
|
||||
|
||||
const setStatusMessage = (message:string, timeout:number = 0)=>{
|
||||
@@ -106,7 +115,7 @@
|
||||
}
|
||||
if(translateText){
|
||||
if(!$DataBase.legacyTranslation){
|
||||
const marked = await ParseMarkdown(data, charArg, 'pretranslate', chatID)
|
||||
const marked = await ParseMarkdown(data, charArg, 'pretranslate', chatID, getCbsCondition())
|
||||
translating = true
|
||||
const translated = await postTranslationParse(await translateHTML(marked, false, charArg, chatID))
|
||||
translating = false
|
||||
@@ -115,7 +124,7 @@
|
||||
return translated
|
||||
}
|
||||
else{
|
||||
const marked = await ParseMarkdown(data, charArg, mode, chatID)
|
||||
const marked = await ParseMarkdown(data, charArg, mode, chatID, getCbsCondition())
|
||||
translating = true
|
||||
const translated = await translateHTML(marked, false, charArg, chatID)
|
||||
translating = false
|
||||
@@ -125,7 +134,7 @@
|
||||
}
|
||||
}
|
||||
else{
|
||||
const marked = await ParseMarkdown(data, charArg, mode, chatID)
|
||||
const marked = await ParseMarkdown(data, charArg, mode, chatID, getCbsCondition())
|
||||
lastParsed = marked
|
||||
lastCharArg = charArg
|
||||
return marked
|
||||
|
||||
@@ -607,6 +607,7 @@
|
||||
idx={-1}
|
||||
altGreeting={$CurrentCharacter.alternateGreetings.length > 0}
|
||||
largePortrait={$CurrentCharacter.largePortrait}
|
||||
firstMessage={true}
|
||||
onReroll={() => {
|
||||
const cha = $CurrentCharacter
|
||||
const chat = $CurrentChat
|
||||
|
||||
@@ -5,16 +5,12 @@ import { getFileSrc } from './storage/globalApi';
|
||||
import { processScriptFull } from './process/scripts';
|
||||
import { get } from 'svelte/store';
|
||||
import css, { type CssAtRuleAST } from '@adobe/css-tools'
|
||||
import { CurrentCharacter, CurrentChat, SizeStore, selectedCharID } from './stores';
|
||||
import { CurrentCharacter, SizeStore, selectedCharID } from './stores';
|
||||
import { calcString } from './process/infunctions';
|
||||
import { findCharacterbyId, getPersonaPrompt, getUserIcon, getUserName, parseKeyValue, sfc32, sleep, uuidtoNumber } from './util';
|
||||
import { getInlayImage, writeInlayImage } from './process/files/image';
|
||||
import { getInlayImage } from './process/files/image';
|
||||
import { getModuleAssets, getModuleLorebooks } from './process/modules';
|
||||
import { HypaProcesser } from './process/memory/hypamemory';
|
||||
import { generateAIImage } from './process/stableDiff';
|
||||
import { requestChatData } from './process/request';
|
||||
import type { OpenAIChat } from './process';
|
||||
import { alertInput, alertNormal } from './alert';
|
||||
import hljs from 'highlight.js/lib/core'
|
||||
import 'highlight.js/styles/atom-one-dark.min.css'
|
||||
|
||||
@@ -386,7 +382,13 @@ export interface simpleCharacterArgument{
|
||||
}
|
||||
|
||||
|
||||
export async function ParseMarkdown(data:string, charArg:(character|simpleCharacterArgument | groupChat | string) = null, mode:'normal'|'back'|'pretranslate' = 'normal', chatID=-1) {
|
||||
export async function ParseMarkdown(
|
||||
data:string,
|
||||
charArg:(character|simpleCharacterArgument | groupChat | string) = null,
|
||||
mode:'normal'|'back'|'pretranslate' = 'normal',
|
||||
chatID=-1,
|
||||
cbsConditions:CbsConditions = {}
|
||||
) {
|
||||
let firstParsed = ''
|
||||
const additionalAssetMode = (mode === 'back') ? 'back' : 'normal'
|
||||
let char = (typeof(charArg) === 'string') ? (findCharacterbyId(charArg)) : (charArg)
|
||||
@@ -395,7 +397,7 @@ export async function ParseMarkdown(data:string, charArg:(character|simpleCharac
|
||||
firstParsed = data
|
||||
}
|
||||
if(char){
|
||||
data = (await processScriptFull(char, data, 'editdisplay', chatID)).data
|
||||
data = (await processScriptFull(char, data, 'editdisplay', chatID, cbsConditions)).data
|
||||
}
|
||||
if(firstParsed !== data && char && char.type !== 'group'){
|
||||
data = await parseAdditionalAssets(data, char, additionalAssetMode, 'post')
|
||||
@@ -625,6 +627,12 @@ type matcherArg = {
|
||||
text?:string,
|
||||
recursiveCount?:number
|
||||
lowLevelAccess?:boolean
|
||||
cbsConditions:CbsConditions
|
||||
}
|
||||
|
||||
export type CbsConditions = {
|
||||
firstmsg?:boolean
|
||||
chatRole?:string
|
||||
}
|
||||
function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string}|null = null ):{
|
||||
text:string,
|
||||
@@ -958,11 +966,26 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
|
||||
return db.subModel
|
||||
}
|
||||
case 'role': {
|
||||
if(matcherArg.cbsConditions.chatRole){
|
||||
return matcherArg.cbsConditions.chatRole
|
||||
}
|
||||
if(matcherArg.cbsConditions.firstmsg){
|
||||
return 'char'
|
||||
}
|
||||
if (chatID !== -1) {
|
||||
const selchar = db.characters[get(selectedCharID)]
|
||||
return selchar.chats[selchar.chatPage].message[chatID].role;
|
||||
}
|
||||
return matcherArg.role ?? 'role'
|
||||
return matcherArg.role ?? 'null'
|
||||
}
|
||||
case 'isfirstmsg':
|
||||
case 'is_first_msg':
|
||||
case 'is_first_message':
|
||||
case 'isfirstmessage':{
|
||||
if(matcherArg.cbsConditions.firstmsg){
|
||||
return '1'
|
||||
}
|
||||
return '0'
|
||||
}
|
||||
case 'jbtoggled':{
|
||||
return db.jailbreakToggle ? '1' : '0'
|
||||
@@ -1740,6 +1763,7 @@ export function risuChatParser(da:string, arg:{
|
||||
runVar?:boolean
|
||||
functions?:Map<string,{data:string,arg:string[]}>
|
||||
callStack?:number
|
||||
cbsConditions?:CbsConditions
|
||||
} = {}):string{
|
||||
const chatID = arg.chatID ?? -1
|
||||
const db = arg.db ?? get(DataBase)
|
||||
@@ -1798,6 +1822,7 @@ export function risuChatParser(da:string, arg:{
|
||||
role: arg.role,
|
||||
runVar: arg.runVar ?? false,
|
||||
consistantChar: arg.consistantChar ?? false,
|
||||
cbsConditions: arg.cbsConditions ?? {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -644,7 +644,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
|
||||
let index = 0
|
||||
for(const msg of ms){
|
||||
let formatedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, role: msg.role}), 'editprocess')
|
||||
let formatedChat = await processScript(nowChatroom,risuChatParser(msg.data, {chara: currentChar, role: msg.role}), 'editprocess', {
|
||||
chatRole: msg.role,
|
||||
})
|
||||
let name = ''
|
||||
if(msg.role === 'char'){
|
||||
if(msg.saying){
|
||||
|
||||
@@ -5,7 +5,7 @@ import { downloadFile } from "../storage/globalApi";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
import { selectSingleFile } from "../util";
|
||||
import { assetRegex, risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
||||
import { assetRegex, type CbsConditions, risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
||||
import { runCharacterJS } from "../plugins/embedscript";
|
||||
import { getModuleAssets, getModuleRegexScripts } from "./modules";
|
||||
import { HypaProcesser } from "./memory/hypamemory";
|
||||
@@ -22,8 +22,8 @@ type pScript = {
|
||||
actions: string[]
|
||||
}
|
||||
|
||||
export async function processScript(char:character|groupChat, data:string, mode:ScriptMode){
|
||||
return (await processScriptFull(char, data, mode)).data
|
||||
export async function processScript(char:character|groupChat, data:string, mode:ScriptMode, cbsConditions:CbsConditions = {}){
|
||||
return (await processScriptFull(char, data, mode, -1, cbsConditions)).data
|
||||
}
|
||||
|
||||
export function exportRegex(s?:customscript[]){
|
||||
@@ -66,7 +66,7 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
||||
|
||||
let bestMatchCache = new Map<string, string>()
|
||||
|
||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1){
|
||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1, cbsConditions:CbsConditions = {}){
|
||||
let db = get(DataBase)
|
||||
let emoChanged = false
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript).concat(getModuleRegexScripts())
|
||||
@@ -102,7 +102,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
||||
|
||||
let input = script.in
|
||||
if(pscript.actions.includes('cbs')){
|
||||
input = risuChatParser(input, { chatID: chatID })
|
||||
input = risuChatParser(input, { chatID: chatID, cbsConditions })
|
||||
}
|
||||
|
||||
const reg = new RegExp(input, flag)
|
||||
@@ -172,7 +172,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
||||
}
|
||||
}
|
||||
else{
|
||||
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID })
|
||||
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID, cbsConditions })
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -215,7 +215,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
||||
}
|
||||
}
|
||||
else{
|
||||
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID })
|
||||
data = risuChatParser(data.replace(reg, outScript), { chatID: chatID, cbsConditions })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user