fix(通知): 账号状态分类合并为一条消息

This commit is contained in:
2026-10-21 16:47:13 +08:00
parent abaf65737e
commit 7bc19e9eaa
7 changed files with 45 additions and 40 deletions
+18 -16
View File
@@ -1169,9 +1169,11 @@ def set_account_status(name, status=""):
def notify_account_status_summary(job_name="", source="计划运行"):
"""汇总账号库的「账号状态」并发通知(webhook 事件 `account.status.summary`)。
用户口径:**不做统计,按状态类型分别发送** —— 每个状态一条消息,
标题是「账号状态:作品异常」,正文列出这个类型的账号(昵称 + 设备)。
空状态(未设置)不单独发;没有可发的类型时不发。
用户口径:**不做统计;所有类型合到一个消息里,按类型分行列出账号**。
例如:
作品异常:A(A01)、B(A02)
账号安全待提升:C(A03)
空状态(未设置)不列;没有可发状态时不发。
"""
try:
with _ctx():
@@ -1192,20 +1194,20 @@ def notify_account_status_summary(job_name="", source="计划运行"):
return 2
return 1
from core import notifier
lines = []
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)
names = "、".join(
"%s(%s)" % (r.get("nickname") or "?",
r.get("device_name") or "未登记")
for r in groups[st])
lines.append("%s:%s" % (st, names))
from core import notifier
notifier.notify(
"account.status.summary",
job_name=job_name or "全部账号", source=source,
groups="\n> ".join(lines),
level=("warning" if any(("异常" in st or "待提升" in st)
for st in groups) else "success"))
return True
except Exception as e:
_log.warning(f"账号状态分类通知失败(不影响主流程): {e}")
+4 -1
View File
@@ -342,6 +342,7 @@ _FIELD_LABELS = {
"stopped": "停止", "failed_devices": "失败设备",
"normal": "正常", "abnormal": "异常", "attention": "待关注",
"status_counts": "状态分布", "status_type": "状态类型", "accounts": "账号",
"groups": "状态分类",
"abnormal_accounts": "异常/待关注账号", "source": "来源",
"failed_items": "失败明细", "filename": "文件", "size": "大小(字节)",
"tables": "表数", "include_apk": "含APK", "user": "操作人", "operator": "操作人",
@@ -455,7 +456,9 @@ def build_message(ev, fields, hook=None):
v = "、".join(str(x) for x in list(v)[:6]) + ("…" if len(v) > 6 else "")
elif isinstance(v, dict):
v = json.dumps(v, ensure_ascii=False)[:200]
rows.append((_label(k), str(v)[:400]))
# 单字段上限 800 字:账号状态分类可能列几十个账号;整条消息仍受
# 各适配器的 byte_limit(企微 4096 字节)兜底截断。
rows.append((_label(k), str(v)[:800]))
# 样本只在**真的合并了多条**时才有意义:合并 1 条时样本就是标题主体本身
if merged and merged.get("merged_count", 0) > 1:
samples = [s for s in (merged.get("samples") or [])[:3]
+3 -4
View File
@@ -126,10 +126,9 @@ EVENTS = [
"抖音停在登录页或要验证码 —— **需要人工登录**(平台绝不代替登录/过滑块),"
"本设备已停止本轮任务", agg_window=0, agg_key=_BY_SERIAL, recommend=True),
_e("account.status.summary", "账号状态分类", "业务",
["title", "job_name", "source", "status_type", "accounts"],
"按账号状态**类型分别发送**:每个类型一条消息,列出该状态的账号"
"(不做总数/正常/异常统计)。每次「检测账号」运行结束发一次,"
"另外每天定时发一次",
["job_name", "source", "groups"],
"**一个消息内**按账号状态类型分行列出账号(不做总数统计)。"
"每次「检测账号」运行结束发一次,另外每天定时发一次",
agg_window=0, recommend=True),
_e("task.video.published", "视频已发布", "业务",
["serial", "device_name", "model", "phone", "nickname", "release_date", "seq",