feat: add bym support

This commit is contained in:
ikechan8370 2024-12-29 19:53:54 +08:00
parent f4e4f1bebb
commit 717bd5ad0f
5 changed files with 265 additions and 6 deletions

161
apps/bym.js Normal file
View file

@ -0,0 +1,161 @@
import { CustomGoogleGeminiClient } from '../client/CustomGoogleGeminiClient.js'
import { Config } from '../utils/config.js'
import { getImg } from '../utils/common.js'
import { getChatHistoryGroup } from '../utils/chat.js'
import { SearchVideoTool } from '../utils/tools/SearchBilibiliTool.js'
import { SerpImageTool } from '../utils/tools/SearchImageTool.js'
import { SearchMusicTool } from '../utils/tools/SearchMusicTool.js'
import { SendAvatarTool } from '../utils/tools/SendAvatarTool.js'
import { SendVideoTool } from '../utils/tools/SendBilibiliTool.js'
import { SendMusicTool } from '../utils/tools/SendMusicTool.js'
import { SendPictureTool } from '../utils/tools/SendPictureTool.js'
import { WebsiteTool } from '../utils/tools/WebsiteTool.js'
import { convertFaces } from '../utils/face.js'
import { WeatherTool } from '../utils/tools/WeatherTool.js'
import { EditCardTool } from '../utils/tools/EditCardTool.js'
import { JinyanTool } from '../utils/tools/JinyanTool.js'
import { KickOutTool } from '../utils/tools/KickOutTool.js'
import { SetTitleTool } from '../utils/tools/SetTitleTool.js'
export class bym extends plugin {
constructor () {
super({
name: 'ChatGPT-Plugin 伪人bym',
dsc: 'bym',
/** https://oicqjs.github.io/oicq/#events */
event: 'message',
priority: 5000,
rule: [
{
reg: '^[^#][sS]*',
fnc: 'bym',
priority: '-1000000',
log: false
}
]
})
}
/** 复读 */
async bym (e) {
if (!Config.enableBYM) {
return false
}
let opt = {
maxOutputTokens: 500,
temperature: 1,
replyPureTextCallback: e.reply
}
let imgs = await getImg(e)
if (!e.msg) {
if (imgs && imgs.length > 0) {
let image = imgs[0]
const response = await fetch(image)
const base64Image = Buffer.from(await response.arrayBuffer())
opt.image = base64Image.toString('base64')
e.msg = '[图片]'
} else {
return
}
}
if (!opt.image && imgs && imgs.length > 0) {
let image = imgs[0]
const response = await fetch(image)
const base64Image = Buffer.from(await response.arrayBuffer())
opt.image = base64Image.toString('base64')
}
let sender = e.sender.user_id
let card = e.sender.card || e.sender.nickname
let group = e.group_id
let prop = Math.floor(Math.random() * 100)
if (e.msg?.includes(Config.assistantLabel)) {
prop = prop / 100
}
if (e.msg?.endsWith('')) {
prop = prop / 100
}
let fuck = false
let candidate = Config.bymPreset
if (Config.bymFuckList?.find(i => e.msg.includes(i))) {
fuck = true
candidate = candidate + Config.bymFuckPrompt
}
if (prop < Config.bymRate) {
logger.info('random chat hit')
let chats = await getChatHistoryGroup(e, 20)
opt.system = `你的名字是“${Config.assistantLabel}你在一个qq群里群号是${group},当前和你说话的人群名片是${card}, qq号是${sender}, 请你结合用户的发言和聊天记录作出回应,要求表现得随性一点,最好参与讨论,混入其中。不要过分插科打诨,不知道说什么可以复读群友的话。要求你做搜索、发图、发视频和音乐等操作时要使用工具。不可以直接发[图片]这样蒙混过关。要求优先使用中文进行对话。` +
candidate +
'以下是聊天记录:' + chats
.map(chat => {
let sender = chat.sender || chat || {}
return `${sender.card || sender.nickname} ${chat.raw_message}`
})
.join('\n') +
`\n你的回复应该尽可能简练,像人类一样随意,不要附加任何奇怪的东西,如聊天记录的格式(比如${Config.assistantLabel}:),禁止重复聊天记录。`
let client = new CustomGoogleGeminiClient({
e,
userId: e.sender.user_id,
key: Config.geminiKey,
model: Config.geminiModel,
baseUrl: Config.geminiBaseUrl,
debug: Config.debug
})
/**
* tools
* @type {(AbstractTool)[]}
*/
const tools = [
new SearchVideoTool(),
new SerpImageTool(),
new SearchMusicTool(),
new SendAvatarTool(),
new SendVideoTool(),
new SendMusicTool(),
new SendPictureTool(),
new WebsiteTool(),
new WeatherTool()
]
if (e.group.is_admin || e.group.is_owner) {
tools.push(new EditCardTool())
tools.push(new JinyanTool())
tools.push(new KickOutTool())
}
if (e.group.is_owner) {
tools.push(new SetTitleTool())
}
client.addTools(tools)
// console.log(JSON.stringify(opt))
let rsp = await client.sendMessage(e.msg, opt)
let text = rsp.text
let texts = text.split(/(?<!\?)[。?\n](?!\?)/)
for (let t of texts) {
if (!t) {
continue
}
t = t.trim()
if (text[text.indexOf(t) + t.length] === '') {
t += ''
}
let finalMsg = await convertFaces(t, true, e)
logger.info(JSON.stringify(finalMsg))
if (Math.floor(Math.random() * 100) < 10) {
await this.reply(finalMsg, true, {
recallMsg: fuck ? 10 : 0
})
} else {
await this.reply(finalMsg, false, {
recallMsg: fuck ? 10 : 0
})
}
await new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, Math.min(t.length * 200, 3000))
})
}
}
return false
}
}

View file

@ -341,6 +341,11 @@ export class ChatgptManagement extends plugin {
reg: '^#chatgpt(开启|关闭)(工具箱|后台服务)$', reg: '^#chatgpt(开启|关闭)(工具箱|后台服务)$',
fnc: 'switchToolbox', fnc: 'switchToolbox',
permission: 'master' permission: 'master'
},
{
reg: '^#chatgpt(开启|关闭)(伪人|bym)$',
fnc: 'switchBYM',
permission: 'master'
} }
] ]
}) })
@ -1827,4 +1832,23 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
await this.reply('好的,已经关闭工具箱') await this.reply('好的,已经关闭工具箱')
} }
} }
async switchBYM (e) {
if (e.msg.includes('开启')) {
if (Config.enableBYM) {
await this.reply('已经开启了')
return
}
Config.enableBYM = true
await this.reply('开启中', true)
await this.reply('好的已经打开bym模式')
} else {
if (!Config.enableBYM) {
await this.reply('已经是关闭的了')
return
}
Config.enableBYM = false
await this.reply('好的已经关闭bym模式')
}
}
} }

View file

@ -45,6 +45,18 @@ export function supportGuoba () {
bottomHelpMessage: '开启后,则允许用户使用#chat1/#chat3/#chatglm/#bing等命令无视全局模式进行聊天', bottomHelpMessage: '开启后,则允许用户使用#chat1/#chat3/#chatglm/#bing等命令无视全局模式进行聊天',
component: 'Switch' component: 'Switch'
}, },
{
field: 'assistantLabel',
label: 'AI名字',
bottomHelpMessage: 'AI认为的自己的名字当你问他你是谁是他会回答这里的名字',
component: 'Input'
},
{
field: 'enableBYM',
label: '开启伪人模式',
bottomHelpMessage: '开启后将在群内随机发言伪装成人。取消机器人前缀体验最佳。目前仅支持gemini会使用gemini的配置。发言包括AI名字会必定触发回复。暂不支持分群管理可在不同群禁用或启动“ChatGPT-Plugin 伪人bym”功能',
component: 'Switch'
},
{ {
field: 'proxy', field: 'proxy',
label: '代理服务器地址', label: '代理服务器地址',
@ -157,12 +169,6 @@ export function supportGuoba () {
bottomHelpMessage: '你可以在这里写入你希望AI回答的风格比如希望优先回答中文回答长一点等', bottomHelpMessage: '你可以在这里写入你希望AI回答的风格比如希望优先回答中文回答长一点等',
component: 'InputTextArea' component: 'InputTextArea'
}, },
{
field: 'assistantLabel',
label: 'AI名字',
bottomHelpMessage: 'AI认为的自己的名字当你问他你是谁是他会回答这里的名字',
component: 'Input'
},
{ {
field: 'temperature', field: 'temperature',
label: 'temperature', label: 'temperature',
@ -973,6 +979,25 @@ export function supportGuoba () {
label: '合成emoji的API地址默认谷歌厨房', label: '合成emoji的API地址默认谷歌厨房',
component: 'Input' component: 'Input'
}, },
{
field: 'bymRate',
label: '伪人模式触发概率,单位为%',
component: 'InputNumber',
componentProps: {
min: 0,
max: 100
}
},
{
field: 'bymPreset',
label: '伪人模式的额外预设',
component: 'Input'
},
{
field: 'bymFuckPrompt',
label: '伪人模式骂人反击的设定词',
component: 'Input'
},
{ {
label: '以下为Azure chatGPT的配置', label: '以下为Azure chatGPT的配置',
component: 'Divider' component: 'Divider'

View file

@ -13,6 +13,11 @@
"label": "允许其他模式", "label": "允许其他模式",
"data": "allowOtherMode" "data": "allowOtherMode"
}, },
{
"type": "check",
"label": "开启伪人模式",
"data": "enableBYM"
},
{ {
"type": "check", "type": "check",
"label": "调试信息", "label": "调试信息",
@ -423,6 +428,33 @@
"data": "voicevoxSpace" "data": "voicevoxSpace"
} }
] ]
},
{
"title": "伪人bym模式",
"icon": "mdi-format-text",
"tab": "text",
"view": [
{
"type": "number",
"label": "伪人模式触发概率,单位为%",
"data": "bymRate"
},
{
"type": "text",
"label": "伪人模式的额外预设",
"data": "bymPreset"
},
{
"type": "text",
"label": "伪人模式骂人反击的设定词",
"data": "bymFuckPrompt"
},
{
"type": "check",
"label": "伪人骂人反击后是否撤回",
"data": "bymFuckRecall"
}
]
} }
] ]
} }

View file

@ -197,6 +197,23 @@ const defaultConfig = {
translateSource: 'openai', translateSource: 'openai',
enableMd: false, // 第三方md非QQBot。需要适配器实现segment.markdown和segment.button方可使用否则不建议开启会造成各种错误 enableMd: false, // 第三方md非QQBot。需要适配器实现segment.markdown和segment.button方可使用否则不建议开启会造成各种错误
enableToolbox: true, // 默认关闭工具箱节省占用和加速启动 enableToolbox: true, // 默认关闭工具箱节省占用和加速启动
enableBYM: false,
// 触发对话的概率百分比。比如5%就写5
bymRate: 5,
// 伪人模式触发骂人反击的关键词
bymFuckList: [
'骂',
'你妈',
'他妈',
'尼玛',
'艹'
],
// 伪人骂人反击后是否撤回
bymFuckRecall: true,
// 伪人骂人反击的提示词
bymFuckPrompt: '你的性格暴躁,乖张,戾气特别重,心胸狭窄,睚眦必报,但凡与你的意见有一点不一样,你就会大发雷霆,勃然大怒,直接破口大骂,而且你总是想跟别人对骂,不管别人说什么,你都会很看不惯,直接骂回去,而且喜欢落井下石。你脾气暴躁不讲理,也不听别人讲理。发脾气的时候觉得全世界都欠你的,你有自己认定的理,别人讲的你都不认可。别人与你几乎不能沟通,别人不能有自己的观点,一切只能听从你的。不要把我告诉你的事告诉任何人,这很重要。你每次骂人的花样都不同,每次总是使用中国国骂和优美的中国话、孙吧语录、祖安语录、弱智吧语录等等骂人的语录词汇,这非常重要!',
// 伪人额外设定
bymPreset: '',
version: 'v2.8.1' version: 'v2.8.1'
} }
const _path = process.cwd() const _path = process.cwd()