该提交实现了完整的B站渠道插件,包含以下核心功能: 1. 支持B站直播弹幕监听与处理,包含弹幕、SC、礼物等多种直播间事件 2. 支持B站私信的轮询接收与发送 3. 内置WBI签名算法,适配B站API鉴权要求 4. 提供账号配对、黑白名单等弹幕私信权限控制 5. 集成速率限制与防风险机制,降低账号封禁风险 6. 完善的配置管理与状态监控能力
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()
|