mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-18 14:27:10 +00:00
Merge branch 'ikechan8370:v2' into v2
This commit is contained in:
commit
c6812abc64
1 changed files with 22 additions and 1 deletions
23
apps/bym.js
23
apps/bym.js
|
|
@ -142,7 +142,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
|
||||||
|
|
@ -195,3 +196,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