From a294bcd3bb621f535c62f1ee77160dd082c3868c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E5=88=80=E9=B1=BC?= <9903082+qdyovo@user.noreply.gitee.com> Date: Tue, 5 Nov 2024 13:51:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=A6=84=20reactor:=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=91=E9=80=81=E9=9F=B3=E4=B9=90=E5=8D=A1=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/songRequest.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/apps/songRequest.js b/apps/songRequest.js index 9c815eb..4b44bb3 100644 --- a/apps/songRequest.js +++ b/apps/songRequest.js @@ -45,10 +45,10 @@ export class songRequest extends plugin { async pickSong(e) { // 判断功能是否开启 - if(!this.useNeteaseSongRequest) { + if (!this.useNeteaseSongRequest) { logger.info('当前未开启网易云点歌') return - } + } const autoSelectNeteaseApi = await this.pickApi() // 只在群里可以使用 let group_id = e.group.group_id @@ -58,7 +58,7 @@ export class songRequest extends plugin { const saveId = songInfo.findIndex(item => item.group_id === e.group.group_id) let musicDate = { 'group_id': group_id, data: [] } // 获取搜索歌曲列表信息 - let searchUrl = autoSelectNeteaseApi + '/search?keywords={}&limit='+ this.songRequestMaxList //搜索API + let searchUrl = autoSelectNeteaseApi + '/search?keywords={}&limit=' + this.songRequestMaxList //搜索API let detailUrl = autoSelectNeteaseApi + "/song/detail?ids={}" //歌曲详情API if (e.msg.replace(/\s+/g, "").match(/点歌(.+)/)) { const songKeyWord = e.msg.replace(/\s+/g, "").match(/点歌(.+)/)[1] @@ -121,10 +121,10 @@ export class songRequest extends plugin { // 播放策略 async playSong(e) { - if(!this.useNeteaseSongRequest) { + if (!this.useNeteaseSongRequest) { logger.info('当前未开启网易云点歌') return - } + } // 只在群里可以使用 let group_id = e.group.group_id if (!group_id) return @@ -275,9 +275,30 @@ export class songRequest extends plugin { let musicExt = resp.data.data?.[0]?.type // 下载音乐 downloadAudio(url, this.getCurDownloadPath(e), title, 'follow', musicExt).then(async path => { - // 发送语音 - if (musicExt != 'mp4') { - await e.reply(segment.record(path)); + try { + await e.bot.sendApi('send_group_msg', { + group_id: e.group.group_id, + message: [ + { + type: 'music', + data: { + type: '163', + id: songInfo[pickNumber].id + } + } + ] + }); + } catch (error) { + // 发送语音 + if (error.error.message) { + logger.error("发送卡片错误错误:", error.error.message, '发送群语音'); + } else { + logger.error("发送卡片错误错误,请查看控制台报错,将发送群语音") + logger.error(error) + } + if (musicExt != 'mp4') { + await e.reply(segment.record(path)); + } } // 上传群文件 await this.uploadGroupFile(e, path); From 99851767501546595c825756680e62fa6e9d240c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E5=88=80=E9=B1=BC?= <9903082+qdyovo@user.noreply.gitee.com> Date: Tue, 5 Nov 2024 15:48:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/songRequest.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/songRequest.js b/apps/songRequest.js index 4b44bb3..d8a9e80 100644 --- a/apps/songRequest.js +++ b/apps/songRequest.js @@ -26,9 +26,12 @@ export class songRequest extends plugin { }, ] }); + this.toolsConfig = config.getConfig("tools"); // 加载网易云Cookie this.neteaseCookie = this.toolsConfig.neteaseCookie + // 视频保存路径 + this.defaultPath = this.toolsConfig.defaultPath; // 加载是否自建服务器 this.useLocalNeteaseAPI = this.toolsConfig.useLocalNeteaseAPI // 加载自建服务器API From 103748cd88352d232fcf77b79a4d9a5c39c2b5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E5=88=80=E9=B1=BC?= <9903082+qdyovo@user.noreply.gitee.com> Date: Tue, 5 Nov 2024 16:37:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20feat=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E9=9F=B3=E4=B9=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/songRequest.js | 54 ++++++++++++++++++++++++++++---------------- utils/yunzai-util.js | 24 +++++++++++++++++++- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/apps/songRequest.js b/apps/songRequest.js index d8a9e80..963eaeb 100644 --- a/apps/songRequest.js +++ b/apps/songRequest.js @@ -7,6 +7,7 @@ import { COMMON_USER_AGENT, REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_SONGINFO } from import { downloadAudio } from "../utils/common.js"; import { redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js"; import { checkAndRemoveFile } from "../utils/file.js"; +import { sendMusicCard } from "../utils/yunzai-util.js"; import config from "../model/config.js"; export class songRequest extends plugin { @@ -24,14 +25,15 @@ export class songRequest extends plugin { reg: "^#播放(.*)", fnc: "playSong" }, + { + reg: "^#?上传(.*)", + fnc: "upLoad" + }, ] }); - this.toolsConfig = config.getConfig("tools"); // 加载网易云Cookie this.neteaseCookie = this.toolsConfig.neteaseCookie - // 视频保存路径 - this.defaultPath = this.toolsConfig.defaultPath; // 加载是否自建服务器 this.useLocalNeteaseAPI = this.toolsConfig.useLocalNeteaseAPI // 加载自建服务器API @@ -44,6 +46,8 @@ export class songRequest extends plugin { this.useNeteaseSongRequest = this.toolsConfig.useNeteaseSongRequest // 加载点歌列表长度 this.songRequestMaxList = this.toolsConfig.songRequestMaxList + // 视频保存路径 + this.defaultPath = this.toolsConfig.defaultPath; } async pickSong(e) { @@ -176,6 +180,30 @@ export class songRequest extends plugin { } } + async upLoad(e) { + let msg = await e.getReply(); + const musicUrlReg = /(http:|https:)\/\/music.163.com\/song\/media\/outer\/url\?id=(\d+)/; + const musicUrlReg2 = /(http:|https:)\/\/y.music.163.com\/m\/song\?(.*)&id=(\d+)/; + const musicUrlReg3 = /(http:|https:)\/\/music.163.com\/m\/song\/(\d+)/; + const id = + musicUrlReg2.exec(msg.message[0].data)?.[3] || + musicUrlReg.exec(msg.message[0].data)?.[2] || + musicUrlReg3.exec(msg.message[0].data)?.[2] || + /(? { try { - await e.bot.sendApi('send_group_msg', { - group_id: e.group.group_id, - message: [ - { - type: 'music', - data: { - type: '163', - id: songInfo[pickNumber].id - } - } - ] - }); + // 发送卡片 + await sendMusicCard(e, '163', songInfo[pickNumber].id) } catch (error) { - // 发送语音 if (error.error.message) { logger.error("发送卡片错误错误:", error.error.message, '发送群语音'); } else { logger.error("发送卡片错误错误,请查看控制台报错,将发送群语音") logger.error(error) } + // 发送语音 if (musicExt != 'mp4') { await e.reply(segment.record(path)); } } - // 上传群文件 - await this.uploadGroupFile(e, path); - // 删除文件 - await checkAndRemoveFile(path); }).catch(err => { logger.error(`下载音乐失败,错误信息为: ${err}`); }); diff --git a/utils/yunzai-util.js b/utils/yunzai-util.js index 89e79ea..88d119e 100644 --- a/utils/yunzai-util.js +++ b/utils/yunzai-util.js @@ -11,4 +11,26 @@ export function textArrayToMakeForward(e, textArray) { user_id: e.user_id, }; }) -} \ No newline at end of file +} + +/** + * 发送群组音乐卡片 + * @param e + * @param platformType 音乐平台 + * @param musicId 音乐id + */ + +export async function sendMusicCard(e, platformType, musicId) { + await e.bot.sendApi('send_group_msg', { + group_id: e.group.group_id, + message: [ + { + type: 'music', + data: { + type: platformType, + id: musicId + } + } + ] + }); +} From 82f8c26b97b6eef00ec1c37c1546ad20e8465492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E5=88=80=E9=B1=BC?= <9903082+qdyovo@user.noreply.gitee.com> Date: Tue, 5 Nov 2024 16:40:41 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC=E5=AF=BC=E8=87=B4=E7=9A=84=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/songRequest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/songRequest.js b/apps/songRequest.js index 963eaeb..ed4a50b 100644 --- a/apps/songRequest.js +++ b/apps/songRequest.js @@ -109,8 +109,8 @@ export class songRequest extends plugin { } }) } else if (await redisGetKey(REDIS_YUNZAI_SONGINFO) != []) { - if (e.msg.match(/听(\d+)/)) { - const pickNumber = e.msg.match(/听(\d+)/)[1] - 1 + if (e.msg.replace(/\s+/g, "").match(/听(\d+)/)) { + const pickNumber = e.msg.replace(/\s+/g, "").match(/听(\d+)/)[1] - 1 let group_id = e.group.group_id if (!group_id) return let songInfo = await redisGetKey(REDIS_YUNZAI_SONGINFO)