From 3f288a95cc9ed867fff727cadcd352eb35adf24c Mon Sep 17 00:00:00 2001 From: RrOrange <542716863@qq.com> Date: Mon, 10 Apr 2023 20:55:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=90=9C=E4=B9=A6=E9=80=BB=E8=BE=91=20&=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20&=20=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/query.js | 68 ++++++++++++++------------------------------------ utils/books.js | 7 +++--- 2 files changed, 23 insertions(+), 52 deletions(-) diff --git a/apps/query.js b/apps/query.js index 15ab3da..08a6b83 100644 --- a/apps/query.js +++ b/apps/query.js @@ -302,35 +302,31 @@ export class query extends plugin { return true; } - const replyMessage = async msg => { - if (msg && msg.length > 0) { - await e.reply(await Bot.makeForwardMsg(msg)); - } - }; - // 集成易书、zBook try { - const bookList = await Promise.allSettled([getYiBook(e, keyword), getZBook(e, keyword)]); - bookList - .filter(one => one.status === "fulfilled") - .map(item => { - replyMessage(item.value); + const bookList = await Promise.allSettled([ + getYiBook(e, keyword), + getZBook(e, keyword), + ]); + // 压缩直链结果 + const combineRet = bookList + .filter(item => item.status === "fulfilled" && item.value && item.value.length > 0) + .flatMap(item => { + return item.value.flat(); }); - + await e.reply(await Bot.makeForwardMsg(combineRet)); + // ZHelper 特殊处理 const zHelper = await getZHelper(e, keyword); - if (zHelper && zHelper.length > 0) { - await replyMessage(zHelper); - const replyText = - "请选择一个你想要的ID、来源,例如:\n" + - "11918807 superlib\n" + - "只回复11918807 默认zlibrary\n" + - "书源若不对应则回复无效链接,数字字母之间空格"; - await e.reply(replyText); - this.setContext("searchBookContext"); - } + zHelper.unshift({ + message: "⚠️⚠️请输入#bookid选择一个你想要的ID、来源,例如:11918807 superlib\n只回复11918807 默认zlibrary⚠️⚠️", + nickname: e.sender.card || e.user_id, + user_id: e.user_id, + }) + zHelper.length > 1 && + e.reply(await Bot.makeForwardMsg(zHelper)); } catch (err) { logger.error(err); - e.reply("搜书正在施工🚧"); + e.reply("部分搜书正在施工🚧"); } return true; } @@ -360,32 +356,6 @@ export class query extends plugin { return true; } - /** - * @link searchBook 的上下文 - * @returns {Promise} - */ - async searchBookContext() { - // 当前消息 - const curMsg = this.e; - // 上一个消息 - // const preMsg = this.getContext(); - if (!curMsg.msg) { - this.e.reply("请回复id和来源!"); - return; - } - // 获取id和来源 - let id, source; - if (curMsg.msg.includes(" ")) { - [id, source] = curMsg.msg.split(" "); - } else { - id = /\d+/.exec(curMsg.msg)[0]; - source = ""; - } - const res = await getBookDetail(curMsg, id, source); - await this.reply(await Bot.makeForwardMsg(res)); - this.finish("searchBookContext"); - } - // 竹白百科 async zhubaiSearch(e) { const keyword = e.msg.replace("#竹白", "").trim(); diff --git a/utils/books.js b/utils/books.js index 833c6ea..d73c2e0 100644 --- a/utils/books.js +++ b/utils/books.js @@ -4,7 +4,7 @@ import axios from "axios"; /** * 获取易书下载的来源 * @param keyword 书名 - * @returns {Promise} + * @returns {Promise} */ async function getYiBook(e, keyword) { const sendTemplate = { @@ -73,7 +73,7 @@ const zBookDownloadUrl = [ /** * 获取ZBook的数据 - * @returns {Promise} + * @returns {Promise} */ async function getZBook(e, keyword) { const sendTemplate = { @@ -129,8 +129,9 @@ async function getZBook(e, keyword) { /** * 获取ZHelper的数据 + * @param e * @param keyword - * @returns {Promise>} + * @returns {Promise} */ async function getZHelper(e, keyword) { const sendTemplate = {