fix(通知): 账号状态按类型分别发送(不做统计)
This commit is contained in:
+32
-27
@@ -22,7 +22,6 @@ import re
|
||||
import threading
|
||||
import time
|
||||
import uuid
|
||||
from collections import Counter
|
||||
|
||||
from core.logger import get_logger
|
||||
|
||||
@@ -1170,40 +1169,46 @@ def set_account_status(name, status=""):
|
||||
def notify_account_status_summary(job_name="", source="计划运行"):
|
||||
"""汇总账号库的「账号状态」并发通知(webhook 事件 `account.status.summary`)。
|
||||
|
||||
统计口径:`正常` = 状态恰好是「正常」;`异常` = 非空且不是「正常」
|
||||
(作品异常/账号异常/限流…);空状态算「未设置」,不算异常。
|
||||
通知内容:总数 / 正常数 / 异常数 / 状态分布 / 异常账号清单(含设备)。
|
||||
用户口径:**不做统计,按状态类型分别发送** —— 每个状态一条消息,
|
||||
标题是「账号状态:作品异常」,正文列出这个类型的账号(昵称 + 设备)。
|
||||
空状态(未设置)不单独发;没有可发的类型时不发。
|
||||
"""
|
||||
try:
|
||||
with _ctx():
|
||||
rows = roster_rows()
|
||||
if not rows:
|
||||
return False
|
||||
counts = Counter()
|
||||
abnormal_rows = []
|
||||
groups = {}
|
||||
for r in rows:
|
||||
st = (r.get("account_status") or "").strip() or "未设置"
|
||||
counts[st] += 1
|
||||
if st not in ("正常", "未设置"):
|
||||
abnormal_rows.append(r)
|
||||
status_counts = [f"{k} {v}" for k, v in counts.most_common()]
|
||||
abnormal_accounts = [
|
||||
"%s(%s · %s)" % (r.get("nickname") or "?",
|
||||
r.get("account_status") or "未设置",
|
||||
r.get("device_name") or "未登记")
|
||||
for r in abnormal_rows[:20]
|
||||
]
|
||||
st = (r.get("account_status") or "").strip()
|
||||
if not st or st == "未设置":
|
||||
continue
|
||||
groups.setdefault(st, []).append(r)
|
||||
if not groups:
|
||||
return False
|
||||
|
||||
def _prio(st):
|
||||
if "异常" in st:
|
||||
return 0
|
||||
if "正常" in st:
|
||||
return 2
|
||||
return 1
|
||||
|
||||
from core import notifier
|
||||
notifier.notify(
|
||||
"account.status.summary",
|
||||
job_name=job_name or "全部账号", source=source,
|
||||
total=len(rows), normal=counts.get("正常", 0),
|
||||
abnormal=len(abnormal_rows), status_counts=status_counts,
|
||||
abnormal_accounts=abnormal_accounts,
|
||||
level=("warning" if abnormal_rows else "success"))
|
||||
for st in sorted(groups, key=_prio):
|
||||
rs = groups[st]
|
||||
accounts = "、".join(
|
||||
"%s(%s)" % (r.get("nickname") or "?",
|
||||
r.get("device_name") or "未登记")
|
||||
for r in rs)
|
||||
level = ("warning" if ("异常" in st or "待提升" in st)
|
||||
else ("success" if "正常" in st else "info"))
|
||||
notifier.notify(
|
||||
"account.status.summary",
|
||||
title="账号状态:%s" % st,
|
||||
job_name=job_name or "全部账号", source=source,
|
||||
status_type=st, accounts=accounts, level=level)
|
||||
return True
|
||||
except Exception as e:
|
||||
_log.warning(f"账号状态汇总通知失败(不影响主流程): {e}")
|
||||
_log.warning(f"账号状态分类通知失败(不影响主流程): {e}")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user