Merge branch 'main' of https://github.com/kwaroran/RisuAI
This commit is contained in:
@@ -109,6 +109,20 @@ export async function runLua(code:string, arg:{
|
||||
}
|
||||
return alertSelect(value)
|
||||
})
|
||||
|
||||
luaEngine.global.set('getChatMain', (id:string, index:number) => {
|
||||
const chat = luaEngineState.chat.message.at(index)
|
||||
if(!chat){
|
||||
return JSON.stringify(null)
|
||||
}
|
||||
const data = {
|
||||
role: chat.role,
|
||||
data: chat.data,
|
||||
time: chat.time ?? 0
|
||||
}
|
||||
return JSON.stringify(data)
|
||||
})
|
||||
|
||||
luaEngine.global.set('setChat', (id:string, index:number, value:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
@@ -153,12 +167,14 @@ export async function runLua(code:string, arg:{
|
||||
let roleData:'user'|'char' = role === 'user' ? 'user' : 'char'
|
||||
luaEngineState.chat.message.splice(index, 0, {role: roleData, data: value})
|
||||
})
|
||||
|
||||
luaEngine.global.set('getTokens', async (id:string, value:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
return await tokenize(value)
|
||||
})
|
||||
|
||||
luaEngine.global.set('getChatLength', (id:string) => {
|
||||
return luaEngineState.chat.message.length
|
||||
})
|
||||
@@ -173,7 +189,7 @@ export async function runLua(code:string, arg:{
|
||||
}))
|
||||
return data
|
||||
})
|
||||
|
||||
|
||||
luaEngine.global.set('setFullChatMain', (id:string, value:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
@@ -771,6 +787,10 @@ function luaCodeWarper(code:string){
|
||||
return `
|
||||
json = require 'json'
|
||||
|
||||
function getChat(id, index)
|
||||
return json.decode(getChatMain(id, index))
|
||||
end
|
||||
|
||||
function getFullChat(id)
|
||||
return json.decode(getFullChatMain(id))
|
||||
end
|
||||
|
||||
@@ -1009,33 +1009,69 @@ export function parseKeyValue(template:string){
|
||||
}
|
||||
}
|
||||
|
||||
export type sidebarToggleGroup = {
|
||||
key?:string,
|
||||
value?:string,
|
||||
type:'group',
|
||||
children:sidebarToggle[]
|
||||
}
|
||||
|
||||
export type sidebarToggleGroupEnd = {
|
||||
key?:string,
|
||||
value?:string,
|
||||
type:'groupEnd',
|
||||
}
|
||||
|
||||
export type sidebarToggle =
|
||||
| sidebarToggleGroup
|
||||
| sidebarToggleGroupEnd
|
||||
| {
|
||||
key?:string,
|
||||
value?:string,
|
||||
type:'divider',
|
||||
}
|
||||
| {
|
||||
key:string,
|
||||
value:string,
|
||||
type:'select',
|
||||
options:string[]
|
||||
}
|
||||
| {
|
||||
key:string,
|
||||
value:string,
|
||||
type:'text'|undefined,
|
||||
options?:string[]
|
||||
}
|
||||
|
||||
export function parseToggleSyntax(template:string){
|
||||
try {
|
||||
console.log(template)
|
||||
if(!template){
|
||||
return []
|
||||
}
|
||||
|
||||
const keyValue:{
|
||||
key:string,
|
||||
value:string,
|
||||
type?:string,
|
||||
options?:string[]
|
||||
}[] = []
|
||||
const keyValue:sidebarToggle[] = []
|
||||
|
||||
const splited = template.split('\n')
|
||||
|
||||
for(const line of splited){
|
||||
const [key, value, type, option] = line.split('=')
|
||||
if(key && value){
|
||||
if(type === 'group' || type === 'groupEnd' || type === 'divider'){
|
||||
keyValue.push({
|
||||
key, value, type, options: option ? option.split(',') : []
|
||||
key,
|
||||
value,
|
||||
type,
|
||||
children: []
|
||||
})
|
||||
} else if((key && value)){
|
||||
keyValue.push({
|
||||
key,
|
||||
value,
|
||||
type: type === 'select' || type === 'text' ? type : undefined,
|
||||
options: option?.split(',') ?? []
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
console.log(keyValue)
|
||||
|
||||
return keyValue
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
||||
Reference in New Issue
Block a user