diff --git a/apps/query.js b/apps/query.js index accd5a3..028d49e 100644 --- a/apps/query.js +++ b/apps/query.js @@ -58,6 +58,10 @@ export class query extends plugin { reg: "^#竹白(.*)", fnc: "zhubaiSearch", }, + { + reg: "^#(wiki|百科)(.*)$", + fnc: "wiki", + } ], }); } @@ -372,6 +376,51 @@ export class query extends plugin { return true; } + // 百科 + async wiki(e) { + const key = e.msg.replace(/#|百科|wiki/g, "").trim(); + const url = `https://xiaoapi.cn/API/bk.php?m=json&type=sg&msg=${ encodeURI(key) }`; + const bdUrl = `https://xiaoapi.cn/API/bk.php?m=json&type=bd&msg=${ encodeURI(key) }`; + const bkRes = await Promise.all([ + axios + .get(bdUrl, { + headers: { + "User-Agent": + "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", + }, + timeout: 10000, + }) + .then(resp => { + return resp.data; + }), + axios + .get(url, { + headers: { + "User-Agent": + "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", + }, + timeout: 10000, + }) + .then(resp => { + return resp.data; + }), + ]).then(async res => { + return res.map(item => { + return { + message: ` + 解释:${ _.get(item, "msg") }\n + 详情:${ _.get(item, "more") }\n + `, + nickname: e.sender.card || e.user_id, + user_id: e.user_id, + }; + }); + // 小鸡解释:${ _.get(data2, 'content') } + }); + await e.reply(await Bot.makeForwardMsg(bkRes)); + return true; + } + /** * 限制用户调用(默认1分钟1次) * @param e diff --git a/apps/tools.js b/apps/tools.js index 92360b6..1ddad25 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -26,7 +26,14 @@ import { TWITTER_BEARER_TOKEN, XHS_NO_WATERMARK_HEADER, } from "../constants/constant.js"; -import { containsChinese, downloadImg, formatBiliInfo, getIdVideo, secondsToTime } from "../utils/common.js"; +import { + containsChinese, + downloadImg, + downloadMp3, + formatBiliInfo, + getIdVideo, + secondsToTime +} from "../utils/common.js"; import config from "../model/index.js"; import Translate from "../utils/trans-strategy.js"; import * as xBogus from "../utils/x-bogus.cjs"; @@ -87,10 +94,6 @@ export class tools extends plugin { reg: "(bilibili.com|b23.tv|t.bilibili.com)", fnc: "bili", }, - { - reg: "^#(wiki|百科)(.*)$", - fnc: "wiki", - }, { reg: "(x.com)", fnc: "twitter_x", @@ -140,6 +143,10 @@ export class tools extends plugin { { reg: "(miyoushe.com)", fnc: "miyoushe" + }, + { + reg: "(music.163.com|163cn.tv)", + fnc: "netease", } ], }); @@ -492,51 +499,6 @@ export class tools extends plugin { }) } - // 百科 - async wiki(e) { - const key = e.msg.replace(/#|百科|wiki/g, "").trim(); - const url = `https://xiaoapi.cn/API/bk.php?m=json&type=sg&msg=${ encodeURI(key) }`; - const bdUrl = `https://xiaoapi.cn/API/bk.php?m=json&type=bd&msg=${ encodeURI(key) }`; - const bkRes = await Promise.all([ - axios - .get(bdUrl, { - headers: { - "User-Agent": - "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", - }, - timeout: 10000, - }) - .then(resp => { - return resp.data; - }), - axios - .get(url, { - headers: { - "User-Agent": - "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", - }, - timeout: 10000, - }) - .then(resp => { - return resp.data; - }), - ]).then(async res => { - return res.map(item => { - return { - message: ` - 解释:${ _.get(item, "msg") }\n - 详情:${ _.get(item, "more") }\n - `, - nickname: e.sender.card || e.user_id, - user_id: e.user_id, - }; - }); - // 小鸡解释:${ _.get(data2, 'content') } - }); - await e.reply(await Bot.makeForwardMsg(bkRes)); - return true; - } - // 例子:https://twitter.com/chonkyanimalx/status/1595834168000204800 async twitter(e) { // 配置参数及解析 @@ -915,6 +877,55 @@ export class tools extends plugin { return true; } + // 网易云解析 + async netease(e) { + let message = + e.msg === undefined ? e.message.shift().data.replaceAll("\\", "") : e.msg.trim(); + 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 id = + musicUrlReg2.exec(message)?.[3] || + musicUrlReg.exec(message)?.[2] || + /id=(\d+)/.exec(message)[1]; + // 如果没有下载地址跳出if + if (_.isEmpty(id)) { + e.reply(`识别:网易云音乐,解析失败!`); + return + } + if (typeof message !== "string") { + return false; + } + try { + // 小程序 + const musicJson = JSON.parse(message); + const { preview, title, desc } = musicJson.meta.music || musicJson.meta.news; + e.reply([`识别:网易云音乐,${title}--${desc}`, segment.image(preview)]); + JSON.parse(message); + return true; + } catch (err) { + axios.get(`https://www.oranges1.top/neteaseapi.do/song/url?id=${id}`, { + headers: { + "User-Agent": + "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", + }, + }).then(async resp => { + const url = await resp.data.data?.[0].url; + const title = await axios.get(`https://www.oranges1.top/neteaseapi.do/song/detail?ids=${id}`).then(res => { + const song = res.data.songs[0]; + return `${song?.name}-${song?.ar?.[0].name}`.replace(/[\/\?<>\\:\*\|".… ]/g, ""); + }); + e.reply(`识别:网易云音乐,${title}`); + downloadMp3(url, 'follow').then(path => { + Bot.acquireGfs(e.group_id).upload(fs.readFileSync(path), '/', `${title.replace(/[\/\?<>\\:\*\|".… ]/g, '')}.mp3`) + }) + .catch(err => { + console.error(`下载音乐失败,错误信息为: ${err.message}`); + }); + }) + return true; + } + } + /** * 快手解析 * @param e diff --git a/config/help.yaml b/config/help.yaml index 44c14ba..8b2a708 100644 --- a/config/help.yaml +++ b/config/help.yaml @@ -24,14 +24,14 @@ - icon: zhubai title: "#竹白" desc: 基于竹白百科的搜索 + - icon: 百科 + title: "#百科/wiki xxx" + desc: 百度百科/搜狗百科 - group: 工具类合集 list: - icon: translate title: "翻中/英/日 xxx" - desc: 百度翻译,例如:翻中 I want it! - - icon: 百科 - title: "#百科/wiki xxx" - desc: 百度百科/搜狗百科 + desc: R插件翻译引擎 - icon: tiktok title: "xxxv.douyin.com" desc: 抖音分享实时下载 diff --git a/config/version.yaml b/config/version.yaml index 3375edb..47b36d8 100644 --- a/config/version.yaml +++ b/config/version.yaml @@ -1,5 +1,5 @@ - { - version: 1.4.4, + version: 1.4.5, data: [ 新增米游社解析功能,