feat: 新增指令#r番剧

This commit is contained in:
zhiyu1998 2024-08-21 13:51:42 +08:00
parent 883697df60
commit 1eaa43c91b
2 changed files with 12 additions and 12 deletions

View File

@ -5,7 +5,7 @@ import puppeteer from "../../../lib/puppeteer/puppeteer.js";
// http库 // http库
import axios from "axios"; import axios from "axios";
// 常量 // 常量
import { CAT_LIMIT, COMMON_USER_AGENT, REDIS_YUNZAI_ANIMELIST } from "../constants/constant.js"; import { CAT_LIMIT, COMMON_USER_AGENT, DIVIDING_LINE, REDIS_YUNZAI_ANIMELIST } from "../constants/constant.js";
// 配置文件 // 配置文件
import config from "../model/config.js"; import config from "../model/config.js";
import { redisExistAndGetKey } from "../utils/redis-util.js"; import { redisExistAndGetKey } from "../utils/redis-util.js";
@ -44,7 +44,7 @@ export class query extends plugin {
fnc: "zhubaiSearch", fnc: "zhubaiSearch",
}, },
{ {
reg: "^#汇集番剧$", reg: "^#(r|R)番剧(.*)",
fnc: "myAnimeList", fnc: "myAnimeList",
} }
], ],
@ -231,20 +231,19 @@ export class query extends plugin {
} }
async myAnimeList(e) { async myAnimeList(e) {
const title = e.msg.replace(/^#([rR])番剧/, "").trim();
const animeList = await redisExistAndGetKey(REDIS_YUNZAI_ANIMELIST) const animeList = await redisExistAndGetKey(REDIS_YUNZAI_ANIMELIST)
if (animeList == null) { if (animeList == null) {
e.reply("暂无番剧信息"); e.reply("暂无番剧信息");
return; return;
} }
let forwardMsg = []; const findRes = Object.entries(animeList).find(([key, value]) => key.includes(title));
for (let [key, value] of Object.entries(animeList)) { if (findRes == null) {
forwardMsg.push({ e.reply("未找到相关番剧");
message: { type: 'text', text: `${key}\n🪶 在线观看:${value.shortLink}\n🌸 在线观看:${value.shortLink2}` }, return;
nickname: this.e.sender.card || this.e.user_id,
user_id: this.e.user_id,
})
} }
e.reply(await Bot.makeForwardMsg(forwardMsg)); const { cover, shortLink, shortLink2 } = findRes[1];
e.reply([segment.image(cover), `${findRes[0]}\n\n🪶 在线观看: ${ shortLink }\n🌸 在线观看: ${ shortLink2 }\n${DIVIDING_LINE.replace("{}", "收录信息")}\n当前管理员已经收录了: ${ Object.keys(animeList).length } 个番剧`]);
return true; return true;
} }

View File

@ -662,7 +662,7 @@ export class tools extends plugin {
"收藏": favorite, "收藏": favorite,
}; };
// 截断标题查看Redis中是否存在避免频繁走网络连接 // 截断标题查看Redis中是否存在避免频繁走网络连接
const { shortLink, shortLink2 } = await this.biliAnimeCacheDetect(result.title); const { shortLink, shortLink2 } = await this.biliAnimeCacheDetect(result.title, result.cover);
e.reply([ e.reply([
segment.image(resp.result.cover), segment.image(resp.result.cover),
`${ this.identifyPrefix }识别:哔哩哔哩番剧,${ result.title }\n🎯 评分: ${ result?.rating?.score ?? '-' } / ${ result?.rating?.count ?? '-' }\n📺 ${ result.new_ep.desc }, ${ result.seasons[0].new_ep.index_show }\n`, `${ this.identifyPrefix }识别:哔哩哔哩番剧,${ result.title }\n🎯 评分: ${ result?.rating?.score ?? '-' } / ${ result?.rating?.count ?? '-' }\n📺 ${ result.new_ep.desc }, ${ result.seasons[0].new_ep.index_show }\n`,
@ -678,7 +678,7 @@ export class tools extends plugin {
* @param title * @param title
* @returns {Promise<{shortLink2: string, shortLink: string}|*>} * @returns {Promise<{shortLink2: string, shortLink: string}|*>}
*/ */
async biliAnimeCacheDetect(title) { async biliAnimeCacheDetect(title, cover) {
const animeList = await redisExistAndGetKey(REDIS_YUNZAI_ANIMELIST) const animeList = await redisExistAndGetKey(REDIS_YUNZAI_ANIMELIST)
if (animeList && animeList?.[title] !== undefined) { if (animeList && animeList?.[title] !== undefined) {
return animeList?.[title]; return animeList?.[title];
@ -687,6 +687,7 @@ export class tools extends plugin {
const shortLink2 = await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK2 + title); const shortLink2 = await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK2 + title);
await redisExistAndInsertObject(REDIS_YUNZAI_ANIMELIST, { await redisExistAndInsertObject(REDIS_YUNZAI_ANIMELIST, {
[title]: { [title]: {
cover,
shortLink, shortLink,
shortLink2 shortLink2
} }