Merge branch 'ikechan8370:v2' into v2

This commit is contained in:
gaoao-3 2025-01-03 14:36:38 +08:00 committed by GitHub
commit c6812abc64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -142,7 +142,8 @@ export class bym extends plugin {
// console.log(JSON.stringify(opt))
let rsp = await client.sendMessage(e.msg, opt)
let text = rsp.text
let texts = text.split(/(?<!\?)[。?\n](?!\?)/, 3)
let texts = customSplitRegex(text, /(?<!\?)[。?\n](?!\?)/, 3)
// let texts = text.split(/(?<!\?)[。?\n](?!\?)/, 3)
for (let t of texts) {
if (!t) {
continue
@ -195,3 +196,23 @@ function filterResponseChunk (msg) {
}
return msg
}
function customSplitRegex (text, regex, limit) {
const result = []
let match
let lastIndex = 0
const globalRegex = new RegExp(regex, 'g')
while ((match = globalRegex.exec(text)) !== null) {
if (result.length < limit - 1) {
result.push(text.slice(lastIndex, match.index))
lastIndex = match.index + match[0].length
} else {
break
}
}
// 添加剩余部分
result.push(text.slice(lastIndex))
return result
}