mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: text split error
This commit is contained in:
parent
43faf96cfe
commit
25520ba9fe
1 changed files with 22 additions and 1 deletions
23
apps/bym.js
23
apps/bym.js
|
|
@ -136,7 +136,8 @@ export class bym extends plugin {
|
||||||
// console.log(JSON.stringify(opt))
|
// console.log(JSON.stringify(opt))
|
||||||
let rsp = await client.sendMessage(e.msg, opt)
|
let rsp = await client.sendMessage(e.msg, opt)
|
||||||
let text = rsp.text
|
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) {
|
for (let t of texts) {
|
||||||
if (!t) {
|
if (!t) {
|
||||||
continue
|
continue
|
||||||
|
|
@ -189,3 +190,23 @@ function filterResponseChunk (msg) {
|
||||||
}
|
}
|
||||||
return 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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue