mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
feat: 一些小工具
This commit is contained in:
parent
c99af43571
commit
ca28b00679
3 changed files with 113 additions and 9 deletions
33
apps/chat.js
33
apps/chat.js
|
|
@ -40,7 +40,6 @@ import ChatGLMClient from '../utils/chatglm.js'
|
||||||
import { convertFaces } from '../utils/face.js'
|
import { convertFaces } from '../utils/face.js'
|
||||||
import uploadRecord from '../utils/uploadRecord.js'
|
import uploadRecord from '../utils/uploadRecord.js'
|
||||||
import { SlackClaudeClient } from '../utils/slack/slackClient.js'
|
import { SlackClaudeClient } from '../utils/slack/slackClient.js'
|
||||||
import { ChatgptManagement } from './management.js'
|
|
||||||
import { getPromptByName } from '../utils/prompts.js'
|
import { getPromptByName } from '../utils/prompts.js'
|
||||||
import BingDrawClient from '../utils/BingDraw.js'
|
import BingDrawClient from '../utils/BingDraw.js'
|
||||||
import XinghuoClient from '../utils/xinghuo/xinghuo.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 { SendMusicTool } from '../utils/tools/SendMusicTool.js'
|
||||||
import { SendVideoTool } from '../utils/tools/SendBilibiliTool.js'
|
import { SendVideoTool } from '../utils/tools/SendBilibiliTool.js'
|
||||||
import { KickOutTool } from '../utils/tools/KickOutTool.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 { EditCardTool } from '../utils/tools/EditCardTool.js'
|
||||||
import { SearchVideoTool } from '../utils/tools/SearchBilibiliTool.js'
|
import { SearchVideoTool } from '../utils/tools/SearchBilibiliTool.js'
|
||||||
import { SearchMusicTool } from '../utils/tools/SearchMusicTool.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 { TTSTool } from '../utils/tools/TTSTool.js'
|
||||||
import { ProcessPictureTool } from '../utils/tools/ProcessPictureTool.js'
|
import { ProcessPictureTool } from '../utils/tools/ProcessPictureTool.js'
|
||||||
import { APTool } from '../utils/tools/APTool.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 {
|
try {
|
||||||
await import('emoji-strip')
|
await import('emoji-strip')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -1979,24 +1978,40 @@ export class chatgpt extends plugin {
|
||||||
new TTSTool(),
|
new TTSTool(),
|
||||||
new ProcessPictureTool(),
|
new ProcessPictureTool(),
|
||||||
new APTool(),
|
new APTool(),
|
||||||
new QueryGenshinTool()
|
new QueryGenshinTool(),
|
||||||
|
new HandleMessageMsgTool(),
|
||||||
|
new QueryUserinfoTool()
|
||||||
]
|
]
|
||||||
// todo 3.0再重构tool的插拔和管理
|
// todo 3.0再重构tool的插拔和管理
|
||||||
let tools = [
|
let tools = [
|
||||||
// new SendAvatarTool(),
|
// new SendAvatarTool(),
|
||||||
// new SendDiceTool(),
|
// new SendDiceTool(),
|
||||||
new EditCardTool(),
|
// new EditCardTool(),
|
||||||
new QueryStarRailTool(),
|
new QueryStarRailTool(),
|
||||||
new QueryGenshinTool(),
|
new QueryGenshinTool(),
|
||||||
new WebsiteTool(),
|
new WebsiteTool(),
|
||||||
new JinyanTool(),
|
// new JinyanTool(),
|
||||||
new KickOutTool(),
|
// new KickOutTool(),
|
||||||
new WeatherTool(),
|
new WeatherTool(),
|
||||||
new SendPictureTool(),
|
new SendPictureTool(),
|
||||||
new TTSTool(),
|
new TTSTool(),
|
||||||
new APTool(),
|
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 = []
|
let img = []
|
||||||
if (e.source) {
|
if (e.source) {
|
||||||
// 优先从回复找图
|
// 优先从回复找图
|
||||||
|
|
|
||||||
42
utils/tools/HandleMessageMsgTool.js
Normal file
42
utils/tools/HandleMessageMsgTool.js
Normal file
|
|
@ -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 = '用来撤回消息或将消息设为精华'
|
||||||
|
}
|
||||||
47
utils/tools/QueryUserinfoTool.js
Normal file
47
utils/tools/QueryUserinfoTool.js
Normal file
|
|
@ -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'
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue