Skip to content

Commit

Permalink
add: new config item of BiliDynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Oct 11, 2024
1 parent 58cb7b5 commit fc3c662
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 2.0.5
* 新增获取B站up数据的随机延迟配置项
* 新增puppeteer渲染图片测试脚本

# 2.0.4
Expand Down
6 changes: 5 additions & 1 deletion defaultConfig/bilibili/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ pushTime: '*/23 * * * *'
# 推送监测间隔,单位为秒,默认7200秒即2小时,即以当前时间为基准,监测过去2小时内的动态,并推送。取值范围:3600-36000秒,即过去的1-10h。应大于pushTime的周期。
interval: 7200

# 顺序检测相邻up主的动态并获取数据的最大随机间隔时间,单位为毫秒,默认 8000,即 8000 毫秒(8秒),即获取该up的动态数据后,随机等待2(内置值)-8秒后再获取下一位up的动态数据。取值范围:4000 ≦ x < pushTime的周期,单位为毫秒。
# 该数值大小影响风控概率, 请谨慎调整,建议不要设置过小,否则可能被风控导致动态获取失败。
getDataRandomDelay: 8000

# 全部订阅的转发动态是否推送: 默认 1 - 开启推送, 0 - 关闭推送。 如果仅仅需要关闭单个订阅的转发动态推送,使用分类订阅指令不包含 转发 分类即可,无需修改此配置。
pushTransmit: 1

# 推送动态时,限制发送多少张图片
# 推送文字和图文动态时,限制发送多少张图片
pushPicCountLimit: 3

# 推送文字和图文动态时,限制字数是多少
Expand Down
18 changes: 7 additions & 11 deletions models/bilibili/bilibili.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ export class BiliTask {
async runTask() {
let biliConfigData = await Config.getUserConfig('bilibili', 'config');
let biliPushData = await Config.getUserConfig('bilibili', 'push');
let interval: number = biliConfigData.interval || 7200;
let lastLiveStatus = JSON.parse(await Redis.get('yuki:bililive:lastlivestatus')) || {};
let interval: number = biliConfigData?.interval || 7200;
const uidMap: Map<any, Map<string, any>> = new Map(); // 存放group 和 private 对应所属 uid 与推送信息的映射
const dynamicList = {}; // 存放获取的所有动态,键为 uid,值为动态数组

await this.processBiliData(biliPushData, uidMap, dynamicList, lastLiveStatus);
await this.processBiliData(biliPushData, biliConfigData, uidMap, dynamicList);

let now: number = Date.now() / 1000; // 时间戳(秒)
await this.pushDynamicMessages(uidMap, dynamicList, now, interval, biliConfigData);
Expand Down Expand Up @@ -82,10 +81,11 @@ export class BiliTask {
}[];
};
},
biliConfigData: any,
uidMap: Map<any, Map<string, any>>,
dynamicList: any,
lastLiveStatus: any
dynamicList: any
) {
let getDataRandomDelay: number = biliConfigData?.getDataRandomDelay || 8000; // 获取相邻up动态数据的随机延时间隔
const requestedDataOfUids = new Map<string, any>(); // 存放已请求的 uid 映射
for (let chatType in biliPushData) {
// 遍历 group 和 private
Expand All @@ -100,10 +100,6 @@ export class BiliTask {
biliPushData[chatType][chatId] || []
);
for (let subInfoOfup of subUpsOfChat) {
if (!lastLiveStatus[subInfoOfup.uid]) {
lastLiveStatus[subInfoOfup.uid] = 0;
}

let resp: any;
// 检查是否已经请求过该 uid
if (requestedDataOfUids.has(subInfoOfup.uid)) {
Expand Down Expand Up @@ -133,7 +129,7 @@ export class BiliTask {
const bot_id: string[] | number[] = subInfoOfup.bot_id || [];
const { name, type } = subInfoOfup;
chatTypeMap.set(subInfoOfup.uid, { chatIds, bot_id, upName: name, type });
await this.randomDelay(1000, 4000); // 随机延时1-4秒
await this.randomDelay(2000, getDataRandomDelay); // 随机延时
}
}
}
Expand Down Expand Up @@ -216,7 +212,7 @@ export class BiliTask {
let boxGrid: boolean = !!biliConfigData.boxGrid === false ? false : true; // 是否启用九宫格样式,默认为 true
let isSplit: boolean = !!biliConfigData.isSplit === false ? false : true; // 是否启用分片截图,默认为 true
let style: string = isSplit ? '' : `.unfold { max-height: ${biliConfigData?.noSplitHeight ?? 7500}px; }`; // 不启用分片截图模式的样式
let splitHeight: number = biliConfigData?.splitHeight ?? 8000; // 分片截图高度,默认 8000, 单位 px,启用分片截图时生效
let splitHeight: number = biliConfigData?.splitHeight || 8000; // 分片截图高度,默认 8000, 单位 px,启用分片截图时生效

const urlQrcodeData: string = await QRCode.toDataURL(extentData?.url);
let renderData: MainProps = this.buildRenderData(extentData, urlQrcodeData, boxGrid);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yuki-plugin",
"version": "2.0.5-0",
"version": "2.0.5-1",
"author": "snowtafir",
"description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件",
"main": "./index",
Expand Down

0 comments on commit fc3c662

Please sign in to comment.