Skip to content

Commit

Permalink
optimize: biliLiveDynamic add new config: @ALL user
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Jan 3, 2025
1 parent 0c4332a commit 8d74ca5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 2.0.6
* 优化文字动态图片资源的发送
* 依赖升级
* 新增哔哩直播动态@全体成员功能,开启前请检查机器人管理员权限和所在聊天类型是否支持

# 2.0.5
* 优化ck
Expand Down
8 changes: 7 additions & 1 deletion defaultConfig/bilibili/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# b站推送,1 开启 0 关闭,保留添加的相关数据,但是不再推送
pushStatus: 1

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

# 动态卡片分页截图高度,默认8000px(仅填数字,无需填入单位),请勿设置过大或过小。启用分片截图时生效。
splitHeight: 8000

# 直播动态是否@全体成员,默认 0 关闭,1 开启。开启前请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持],某些聊天平台或类型不支持@全体成员,如qq官方机器人等。
liveAtAll: 0

# 直播动态@全体成员的共享冷却时间CD,单位秒,默认 1800 秒(30分钟),即每个群聊30分钟内不论多少条直播动态,只会@一次。注意,qq群有 @全体成员 10次/日 的限制,所以请合理设置。
liveAtAllCD: 1800
2 changes: 1 addition & 1 deletion defaultConfig/weibo/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 微博推送,1 开启 0 关闭,保留添加的相关数据,但是不再推送
pushStatus: 1

# 检测微博动态的周期,Cron表达式,作用域共6位,具体方法浏览器搜索 “node-schedule cron表达式”,示例:
# 检测微博动态的冷却时间 CD,Cron表达式,作用域共6位,具体方法浏览器搜索 “node-schedule cron表达式”,示例:
# "*/15 * * * *" #每15min检测一次
# "*/31 * * * *" #每31min检测一次
# "0 5,35 * * * *" #每小时固定第5分0秒、第35分0秒检测一次,共2次/h
Expand Down
13 changes: 7 additions & 6 deletions models/bilibili/bilibili.main.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export class BiliQuery {
content: any,
dynamicTitle: any;
let title = `B站【${upName}】动态推送:\n`;
let dynamicType: string = data.type;

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

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

return { msg, pics };
return { msg, pics, dynamicType };

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

return { msg, pics };
return { msg, pics, dynamicType };

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

return { msg, pics };
return { msg, pics, dynamicType };

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

return { msg, pics };
return { msg, pics, dynamicType };

case 'DYNAMIC_TYPE_FORWARD':
// 处理转发动态
Expand Down Expand Up @@ -610,7 +611,7 @@ export class BiliQuery {
...origContent
];

return { msg, pics };
return { msg, pics, dynamicType };

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

pics = [Segment.image(desc.cover)];
return { msg, pics };
return { msg, pics, dynamicType };

default:
// 处理未定义的动态类型
Expand Down
32 changes: 32 additions & 0 deletions models/bilibili/bilibili.main.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export class BiliTask {
}
if (sended) return; // 如果已经发送过,则直接返回

let liveAtAll: boolean = biliConfigData.liveAtAll === true ? true : false; // 直播动态是否@全体成员,默认false
let liveAtAllCD: number = biliConfigData.liveAtAllCD || 1800; // 直播动态@全体成员 冷却时间CD,默认 30 分钟
let liveAtAllMark: number | string = await Redis.get(`${markKey}${chatId}:liveAtAllMark`); // 直播动态@全体成员标记,默认 0

if (!!biliConfigData.pushMsgMode) {
const { data, uid } = await BiliQuery.formatDynamicData(pushDynamicData); // 处理动态数据
const extentData = { ...data };
Expand Down Expand Up @@ -245,6 +249,16 @@ export class BiliTask {

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

if (liveAtAll && liveAtAllMark && extentData?.type === 'DYNAMIC_TYPE_LIVE_RCMD') {
try {
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
} catch (error) {
logger.error(`直播动态发送@全体成员失败,请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持] :${error}`);
await this.sendMessage(chatId, bot_id, chatType, ['直播动态发送@全体成员失败,请检查权限或平台是否支持']);
}
}

for (let i = 0; i < imgs.length; i++) {
const image: Buffer = imgs[i];
await this.sendMessage(chatId, bot_id, chatType, Segment.image(image));
Expand Down Expand Up @@ -272,8 +286,26 @@ export class BiliTask {
let mergeTextPic: boolean = !!biliConfigData.mergeTextPic === false ? false : true; // 是否合并文本和图片,默认为 true
if (mergeTextPic) {
const mergeMsg = [...dynamicMsg.msg, ...dynamicMsg.pics];
if (liveAtAll && liveAtAllMark && dynamicMsg.dynamicType === 'DYNAMIC_TYPE_LIVE_RCMD') {
try {
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
} catch (error) {
logger.error(`直播动态发送@全体成员失败,请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持] :${error}`);
await this.sendMessage(chatId, bot_id, chatType, ['直播动态发送@全体成员失败,请检查权限或平台是否支持']);
}
}
await this.sendMessage(chatId, bot_id, chatType, mergeMsg);
} else {
if (liveAtAll && liveAtAllMark && dynamicMsg.dynamicType === 'DYNAMIC_TYPE_LIVE_RCMD') {
try {
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
} catch (error) {
logger.error(`直播动态发送@全体成员失败,请检查 <机器人> 是否有 [管理员权限] 或 [聊天平台是否支持] :${error}`);
await this.sendMessage(chatId, bot_id, chatType, ['直播动态发送@全体成员失败,请检查权限或平台是否支持']);
}
}
await this.sendMessage(chatId, bot_id, chatType, dynamicMsg.msg);
const pics = dynamicMsg.pics;
if (pics && pics.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion models/bilibili/bilibili.mian.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function applyLoginQRCode(e: EventType) {
const { img } = qrCodeImage;
qrCodeBufferArray = img;
}
let msg: string[] = [];
let msg: any[] = [];
if (qrCodeBufferArray.length === 0) {
msg.push('渲染二维码图片失败,请查看终端输出的实时日志,\n复制哔哩登陆二维码URL,使用在线或本地二维码生成工具生成二维码并扫码。');
} else {
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.6-4",
"version": "2.0.6-5",
"author": "snowtafir",
"description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件",
"main": "./index",
Expand Down

0 comments on commit 8d74ca5

Please sign in to comment.