-
Notifications
You must be signed in to change notification settings - Fork 11
style: enforce PEP8 compliance and update documentation structure #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
00ce1b9
9fb62fe
d98a733
e3817f9
11595bb
d35d81b
806dc9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ## 贡献指南 | ||
| 欢迎贡献代码!为了确保项目的高质量和一致性,请遵循以下贡献规程: | ||
| ### 提交规范 | ||
| - 提交信息必须符合 Angular 提交信息规范,格式如下: | ||
| - `type(scope): description` | ||
| - 例如:`feat(user): 添加用户注册功能` | ||
| ### 与数据库、API 代码相关的更改 | ||
| - 请确保所有更改都经过严格的测试,并且不会引入新的错误。 | ||
| ### 创建 Pull Request | ||
| - 请确保创建 Pull Request 前进行本地测试,确保通过所有 CI/CD 测试。 | ||
| ### 支持的 Type 列表 | ||
|
|
||
| | Type | 描述 | | ||
| |----------|-------------------------------------------------------------| | ||
| | feat | 添加新功能,比如新增用户注册、功能扩展等 | | ||
| | fix | 修复 bug 或错误,解决问题的修改 | | ||
| | docs | 文档相关修改,如更新说明文档、README、注释等 | | ||
| | style | 代码格式、标点、空格等修改,不影响代码逻辑运行 | | ||
| | refactor | 代码重构,调整代码结构而不改变功能 | | ||
| | perf | 性能优化修改,提升效率或降低资源消耗 | | ||
| | test | 添加或更新测试代码,保证项目稳定性 | | ||
| | chore | 杂项维护,如依赖更新、构建脚本修改,不涉及代码逻辑 | | ||
| | ci | 持续集成相关修改,如 GitHub Actions 工作流程优化 | | ||
| --- | ||
| 感谢您的贡献! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| <p align="center"> | ||
| <img src="https://github.com/user-attachments/assets/7fcbb16b-577d-4de2-b1b0-23ec9b839f17" alt="embyBot logo" width=200 height=200 /> | ||
| </p> | ||
| <h1 align="center">embyBot</h1> | ||
| <p align="center"> | ||
| <em>⚡ The next-generation emby management bot</em> | ||
| </p> | ||
|
|
||
| <p align="center"> | ||
| <a href="https://opensource.org/licenses/Apache-2.0"> | ||
| <img src="https://img.shields.io/github/license/embyplus/embyBot" alt="license"> | ||
| </a> | ||
| <img src="https://img.shields.io/badge/python-3.10+-blue?logo=python&logoColor=edb641" alt="python"> | ||
| <a href="https://www.python.org/dev/peps/pep-0008/"> | ||
| <img src="https://img.shields.io/badge/code%20style-PEP%208-000000.svg?logo=python&logoColor=blue" alt="PEP 8"> | ||
| </a> | ||
| <a href="https://codecov.io/gh/embyplus/embyBot"> | ||
| <img src="https://codecov.io/gh/embyplus/embyBot/branch/master/graph/badge.svg" alt="codecov"/> | ||
| </a> | ||
| <br /> | ||
| <a bref="https://github.com/astral-sh/ruff"> | ||
| <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json" alt="ruff"> | ||
| </a> | ||
| <a href="https://github.com/astral-sh/uv"> | ||
| <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv"> | ||
| </a> | ||
| <a href="https://results.pre-commit.ci/latest/github/nonebot/nonebot2/master"> | ||
| <img src="https://results.pre-commit.ci/badge/github/nonebot/nonebot2/master.svg" alt="pre-commit" /> | ||
| </a> | ||
| <a href="https://github.com/nonebot/nonebot2/actions/workflows/pyright.yml"> | ||
| <img src="https://github.com/nonebot/nonebot2/actions/workflows/pyright.yml/badge.svg?branch=master&event=push" alt="pyright"> | ||
| </a> | ||
| <a href="https://github.com/nonebot/nonebot2/actions/workflows/ruff.yml"> | ||
| <img src="https://github.com/nonebot/nonebot2/actions/workflows/ruff.yml/badge.svg?branch=master&event=push" alt="ruff"> | ||
| </a> | ||
| </p> | ||
|
|
||
| > [!IMPORTANT] | ||
| > ⭐️ Thanks **everyone** who has contributed to the project, it means a lot! | ||
|
|
||
| ## 📣 Introduction | ||
|
|
||
| A Telegram bot for managing **Emby**, developed with **Pyrogram** and using **MySQL** as the database. | ||
|
|
||
| ## ✨ Features | ||
|
|
||
|
|
||
| #### User Management: | ||
|
|
||
| - Create Emby users with invitation codes and assign default passwords and policies. | ||
| - Provide admin commands to disable/enable Emby accounts. | ||
| - View current user information (whitelist status, admin privileges, ban status, etc.). | ||
|
|
||
| #### Invitation Code Management: | ||
|
|
||
| - Generate standard and whitelist invitation codes. | ||
| - Automatically update the database and relevant status after using an invitation code. | ||
|
|
||
| #### Route Management: | ||
|
|
||
| - Integrate the routing service API to allow users to quickly switch playback routes through the bot. | ||
|
|
||
| #### Other Features: | ||
|
|
||
| - View the current number of Emby media items. | ||
| - Support limited-time or limited-quantity registration. | ||
|
|
||
| ## 🔰 Installation | ||
|
|
||
| 1. Clone the repository: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/embyplus/embyBot | ||
| ``` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): 占位符内容:单元测试 “单元测试”部分似乎不完整。要么用实际内容充实它,要么暂时删除它。 建议的实现方式: 如果您稍后决定向“单元测试”添加内容,只需插入一个包含适当信息或测试的新部分即可。 Original comment in Englishsuggestion (testing): Placeholder content: Unit Tests The "Unit Tests" section seems incomplete. Either flesh it out with actual content or remove it for now. Suggested implementation: If you later decide to add content to "Unit Tests", simply insert a new section with the appropriate information or tests. |
||
|
|
||
| 2. Copy and edit the environment variables file: | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| vim .env | ||
| ``` | ||
|
|
||
| 3. Sync dependency environment | ||
|
|
||
| ```bash | ||
| uv sync | ||
| ``` | ||
|
|
||
| 4. Run the bot: | ||
|
|
||
| ```bash | ||
| uv run app.py | ||
| ``` | ||
|
|
||
|
|
||
| ### ⛏ Code Quality | ||
|
|
||
| ### Unit Tests | ||
|
|
||
| ```shell | ||
| $ Writing... | ||
| ``` | ||
|
|
||
| ### Integration Tests | ||
|
|
||
| Continuous integration with [Sourcery-ai](https://sourcery.ai//). | ||
|
Comment on lines
+104
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (testing): 链接损坏且内容不完整:集成测试 指向 Sourcery-ai 的链接已损坏(缺少斜杠)。此外,请考虑添加有关集成测试的更多详细信息。 Original comment in Englishissue (testing): Broken link and incomplete content: Integration Tests The link to Sourcery-ai is broken (missing a slash). Also, consider adding more details about the integration tests. |
||
|
|
||
| ### Code Standards | ||
|
|
||
| Use [Ruff](https://docs.astral.sh/ruff/) and [Codecov](https://codecov.io/) to maintain code quality. | ||
|
|
||
| ## Contribution Guide | ||
|
|
||
| Please refer to the [Contribution Guide](./CONTRIBUTING.md). | ||
|
|
||
| ## Acknowledgments | ||
| - [Pyrogram](https://docs.pyrogram.org/) - Telegram API for Python | ||
| - [SQLAlchemy](https://www.sqlalchemy.org/) - Python SQL Toolkit and Object-Relational Mapping | ||
| - [Emby Management Bot by 小草](https://github.com/xiaocao666tzh/EmbyBot) | ||
|
|
||
| ## 🎡 Activities | ||
|
|
||
|  | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| from datetime import datetime | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import pytz | ||||||||||||||||||||||||||||||||||||||||||||||
| from py_tools.connections.db.mysql import DBManager, BaseOrmTable, SQLAlchemyManager | ||||||||||||||||||||||||||||||||||||||||||||||
| from py_tools.connections.db.mysql import ( | ||||||||||||||||||||||||||||||||||||||||||||||
| DBManager, | ||||||||||||||||||||||||||||||||||||||||||||||
| BaseOrmTable, | ||||||||||||||||||||||||||||||||||||||||||||||
| SQLAlchemyManager, | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| from sqlalchemy import text | ||||||||||||||||||||||||||||||||||||||||||||||
| from sqlalchemy.ext.asyncio import create_async_engine | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -15,6 +19,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Initialize logger | ||||||||||||||||||||||||||||||||||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||||||||||||||||||||||||||||||||||
| console_handler = logging.StreamHandler() | ||||||||||||||||||||||||||||||||||||||||||||||
| console_handler.setLevel(logging.INFO) | ||||||||||||||||||||||||||||||||||||||||||||||
| logger.addHandler(console_handler) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
20
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): 多个日志处理程序可能会导致重复的日志消息。 app.py 中的日志配置现在同时添加了控制台处理程序和文件处理程序,并且 _init_logger() 添加了额外的处理程序。请确保重复初始化不会无意中注册重复的处理程序,这将导致重复的日志输出。
Suggested change
Original comment in Englishsuggestion (bug_risk): Multiple logger handlers may lead to duplicate log messages. The logger configuration in app.py now adds both a console handler and a file handler, and _init_logger() adds additional handlers. Make sure that repeated initialization does not inadvertently register duplicate handlers, which would result in repeated logging outputs.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| async def create_database_if_not_exists() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -97,7 +104,9 @@ async def setup_bot() -> BotClient: | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| async def fetch_group_members(bot_client: BotClient) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||
| """获取群组成员并更新配置。""" | ||||||||||||||||||||||||||||||||||||||||||||||
| members_in_group = await bot_client.get_group_members(config.telegram_group_ids) | ||||||||||||||||||||||||||||||||||||||||||||||
| members_in_group = await bot_client.get_group_members( | ||||||||||||||||||||||||||||||||||||||||||||||
| config.telegram_group_ids | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| for group_members in members_in_group.values(): | ||||||||||||||||||||||||||||||||||||||||||||||
| for telegram_id in group_members: | ||||||||||||||||||||||||||||||||||||||||||||||
| config.group_members[telegram_id] = group_members[telegram_id] | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -123,7 +132,9 @@ async def main() -> None: | |||||||||||||||||||||||||||||||||||||||||||||
| emby_router_api = EmbyRouterAPI(config.api_url, config.api_key) | ||||||||||||||||||||||||||||||||||||||||||||||
| command_handler = CommandHandler( | ||||||||||||||||||||||||||||||||||||||||||||||
| bot_client=bot_client, | ||||||||||||||||||||||||||||||||||||||||||||||
| user_service=UserService(emby_api=emby_api, emby_router_api=emby_router_api), | ||||||||||||||||||||||||||||||||||||||||||||||
| user_service=UserService( | ||||||||||||||||||||||||||||||||||||||||||||||
| emby_api=emby_api, emby_router_api=emby_router_api | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Emby API 和命令处理器初始化完成。") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (typo): 错别字:"pre-commit" 中缺少空格
在徽章链接中的 "pre" 和 "commit" 之间添加一个空格。
Original comment in English
issue (typo): Typo: Missing space in "pre-commit"
Add a space between "pre" and "commit" in the badge link.