mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
✨ feat: B站番剧链接加入缓存,更快!
This commit is contained in:
parent
856e372141
commit
fc0d4e372d
@ -1,6 +1,6 @@
|
||||
import config from "../model/config.js";
|
||||
import schedule from 'node-schedule';
|
||||
import { REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_LAGRANGE, REDOS_YUNZAI_WHITELIST } from "../constants/constant.js";
|
||||
import { REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_LAGRANGE, REDIS_YUNZAI_WHITELIST } from "../constants/constant.js";
|
||||
import { deleteFolderRecursive, readCurrentDir } from "../utils/file.js";
|
||||
import { redisExistAndGetKey, redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js";
|
||||
|
||||
@ -142,7 +142,7 @@ export class switchers extends plugin {
|
||||
e.reply("无效的R信任用户");
|
||||
return;
|
||||
}
|
||||
let whiteList = await redisExistAndGetKey(REDOS_YUNZAI_WHITELIST);
|
||||
let whiteList = await redisExistAndGetKey(REDIS_YUNZAI_WHITELIST);
|
||||
// 不存在就创建
|
||||
if (whiteList == null) {
|
||||
whiteList = [];
|
||||
@ -154,7 +154,7 @@ export class switchers extends plugin {
|
||||
}
|
||||
whiteList = [...whiteList, trustUserId];
|
||||
// 放置到Redis里
|
||||
await redisSetKey(REDOS_YUNZAI_WHITELIST, whiteList);
|
||||
await redisSetKey(REDIS_YUNZAI_WHITELIST, whiteList);
|
||||
e.reply(`成功添加R信任用户:${ trustUserId }`);
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ export class switchers extends plugin {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async getWhiteList(e) {
|
||||
let whiteList = await redisExistAndGetKey(REDOS_YUNZAI_WHITELIST);
|
||||
let whiteList = await redisExistAndGetKey(REDIS_YUNZAI_WHITELIST);
|
||||
if (whiteList == null) {
|
||||
whiteList = [];
|
||||
}
|
||||
@ -191,7 +191,7 @@ export class switchers extends plugin {
|
||||
// 如果不是回复就看发送内容
|
||||
trustUserId = e.msg.replace("#设置R信任用户", "");
|
||||
}
|
||||
let whiteList = await redisExistAndGetKey(REDOS_YUNZAI_WHITELIST);
|
||||
let whiteList = await redisExistAndGetKey(REDIS_YUNZAI_WHITELIST);
|
||||
if (whiteList == null) {
|
||||
e.reply("R插件当前没有任何信任用户!");
|
||||
return;
|
||||
@ -215,7 +215,7 @@ export class switchers extends plugin {
|
||||
trustUserId = e.msg.replace("#删除R信任用户", "");
|
||||
}
|
||||
// 校准不是string的用户
|
||||
let whiteList = (await redisExistAndGetKey(REDOS_YUNZAI_WHITELIST)).map(item =>
|
||||
let whiteList = (await redisExistAndGetKey(REDIS_YUNZAI_WHITELIST)).map(item =>
|
||||
typeof item === 'string' ? item : item.toString()
|
||||
);
|
||||
if (whiteList == null) {
|
||||
@ -229,7 +229,7 @@ export class switchers extends plugin {
|
||||
}
|
||||
whiteList = whiteList.filter((item) => item !== trustUserId);
|
||||
// 放置到Redis里
|
||||
await redisSetKey(REDOS_YUNZAI_WHITELIST, whiteList);
|
||||
await redisSetKey(REDIS_YUNZAI_WHITELIST, whiteList);
|
||||
e.reply(`成功删除R信任用户:${ trustUserId }`);
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ import {
|
||||
douyinTypeMap,
|
||||
DOWNLOAD_WAIT_DETECT_FILE_TIME,
|
||||
HELP_DOC,
|
||||
MESSAGE_RECALL_TIME,
|
||||
MESSAGE_RECALL_TIME, REDIS_YUNZAI_ANIMELIST,
|
||||
REDIS_YUNZAI_ISOVERSEA,
|
||||
REDIS_YUNZAI_LAGRANGE,
|
||||
REDOS_YUNZAI_WHITELIST,
|
||||
REDIS_YUNZAI_WHITELIST,
|
||||
SUMMARY_PROMPT,
|
||||
transMap,
|
||||
TWITTER_BEARER_TOKEN,
|
||||
@ -85,7 +85,13 @@ import { LagrangeAdapter } from "../utils/lagrange-adapter.js";
|
||||
import { contentEstimator } from "../utils/link-share-summary-util.js";
|
||||
import { getDS } from "../utils/mihoyo.js";
|
||||
import { OpenaiBuilder } from "../utils/openai-builder.js";
|
||||
import { redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js";
|
||||
import {
|
||||
redisExistAndGetKey,
|
||||
redisExistAndInsertObject,
|
||||
redisExistKey,
|
||||
redisGetKey,
|
||||
redisSetKey
|
||||
} from "../utils/redis-util.js";
|
||||
import { saveTDL, startTDL } from "../utils/tdl-util.js";
|
||||
import Translate from "../utils/trans-strategy.js";
|
||||
import { mid2id } from "../utils/weibo.js";
|
||||
@ -655,16 +661,42 @@ export class tools extends plugin {
|
||||
"追番": favorites,
|
||||
"收藏": favorite,
|
||||
};
|
||||
// 截断标题,查看Redis中是否存在,避免频繁走网络连接
|
||||
const { shortLink, shortLink2 } = await this.biliAnimeCacheDetect(result.title);
|
||||
e.reply([
|
||||
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`,
|
||||
`${ formatBiliInfo(dataProcessMap) }`,
|
||||
`\n\n🪶 在线观看: ${ await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK + result.title) }`,
|
||||
`\n🌸 在线观看: ${ await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK2 + result.title) }`
|
||||
`\n\n🪶 在线观看: ${ shortLink }`,
|
||||
`\n🌸 在线观看: ${ shortLink2 }`
|
||||
], true);
|
||||
return ep;
|
||||
}
|
||||
|
||||
/**
|
||||
* 短链接缓存
|
||||
* @param title
|
||||
* @returns {Promise<{shortLink2: string, shortLink: string}|*>}
|
||||
*/
|
||||
async biliAnimeCacheDetect(title) {
|
||||
const animeList = await redisExistAndGetKey(REDIS_YUNZAI_ANIMELIST)
|
||||
if (animeList && animeList?.[title] !== undefined) {
|
||||
return animeList?.[title];
|
||||
}
|
||||
const shortLink = await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK + title);
|
||||
const shortLink2 = await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK2 + title);
|
||||
await redisExistAndInsertObject(REDIS_YUNZAI_ANIMELIST, {
|
||||
[title]: {
|
||||
shortLink,
|
||||
shortLink2
|
||||
}
|
||||
});
|
||||
return {
|
||||
shortLink,
|
||||
shortLink2
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 哔哩哔哩下载策略
|
||||
* @param e 事件
|
||||
@ -2286,10 +2318,10 @@ export class tools extends plugin {
|
||||
*/
|
||||
async isTrustUser(userId) {
|
||||
// 如果不存在则返回
|
||||
if (!(await redisExistKey(REDOS_YUNZAI_WHITELIST))) {
|
||||
if (!(await redisExistKey(REDIS_YUNZAI_WHITELIST))) {
|
||||
return false;
|
||||
}
|
||||
const whiteList = await redisGetKey(REDOS_YUNZAI_WHITELIST);
|
||||
const whiteList = await redisGetKey(REDIS_YUNZAI_WHITELIST);
|
||||
return whiteList.includes(userId.toString()) || whiteList.includes(userId);
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,13 @@ export const REDIS_YUNZAI_LAGRANGE = "Yz:rconsole:tools:lagrange";
|
||||
* 某些功能的解析白名单
|
||||
* @type {string}
|
||||
*/
|
||||
export const REDOS_YUNZAI_WHITELIST = "Yz:rconsole:tools:whitelist";
|
||||
export const REDIS_YUNZAI_WHITELIST = "Yz:rconsole:tools:whitelist";
|
||||
|
||||
/**
|
||||
* 番剧列表缓存
|
||||
* @type {string}
|
||||
*/
|
||||
export const REDIS_YUNZAI_ANIMELIST = "Yz:rconsole:tools:anime";
|
||||
|
||||
export const TWITTER_BEARER_TOKEN = "";
|
||||
|
||||
|
@ -40,3 +40,19 @@ export async function redisExistAndGetKey(key) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在某个 key 的末尾插入一个对象
|
||||
* @param key
|
||||
* @param obj
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function redisExistAndInsertObject(key, obj) {
|
||||
let objs = await redisExistAndGetKey(key);
|
||||
if (objs) {
|
||||
objs = {...objs, ...obj};
|
||||
await redis.set(key, JSON.stringify(objs));
|
||||
} else {
|
||||
await redis.set(key, JSON.stringify(obj));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user