arielBot
基于 NoneBot2 + Clean Architecture 的 B站 动态/直播 推送 QQ 机器人。
学习 Python? 这个项目是很好的学习材料。阅读 项目学习笔记 了解 Clean Architecture、异步编程、设计模式等核心概念。
功能
- 订阅 B站 UP 主的动态和直播
- 自动推送新动态(Skia 渲染卡片)和开播通知到 QQ 群
- 扫码登录 B站,自动刷新 Cookie
- 每 8 秒检查新动态,每 10 秒检查直播状态
- 按群开关推送、按订阅开关动态/直播推送
- 按动态 ID 查询动态卡片或提取原始图片
- 动态自动归档(7 天后从 Dynamic 表迁移至 DynamicArchive,查询兼容两表)
架构
arielbot/
├── __init__.py # CLI 入口 (click)
├── bot.py # NoneBot 初始化
├── domain/ # 领域层
│ ├── entities.py # SubTarget, SubChannel, BotStatus
│ ├── events.py # DynamicDetected, LiveStatusChanged, ...
│ └── interfaces/ # ABC 抽象接口
│ ├── api.py # BiliAuthAPI, BiliContentAPI
│ ├── bot_client.py # BotClient
│ ├── event_bus.py # EventBus
│ ├── renderer.py # DynRenderer, SubListRenderer, HelpRenderer
│ └── repository.py # 5 个 Repository 接口
├── application/ # 应用层 (业务逻辑)
│ ├── auth_service.py # 扫码登录 + Cookie 管理
│ ├── bot_status_service.py # Bot 状态管理
│ ├── query_service.py # 查询服务 (动态/图片/列表)
│ ├── subscription_service.py # 订阅管理
│ └── push/
│ ├── check_jobs.py # DynCheckJob (8s), LiveCheckJob (10s)
│ └── handlers.py # DynPushHandler, LivePushHandler, ...
├── infrastructure/ # 基础设施层
│ ├── container.py # DI 容器 (所有依赖注入)
│ ├── database.py # SQLite + WAL 模式 + 索引 + 迁移
│ ├── event_bus.py # asyncio.Queue 事件总线
│ ├── repositories/ # 仓储实现
│ │ ├── bot_repository.py
│ │ ├── cookie_repository.py
│ │ ├── dyn_repository.py # 含 DynamicArchive 归档逻辑
│ │ ├── sub_repository.py # SqlSubChannelRepository
│ │ └── target_repository.py # SqlSubTargetRepository
│ └── adapters/ # 外部适配器
│ ├── bili_api.py # B站 API (WBI 签名)
│ ├── bili_auth.py # 登录 + CookieManager
│ ├── bili_cookie_utils.py # Cookie 序列化/解析
│ ├── bot_client.py # NoneBot 消息发送
│ └── renderer.py # Skia 渲染 (线程池) + SkiaHelpRenderer
├── presentation/ # 表现层
│ ├── message_utils.py # MessageSegment 封装
│ ├── commands/ # 命令注册 + 处理器工厂
│ │ ├── registry.py # 12 个命令注册器
│ │ ├── auth_commands.py
│ │ ├── sub_commands.py
│ │ └── query_commands.py
│ ├── scheduler/__init__.py # APScheduler 定时任务 (含动态归档)
│ └── middleware/__init__.py # 权限规则 + 生命周期钩子
└── plugins/Core/__init__.py # 组合根 (插件入口)
设计原则
| 原则 | 实现方式 |
|---|---|
| SRP 单一职责 | 每层独立,每个 Service/Repository 单一职责 |
| OCP 开闭原则 | 新增推送类型只需添加 CheckJob + Handler,无需改现有代码 |
| LSP 里氏替换 | 全 ABC 接口定义契约,实现可任意替换 |
| ISP 接口隔离 | 5 个 Repository 接口,各自只暴露相关方法 |
| DIP 依赖反转 | 服务依赖接口,Container 注入具体实现 |
| LoD 迪米特法则 | Service 只调用 Repository/API 接口 |
数据流
定时任务 → CheckJob.run()
→ API 获取数据 → 缓存去重 → 查推送目标 → 渲染
→ event_bus.publish(事件)
↓
Handler.handle(事件) → bot_client.send_group_msg()
事件驱动架构
┌────────────────────────────────────────────────────┐
│ EventBus (asyncio.Queue) │
│ │
│ DynCheckJob ──→ DynamicDetected ──→ DynPush │
│ LiveCheckJob ─→ LiveStatusChanged ──→ LivePush │
│ driver.on_connect ─→ BotConnected ──→ Lifecycle │
│ driver.on_disconnect → BotDisconnected │
│ driver.on_shutdown → BotShutdown │
└────────────────────────────────────────────────────┘
安装
git clone https://github.com/Polyisoprene/ariel.git
cd ariel
poetry install
运行
poetry run ariel run
首次运行会自动在项目根目录创建 .env.prod 配置文件和 plugins/ 目录。
命令列表
| 命令 | 别名 | 权限 | 说明 |
|---|---|---|---|
/login |
登录 | SUPERUSER | 扫码登录 B站 |
/sub <uid> |
订阅 | 管理员 | 订阅 UP 主 |
/unsub <uid> |
删除 | 管理员 | 取消订阅 |
/live_on <uid> |
— | 管理员 | 开启直播推送 |
/live_off <uid> |
— | 管理员 | 关闭直播推送 |
/dyn_on <uid> |
— | 管理员 | 开启动态推送 |
/dyn_off <uid> |
— | 管理员 | 关闭动态推送 |
/bot_on |
— | 管理员 | 开启群内推送 |
/bot_off |
— | 管理员 | 关闭群内推送 |
/list |
列表 | — | 查看订阅列表 |
/help |
— | — | 帮助信息 |
/sd <dyn_id> |
— | — | 查看动态渲染卡片 |
/img <dyn_id> |
— | — | 提取动态原始图片 |
测试
poetry run pytest tests/ -v
87 个测试覆盖 domain / application / infrastructure / presentation 四层。
tests/
├── test_domain/ # 7 tests
├── test_application/ # 42 tests
├── test_infrastructure/ # 25 tests
└── test_presentation/ # 2 tests
代码质量
| 维度 | 评分 |
|---|---|
| 架构 | 29/30 |
| 健壮性 | 26/30 |
| 可扩展性 | 12/15 |
| 设计原则 | 17/18 |
| 性能 | 8/7 |
| 总计 | 92/100 |
技术栈
| 组件 | 技术 |
|---|---|
| 框架 | NoneBot2 + OneBot V11 |
| 驱动 | FastAPI |
| 数据库 | SQLite (aiosqlite + WAL) |
| 渲染 | Skia-python (dynrender-skia) |
| 调度 | APScheduler |
| HTTP | httpx.AsyncClient |
| 加密 | pycryptodome (RSA-OAEP) |
| QR | qrcode + PyPNG |
| 包管理 | Poetry |
| 测试 | pytest + pytest-asyncio |
License
MIT
Metadata
Release files for arielBot 0.7.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| arielbot-0.7.6.tar.gz | 23.1 kB | Without provenance | Details for arielbot-0.7.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| arielbot-0.7.6-py3-none-any.whl | Python 3 | none | any | Details for arielbot-0.7.6-py3-none-any.whl |
Total release size: 61.1 kB
Release files / arielbot-0.7.6.tar.gz
| Download URL | arielbot-0.7.6.tar.gz |
|---|---|
| Size | 23.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9dd58455ce203b19444b320a1614745c8b8b33608f685f7b5b74cf6b881921d1
|
|
BLAKE2b-256 checksum How to use checksums |
7a46da1e6d8c535492215ba33bd32e3ca9edbfcd43c2ff6dd5910360c528e58a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.12.8 Windows/10
|
Release files / arielbot-0.7.6-py3-none-any.whl
| Download URL | arielbot-0.7.6-py3-none-any.whl |
|---|---|
| Size | 38.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e795423b1df93aa18cea62d0e322b9efa96b46f48a63a5902552c068aae3389d
|
|
BLAKE2b-256 checksum How to use checksums |
9b61fc1a11859847528efc41a69e89842585649ae0706f93dcb74118a77faed5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.12.8 Windows/10
|
Security for arielBot 0.7.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.