Skip to content

Commit

Permalink
fix: LiveBiliDynamic mention user
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Jan 8, 2025
1 parent 301e416 commit c9a6873
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions apps/weibo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Plugin } from 'yunzaijs';
import { WeiboQuery } from '@/models/weibo/weibo.query';
import { WeiboTask } from '@/models/weibo/weibo.task';
import { WeiboQuery } from '@/models/weibo/weibo.main.query';
import { WeiboTask } from '@/models/weibo/weibo.main.task';
import Config from '@/utils/config';
import { _paths } from '@/utils/paths';
import { WeiboGetWebData } from '@/models/weibo/weibo.get.web.data';
import { WeiboGetWebData } from '@/models/weibo/weibo.main.get.web.data';

declare const logger: any;

Expand Down
16 changes: 10 additions & 6 deletions models/bilibili/bilibili.main.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class BiliTask {
let biliConfigData = await Config.getUserConfig('bilibili', 'config');
let biliPushData = await Config.getUserConfig('bilibili', 'push');
let interval: number = biliConfigData?.interval || 7200;
logger.debug(`当前B站功能配置:${JSON.stringify(biliConfigData)}`);
const uidMap: Map<any, Map<string, any>> = new Map(); // 存放group 和 private 对应所属 uid 与推送信息的映射
const dynamicList = {}; // 存放获取的所有动态,键为 uid,值为动态数组

Expand Down Expand Up @@ -207,10 +208,13 @@ export class BiliTask {
}
if (sended) return; // 如果已经发送过,则直接返回

let liveAtAll: boolean = biliConfigData.liveAtAll === true ? true : false; // 直播动态是否@全体成员,默认false
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
let liveAtAllGroupList = new Set(Array.isArray(biliConfigData.liveAtAllGroupList) ? biliConfigData.liveAtAllGroupList : []); // 直播动态@全体成员的群组列表,默认空数组,为空则不进行@全体成员操作
let liveAtAllMark: number | string = await Redis.get(`${markKey}${chatId}:liveAtAllMark`); // 直播动态@全体成员标记
// 直播动态@全体成员的群组列表,默认空数组,为空则不进行@全体成员操作
let liveAtAllGroupList = new Set(
Array.isArray(biliConfigData?.liveAtAllGroupList) ? Array.from(biliConfigData.liveAtAllGroupList).map(item => String(item)) : []
);

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

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

if (liveAtAll && liveAtAllMark && extentData?.type === 'DYNAMIC_TYPE_LIVE_RCMD' && liveAtAllGroupList.has(chatId)) {
if (liveAtAll && !liveAtAllMark && extentData?.type === 'DYNAMIC_TYPE_LIVE_RCMD' && liveAtAllGroupList.has(String(chatId))) {
try {
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
Expand Down Expand Up @@ -287,7 +291,7 @@ 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' && liveAtAllGroupList.has(chatId)) {
if (liveAtAll && !liveAtAllMark && dynamicMsg.dynamicType === 'DYNAMIC_TYPE_LIVE_RCMD' && liveAtAllGroupList.has(String(chatId))) {
try {
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
Expand All @@ -298,7 +302,7 @@ export class BiliTask {
}
await this.sendMessage(chatId, bot_id, chatType, mergeMsg);
} else {
if (liveAtAll && liveAtAllMark && dynamicMsg.dynamicType === 'DYNAMIC_TYPE_LIVE_RCMD' && liveAtAllGroupList.has(chatId)) {
if (liveAtAll && !liveAtAllMark && dynamicMsg.dynamicType === 'DYNAMIC_TYPE_LIVE_RCMD' && liveAtAllGroupList.has(String(chatId))) {
try {
await this.sendMessage(chatId, bot_id, chatType, Segment.at('all'));
await Redis.set(`${markKey}${chatId}:liveAtAllMark`, 1, { EX: liveAtAllCD }); // 设置直播动态@全体成员标记为 1
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import { EventType } from 'yunzaijs';
import { WeiboApi } from '@/models/weibo/weibo.api';
import { WeiboQuery } from '@/models/weibo/weibo.query';
import { WeiboApi } from '@/models/weibo/weibo.main.api';
import { WeiboQuery } from '@/models/weibo/weibo.main.query';

declare const logger: any;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment from 'moment';
import fetch from 'node-fetch';
import { WeiboApi } from '@/models/weibo/weibo.api';
import { WeiboApi } from '@/models/weibo/weibo.main.api';
import { Segment } from 'yunzaijs';
import { JSDOM } from 'jsdom';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { MainProps } from '@/components/dynamic/MainPage';
import Config from '@/utils/config';
import { renderPage } from '@/utils/image';
import { ScreenshotOptions } from '@/utils/puppeteer.render';
import { WeiboGetWebData } from '@/models/weibo/weibo.get.web.data';
import { WeiboQuery } from '@/models/weibo/weibo.query';
import { WeiboGetWebData } from '@/models/weibo/weibo.main.get.web.data';
import { WeiboQuery } from '@/models/weibo/weibo.main.query';

declare const logger: any;

Expand All @@ -24,6 +24,7 @@ export class WeiboTask {
let weiboConfigData = await Config.getUserConfig('weibo', 'config');
let weiboPushData = await Config.getUserConfig('weibo', 'push');
let interval: number = weiboConfigData.interval || 7200; // 推送间隔时间,单位为秒,默认2小时
logger.debug(`当前微博功能配置:${JSON.stringify(weiboConfigData)}`);
const uidMap: Map<any, Map<string, any>> = new Map(); // 存放group 和 private 对应所属 uid 与推送信息的映射
const dynamicList = {}; // 存放获取的所有动态,键为 uid,值为动态数组

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-6",
"version": "2.0.6-7",
"author": "snowtafir",
"description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件",
"main": "./index",
Expand Down

0 comments on commit c9a6873

Please sign in to comment.