mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 22:07:10 +00:00
feat: 搜图和发图
This commit is contained in:
parent
8d13145d2f
commit
5ccefa6fa6
3 changed files with 60 additions and 18 deletions
|
|
@ -58,6 +58,8 @@ import { WebsiteTool } from '../utils/tools/WebsiteTool.js'
|
||||||
import { WeatherTool } from '../utils/tools/WeatherTool.js'
|
import { WeatherTool } from '../utils/tools/WeatherTool.js'
|
||||||
import { SerpTool } from '../utils/tools/SerpTool.js'
|
import { SerpTool } from '../utils/tools/SerpTool.js'
|
||||||
import { SerpIkechan8370Tool } from '../utils/tools/SerpIkechan8370Tool.js'
|
import { SerpIkechan8370Tool } from '../utils/tools/SerpIkechan8370Tool.js'
|
||||||
|
import {SendPictureTool} from "../utils/tools/SendPictureTool.js";
|
||||||
|
import {SerpImageTool} from "../utils/tools/SearchImageTool.js";
|
||||||
try {
|
try {
|
||||||
await import('emoji-strip')
|
await import('emoji-strip')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -1963,6 +1965,8 @@ export class chatgpt extends plugin {
|
||||||
new JinyanTool(),
|
new JinyanTool(),
|
||||||
new KickOutTool(),
|
new KickOutTool(),
|
||||||
new WeatherTool(),
|
new WeatherTool(),
|
||||||
|
new SendPictureTool(),
|
||||||
|
new SerpImageTool(),
|
||||||
serpTool
|
serpTool
|
||||||
]
|
]
|
||||||
// if (e.sender.role === 'admin' || e.sender.role === 'owner') {
|
// if (e.sender.role === 'admin' || e.sender.role === 'owner') {
|
||||||
|
|
|
||||||
30
utils/tools/SearchImageTool.js
Normal file
30
utils/tools/SearchImageTool.js
Normal 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. '
|
||||||
|
}
|
||||||
|
|
@ -1,33 +1,41 @@
|
||||||
import {AbstractTool} from "./AbstractTool.js";
|
import { AbstractTool } from './AbstractTool.js'
|
||||||
|
|
||||||
|
|
||||||
export class SendPictureTool extends AbstractTool {
|
export class SendPictureTool extends AbstractTool {
|
||||||
name = 'sendPicture'
|
name = 'sendPicture'
|
||||||
|
|
||||||
parameters = {
|
parameters = {
|
||||||
picture: {
|
properties: {
|
||||||
type: 'string',
|
picture: {
|
||||||
description: '图片的url,多个用空格隔开'
|
type: 'string',
|
||||||
},
|
description: 'the url of the pictures, split with space if more than one '
|
||||||
groupId: {
|
},
|
||||||
type: 'string',
|
groupId: {
|
||||||
description: '群号或qq号,发送目标'
|
type: 'string',
|
||||||
|
description: '群号或qq号,发送目标'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
required: ['picture', 'groupId']
|
required: ['picture', 'groupId']
|
||||||
}
|
}
|
||||||
|
|
||||||
func = async function (picture, groupId) {
|
func = async function (opt) {
|
||||||
|
let { picture, groupId } = opt
|
||||||
let pictures = picture.trim().split(' ')
|
let pictures = picture.trim().split(' ')
|
||||||
pictures = pictures.map(img => segment.image(img))
|
pictures = pictures.map(img => segment.image(img))
|
||||||
let groupList = await Bot.getGroupList()
|
let groupList = await Bot.getGroupList()
|
||||||
if (groupList.get(groupId)) {
|
try {
|
||||||
let group = await Bot.pickGroup(groupId)
|
if (groupList.get(groupId)) {
|
||||||
await group.sendMsg(pictures)
|
let group = await Bot.pickGroup(groupId)
|
||||||
} else {
|
await group.sendMsg(pictures)
|
||||||
let user = await Bot.pickFriend(groupId)
|
return `picture has been sent to group ${groupId}`
|
||||||
await user.sendMsg(pictures)
|
} 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. '
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue