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 cf73848 commit 57cb132
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yz-yuki-plugin",
"version": "2.0.6-6",
"version": "2.0.6-7",
"description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
"author": "snowtafir",
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions src/apps/weibo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Messages, EventType } from 'yunzaijs';
import { WeiboQuery } from '@src/models/weibo/weibo.query';
import { WeiboTask } from '@src/models/weibo/weibo.task';
import { WeiboQuery } from '@src/models/weibo/weibo.main.query';
import { WeiboTask } from '@src/models/weibo/weibo.main.task';
import Config from '@src/utils/config';
import { _paths } from '@src/utils/paths';
import { WeiboGetWebData } from '@src/models/weibo/weibo.get.web.data';
import { WeiboGetWebData } from '@src/models/weibo/weibo.main.get.web.data';

declare const logger: any;

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
import { _paths } from '@src/utils/paths';
import * as apps from '@src/apps/index';
import { BiliTask } from '@src/models/bilibili/bilibili.main.task';
import { WeiboTask } from '@src/models/weibo/weibo.task';
import { WeiboTask } from '@src/models/weibo/weibo.main.task';
declare const logger: any;
type RulesType = {
reg: RegExp | string;
Expand Down
16 changes: 10 additions & 6 deletions src/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 | null = 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 @@ -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 @@ -285,9 +289,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 @@ -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 '@src/models/weibo/weibo.api';
import { WeiboQuery } from '@src/models/weibo/weibo.query';
import { WeiboApi } from '@src/models/weibo/weibo.main.api';
import { WeiboQuery } from '@src/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 '@src/models/weibo/weibo.api';
import { WeiboApi } from '@src/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 '@src/components/dynamic/MainPage';
import Config from '@src/utils/config';
import { renderPage } from '@src/utils/image';
import { ScreenshotOptions } from '@src/utils/puppeteer.render';
import { WeiboGetWebData } from '@src/models/weibo/weibo.get.web.data';
import { WeiboQuery } from '@src/models/weibo/weibo.query';
import { WeiboGetWebData } from '@src/models/weibo/weibo.main.get.web.data';
import { WeiboQuery } from '@src/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

0 comments on commit 57cb132

Please sign in to comment.