该提交实现了完整的B站渠道插件,包含以下核心功能: 1. 支持B站直播弹幕监听与处理,包含弹幕、SC、礼物等多种直播间事件 2. 支持B站私信的轮询接收与发送 3. 内置WBI签名算法,适配B站API鉴权要求 4. 提供账号配对、黑白名单等弹幕私信权限控制 5. 集成速率限制与防风险机制,降低账号封禁风险 6. 完善的配置管理与状态监控能力
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
from __future__ import annotations
|
||
|
||
from yuxi.channel.extensions.bilibili.types import BilibiliAccountConfig
|
||
|
||
|
||
class BilibiliSecurity:
|
||
def __init__(self, account: BilibiliAccountConfig | None = None):
|
||
self._account = account or BilibiliAccountConfig()
|
||
|
||
def check_dm_policy(self, sender_uid: str) -> bool:
|
||
policy = self._account.dm_policy
|
||
if policy == "disabled":
|
||
return False
|
||
if policy == "open":
|
||
return True
|
||
if policy == "allowlist":
|
||
return sender_uid in self._account.dm_allow_from
|
||
if policy == "pairing":
|
||
from yuxi.channel.extensions.bilibili.pairing import check_pairing
|
||
|
||
return check_pairing(sender_uid, self._account)
|
||
return False
|
||
|
||
def check_danmaku_policy(self, room_id: int) -> bool:
|
||
return room_id in self._account.room_ids
|
||
|
||
def resolve_dm_policy(self) -> str:
|
||
return self._account.dm_policy.value
|
||
|
||
def collect_warnings(self, config: dict, account_id: str | None = None, account: dict | None = None) -> list[str]:
|
||
warnings = []
|
||
acct = account or {}
|
||
if acct.get("dm_enabled") and acct.get("dm_policy") in ("open", "allowlist"):
|
||
warnings.append("私信功能已启用,使用非官方 API,存在账号风险")
|
||
if not acct.get("room_ids"):
|
||
warnings.append("未配置直播间 ID,弹幕功能不会启动")
|
||
return warnings
|