From 0319f705c489e2ea2c8b122439beeefaa9e4945f Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 23:14:28 +0900 Subject: [PATCH 1/6] Add array cbs --- src/ts/parser.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index b5f8ac8d..b9ddd441 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -821,6 +821,32 @@ const matcher = (p1:string,matcherArg:matcherArg) => { case 'pow':{ return Math.pow(Number(arra[1]), Number(arra[2])).toString() } + case 'arrayelement': + case 'array_element':{ + return arra[1].split('§')[Number(arra[2])] + } + case 'arrayshift': + case 'array_shift':{ + const arr = arra[1].split('§') + arr.shift() + return arr.join('§') + } + case 'arraypop': + case 'array_pop':{ + const arr = arra[1].split('§') + arr.pop() + return arr.join('§') + } + case 'arraypush': + case 'array_push':{ + return arra[1] + '§' + arra[2] + } + case 'arraysplice': + case 'array_splice':{ + const arr = arra[1].split('§') + arr.splice(Number(arra[2]), Number(arra[3]), arra[4]) + return arr.join('§') + } } } if(p1.startsWith('random')){ From 2a3f0830cee12bfe911d0aa2275e29697c035548 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 3 Apr 2024 23:15:17 +0900 Subject: [PATCH 2/6] Add support for creating arrays in the matcher function --- src/ts/parser.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index b9ddd441..596e2722 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -847,6 +847,12 @@ const matcher = (p1:string,matcherArg:matcherArg) => { arr.splice(Number(arra[2]), Number(arra[3]), arra[4]) return arr.join('§') } + case 'makearray': + case 'array': + case 'a': + case 'make_array':{ + return arra.slice(1).join('§') + } } } if(p1.startsWith('random')){ From 63657a9252cc7f87fba3c44d266a0a86d92ffb55 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Thu, 4 Apr 2024 06:30:33 +0900 Subject: [PATCH 3/6] Fix blockStartMatcher function to handle nested blocks --- src/ts/parser.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 596e2722..edc5d26f 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -977,7 +977,7 @@ type blockMatch = 'ignore'|'parse'|'nothing'|'parse-pure' function blockStartMatcher(p1:string,matcherArg:matcherArg):blockMatch{ if(p1.startsWith('#if') || p1.startsWith('#if_pure ')){ - const statement = p1.substring(p1.indexOf(' ') + 1) + const statement = p1.split(' ', 2) const state = statement[1] if(state === 'true' || state === '1'){ return p1.startsWith('#if_pure') ? 'parse-pure' : 'parse' @@ -1109,6 +1109,7 @@ export function risuChatParser(da:string, arg:{ } const matchResult = blockStartMatcher(dat, matcherObj) if(matchResult === 'nothing'){ + nested[0] += `{{${dat}}}` break } else{ From d7f0892c14e770f32f522fa7f554be420b115fb6 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Thu, 4 Apr 2024 06:51:14 +0900 Subject: [PATCH 4/6] Add datetimeformat function to parser.ts --- src/ts/parser.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index edc5d26f..046305b3 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -905,6 +905,28 @@ const matcher = (p1:string,matcherArg:matcherArg) => { } return (Math.floor(Math.random() * maxRoll) + 1).toString() } + if(p1.startsWith('datetimeformat')){ + const date = new Date() + let main = p1.substring("datetimeformat".length + 1) + if(!main){ + return '' + } + if(main.startsWith(':')){ + main = main.substring(1) + } + return main + .replace(/YYYY/g, date.getFullYear().toString()) + .replace(/YY/g, date.getFullYear().toString().substring(2)) + .replace(/MM?/g, (date.getMonth() + 1).toString().padStart(2, '0')) + .replace(/DD?/g, date.getDate().toString().padStart(2, '0')) + .replace(/DDDD?/g, (date.getDay() + (date.getMonth() * 30)).toString()) + .replace(/HH?/g, date.getHours().toString().padStart(2, '0')) + .replace(/hh?/g, (date.getHours() % 12).toString().padStart(2, '0')) + .replace(/mm?/g, date.getMinutes().toString().padStart(2, '0')) + .replace(/ss?/g, date.getSeconds().toString().padStart(2, '0')) + .replace(/A/g, date.getHours() >= 12 ? 'PM' : 'AM') + .replace(/MMMM?/g, Intl.DateTimeFormat('en', { month: 'long' }).format(date)) + } return null } catch (error) { return null From 9d55f61230fda5f8b0bc859b6116137340dce748 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Thu, 4 Apr 2024 06:52:20 +0900 Subject: [PATCH 5/6] Add 'remaind' function to calculate remainder --- src/ts/parser.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ts/parser.ts b/src/ts/parser.ts index 046305b3..d4d06ba2 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -807,6 +807,9 @@ const matcher = (p1:string,matcherArg:matcherArg) => { case 'abs':{ return Math.abs(Number(arra[1])).toString() } + case 'remaind':{ + return (Number(arra[1]) % Number(arra[2])).toString() + } case 'previous_chat_log':{ const selchar = db.characters[get(selectedCharID)] const chat = selchar?.chats?.[selchar.chatPage] From 74c5b5a8d6402eb88aa42f24fd1110a54937a4fe Mon Sep 17 00:00:00 2001 From: kwaroran Date: Thu, 4 Apr 2024 06:56:41 +0900 Subject: [PATCH 6/6] Update version to 1.92.0 --- src-tauri/tauri.conf.json | 2 +- src/etc/patchNote.ts | 28 +++++++++++----------------- src/ts/storage/database.ts | 2 +- version.json | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f6aa2209..2b2923e4 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "RisuAI", - "version": "1.91.0" + "version": "1.92.0" }, "tauri": { "allowlist": { diff --git a/src/etc/patchNote.ts b/src/etc/patchNote.ts index c901880c..370b9f40 100644 --- a/src/etc/patchNote.ts +++ b/src/etc/patchNote.ts @@ -1,23 +1,17 @@ export const patchNote = { - version: "1.91", + version: "1.92", content: ` -# 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 +# Update 1.92.0 +- Added {{remaind::A::B}} which will return remainder of A divided by B +- Added {{array_element::A::B}} which will return Bth element of array A +- Added {{array_shift::A}} which will return A without first element +- Added {{array_pop::A}} which will return A without last element +- Added {{array_push::A::B}} which will return A with B pushed at the end +- Added {{array_splice::A::B::C::D}} which will return A with C elements removed starting from Bth element and D elements added at Bth position +- Added {{array::A::B...}} which will return an array with A, B and so on +- Added {{datetimeformat::A}} which will return formatted date time string according to A +- Fixed {{#if}} not working in some cases ` } diff --git a/src/ts/storage/database.ts b/src/ts/storage/database.ts index d5e87c97..e772b271 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.91.0" +export let appVer = "1.92.0" export let webAppSubVer = '' export function setDatabase(data:Database){ diff --git a/version.json b/version.json index 83a6f54f..569de7f1 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version":"1.91.0"} \ No newline at end of file +{"version":"1.92.0"} \ No newline at end of file