From f97deccb0254be50461eafa0f84dcd05cbc8ff00 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:12:48 +0900 Subject: [PATCH 01/12] Add pick and pow CBS --- src/ts/parser.ts | 24 +++++++++++++++++++++++- src/ts/util.ts | 23 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 6387af96..b5970cb4 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -9,7 +9,7 @@ import { get } from 'svelte/store'; import css from '@adobe/css-tools' import { selectedCharID } from './stores'; import { calcString } from './process/infunctions'; -import { findCharacterbyId } from './util'; +import { findCharacterbyId, sfc32, uuidtoNumber } from './util'; import { getInlayImage } from './process/files/image'; import { autoMarkNew } from './plugins/automark'; import { getModuleLorebooks } from './process/modules'; @@ -779,6 +779,9 @@ const matcher = (p1:string,matcherArg:matcherArg) => { return !isNaN(Number(v)) || v === '.' }).join('') } + case 'pow':{ + return Math.pow(Number(arra[1]), Number(arra[2])).toString() + } } } if(p1.startsWith('random')){ @@ -798,6 +801,25 @@ const matcher = (p1:string,matcherArg:matcherArg) => { return arr[randomIndex] } } + if(p1.startsWith('pick')){ + const selchar = db.characters[get(selectedCharID)] + const rand = sfc32(uuidtoNumber(selchar.chaId), chatID, uuidtoNumber(selchar.chaId), chatID) + if(p1.startsWith('random::')){ + const randomIndex = Math.floor(rand() * (arra.length - 1)) + 1 + if(matcherArg.tokenizeAccurate){ + return arra[0] + } + return arra[randomIndex] + } + else{ + const arr = p1.split(/\:|\,/g) + const randomIndex = Math.floor(rand() * (arr.length - 1)) + 1 + if(matcherArg.tokenizeAccurate){ + return arra[0] + } + return arr[randomIndex] + } + } if(p1.startsWith('roll')){ const arr = p1.split(/\:|\ /g) let ina = arr.at(-1) diff --git a/src/ts/util.ts b/src/ts/util.ts index 469ebb64..cfede7b7 100644 --- a/src/ts/util.ts +++ b/src/ts/util.ts @@ -442,4 +442,25 @@ export function blobToUint8Array(data:Blob){ }) } -export const languageCodes = ["af","ak","am","an","ar","as","ay","az","be","bg","bh","bm","bn","br","bs","ca","co","cs","cy","da","de","dv","ee","el","en","eo","es","et","eu","fa","fi","fo","fr","fy","ga","gd","gl","gn","gu","ha","he","hi","hr","ht","hu","hy","ia","id","ig","is","it","iu","ja","jv","ka","kk","km","kn","ko","ku","ky","la","lb","lg","ln","lo","lt","lv","mg","mi","mk","ml","mn","mr","ms","mt","my","nb","ne","nl","nn","no","ny","oc","om","or","pa","pl","ps","pt","qu","rm","ro","ru","rw","sa","sd","si","sk","sl","sm","sn","so","sq","sr","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ug","uk","ur","uz","vi","wa","wo","xh","yi","yo","zh","zu"] \ No newline at end of file +export const languageCodes = ["af","ak","am","an","ar","as","ay","az","be","bg","bh","bm","bn","br","bs","ca","co","cs","cy","da","de","dv","ee","el","en","eo","es","et","eu","fa","fi","fo","fr","fy","ga","gd","gl","gn","gu","ha","he","hi","hr","ht","hu","hy","ia","id","ig","is","it","iu","ja","jv","ka","kk","km","kn","ko","ku","ky","la","lb","lg","ln","lo","lt","lv","mg","mi","mk","ml","mn","mr","ms","mt","my","nb","ne","nl","nn","no","ny","oc","om","or","pa","pl","ps","pt","qu","rm","ro","ru","rw","sa","sd","si","sk","sl","sm","sn","so","sq","sr","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ug","uk","ur","uz","vi","wa","wo","xh","yi","yo","zh","zu"] + +export function sfc32(a:number, b:number, c:number, d:number) { + return function() { + a |= 0; b |= 0; c |= 0; d |= 0; + let t = (a + b | 0) + d | 0; + d = d + 1 | 0; + a = b ^ b >>> 9; + b = c + (c << 3) | 0; + c = (c << 21 | c >>> 11); + c = c + t | 0; + return (t >>> 0) / 4294967296; + } +} + +export function uuidtoNumber(uuid:string){ + let result = 0 + for(let i=0;i Date: Wed, 3 Apr 2024 19:12:59 +0900 Subject: [PATCH 02/12] Trim whitespace in blockEndMatcher function --- src/ts/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index b5970cb4..cdbf44de 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -921,7 +921,7 @@ function blockEndMatcher(p1:string,type:blockMatch,matcherArg:matcherArg):string return '' } if(type === 'parse'){ - return p1 + return p1.trim() } return '' From 2ad8d0e105a19e2a0ee50227c5e5a2afe69b7788 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:15:41 +0900 Subject: [PATCH 03/12] Add parse pure and fix statements --- src/ts/parser.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index cdbf44de..cc3ca55b 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -901,15 +901,15 @@ const legacyBlockMatcher = (p1:string,matcherArg:matcherArg) => { return null } -type blockMatch = 'ignore'|'parse'|'nothing' +type blockMatch = 'ignore'|'parse'|'nothing'|'parse-pure' function blockStartMatcher(p1:string,matcherArg:matcherArg):blockMatch{ - if(p1.startsWith('#if')){ - const statement = p1.split(" ", 2) + if(p1.startsWith('#if') || p1.startsWith('#if_pure ')){ + const statement = p1.substring(p1.indexOf(' ') + 1) const state = statement[1] if(state === 'true' || state === '1'){ - return 'parse' + return p1.startsWith('#if_pure') ? 'parse-pure' : 'parse' } return 'ignore' } @@ -922,7 +922,9 @@ function blockEndMatcher(p1:string,type:blockMatch,matcherArg:matcherArg):string } if(type === 'parse'){ return p1.trim() - + } + if(type === 'parse-pure'){ + return p1.trim() } return '' } From 9d90901223eb91d9fceadbe12355b47fa51241e0 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:17:39 +0900 Subject: [PATCH 04/12] Remove trim() function call in parse-pure --- src/ts/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index cc3ca55b..bc48b02e 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -924,7 +924,7 @@ function blockEndMatcher(p1:string,type:blockMatch,matcherArg:matcherArg):string return p1.trim() } if(type === 'parse-pure'){ - return p1.trim() + return p1 } return '' } From 28d4ee93cfb5e173d013c2761c98240643bef610 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:18:28 +0900 Subject: [PATCH 05/12] Refactor blockEndMatcher function to use switch statement --- src/ts/parser.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index bc48b02e..5fc291f3 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -917,16 +917,20 @@ function blockStartMatcher(p1:string,matcherArg:matcherArg):blockMatch{ } function blockEndMatcher(p1:string,type:blockMatch,matcherArg:matcherArg):string{ - if(type === 'ignore'){ - return '' - } - if(type === 'parse'){ - return p1.trim() - } - if(type === 'parse-pure'){ - return p1 + switch(type){ + case 'ignore':{ + return '' + } + case 'parse':{ + return p1.trim() + } + case 'parse-pure':{ + return p1 + } + default:{ + return '' + } } - return '' } export function risuChatParser(da:string, arg:{ From 8f8441e529ab3bc41d0929760ad4fc19d5f3aa74 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:19:15 +0900 Subject: [PATCH 06/12] make parse block to trim leading and trailing whitespace in parse function --- src/ts/parser.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 5fc291f3..1f06904e 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -922,7 +922,10 @@ function blockEndMatcher(p1:string,type:blockMatch,matcherArg:matcherArg):string return '' } case 'parse':{ - return p1.trim() + const trimedLines = p1.split('\n').map((v) => { + return v.trim() + }).join('\n').trim() + return trimedLines } case 'parse-pure':{ return p1 From 1c3c3cc16d22643a38315f755078831768537aa1 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:36:27 +0900 Subject: [PATCH 07/12] Add new cbs to the parser.ts file --- src/ts/parser.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 1f06904e..3dfe976a 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -405,7 +405,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => { const db = matcherArg.db const chara = matcherArg.chara switch(lowerCased){ - case 'previous_char_chat':{ + case 'previous_char_chat': + case 'lastusermessage':{ if(chatID !== -1){ const selchar = db.characters[get(selectedCharID)] const chat = selchar.chats[selchar.chatPage] @@ -420,7 +421,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => { } return '' } - case 'previous_user_chat':{ + case 'previous_user_chat': + case 'lastcharmessage':{ if(chatID !== -1){ const selchar = db.characters[get(selectedCharID)] const chat = selchar.chats[selchar.chatPage] @@ -625,7 +627,8 @@ const matcher = (p1:string,matcherArg:matcherArg) => { //output, like 1:30:00 return hours.toString() + ':' + minutes.toString().padStart(2,'0') + ':' + seconds.toString().padStart(2,'0') } - case 'br':{ + case 'br': + case 'newline':{ return '\n' } case 'model':{ @@ -643,6 +646,26 @@ const matcher = (p1:string,matcherArg:matcherArg) => { case 'random':{ return Math.random().toString() } + case 'maxcontext':{ + return db.maxContext.toString() + } + case 'lastmessage':{ + const selchar = db.characters[get(selectedCharID)] + if(!selchar){ + return '' + } + const chat = selchar.chats[selchar.chatPage] + return chat.message[chat.message.length - 1].data + } + case 'lastmessageid': + case 'lastmessageindex':{ + const selchar = db.characters[get(selectedCharID)] + if(!selchar){ + return '' + } + const chat = selchar.chats[selchar.chatPage] + return chat.message.length - 1 + } } const arra = p1.split("::") if(arra.length > 1){ From 6a9d88e5250685703d21e6e2b58d966dd797c7d5 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:37:33 +0900 Subject: [PATCH 08/12] remame time and date cbs to message_time and message_date --- src/ts/parser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 3dfe976a..6f5a92fe 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -539,7 +539,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { case 'none':{ return '' } - case 'time':{ + case 'message_time':{ if(matcherArg.tokenizeAccurate){ return `00:00:00` } @@ -557,7 +557,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { //output time in format like 10:30 AM return date.toLocaleTimeString() } - case 'date':{ + case 'message_date':{ if(matcherArg.tokenizeAccurate){ return `00:00:00` } From d302aaa79fdd524d7d3a27d60c139d4ada037dc3 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:47:26 +0900 Subject: [PATCH 09/12] Add date and time formatting cbs --- src/ts/parser.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 6f5a92fe..6bae79c1 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -574,6 +574,22 @@ const matcher = (p1:string,matcherArg:matcherArg) => { //output date in format like Aug 23, 2021 return date.toLocaleDateString() } + case 'time':{ + const now = new Date() + return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}` + } + case 'date':{ + const now = new Date() + return `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}` + } + case 'isotime':{ + const now = new Date() + return `${now.getUTCHours()}:${now.getUTCMinutes()}:${now.getUTCSeconds()}` + } + case 'isodate':{ + const now = new Date() + return `${now.getUTCFullYear()}-${now.getUTCMonth() + 1}-${now.getUTCDate()}` + } case 'idle_duration':{ if(matcherArg.tokenizeAccurate){ return `00:00:00` From 3c568b5287a2eea117e247cb5ad196dea0c56c93 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:55:04 +0900 Subject: [PATCH 10/12] Fix name in parser.ts --- src/ts/parser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 6bae79c1..8da7930c 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -406,7 +406,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { const chara = matcherArg.chara switch(lowerCased){ case 'previous_char_chat': - case 'lastusermessage':{ + case 'lastcharmessage':{ if(chatID !== -1){ const selchar = db.characters[get(selectedCharID)] const chat = selchar.chats[selchar.chatPage] @@ -422,7 +422,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { return '' } case 'previous_user_chat': - case 'lastcharmessage':{ + case 'lastusermessage':{ if(chatID !== -1){ const selchar = db.characters[get(selectedCharID)] const chat = selchar.chats[selchar.chatPage] From 5a4a1d7071ad1576786563259b4ad3713519b52d Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 19:56:37 +0900 Subject: [PATCH 11/12] Fix incorrect condition in parser.ts --- src/ts/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 8da7930c..b5f8ac8d 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -843,7 +843,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { if(p1.startsWith('pick')){ const selchar = db.characters[get(selectedCharID)] const rand = sfc32(uuidtoNumber(selchar.chaId), chatID, uuidtoNumber(selchar.chaId), chatID) - if(p1.startsWith('random::')){ + if(p1.startsWith('pick::')){ const randomIndex = Math.floor(rand() * (arra.length - 1)) + 1 if(matcherArg.tokenizeAccurate){ return arra[0] From f35e3e6fd39ade2923da4014e61918c17f6f0aaa Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 20:08:51 +0900 Subject: [PATCH 12/12] Update version to 1.91.0 --- src-tauri/tauri.conf.json | 2 +- src/etc/patchNote.ts | 22 +++++++++++++++++----- src/ts/storage/database.ts | 2 +- version.json | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 81977aae..f6aa2209 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "RisuAI", - "version": "1.90.1" + "version": "1.91.0" }, "tauri": { "allowlist": { diff --git a/src/etc/patchNote.ts b/src/etc/patchNote.ts index 1fb3c6e4..c901880c 100644 --- a/src/etc/patchNote.ts +++ b/src/etc/patchNote.ts @@ -1,11 +1,23 @@ export const patchNote = { - version: "1.90", + version: "1.91", content: ` -# Update 1.90.1 -- Added {{spread::A}} and {{trim::B}} -- Fixed undefined variable crashing the app -- Now invaild curly brace syntax will be ignored +# Update 1.91.0 +- {{#if A}} now trims the whitespace inside the content +- Old {{time}} and {{date}} is renamed to {{message_time}} and {{message_date}} +- Added {{lastcharmessage}} as allias for {{previous_char_chat}} +- Added {{lastusermessage}} as allias for {{previous_user_chat}} +- Added {{newline}} as allias for {{br}} +- Added {{lastmessage}}, which returns the last message sent in the current chat +- Added {{maxcontext}}, which returns the maximum context length +- Added {{lastmessageid}}, which returns the index of the last message sent in the current chat +- Added {{pow::A::B}}, which returns A raised to the power of B +- Added {{pick::A::B...}} which returns a random element from the list, but is consistent across the same message +- Added {{time}}, which returns the current time in the format HH:MM:SS in your timezone +- Added {{date}}, which returns the current date in the format YYYY-MM-DD in your timezone +- Added {{isotime}}, which returns the current time in the format HH:MM:SS in UTC +- Added {{isodate}}, which returns the current date in the format YYYY-MM-DD in UTC +- Added {{#if-pure A}} which is the same as {{#if A}}, but does not trim the whitespace inside the content ` } diff --git a/src/ts/storage/database.ts b/src/ts/storage/database.ts index 1b0c8c31..d5e87c97 100644 --- a/src/ts/storage/database.ts +++ b/src/ts/storage/database.ts @@ -15,7 +15,7 @@ import type { OobaChatCompletionRequestParams } from '../model/ooba'; export const DataBase = writable({} as any as Database) export const loadedStore = writable(false) -export let appVer = "1.90.1" +export let appVer = "1.91.0" export let webAppSubVer = '' export function setDatabase(data:Database){ diff --git a/version.json b/version.json index 2be664bc..83a6f54f 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version":"1.90.1"} \ No newline at end of file +{"version":"1.91.0"} \ No newline at end of file