42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from yuxi.channel.extensions.bilibili.types import BilibiliAccountConfig, is_account_configured
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def get_status(ctx) -> dict:
|
|||
|
|
account = await _resolve_account(ctx)
|
|||
|
|
issues = []
|
|||
|
|
|
|||
|
|
if not is_account_configured(account):
|
|||
|
|
issues.append({"severity": "error", "message": "Cookie 配置不完整"})
|
|||
|
|
|
|||
|
|
if not account.room_ids:
|
|||
|
|
issues.append({"severity": "warning", "message": "未配置直播间 ID"})
|
|||
|
|
|
|||
|
|
if account.dm_enabled:
|
|||
|
|
issues.append(
|
|||
|
|
{
|
|||
|
|
"severity": "warning",
|
|||
|
|
"message": "私信功能已启用 — 使用非官方 API,存在账号风险",
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
"running": getattr(ctx, "running", False),
|
|||
|
|
"configured": is_account_configured(account),
|
|||
|
|
"issues": issues,
|
|||
|
|
"room_count": len(account.room_ids),
|
|||
|
|
"dm_enabled": account.dm_enabled,
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def _resolve_account(ctx) -> BilibiliAccountConfig:
|
|||
|
|
config = getattr(ctx, "config", {}) or {}
|
|||
|
|
channel_cfg = config.get("channels", {}).get("bilibili", {})
|
|||
|
|
account_id = getattr(ctx, "account_id", "default")
|
|||
|
|
accounts = channel_cfg.get("accounts", {})
|
|||
|
|
account_dict = accounts.get(account_id, {})
|
|||
|
|
if isinstance(account_dict, BilibiliAccountConfig):
|
|||
|
|
return account_dict
|
|||
|
|
return BilibiliAccountConfig(**account_dict) if account_dict else BilibiliAccountConfig()
|