Skip to content
Closed
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
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 工作流程优化 |
---
感谢您的贡献!
123 changes: 123 additions & 0 deletions README.md
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" />
Copy link

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" 之间添加一个空格。

Suggested change
<img src="https://results.pre-commit.ci/badge/github/nonebot/nonebot2/master.svg" alt="pre-commit" />
<img src="https://results.pre-commit.ci/badge/github/nonebot/nonebot2/master.svg" alt="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.

Suggested change
<img src="https://results.pre-commit.ci/badge/github/nonebot/nonebot2/master.svg" alt="pre-commit" />
<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
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): 占位符内容:单元测试

“单元测试”部分似乎不完整。要么用实际内容充实它,要么暂时删除它。

建议的实现方式:

<!-- 删除不完整的单元测试部分 -->

如果您稍后决定向“单元测试”添加内容,只需插入一个包含适当信息或测试的新部分即可。

Original comment in English

suggestion (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:

<!-- Removed incomplete Unit Tests section -->

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): 链接损坏且内容不完整:集成测试

指向 Sourcery-ai 的链接已损坏(缺少斜杠)。此外,请考虑添加有关集成测试的更多详细信息。

Original comment in English

issue (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

![Alt](https://repobeats.axiom.co/api/embed/079b23892e48f7b9e6be2f0cb2c66b2833eeffda.svg "Repobeats analytics image")
17 changes: 14 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): 多个日志处理程序可能会导致重复的日志消息。

app.py 中的日志配置现在同时添加了控制台处理程序和文件处理程序,并且 _init_logger() 添加了额外的处理程序。请确保重复初始化不会无意中注册重复的处理程序,这将导致重复的日志输出。

Suggested change
# Initialize logger
logger = logging.getLogger(__name__)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
logger.addHandler(console_handler)
# 初始化日志记录器
logger = logging.getLogger(__name__)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
if not any(isinstance(handler, logging.StreamHandler) for handler in logger.handlers):
logger.addHandler(console_handler)
Original comment in English

suggestion (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
# Initialize logger
logger = logging.getLogger(__name__)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
logger.addHandler(console_handler)
# Initialize logger
logger = logging.getLogger(__name__)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
if not any(isinstance(handler, logging.StreamHandler) for handler in logger.handlers):
logger.addHandler(console_handler)



async def create_database_if_not_exists() -> None:
Expand Down Expand Up @@ -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]
Expand All @@ -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 和命令处理器初始化完成。")

Expand Down
6 changes: 5 additions & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from .bot_client import BotClient
from .commands import CommandHandler
from .filters import user_in_group_on_filter, admin_user_on_filter, emby_user_on_filter
from .filters import (
user_in_group_on_filter,
admin_user_on_filter,
emby_user_on_filter,
)
from .message_helper import get_user_telegram_id
from .utils import parse_iso8601_to_normal_date, parse_timestamp_to_normal_date

Expand Down
Loading
Loading