🎈 perf: 优化搜书冗余代码

This commit is contained in:
zhiyu1998 2023-04-01 14:47:49 +08:00
parent edb94fd0b4
commit b0b207b47b

View File

@ -285,31 +285,35 @@ export class query extends plugin {
// 搜书 // 搜书
async searchBook(e) { async searchBook(e) {
let keyword = e.msg.replace(/#|搜书/g, "").trim(); let keyword = e.msg.replace(/#|搜书/g, "").trim();
if (_.isEmpty(keyword)) { if (!keyword) {
e.reply(`请输入书名,例如:#搜书 非暴力沟通`); e.reply("请输入书名,例如:#搜书 非暴力沟通");
return true; return true;
} }
const thisBookMethod = this;
// 主要数据来源 const replyMessage = async (msg) => {
await Promise.all([getZHelper(e, keyword), getYiBook(e, keyword)]).then(async allRes => { if (msg && msg.length > 0) {
const [zHelper, yiBook] = allRes; await e.reply(await Bot.makeForwardMsg(msg));
if (!_.isUndefined(yiBook) && yiBook.length > 0) {
await e.reply(await Bot.makeForwardMsg(yiBook));
} }
if (!_.isUndefined(zHelper) && zHelper.length > 0) { };
await e.reply(await Bot.makeForwardMsg(zHelper));
await e.reply( const [zHelper, yiBook] = await Promise.all([getZHelper(e, keyword), getYiBook(e, keyword)]);
"请选择一个你想要的ID、来源例如\n" +
"11918807 superlib\n" + await replyMessage(yiBook);
"只回复11918807 默认zlibrary\n" +
"书源若不对应则回复无效链接,数字字母之间空格", if (zHelper && zHelper.length > 0) {
); await replyMessage(zHelper);
thisBookMethod.setContext("searchBookContext"); const replyText = "请选择一个你想要的ID、来源例如\n" +
} "11918807 superlib\n" +
}); "只回复11918807 默认zlibrary\n" +
"书源若不对应则回复无效链接,数字字母之间空格";
await e.reply(replyText);
this.setContext("searchBookContext");
}
return true; return true;
} }
// 通过id搜书 // 通过id搜书
async searchBookById(e) { async searchBookById(e) {
let keyword = e.msg.replace(/#bookid/, "").trim(); let keyword = e.msg.replace(/#bookid/, "").trim();