From 35bf11af2018b13e04a61906b304bb1d79ae3556 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Mon, 10 Jun 2024 22:12:06 +0900 Subject: [PATCH] feat: add time related syntax --- src/ts/gui/highlight.ts | 2 +- src/ts/parser.ts | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ts/gui/highlight.ts b/src/ts/gui/highlight.ts index 597eff62..2da6776a 100644 --- a/src/ts/gui/highlight.ts +++ b/src/ts/gui/highlight.ts @@ -97,7 +97,7 @@ const normalCBSwithParams = [ 'arraypop', 'array_pop', 'arraypush', 'array_push', 'arraysplice', 'array_splice', 'makearray', 'array', 'a', 'make_array', 'history', 'messages', 'range', 'date', 'time', 'datetimeformat', 'date_time_format', 'random', 'pick', 'roll', 'datetimeformat', 'hidden_key', 'reverse', 'getglobalvar', 'position', 'slot', 'rollp', - 'and', 'or', 'not', + 'and', 'or', 'not', 'message_time_array' ] const displayRelatedCBS = [ diff --git a/src/ts/parser.ts b/src/ts/parser.ts index e539ff23..91bbba05 100644 --- a/src/ts/parser.ts +++ b/src/ts/parser.ts @@ -564,6 +564,17 @@ const matcher = (p1:string,matcherArg:matcherArg) => { //output date in format like Aug 23, 2021 return date.toLocaleDateString() } + case 'message_unixtime_array':{ + const selchar = db.characters[get(selectedCharID)] + const chat = selchar.chats[selchar.chatPage] + return chat.message.map((f) => { + return f.time ?? 0 + }).join('ยง') + } + case 'unixtime':{ + const now = new Date() + return (now.getTime() / 1000).toFixed(0) + } case 'time':{ const now = new Date() return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}` @@ -946,7 +957,15 @@ const matcher = (p1:string,matcherArg:matcherArg) => { case 'time': case 'datetimeformat': case 'date_time_format':{ - return dateTimeFormat(arra[1]) + const secondParam = arra[2] + let t = 0 + if(secondParam){ + t = (Number(secondParam) / 1000) + if(isNaN(t)){ + t = 0 + } + } + return dateTimeFormat(arra[1],t) } case 'module_enabled':{ const selchar = db.characters[get(selectedCharID)] @@ -1064,8 +1083,8 @@ function pickHashRand(cid:number,word:string) { return randF() } -const dateTimeFormat = (main:string) => { - const date = new Date() +const dateTimeFormat = (main:string, time = 0) => { + const date = time === 0 ? (new Date()) : (new Date(time)) if(!main){ return '' }