🐞 fix: 删除没必要的功能 & 更新搜书功能

作者被勒索更新了,没办法,非要更新这个搜书,顺便删点垃圾功能,增强一下哔哩哔哩总结
This commit is contained in:
RrOrange 2023-07-03 00:39:18 +08:00
parent 586e8771a7
commit 0e166c5a1e
5 changed files with 97 additions and 189 deletions

View File

@ -8,7 +8,7 @@ import axios from "axios";
// 常量
import { CAT_LIMIT } from "../utils/constant.js";
// 书库
import { getZHelper, getBookDetail, getYiBook, getZBook } from "../utils/books.js";
import { getZHelper, getYiBook, getZBook } from "../utils/books.js";
// 工具类
import _ from "lodash";
import TokenBucket from '../utils/token-bucket.js'
@ -49,10 +49,6 @@ export class query extends plugin {
reg: "^#搜书(.*)$",
fnc: "searchBook",
},
{
reg: "^#bookid(.*)$",
fnc: "searchBookById",
},
{
reg: "^#竹白(.*)",
fnc: "zhubaiSearch",
@ -319,20 +315,6 @@ export class query extends plugin {
combineRet.length > 0 && await e.reply(await Bot.makeForwardMsg(combineRet));
// ZHelper 特殊处理
const zHelper = await getZHelper(e, keyword);
zHelper.unshift({
message: "回复格式如下\n" +
"#bookidid来源\n" +
"\n" +
"示例⬇️\n" +
"#bookid 13366067 superlib \n" +
"\n" +
"注意‼️\n" +
"1⃣数字字母之间空格\n" +
"2⃣id就是每条介绍最前面那串短数字不是isbn号\n" +
"3⃣注意看书籍来源只回复#bookid id 默认来源zlibrary ",
nickname: e.sender.card || e.user_id,
user_id: e.user_id,
})
zHelper.length > 1 &&
e.reply(await Bot.makeForwardMsg(zHelper));
} catch (err) {
@ -344,33 +326,6 @@ export class query extends plugin {
return true;
}
// 通过id搜书
async searchBookById(e) {
let keyword = e.msg.replace(/#bookid/, "").trim();
if (_.isEmpty(keyword)) {
e.reply(`请输入书名,例如:#bookid 13366067`);
return true;
}
let id, source;
if (keyword.includes(" ")) {
[id, source] = keyword.split(" ");
} else {
id = /\d+/.exec(keyword)[0];
source = "";
}
await this.limitUserUse(e, async () => {
try {
const res = await getBookDetail(e, id, source);
e.reply(await Bot.makeForwardMsg(res));
} catch (err) {
logger.error(err);
e.reply("搜书正在施工🚧");
}
})
return true;
}
// 竹白百科
async zhubaiSearch(e) {
const keyword = e.msg.replace("#竹白", "").trim();

View File

@ -9,7 +9,7 @@ import HttpProxyAgent from "https-proxy-agent";
import { mkdirIfNotExists, checkAndRemoveFile, deleteFolderRecursive } from "../utils/file.js";
import { downloadBFile, getDownloadUrl, mergeFileToMp4 } from "../utils/bilibili.js";
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
import { transMap, douyinTypeMap, XHS_CK, TEN_THOUSAND, PROMPT_MAP } from "../utils/constant.js";
import { transMap, douyinTypeMap, XHS_CK, TEN_THOUSAND } from "../utils/constant.js";
import { getIdVideo } from "../utils/common.js";
import config from "../model/index.js";
import Translate from "../utils/trans-strategy.js";
@ -17,7 +17,7 @@ import * as xBogus from "../utils/x-bogus.cjs";
import { getVideoInfo, getDynamic } from "../utils/biliInfo.js";
import { getBiliGptInputText } from "../utils/biliSummary.js";
import { getBodianAudio, getBodianMv, getBodianMusicInfo } from "../utils/bodian.js";
import { ChatGPTBrowserClient } from "@waylaidwanderer/chatgpt-api";
import { ChatGPTBrowserClient, ChatGPTClient } from "@waylaidwanderer/chatgpt-api";
import { av2BV } from "../utils/bilibili-bv-av-convert.js";
import querystring from "querystring";
import TokenBucket from "../utils/token-bucket.js";
@ -34,10 +34,6 @@ export class tools extends plugin {
reg: `^(翻|trans)[${tools.Constants.existsTransKey}]`,
fnc: "trans",
},
{
reg: `^#(ocr|OCR)(${tools.Constants.existsPromptKey})?$`,
fnc: "ocr2anything",
},
{
reg: "(v.douyin.com)",
fnc: "douyin",
@ -97,13 +93,22 @@ export class tools extends plugin {
this.biliSessData = this.toolsConfig.biliSessData;
// 加载哔哩哔哩的限制时长
this.biliDuration = this.toolsConfig.biliDuration;
// 加载gpt配置
// 加载gpt配置accessToken、apiKey、模型
this.openaiAccessToken = this.toolsConfig.openaiAccessToken;
// 加载gpt客户端
this.chatGptClient = new ChatGPTBrowserClient({
this.openaiApiKey = this.toolsConfig.openaiApiKey;
this.openaiModel = this.toolsConfig.openaiModel;
// 加载gpt客户端默认加载sk如果填了AccessToken就用AccessToken
this.chatGptClient = this.openaiAccessToken === '' ? new ChatGPTClient(this.openaiApiKey, {
modelOptions: {
model: this.openaiModel,
temperature: 0,
},
proxy: this.myProxy,
debug: false,
}) : new ChatGPTBrowserClient({
reverseProxyUrl: "https://bypass.churchless.tech/api/conversation",
accessToken: this.openaiAccessToken,
model: "gpt-3.5-turbo",
model: this.openaiModel,
})
}
@ -140,50 +145,6 @@ export class tools extends plugin {
return true;
}
// 图像识别文字
async ocr2anything(e) {
e.reply(" 👀请发送图片")
this.setContext("ocr2anythingContext");
return true;
}
/**
* 图像识别文字核心
* @link{ocr2anythingContext} 的上下文
* @return Promise{void}
**/
async ocr2anythingContext() {
// 当前消息
const curMsg = this.e;
// 上一个消息
const preMsg = this.getContext().ocr2anythingContext;
try {
const defaultPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`
await this.downloadImg(curMsg.img, defaultPath, "temp.jpg").then(async _ => {
// OCR
const ocrRst = await Bot.imageOcr(fs.readFileSync(`${defaultPath}/temp.jpg`));
const wordList = ocrRst.wordslist;
// OCR结果
let OCRInfo = wordList.map(item => item.words).join(" ");
if (this.openaiAccessToken) {
// 构造输入
const func = preMsg.msg.replace("#ocr", "").trim();
const prompt = PROMPT_MAP[func] + OCRInfo;
// 得到结果
const response = await this.chatGptClient.sendMessage(prompt);
OCRInfo = `${OCRInfo}\n-----------------\n${response.response}`;
}
curMsg.reply(OCRInfo);
});
} catch (err) {
curMsg.reply(" ❌OCR失败或者存在多账号竞争回答问题");
logger.error(err);
} finally {
this.finish("ocr2anythingContext")
}
this.finish("ocr2anythingContext")
}
// 抖音解析
async douyin(e) {
const urlRex = /(http:|https:)\/\/v.douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
@ -1236,7 +1197,6 @@ export class tools extends plugin {
*/
static Constants = {
existsTransKey: Object.keys(transMap).join("|"),
existsPromptKey: Object.keys(PROMPT_MAP).join("|").slice(0, -1),
};
/**

View File

@ -6,6 +6,8 @@ translateAppId: '' # 百度翻译APP ID
translateSecret: '' # 百度翻译密匙
biliSessData: '' # 哔哩哔哩的SESSDATA
biliDuration: 900 # 哔哩哔哩限制的最大视频时长默认15分钟),单位:秒
biliDuration: 480 # 哔哩哔哩限制的最大视频时长默认8分钟),单位:秒
openaiAccessToken: '' # 通过获取https://chat.openai.com/api/auth/session
openaiApiKey: '' # sk...
openaiModel: 'gpt-3.5-turbo' # 目前gpt-3.5-turbo效果比较好廉价适合群友

View File

@ -134,12 +134,14 @@ async function getZBook(e, keyword) {
* @returns {Promise<Array>}
*/
async function getZHelper(e, keyword) {
const LIMIT = 5;
const sendTemplate = {
nickname: e.sender.card || e.user_id,
user_id: e.user_id,
};
return axios
.post("https://api.ylibrary.org/api/search/", {
const anna = axios
.post("https://anna.bookpan.net/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",
@ -149,84 +151,84 @@ async function getZHelper(e, keyword) {
page: 1,
sensitive: false,
})
.then(async resp => {
return resp.data.data.map(item => {
const { title, author, publisher, isbn, extension, filesize, year, id, source } =
item;
// 数据组合
return {
message: {
type: "text",
text:
`${id}: <${title}>\n` +
`作者:${author}\n` +
`书籍类型:${extension}\n` +
`出版年月:${year}\n` +
`来源:${source}\n` +
`ISBN${isbn || "暂无"}\n` +
`出版社:${publisher}\n` +
`文件大小:${(Number(filesize) / 1024 / 1024).toFixed(2)}MB`,
},
...sendTemplate,
};
});
});
}
/**
* 获取书籍下载方式
* @param e
* @param id
* @param source
* @returns {Promise<Array>}
*/
async function getBookDetail(e, id, source) {
return axios
.post("https://api.ylibrary.org/api/detail/", {
const slib2 = axios
.post("https://slib2.ylibrary.org/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/",
},
id: id,
source: source || "zlibrary",
keyword: keyword,
page: 1,
sensitive: false,
})
.then(async resp => {
const {
author,
extension,
filesize,
id,
in_libgen,
ipfs_cid,
md5,
publisher,
source,
title,
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 cleverPass = `https://rapidupload.1kbtool.com/${reqUrl}`;
const cleverPass2 = `https://rulite.1kbtool.com/${reqUrl}`;
return [
// `Libgen${Libgen}`,
// `ipfs${ipfs}`,
`秒传:${cleverPass}`,
`秒传Lite${cleverPass2}`,
].map(item => {
return {
message: { type: "text", text: item },
nickname: e.sender.card || e.user_id,
user_id: e.user_id,
};
});
});
// 组合数据
return Promise.allSettled([slib2, anna]).then(async resp => {
// 解析第一个数据
const slib2Data = await resp[0].value.data.data.slice(0, LIMIT).map(item => {
const { code, download_link, info } = item;
const { name, url } = download_link?.[0];
// 数据组合
return {
message: {
type: "text",
text: `标题: ${info}\n`+
`${name}: ${url}`
},
...sendTemplate,
}
})
// 解析第一个数据
const annaDataPromises = resp[1].value.data.data.slice(0, LIMIT).map(async (item) => {
const { author, cover, extension, id, link, publisher, sizestring, source, title } = item;
// 固定一个模板
let resBooks = `<${title}>\n` +
`作者:${author}\n` +
`书籍类型:${extension}\n` +
`来源:${source}\n` +
`出版社:${publisher}\n` +
`文件大小:${sizestring}`;
// 发送一个需要下载链接的请求
const downloadLink = await getDownloadLink(id);
resBooks += downloadLink;
return {
message: {
type: "text",
text: resBooks
},
...sendTemplate,
}
})
// 合并数据
const annaData = await Promise.all(annaDataPromises);
return [...slib2Data, ...annaData];
})
}
export { getYiBook, getZBook, getBookDetail, getZHelper };
async function getDownloadLink(id) {
if (id === undefined || id === "") {
return "";
}
const resp = await axios.post("https://anna.bookpan.net/api/detail/", {
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/",
},
id: id,
source: "anna",
});
const { download_link } = resp.data;
const links = download_link.slice(0, 2).map((item, index) => {
return `直链 #${index}: ${item?.url}\n`
})
return `\n${links}`;
}
export { getYiBook, getZBook, getZHelper };

View File

@ -34,17 +34,6 @@ export const douyinTypeMap = {
150: "image",
};
export const PROMPT_MAP = {
"解决": "You are now a programmer, the following is an error, please tell me how to solve this error in Chinese. ",
"解释": "You are now a programming language expert, please tell me what the following code is doing in Chinese. ",
"优化": "You are now a Clean Code expert. I have the following code. Please rewrite it in a cleaner and simpler way to make it easier for my colleagues to maintain the code. Also, explain in Chinese why you want to refactor like this, so I can add the refactor method description to the Pull Request. Attach code ",
"翻译": "I want you to act as an Chinese translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements, then result of Chinese translation and nothing else, do not write explanations. My first sentence is ",
"面试": "For the following interview questions, please provide in Chinese what you think is correct and common, and ask some common interview questions? ",
"百科": "I want you to act as a Wikipedia page. I will give you the name of a topic, and you will provide a summary in Chinese of that topic in the format of a Wikipedia page. Your summary should be informative and factual, covering the most important aspects of the topic. Start your summary with an introductory paragraph that gives an overview of the topic. My first topic is ",
"单词": "Below is an English article. You will extract key words from the article and convert English words into full explanations including Chinese translations, English definitions and an example sentence, in the format of [Key Words] - [Chinese Translation] - [English Interpretation]. Please check that all information is accurate and keep your answers concise without any additional feedback: ",
"": "Summarize the key points of this article in Chinese and in a list of points. Choose an appropriate emoji for each bullet point. Each bullet point format is [emoji] - [text]."
}
export const TEN_THOUSAND = 10000;
export const CAT_LIMIT = 10;