mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-18 06:17:06 +00:00
fix: 修复一些功能易用性
This commit is contained in:
parent
be7ceafb4b
commit
599f37e627
8 changed files with 249 additions and 61 deletions
|
|
@ -1,14 +1,13 @@
|
|||
import fetch from 'node-fetch'
|
||||
import {AbstractTool} from "./AbstractTool.js";
|
||||
import { AbstractTool } from './AbstractTool.js'
|
||||
|
||||
export class SendMusicTool extends AbstractTool {
|
||||
name = 'sendMusic'
|
||||
|
||||
parameters = {
|
||||
properties: {
|
||||
keyword: {
|
||||
id: {
|
||||
type: 'string',
|
||||
description: '音乐的标题或关键词'
|
||||
description: '音乐的id'
|
||||
},
|
||||
groupId: {
|
||||
type: 'string',
|
||||
|
|
@ -19,28 +18,16 @@ export class SendMusicTool extends AbstractTool {
|
|||
}
|
||||
|
||||
func = async function (opts) {
|
||||
let { keyword, groupId } = opts
|
||||
let { id, groupId } = opts
|
||||
groupId = parseInt(groupId.trim())
|
||||
try {
|
||||
let { id, name } = await searchMusic163(keyword)
|
||||
let group = await Bot.pickGroup(groupId)
|
||||
await group.shareMusic('163', id)
|
||||
return `the music ${name} has been shared to ${groupId}`
|
||||
return `the music has been shared to ${groupId}`
|
||||
} catch (e) {
|
||||
return `music share failed: ${e}`
|
||||
}
|
||||
}
|
||||
|
||||
description = 'Useful when you want to share music. The input should be the group number and the name of the music to be sent or the keywords that can find the music, connected with a space'
|
||||
}
|
||||
|
||||
export async function searchMusic163 (name) {
|
||||
let response = await fetch(`http://music.163.com/api/search/get/web?s=${name}&type=1&offset=0&total=true&limit=20`)
|
||||
let json = await response.json()
|
||||
if (json.result?.songCount > 0) {
|
||||
let id = json.result.songs[0].id
|
||||
let name = json.result.songs[0].name
|
||||
return { id, name }
|
||||
}
|
||||
return null
|
||||
description = 'Useful when you want to share music. You must use searchMusic first to get the music id'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue