chatgpt-plugin/utils/tools/SendPictureTool.js
2023-06-24 18:02:02 +08:00

42 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { AbstractTool } from './AbstractTool.js'
export class SendPictureTool extends AbstractTool {
name = 'sendPicture'
parameters = {
properties: {
picture: {
type: 'string',
description: 'the url of the pictures, split with space if more than one '
},
groupId: {
type: 'string',
description: '群号或qq号发送目标'
}
},
required: ['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()
groupId = parseInt(groupId)
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: ${JSON.stringify(err)}`
}
}
description = 'Useful when you want to send one or more pictures. '
}