feat: add time related syntax
This commit is contained in:
@@ -97,7 +97,7 @@ const normalCBSwithParams = [
|
|||||||
'arraypop', 'array_pop', 'arraypush', 'array_push', 'arraysplice', 'array_splice',
|
'arraypop', 'array_pop', 'arraypush', 'array_push', 'arraysplice', 'array_splice',
|
||||||
'makearray', 'array', 'a', 'make_array', 'history', 'messages', 'range', 'date', 'time', 'datetimeformat', 'date_time_format',
|
'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',
|
'random', 'pick', 'roll', 'datetimeformat', 'hidden_key', 'reverse', 'getglobalvar', 'position', 'slot', 'rollp',
|
||||||
'and', 'or', 'not',
|
'and', 'or', 'not', 'message_time_array'
|
||||||
]
|
]
|
||||||
|
|
||||||
const displayRelatedCBS = [
|
const displayRelatedCBS = [
|
||||||
|
|||||||
@@ -564,6 +564,17 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
|||||||
//output date in format like Aug 23, 2021
|
//output date in format like Aug 23, 2021
|
||||||
return date.toLocaleDateString()
|
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':{
|
case 'time':{
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
|
return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
|
||||||
@@ -946,7 +957,15 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
|||||||
case 'time':
|
case 'time':
|
||||||
case 'datetimeformat':
|
case 'datetimeformat':
|
||||||
case 'date_time_format':{
|
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':{
|
case 'module_enabled':{
|
||||||
const selchar = db.characters[get(selectedCharID)]
|
const selchar = db.characters[get(selectedCharID)]
|
||||||
@@ -1064,8 +1083,8 @@ function pickHashRand(cid:number,word:string) {
|
|||||||
return randF()
|
return randF()
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateTimeFormat = (main:string) => {
|
const dateTimeFormat = (main:string, time = 0) => {
|
||||||
const date = new Date()
|
const date = time === 0 ? (new Date()) : (new Date(time))
|
||||||
if(!main){
|
if(!main){
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user