mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🎈 pref: 优化触发词
This commit is contained in:
parent
69d68c6f98
commit
e534f58b56
@ -17,7 +17,7 @@ export class songRequest extends plugin {
|
|||||||
priority: 300,
|
priority: 300,
|
||||||
rule: [
|
rule: [
|
||||||
{
|
{
|
||||||
reg: '^点歌|#听[1-9][0-9]|#听[0-9]*$',
|
reg: '^点歌|#?听[1-9][0-9]|#?听[0-9]*$',
|
||||||
fnc: 'pickSong'
|
fnc: 'pickSong'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -52,81 +52,8 @@ export class songRequest extends plugin {
|
|||||||
return (await redisGetKey(REDIS_YUNZAI_ISOVERSEA)).os;
|
return (await redisGetKey(REDIS_YUNZAI_ISOVERSEA)).os;
|
||||||
}
|
}
|
||||||
|
|
||||||
async pickSong(e) {
|
// 网易云音乐下载策略
|
||||||
const isOversea = await this.isOverseasServer();
|
neteasePlay(pickSongUrl, songInfo, pickNumber = 0, isCkExpired){
|
||||||
let autoSelectNeteaseApi
|
|
||||||
if (this.useLocalNeteaseAPI) {
|
|
||||||
// 使用自建 API
|
|
||||||
autoSelectNeteaseApi = this.neteaseCloudAPIServer
|
|
||||||
} else {
|
|
||||||
// 自动选择 API
|
|
||||||
autoSelectNeteaseApi = isOversea ? NETEASE_SONG_DOWNLOAD : NETEASE_API_CN;
|
|
||||||
}
|
|
||||||
let songInfo = []
|
|
||||||
|
|
||||||
// 获取搜索歌曲列表信息
|
|
||||||
|
|
||||||
let searchUrl = autoSelectNeteaseApi + '/search?keywords={}&limit=10' //搜索API
|
|
||||||
let detailUrl = autoSelectNeteaseApi + "/song/detail?ids={}" //歌曲详情API
|
|
||||||
if (e.msg.replace(/\s+/g, "").match(/点歌(.+)/)) {
|
|
||||||
const songKeyWord = e.msg.replace(/\s+/g, "").match(/点歌(.+)/)[1]
|
|
||||||
searchUrl = searchUrl.replace("{}", songKeyWord)
|
|
||||||
await axios.get(searchUrl, {
|
|
||||||
headers: {
|
|
||||||
"User-Agent": COMMON_USER_AGENT
|
|
||||||
},
|
|
||||||
}).then(async res => {
|
|
||||||
if (res.data.result.songs) {
|
|
||||||
for (const info of res.data.result.songs) {
|
|
||||||
songInfo.push({
|
|
||||||
'id': info.id,
|
|
||||||
'songName': info.name,
|
|
||||||
'singerName': info.artists[0]?.name,
|
|
||||||
'duration': formatTime(info.duration)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const ids = songInfo.map(item => item.id).join(',');
|
|
||||||
detailUrl = detailUrl.replace("{}", ids)
|
|
||||||
await axios.get(detailUrl, {
|
|
||||||
headers: {
|
|
||||||
"User-Agent": COMMON_USER_AGENT
|
|
||||||
},
|
|
||||||
}).then(res => {
|
|
||||||
for (let i = 0; i < res.data.songs.length; i++) {
|
|
||||||
songInfo[i].cover = res.data.songs[i].al.picUrl
|
|
||||||
}
|
|
||||||
})
|
|
||||||
await redisSetKey(REDIS_YUNZAI_SONGINFO, songInfo)
|
|
||||||
const data = await new PickSongList(e).getData(songInfo)
|
|
||||||
let img = await puppeteer.screenshot("pick-song", data);
|
|
||||||
e.reply(img, true);
|
|
||||||
} else {
|
|
||||||
e.reply('暂未找到你想听的歌哦~')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else if (await redisGetKey(REDIS_YUNZAI_SONGINFO) != []) {
|
|
||||||
if (e.msg.match(/#听(\d+)/)) {
|
|
||||||
const pickNumber = e.msg.match(/#听(\d+)/)[1] - 1
|
|
||||||
let songInfo = await redisGetKey(REDIS_YUNZAI_SONGINFO)
|
|
||||||
const AUTO_NETEASE_SONG_DOWNLOAD = autoSelectNeteaseApi + "/song/url/v1?id={}&level=" + this.neteaseCloudAudioQuality;
|
|
||||||
const pickSongUrl = AUTO_NETEASE_SONG_DOWNLOAD.replace("{}", songInfo[pickNumber].id)
|
|
||||||
const statusUrl = autoSelectNeteaseApi + '/login/status' //用户状态API
|
|
||||||
const isCkExpired = await axios.get(statusUrl, {
|
|
||||||
headers: {
|
|
||||||
"User-Agent": COMMON_USER_AGENT,
|
|
||||||
"Cookie": this.neteaseCookie
|
|
||||||
},
|
|
||||||
}).then(res => {
|
|
||||||
const userInfo = res.data.data.profile
|
|
||||||
if (userInfo) {
|
|
||||||
logger.info('ck活着,使用ck进行高音质下载')
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
logger.info('ck失效,将启用临时接口下载')
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// // 请求netease数据
|
|
||||||
axios.get(pickSongUrl, {
|
axios.get(pickSongUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": COMMON_USER_AGENT,
|
"User-Agent": COMMON_USER_AGENT,
|
||||||
@ -192,9 +119,6 @@ export class songRequest extends plugin {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async musicTempApi(e, title, musicType) {
|
async musicTempApi(e, title, musicType) {
|
||||||
let musicReqApi = NETEASE_TEMP_API;
|
let musicReqApi = NETEASE_TEMP_API;
|
||||||
@ -212,6 +136,86 @@ export class songRequest extends plugin {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async pickSong(e) {
|
||||||
|
const isOversea = await this.isOverseasServer();
|
||||||
|
let autoSelectNeteaseApi
|
||||||
|
if (this.useLocalNeteaseAPI) {
|
||||||
|
// 使用自建 API
|
||||||
|
autoSelectNeteaseApi = this.neteaseCloudAPIServer
|
||||||
|
} else {
|
||||||
|
// 自动选择 API
|
||||||
|
autoSelectNeteaseApi = isOversea ? NETEASE_SONG_DOWNLOAD : NETEASE_API_CN;
|
||||||
|
}
|
||||||
|
let songInfo = []
|
||||||
|
// 获取搜索歌曲列表信息
|
||||||
|
let searchUrl = autoSelectNeteaseApi + '/search?keywords={}&limit=10' //搜索API
|
||||||
|
let detailUrl = autoSelectNeteaseApi + "/song/detail?ids={}" //歌曲详情API
|
||||||
|
if (e.msg.replace(/\s+/g, "").match(/点歌(.+)/)) {
|
||||||
|
const songKeyWord = e.msg.replace(/\s+/g, "").match(/点歌(.+)/)[1]
|
||||||
|
searchUrl = searchUrl.replace("{}", songKeyWord)
|
||||||
|
await axios.get(searchUrl, {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": COMMON_USER_AGENT
|
||||||
|
},
|
||||||
|
}).then(async res => {
|
||||||
|
if (res.data.result.songs) {
|
||||||
|
for (const info of res.data.result.songs) {
|
||||||
|
songInfo.push({
|
||||||
|
'id': info.id,
|
||||||
|
'songName': info.name,
|
||||||
|
'singerName': info.artists[0]?.name,
|
||||||
|
'duration': formatTime(info.duration)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ids = songInfo.map(item => item.id).join(',');
|
||||||
|
detailUrl = detailUrl.replace("{}", ids)
|
||||||
|
await axios.get(detailUrl, {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": COMMON_USER_AGENT
|
||||||
|
},
|
||||||
|
}).then(res => {
|
||||||
|
for (let i = 0; i < res.data.songs.length; i++) {
|
||||||
|
songInfo[i].cover = res.data.songs[i].al.picUrl
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await redisSetKey(REDIS_YUNZAI_SONGINFO, songInfo)
|
||||||
|
const data = await new PickSongList(e).getData(songInfo)
|
||||||
|
let img = await puppeteer.screenshot("pick-song", data);
|
||||||
|
e.reply(img, true);
|
||||||
|
} else {
|
||||||
|
e.reply('暂未找到你想听的歌哦~')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (await redisGetKey(REDIS_YUNZAI_SONGINFO) != []) {
|
||||||
|
if (e.msg.match(/听(\d+)/)) {
|
||||||
|
const pickNumber = e.msg.match(/听(\d+)/)[1] - 1
|
||||||
|
let songInfo = await redisGetKey(REDIS_YUNZAI_SONGINFO)
|
||||||
|
const AUTO_NETEASE_SONG_DOWNLOAD = autoSelectNeteaseApi + "/song/url/v1?id={}&level=" + this.neteaseCloudAudioQuality;
|
||||||
|
const pickSongUrl = AUTO_NETEASE_SONG_DOWNLOAD.replace("{}", songInfo[pickNumber].id)
|
||||||
|
const statusUrl = autoSelectNeteaseApi + '/login/status' //用户状态API
|
||||||
|
const isCkExpired = await axios.get(statusUrl, {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": COMMON_USER_AGENT,
|
||||||
|
"Cookie": this.neteaseCookie
|
||||||
|
},
|
||||||
|
}).then(res => {
|
||||||
|
const userInfo = res.data.data.profile
|
||||||
|
if (userInfo) {
|
||||||
|
logger.info('ck活着,使用ck进行高音质下载')
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
logger.info('ck失效,将启用临时接口下载')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// // 请求netease数据
|
||||||
|
this.neteasePlay(pickSongUrl, songInfo, pickNumber, isCkExpired)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前发送人/群的下载路径
|
* 获取当前发送人/群的下载路径
|
||||||
* @param e Yunzai 机器人事件
|
* @param e Yunzai 机器人事件
|
||||||
|
Loading…
x
Reference in New Issue
Block a user