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/parser.ts b/src/ts/parser.ts index 6387af96..b5f8ac8d 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'; @@ -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 'lastcharmessage':{ 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 'lastusermessage':{ if(chatID !== -1){ const selchar = db.characters[get(selectedCharID)] const chat = selchar.chats[selchar.chatPage] @@ -537,7 +539,7 @@ const matcher = (p1:string,matcherArg:matcherArg) => { case 'none':{ return '' } - case 'time':{ + case 'message_time':{ if(matcherArg.tokenizeAccurate){ return `00:00:00` } @@ -555,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` } @@ -572,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` @@ -625,7 +643,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 +662,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){ @@ -779,6 +818,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 +840,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('pick::')){ + 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) @@ -879,15 +940,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' } @@ -895,14 +956,23 @@ 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 - + switch(type){ + case 'ignore':{ + return '' + } + case 'parse':{ + const trimedLines = p1.split('\n').map((v) => { + return v.trim() + }).join('\n').trim() + return trimedLines + } + case 'parse-pure':{ + return p1 + } + default:{ + return '' + } } - return '' } export function risuChatParser(da:string, arg:{ 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/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