From a0216dae4f92f1a74ab9c3da7d3cfaa3578fb6e7 Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Wed, 15 Mar 2023 23:45:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=88=20style:=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/query.js | 53 +++++++++++++++++++++++++-------------------- apps/tools.js | 59 ++++++++++++++++++++++++++++----------------------- 2 files changed, 62 insertions(+), 50 deletions(-) diff --git a/apps/query.js b/apps/query.js index 74722e9..4911a65 100644 --- a/apps/query.js +++ b/apps/query.js @@ -8,7 +8,7 @@ import _ from "lodash"; import axios from "axios"; import fs from "node:fs"; // 常量 -import {CAT_LIMIT} from "../utils/constant.js"; +import { CAT_LIMIT } from "../utils/constant.js"; export class query extends plugin { constructor() { @@ -425,7 +425,7 @@ export class query extends plugin { headers: { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1660.14", - "referer": "https://search.zhelper.net/" + referer: "https://search.zhelper.net/", }, keyword: keyword, page: 1, @@ -456,9 +456,9 @@ export class query extends plugin { `书籍类型:${extension}\n` + `出版年月:${year}\n` + `来源:${source}\n` + - `ISBN:${isbn||"暂无"}\n` + + `ISBN:${isbn || "暂无"}\n` + `出版社:${publisher}\n` + - `文件大小:${(Number(filesize)/1024/1024).toFixed(2)}MB` + `文件大小:${(Number(filesize) / 1024 / 1024).toFixed(2)}MB`, }, ...sendTemplate, }); @@ -492,22 +492,25 @@ export class query extends plugin { */ async getDirectDownload(keyword) { // 下载字典(异步去执行) - return axios + return axios .post("https://worker.zlib.app/api/search/", { headers: { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1660.14", - "referer": "https://search.zhelper.net/" + referer: "https://search.zhelper.net/", }, keyword: keyword, page: 1, sensitive: false, - }).then(resp => { - // 标题去重 - return resp.data.data.filter(item => { - return item.title === keyword - }).map(item => `https://worker.zlib.app/download/${item.id}`) }) + .then(resp => { + // 标题去重 + return resp.data.data + .filter(item => { + return item.title === keyword; + }) + .map(item => `https://worker.zlib.app/download/${item.id}`); + }); } /** @@ -568,8 +571,12 @@ export class query extends plugin { year, } = resp.data; const Libgen = `https://libgendown.1kbtool.com/${md5}`; - const ipfs = `https://ipfs-checker.1kbtool.com/${ipfs_cid}?filename=${encodeURIComponent(title)}_${source}-search.${extension}`; - const reqUrl = `${md5}#${filesize}#${encodeURIComponent(title)}_${encodeURIComponent(author)}_${id}_${source}-search.${extension}`; + const ipfs = `https://ipfs-checker.1kbtool.com/${ipfs_cid}?filename=${encodeURIComponent( + title, + )}_${source}-search.${extension}`; + const reqUrl = `${md5}#${filesize}#${encodeURIComponent( + title, + )}_${encodeURIComponent(author)}_${id}_${source}-search.${extension}`; const cleverPass = `https://rapidupload.1kbtool.com/${reqUrl}`; const cleverPass2 = `https://rulite.1kbtool.com/${reqUrl}`; let bookMethods = [ @@ -579,12 +586,12 @@ export class query extends plugin { `秒传Lite:${cleverPass2}`, ].map(item => { return { - message: {type: "text", text: item}, + message: { type: "text", text: item }, nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id, - } - }) - await this.reply(await Bot.makeForwardMsg(bookMethods)) + }; + }); + await this.reply(await Bot.makeForwardMsg(bookMethods)); // 异步获取直连 console.log(source); console.log(source === Buffer.from("ei1saWJyYXJ5", "base64").toString("utf8")); @@ -592,15 +599,15 @@ export class query extends plugin { this.getDirectDownload(title).then(async res => { const directDownloadUrls = res.map(item => { return { - message: {type: "text", text: item}, + message: { type: "text", text: item }, nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id, - } - }) + }; + }); if (directDownloadUrls.length) { - await this.reply(await Bot.makeForwardMsg(directDownloadUrls)) + await this.reply(await Bot.makeForwardMsg(directDownloadUrls)); } - }) + }); } }); } @@ -610,4 +617,4 @@ export class query extends plugin { const titleRex = /<[^>]+>/g; return title.replace(titleRex, ""); } -} \ No newline at end of file +} diff --git a/apps/tools.js b/apps/tools.js index 5174c57..f9ad4e8 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -641,15 +641,16 @@ export class tools extends plugin { } async netease(e) { - const message = e.msg === undefined ? e.message.shift().data.replaceAll("\\", "") : e.msg.trim(); + const 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 id = musicUrlReg.exec(message)[2] || /id=(\d+)/.exec(message)[1]; - const musicJson = JSON.parse(message) - const {musicUrl, preview, title, desc} = musicJson.meta.music + const musicJson = JSON.parse(message); + const { musicUrl, preview, title, desc } = musicJson.meta.music; // 如果没有下载地址跳出if if (_.isNull(musicUrl) || _.isUndefined(musicUrl)) { e.reply(`识别:网易云音乐,解析失败!`); - return + return; } else { fetch(`https://www.oranges1.top/neteaseapi.do/song/url?id=${id}`, { headers: { @@ -657,16 +658,21 @@ export class tools extends plugin { "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 JSON.parse(await resp.text()).data[0].url + const url = await JSON.parse(await resp.text()).data[0].url; // 反之解析官方地址 e.reply([`识别:网易云音乐,${title}--${desc}`, segment.image(preview)]); - this.downloadMp3(url, 'follow').then(path => { - Bot.acquireGfs(e.group_id).upload(fs.readFileSync(path), '/', `${title.replace(/[\/\?<>\\:\*\|".… ]/g, '')}.mp3`) - }) + this.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; } @@ -835,31 +841,30 @@ export class tools extends plugin { * @param redirect * @returns {Promise} */ - async downloadMp3(mp3Url, redirect='manual') { + async downloadMp3(mp3Url, redirect = "manual") { return fetch(mp3Url, { 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", }, responseType: "stream", - redirect: redirect - }) - .then(res => { - const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp3` - const fileStream = fs.createWriteStream(path); - res.body.pipe(fileStream); - return new Promise((resolve, reject) => { - fileStream.on("finish", () => { - fileStream.close(() => { - resolve(path); - }); - }); - fileStream.on("error", err => { - fs.unlink(path, () => { - reject(err); - }); + redirect: redirect, + }).then(res => { + const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp3`; + const fileStream = fs.createWriteStream(path); + res.body.pipe(fileStream); + return new Promise((resolve, reject) => { + fileStream.on("finish", () => { + fileStream.close(() => { + resolve(path); }); }); - }) + fileStream.on("error", err => { + fs.unlink(path, () => { + reject(err); + }); + }); + }); + }); } }