Merge branch 'v2' into v2

This commit is contained in:
ycxom 2025-01-08 20:53:34 +08:00 committed by GitHub
commit 8091c99736
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 47 deletions

View file

@ -20,6 +20,7 @@ import { SerpTool } from '../utils/tools/SerpTool.js'
import { initializeImageTool } from '../utils/tools/ImageTool.js'
import { DailyNewsTool } from '../utils/tools/DailyNewsTool.js'
import { SendMessageToSpecificGroupOrUserTool } from '../utils/tools/SendMessageToSpecificGroupOrUserTool.js'
import { customSplitRegex, filterResponseChunk } from '../utils/text.js'
const DefaultConfig = {
returnQQ: [],
@ -389,45 +390,3 @@ export class bym extends plugin {
}
}
/**
* 过滤
* @param msg
*/
function filterResponseChunk(msg) {
if (typeof msg === 'object') {
return msg || false
}
if (!msg || typeof msg !== 'string') {
return false
}
if (!msg.trim()) {
return false
}
if (msg.trim() === '```') {
return false
}
if (msg.trim() === '<EMPTY>') {
return false
}
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
}