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 d5a2e1e commit ed1b164
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,8 +1,8 @@
import { WeiboQuery } from '@/models/weibo/weibo.query';
import { WeiboTask } from '@/models/weibo/weibo.task';
import { WeiboQuery } from '@/models/weibo/weibo.main.query.js';
import { WeiboTask } from '@/models/weibo/weibo.main.task.js';
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.js';
import plugin from '../../../lib/plugins/plugin.js';

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 @@ -44,6 +44,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 @@ -208,10 +209,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 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 @@ -251,7 +255,7 @@ export class BiliTask {

(logger ?? Bot.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 @@ -286,9 +290,9 @@ export class BiliTask {
}

let mergeTextPic: boolean = !!biliConfigData.mergeTextPic === false ? false : true; // 是否合并文本和图片,默认为 true
if (mergeTextPic) {
if (mergeTextPic === true) {
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 @@ -299,7 +303,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,6 +1,6 @@
import axios from 'axios';
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, Bot: 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 { JSDOM } from 'jsdom';

declare const Bot: any, segment: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,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 Bot: any, redis: any, segment: any;

Expand All @@ -25,6 +25,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 ed1b164

Please sign in to comment.