From b73594975d79768a8f97552d8a32433ecb232b55 Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 8 Apr 2026 14:23:52 +0800 Subject: [PATCH] fix: restore douyu core active users in daily reports --- plugins/douyu/main.py | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/plugins/douyu/main.py b/plugins/douyu/main.py index a381eb4..389d71d 100644 --- a/plugins/douyu/main.py +++ b/plugins/douyu/main.py @@ -379,6 +379,7 @@ class DouyuRedisManager: class DouyuPlugin(MessagePluginInterface): + _DAILY_REPORT_CACHE_VERSION = 2 FEATURE_KEY = "DOUYU_MONITOR" FEATURE_DESCRIPTION = "🎮 斗鱼开播提醒 [订阅斗鱼 房间号, 取消订阅斗鱼 房间号]" @@ -1110,6 +1111,7 @@ class DouyuPlugin(MessagePluginInterface): } top_badge_counter = Counter() top_badge_message_counter = Counter() + top_active_user_map: Dict[str, Dict[str, Any]] = {} nickname = "" room_name = "" @@ -1153,6 +1155,39 @@ class DouyuPlugin(MessagePluginInterface): if badge_name: top_badge_counter[badge_name] += int(item.get("user_count", 0) or 0) top_badge_message_counter[badge_name] += int(item.get("message_count", 0) or 0) + for item in operator_metrics.get("top_active_users", []) or []: + uid = str(item.get("uid") or "").strip() + if not uid: + continue + existing = top_active_user_map.get(uid) + message_count = int(item.get("message_count", 0) or 0) + organized_message_count = int(item.get("organized_message_count", 0) or 0) + room_level = int(item.get("room_level", 0) or 0) + fans_level = int(item.get("fans_level", 0) or 0) + if not existing: + top_active_user_map[uid] = { + "uid": uid, + "nickname": str(item.get("nickname") or "").strip(), + "message_count": message_count, + "organized_message_count": organized_message_count, + "room_level": room_level, + "fans_name": str(item.get("fans_name") or "").strip(), + "fans_level": fans_level, + "noble_name": str(item.get("noble_name") or "").strip(), + } + continue + existing["message_count"] = int(existing.get("message_count", 0) or 0) + message_count + existing["organized_message_count"] = int(existing.get("organized_message_count", 0) or 0) + organized_message_count + if not str(existing.get("nickname") or "").strip(): + existing["nickname"] = str(item.get("nickname") or "").strip() + if room_level > int(existing.get("room_level", 0) or 0): + existing["room_level"] = room_level + if fans_level > int(existing.get("fans_level", 0) or 0): + existing["fans_level"] = fans_level + if not str(existing.get("fans_name") or "").strip(): + existing["fans_name"] = str(item.get("fans_name") or "").strip() + if not str(existing.get("noble_name") or "").strip(): + existing["noble_name"] = str(item.get("noble_name") or "").strip() for session_message in messages: uid = str(session_message.get("uid") or "").strip() @@ -1191,6 +1226,14 @@ class DouyuPlugin(MessagePluginInterface): } for badge_name, user_count in top_badge_counter.most_common(10) ], + "top_active_users": sorted( + top_active_user_map.values(), + key=lambda item: ( + int(item.get("message_count", 0) or 0), + int(item.get("organized_message_count", 0) or 0), + ), + reverse=True, + )[:12], }, "sessions": [ { @@ -1535,7 +1578,8 @@ class DouyuPlugin(MessagePluginInterface): cached = self._load_daily_report_cache(room_id, anchor_day) or {} cached_image = self._resolve_existing_report_image(cached.get("report_image")) cached_text = str(cached.get("report_text") or "").strip() - if cached_image or cached_text: + cached_version = int(cached.get("cache_version", 0) or 0) + if cached_version >= self._DAILY_REPORT_CACHE_VERSION and (cached_image or cached_text): return { "report_text": cached_text, "report_image": cached_image, @@ -1550,6 +1594,7 @@ class DouyuPlugin(MessagePluginInterface): result = { "room_id": room_id, "anchor_day": anchor_day, + "cache_version": self._DAILY_REPORT_CACHE_VERSION, "report_text": report_text, "report_image": report_image, "generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),