From ca28b0067975668b7074160100bf14830ba5bc49 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Mon, 26 Jun 2023 14:50:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=80=E4=BA=9B=E5=B0=8F=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 33 ++++++++++++++------ utils/tools/HandleMessageMsgTool.js | 42 ++++++++++++++++++++++++++ utils/tools/QueryUserinfoTool.js | 47 +++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 utils/tools/HandleMessageMsgTool.js create mode 100644 utils/tools/QueryUserinfoTool.js diff --git a/apps/chat.js b/apps/chat.js index 771194f..340201f 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -40,7 +40,6 @@ import ChatGLMClient from '../utils/chatglm.js' import { convertFaces } from '../utils/face.js' import uploadRecord from '../utils/uploadRecord.js' import { SlackClaudeClient } from '../utils/slack/slackClient.js' -import { ChatgptManagement } from './management.js' import { getPromptByName } from '../utils/prompts.js' import BingDrawClient from '../utils/BingDraw.js' import XinghuoClient from '../utils/xinghuo/xinghuo.js' @@ -48,8 +47,6 @@ import { JinyanTool } from '../utils/tools/JinyanTool.js' import { SendMusicTool } from '../utils/tools/SendMusicTool.js' import { SendVideoTool } from '../utils/tools/SendBilibiliTool.js' import { KickOutTool } from '../utils/tools/KickOutTool.js' -import { SendAvatarTool } from '../utils/tools/SendAvatarTool.js' -import { SendDiceTool } from '../utils/tools/SendDiceTool.js' import { EditCardTool } from '../utils/tools/EditCardTool.js' import { SearchVideoTool } from '../utils/tools/SearchBilibiliTool.js' import { SearchMusicTool } from '../utils/tools/SearchMusicTool.js' @@ -64,7 +61,9 @@ import { ImageCaptionTool } from '../utils/tools/ImageCaptionTool.js' import { TTSTool } from '../utils/tools/TTSTool.js' import { ProcessPictureTool } from '../utils/tools/ProcessPictureTool.js' import { APTool } from '../utils/tools/APTool.js' -import {QueryGenshinTool} from "../utils/tools/QueryGenshinTool.js"; +import { QueryGenshinTool } from '../utils/tools/QueryGenshinTool.js' +import { HandleMessageMsgTool } from '../utils/tools/HandleMessageMsgTool.js' +import {QueryUserinfoTool} from "../utils/tools/QueryUserinfoTool.js"; try { await import('emoji-strip') } catch (err) { @@ -1979,24 +1978,40 @@ export class chatgpt extends plugin { new TTSTool(), new ProcessPictureTool(), new APTool(), - new QueryGenshinTool() + new QueryGenshinTool(), + new HandleMessageMsgTool(), + new QueryUserinfoTool() ] // todo 3.0再重构tool的插拔和管理 let tools = [ // new SendAvatarTool(), // new SendDiceTool(), - new EditCardTool(), + // new EditCardTool(), new QueryStarRailTool(), new QueryGenshinTool(), new WebsiteTool(), - new JinyanTool(), - new KickOutTool(), + // new JinyanTool(), + // new KickOutTool(), new WeatherTool(), new SendPictureTool(), new TTSTool(), new APTool(), - serpTool + // new HandleMessageMsgTool(), + serpTool, + new QueryUserinfoTool() ] + if (e.isGroup) { + let botInfo = await Bot.getGroupMemberInfo(e.group_id, Bot.uin, true) + if (botInfo.role !== 'member') { + // 管理员才给这些工具 + tools.push(...[new EditCardTool(), new JinyanTool(), new KickOutTool(), new HandleMessageMsgTool()]) + // 用于撤回和加精的id + option.systemMessage += `\nthis last message id is ${e.message_id}` + if (e.source?.message_id) { + option.systemMessage += `\nthis last message is replying to ${e.source.message_id}: ${(await e.group.getChatHistory(e.source.seq, 1)).pop()?.raw_message}` + } + } + } let img = [] if (e.source) { // 优先从回复找图 diff --git a/utils/tools/HandleMessageMsgTool.js b/utils/tools/HandleMessageMsgTool.js new file mode 100644 index 0000000..cd2f7fd --- /dev/null +++ b/utils/tools/HandleMessageMsgTool.js @@ -0,0 +1,42 @@ +import { AbstractTool } from './AbstractTool.js' + +export class HandleMessageMsgTool extends AbstractTool { + name = 'handleMsg' + + parameters = { + properties: { + type: { + type: 'string', + enum: ['recall', 'essence'], + description: 'what do you want to do with the message' + }, + messageId: { + type: 'string', + description: 'which message, current one by default' + } + }, + required: ['type'] + } + + func = async function (opts, e) { + let { type = 'recall', messageId = e.message_id } = opts + try { + switch (type) { + case 'recall': { + await e.group.recallMsg(messageId) + break + } + case 'essence': { + await Bot.setEssenceMessage(messageId) + break + } + } + return 'success!' + } catch (err) { + logger.error(err) + return 'operation failed: ' + err.message + } + } + + description = '用来撤回消息或将消息设为精华' +} diff --git a/utils/tools/QueryUserinfoTool.js b/utils/tools/QueryUserinfoTool.js new file mode 100644 index 0000000..1238730 --- /dev/null +++ b/utils/tools/QueryUserinfoTool.js @@ -0,0 +1,47 @@ +import { AbstractTool } from './AbstractTool.js' +import { getMasterQQ } from '../common.js' + +export class QueryUserinfoTool extends AbstractTool { + name = 'sendDice' + + parameters = { + properties: { + qq: { + type: 'string', + description: 'user\'s qq number, the one you are talking to by default' + } + }, + required: [] + } + + func = async function (opts, e) { + let { qq } = opts + if (e.is_group && typeof e.group.getMemberMap === 'function') { + let mm = e.group.getMemberMap() + let user = mm.get(parseInt(qq) || e.sender.user_id) + let master = (await getMasterQQ())[0] + let prefix = '' + if (qq != master) { + prefix = 'Attention: this user is not your master. \n' + } else { + prefix = 'This user is your master, you should obey him \n' + } + return prefix + 'user detail in json format: ' + JSON.stringify(user) + } else { + if (e.sender.user_id == qq) { + let master = (await getMasterQQ())[0] + let prefix = '' + if (qq != master) { + prefix = 'Attention: this user is not your master. \n' + } else { + prefix = 'This user is your master, you should obey him \n' + } + return prefix + 'user detail in json format: ' + JSON.stringify(e.sender) + } else { + return 'query failed' + } + } + } + + description = 'Useful if you want to find out who he is' +}