feat: 搜图和发图

This commit is contained in:
ikechan8370 2023-06-24 17:53:57 +08:00
parent 8d13145d2f
commit 5ccefa6fa6
3 changed files with 60 additions and 18 deletions

View file

@ -58,6 +58,8 @@ import { WebsiteTool } from '../utils/tools/WebsiteTool.js'
import { WeatherTool } from '../utils/tools/WeatherTool.js'
import { SerpTool } from '../utils/tools/SerpTool.js'
import { SerpIkechan8370Tool } from '../utils/tools/SerpIkechan8370Tool.js'
import {SendPictureTool} from "../utils/tools/SendPictureTool.js";
import {SerpImageTool} from "../utils/tools/SearchImageTool.js";
try {
await import('emoji-strip')
} catch (err) {
@ -1963,6 +1965,8 @@ export class chatgpt extends plugin {
new JinyanTool(),
new KickOutTool(),
new WeatherTool(),
new SendPictureTool(),
new SerpImageTool(),
serpTool
]
// if (e.sender.role === 'admin' || e.sender.role === 'owner') {

View file

@ -0,0 +1,30 @@
import { AbstractTool } from './AbstractTool.js'
export class SerpImageTool extends AbstractTool {
name = 'searchImage'
parameters = {
properties: {
q: {
type: 'string',
description: 'search keyword'
}
},
required: ['q']
}
func = async function (opts) {
let { q } = opts
let serpRes = await fetch(`https://serp.ikechan8370.com/image/bing?q=${encodeURIComponent(q)}`, {
headers: {
'X-From-Library': 'ikechan8370'
}
})
serpRes = await serpRes.json()
let res = serpRes.data
return `the images search results are here in json format:\n${JSON.stringify(res)}. the murl field is real picture url. You should use sendPicture to send them`
}
description = 'Useful when you want to search images from the internet. '
}

View file

@ -1,33 +1,41 @@
import {AbstractTool} from "./AbstractTool.js";
import { AbstractTool } from './AbstractTool.js'
export class SendPictureTool extends AbstractTool {
name = 'sendPicture'
parameters = {
properties: {
picture: {
type: 'string',
description: '图片的url,多个用空格隔开'
description: 'the url of the pictures, split with space if more than one '
},
groupId: {
type: 'string',
description: '群号或qq号发送目标'
}
},
required: ['picture', 'groupId']
}
func = async function (picture, groupId) {
func = async function (opt) {
let { picture, groupId } = opt
let pictures = picture.trim().split(' ')
pictures = pictures.map(img => segment.image(img))
let groupList = await Bot.getGroupList()
try {
if (groupList.get(groupId)) {
let group = await Bot.pickGroup(groupId)
await group.sendMsg(pictures)
return `picture has been sent to group ${groupId}`
} else {
let user = await Bot.pickFriend(groupId)
await user.sendMsg(pictures)
return `picture has been sent to user ${groupId}`
}
} catch (err) {
return `failed to send pictures, error: ${err.toString()}`
}
}
description = 'Useful when you want to send some pictures. The input to this tool should be the url of the pictures and the group number or the user\'s qq number, each url and the group number or qq number should be concated with a space, and the group number or qq number should be the last. 如果是在群聊中,优先选择群号发送。'
description = 'Useful when you want to send one or more pictures. '
}