Refactor 'lastcharmessage' cbs (#554)

# PR Checklist
- [ ] Did you check if it works normally in all models? *ignore this
when it dosen't uses models*
- [ ] Did you check if it works normally in all of web, local and node
hosted versions? if it dosen't, did you blocked it in those versions?
- [ ] Did you added a type def?

# Description
While implementing a specific behavior through CBS, I encountered
limitations during handling first message. Therefore, I aim to modify
the effect of certain keywords to accommodate a broader range of cases.
The changes have been tested and presented no issues. However, I kindly
request your review from a structural design perspective to ensure
adequacy.
This commit is contained in:
kwaroran
2024-07-06 01:05:55 +09:00
committed by GitHub

View File

@@ -590,19 +590,16 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
switch(lowerCased){
case 'previous_char_chat':
case 'lastcharmessage':{
if(chatID !== -1){
const selchar = db.characters[get(selectedCharID)]
const chat = selchar.chats[selchar.chatPage]
let pointer = chatID - 1
while(pointer >= 0){
if(chat.message[pointer].role === 'char'){
return chat.message[pointer].data
}
pointer--
const selchar = db.characters[get(selectedCharID)]
const chat = selchar.chats[selchar.chatPage]
let pointer = chatID !== -1 ? chatID - 1 : chat.message.length - 1
while(pointer >= 0){
if(chat.message[pointer].role === 'char'){
return chat.message[pointer].data
}
return selchar.firstMsgIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[selchar.firstMsgIndex]
pointer--
}
return ''
return selchar.firstMsgIndex === -1 ? selchar.firstMessage : selchar.alternateGreetings[selchar.firstMsgIndex]
}
case 'previous_user_chat':
case 'lastusermessage':{