🌈 style: 代码格式化

This commit is contained in:
zhiyu1998 2023-03-15 23:45:36 +08:00
parent 2a917f20f9
commit a0216dae4f
2 changed files with 62 additions and 50 deletions

View File

@ -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));
}
})
});
}
});
}

View File

@ -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<unknown>}
*/
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);
});
});
});
});
}
}