feat: gate media downloads by group and retry douyu checks

This commit is contained in:
liuwei
2026-04-13 15:53:34 +08:00
parent d581b9650e
commit 7df4bd216f
4 changed files with 117 additions and 26 deletions

View File

@@ -32,6 +32,7 @@ class Feature(Enum):
EPIC = 4, "📊 EPIC自动播报 [每周五自动发送]" # 新增的功能
DAILY_SUMMARY = 5, "🕤 每日群发言总结 [每日9:30定时发送]"
GROUP_MEMBER_CHANGE = 6, "👥 群成员变更监控 [自动监控群成员变动并发送通知]"
MEDIA_DOWNLOAD = 7, "🖼️ 图片表情下载 [控制群图片/表情媒资自动下载]"
# DAILY_SUMMARY = 3, "🕤 每日群发言总结 [每日9:30定时发送]"
# AI_CAPABILITY = 4, "🤖 AI对话 [ai, 聊天, AI] 用法ai 如何写一个机器人?"

View File

@@ -19,6 +19,7 @@ from db.levels_db import LevelsDBOperator
from db.message_storage import MessageStorageDB
# 导入积分系统
from db.points_db import PointsDBOperator, PointSource
from utils.robot_cmd.robot_command import Feature, GroupBotManager, PermissionStatus
from utils.wechat.contact_manager import ContactManager
from wechat_ipad import WechatAPIClient
from wechat_ipad.models.message import WxMessage, MessageType
@@ -317,8 +318,22 @@ class MessageStorage:
batch_size: 每次处理多少条默认20条
"""
try:
enabled_groups = [
group_id
for group_id in GroupBotManager.local_cache.get("group_list", set())
if GroupBotManager.get_group_permission(group_id, Feature.MEDIA_DOWNLOAD) == PermissionStatus.ENABLED
]
if not enabled_groups:
logger.debug("媒体下载功能未在任何群启用,跳过本轮媒体处理")
return
# 查询未处理的图片/表情消息
pending_messages = self.message_db.get_pending_media_messages(minutes_ago, batch_size)
pending_messages = self.message_db.get_pending_media_messages(
minutes_ago,
batch_size,
group_ids=enabled_groups
)
if not pending_messages:
logger.debug(f"未发现待处理的媒体消息(最近{minutes_ago}分钟)")