🦄 reactor: 重构tieba解析

This commit is contained in:
zhiyu1998 2024-08-22 12:02:27 +08:00
parent 7c50d87e51
commit d4c74fda83
2 changed files with 57 additions and 3 deletions

View File

@ -34,7 +34,7 @@ import {
DY_COMMENT,
DY_INFO,
DY_TOUTIAO_INFO,
GENERAL_REQ_LINK,
GENERAL_REQ_LINK, HIBI_API_SERVICE,
MIYOUSHE_ARTICLE,
NETEASE_API_CN,
NETEASE_SONG_DOWNLOAD,
@ -157,7 +157,7 @@ export class tools extends plugin {
fnc: "bodianMusic",
},
{
reg: "(kuaishou.com|ixigua.com|h5.pipix.com|h5.pipigx.com|tieba.baidu.com|s.xsj.qq.com|m.okjike.com)",
reg: "(kuaishou.com|ixigua.com|h5.pipix.com|h5.pipigx.com|s.xsj.qq.com|m.okjike.com)",
fnc: "general",
},
{
@ -207,6 +207,10 @@ export class tools extends plugin {
{
reg: "https:\\/\\/t\\.me\\/(?:c\\/\\d+\\/\\d+\\/\\d+|c\\/\\d+\\/\\d+|\\w+\\/\\d+\\/\\d+|\\w+\\/\\d+\\?\\w+=\\d+|\\w+\\/\\d+)",
fnc: "aircraft"
},
{
reg: "tieba.baidu.com",
fnc: "tieba"
}
],
});
@ -1889,6 +1893,50 @@ export class tools extends plugin {
return true;
}
async tieba(e) {
const msg = /https:\/\/tieba\.baidu\.com\/p\/[A-Za-z0-9]+/.exec(e.msg)?.[0];
const id = /\/p\/([A-Za-z0-9]+)/.exec(msg)?.[1];
const hibi = HIBI_API_SERVICE + `/tieba/post_detail?tid=${ id }`;
const hibiResp = await fetch(hibi, {
headers: {
"User-Agent": COMMON_USER_AGENT,
}
});
const postList = (await hibiResp.json()).post_list;
const top = postList[0];
const { title, content } = top;
let sendContent = `${this.identifyPrefix}识别:贴吧,${ title }`
if (content?.[0]?.cdn_src !== undefined) {
sendContent = [sendContent]
for (let contentElement of content) {
if (contentElement?.cdn_src !== undefined) {
sendContent.unshift(segment.image(contentElement.cdn_src));
} else if (contentElement?.text !== undefined) {
sendContent.push(`\n\n📝 简介:${contentElement.text}`);
}
}
}
e.reply(sendContent, true);
const others = postList.slice(1);
const reply = others.map(item => {
if (item?.content?.[0]?.cdn_src !== undefined) {
return {
message: segment.image(item?.content?.[0]?.cdn_src),
nickname: e.sender.card || e.user_id,
user_id: e.user_id,
}
} else if (item?.content?.[0]?.text !== undefined) {
return {
message: { type: 'text', text: item?.content?.[0].text || '-'},
nickname: e.sender.card || e.user_id,
user_id: e.user_id,
}
}
});
e.reply(await Bot.makeForwardMsg(reply));
return true;
}
/**
* 哔哩哔哩下载
* @param title

View File

@ -198,4 +198,10 @@ export const ANIME_SERIES_SEARCH_LINK = "https://ylu.cc/so.php?wd="
* 番剧搜索链接2
* @type {string}
*/
export const ANIME_SERIES_SEARCH_LINK2 = "https://yhdm.one/search?q="
export const ANIME_SERIES_SEARCH_LINK2 = "https://yhdm.one/search?q="
/**
* HIBI API
* @type {string}
*/
export const HIBI_API_SERVICE = "https://hibi.moecube.com/api";