Skip to content

Commit 8d74ca5

Browse files
committed
optimize: biliLiveDynamic add new config: @ALL user
1 parent 0c4332a commit 8d74ca5

File tree

7 files changed

+50
-10
lines changed

7 files changed

+50
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 2.0.6
22
* 优化文字动态图片资源的发送
33
* 依赖升级
4+
* 新增哔哩直播动态@全体成员功能,开启前请检查机器人管理员权限和所在聊天类型是否支持
45

56
# 2.0.5
67
* 优化ck

defaultConfig/bilibili/config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# b站推送,1 开启 0 关闭,保留添加的相关数据,但是不再推送
22
pushStatus: 1
33

4-
# 检测b站动态的周期,Cron表达式,作用域共6位,具体方法浏览器搜索 “node-schedule cron表达式”,示例:
4+
# 检测b站动态的冷却时间 CD,Cron表达式,作用域共6位,具体方法浏览器搜索 “node-schedule cron表达式”,示例:
55
# "*/15 * * * *" #每15min检测一次
66
# "*/31 * * * *" #每31min检测一次
77
# "0 5,35 * * * *" #每小时固定第5分0秒、第35分0秒检测一次,共2次/h
@@ -58,3 +58,9 @@ noSplitHeight: 7500
5858

5959
# 动态卡片分页截图高度,默认8000px(仅填数字,无需填入单位),请勿设置过大或过小。启用分片截图时生效。
6060
splitHeight: 8000
61+
62+
# 直播动态是否@全体成员,默认 0 关闭,1 开启。开启前请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持],某些聊天平台或类型不支持@全体成员,如qq官方机器人等。
63+
liveAtAll: 0
64+
65+
# 直播动态@全体成员的共享冷却时间CD,单位秒,默认 1800 秒(30分钟),即每个群聊30分钟内不论多少条直播动态,只会@一次。注意,qq群有 @全体成员 10次/日 的限制,所以请合理设置。
66+
liveAtAllCD: 1800

defaultConfig/weibo/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 微博推送,1 开启 0 关闭,保留添加的相关数据,但是不再推送
22
pushStatus: 1
33

4-
# 检测微博动态的周期,Cron表达式,作用域共6位,具体方法浏览器搜索 “node-schedule cron表达式”,示例:
4+
# 检测微博动态的冷却时间 CD,Cron表达式,作用域共6位,具体方法浏览器搜索 “node-schedule cron表达式”,示例:
55
# "*/15 * * * *" #每15min检测一次
66
# "*/31 * * * *" #每31min检测一次
77
# "0 5,35 * * * *" #每小时固定第5分0秒、第35分0秒检测一次,共2次/h

models/bilibili/bilibili.main.query.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ export class BiliQuery {
430430
content: any,
431431
dynamicTitle: any;
432432
let title = `B站【${upName}】动态推送:\n`;
433+
let dynamicType: string = data.type;
433434

434435
switch (data.type) {
435436
case 'DYNAMIC_TYPE_AV':
@@ -450,7 +451,7 @@ export class BiliQuery {
450451

451452
pics = [Segment.image(desc?.cover)];
452453

453-
return { msg, pics };
454+
return { msg, pics, dynamicType };
454455

455456
case 'DYNAMIC_TYPE_WORD':
456457
// 处理文字动态
@@ -482,7 +483,7 @@ export class BiliQuery {
482483
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}`
483484
];
484485

485-
return { msg, pics };
486+
return { msg, pics, dynamicType };
486487

487488
case 'DYNAMIC_TYPE_DRAW':
488489
// 处理图文动态
@@ -532,7 +533,7 @@ export class BiliQuery {
532533
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}`
533534
];
534535

535-
return { msg, pics };
536+
return { msg, pics, dynamicType };
536537

537538
case 'DYNAMIC_TYPE_ARTICLE':
538539
// 处理文章动态
@@ -577,7 +578,7 @@ export class BiliQuery {
577578
`时间:${author ? moment(author.pub_ts * 1000).format('YYYY年MM月DD日 HH:mm:ss') : ''}`
578579
];
579580

580-
return { msg, pics };
581+
return { msg, pics, dynamicType };
581582

582583
case 'DYNAMIC_TYPE_FORWARD':
583584
// 处理转发动态
@@ -610,7 +611,7 @@ export class BiliQuery {
610611
...origContent
611612
];
612613

613-
return { msg, pics };
614+
return { msg, pics, dynamicType };
614615

615616
case 'DYNAMIC_TYPE_LIVE_RCMD':
616617
// 处理直播动态
@@ -623,7 +624,7 @@ export class BiliQuery {
623624
msg = [title, `-----------------------------\n`, `标题:${desc.title}\n`, `链接:https:${desc.link}`];
624625

625626
pics = [Segment.image(desc.cover)];
626-
return { msg, pics };
627+
return { msg, pics, dynamicType };
627628

628629
default:
629630
// 处理未定义的动态类型

models/bilibili/bilibili.main.task.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ export class BiliTask {
207207
}
208208
if (sended) return; // 如果已经发送过,则直接返回
209209

210+
let liveAtAll: boolean = biliConfigData.liveAtAll === true ? true : false; // 直播动态是否@全体成员,默认false
211+
let liveAtAllCD: number = biliConfigData.liveAtAllCD || 1800; // 直播动态@全体成员 冷却时间CD,默认 30 分钟
212+
let liveAtAllMark: number | string = await Redis.get(`${markKey}${chatId}:liveAtAllMark`); // 直播动态@全体成员标记,默认 0
213+
210214
if (!!biliConfigData.pushMsgMode) {
211215
const { data, uid } = await BiliQuery.formatDynamicData(pushDynamicData); // 处理动态数据
212216
const extentData = { ...data };
@@ -245,6 +249,16 @@ export class BiliTask {
245249

246250
global?.logger?.mark('优纪插件:B站动态执行推送');
247251

252+
if (liveAtAll && liveAtAllMark && extentData?.type === 'DYNAMIC_TYPE_LIVE_RCMD') {
253+
try {
254+
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
255+
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
256+
} catch (error) {
257+
logger.error(`直播动态发送@全体成员失败,请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持] :${error}`);
258+
await this.sendMessage(chatId, bot_id, chatType, ['直播动态发送@全体成员失败,请检查权限或平台是否支持']);
259+
}
260+
}
261+
248262
for (let i = 0; i < imgs.length; i++) {
249263
const image: Buffer = imgs[i];
250264
await this.sendMessage(chatId, bot_id, chatType, Segment.image(image));
@@ -272,8 +286,26 @@ export class BiliTask {
272286
let mergeTextPic: boolean = !!biliConfigData.mergeTextPic === false ? false : true; // 是否合并文本和图片,默认为 true
273287
if (mergeTextPic) {
274288
const mergeMsg = [...dynamicMsg.msg, ...dynamicMsg.pics];
289+
if (liveAtAll && liveAtAllMark && dynamicMsg.dynamicType === 'DYNAMIC_TYPE_LIVE_RCMD') {
290+
try {
291+
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
292+
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
293+
} catch (error) {
294+
logger.error(`直播动态发送@全体成员失败,请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持] :${error}`);
295+
await this.sendMessage(chatId, bot_id, chatType, ['直播动态发送@全体成员失败,请检查权限或平台是否支持']);
296+
}
297+
}
275298
await this.sendMessage(chatId, bot_id, chatType, mergeMsg);
276299
} else {
300+
if (liveAtAll && liveAtAllMark && dynamicMsg.dynamicType === 'DYNAMIC_TYPE_LIVE_RCMD') {
301+
try {
302+
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
303+
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
304+
} catch (error) {
305+
logger.error(`直播动态发送@全体成员失败,请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持] :${error}`);
306+
await this.sendMessage(chatId, bot_id, chatType, ['直播动态发送@全体成员失败,请检查权限或平台是否支持']);
307+
}
308+
}
277309
await this.sendMessage(chatId, bot_id, chatType, dynamicMsg.msg);
278310
const pics = dynamicMsg.pics;
279311
if (pics && pics.length > 0) {

models/bilibili/bilibili.mian.models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function applyLoginQRCode(e: EventType) {
6262
const { img } = qrCodeImage;
6363
qrCodeBufferArray = img;
6464
}
65-
let msg: string[] = [];
65+
let msg: any[] = [];
6666
if (qrCodeBufferArray.length === 0) {
6767
msg.push('渲染二维码图片失败,请查看终端输出的实时日志,\n复制哔哩登陆二维码URL,使用在线或本地二维码生成工具生成二维码并扫码。');
6868
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yuki-plugin",
3-
"version": "2.0.6-4",
3+
"version": "2.0.6-5",
44
"author": "snowtafir",
55
"description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件",
66
"main": "./index",

0 commit comments

Comments
 (0)