Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,33 @@ skip - 跳过说明

## ⚡ 快速开始(Docker)

1) 创建 `docker-compose.yml`

```yaml
services:
rule-bot:
image: aethersailor/rule-bot:latest
container_name: rule-bot
restart: unless-stopped
environment:
- TELEGRAM_BOT_TOKEN=你的机器人 Token
- GITHUB_TOKEN=你的 GitHub Token
- GITHUB_REPO=your_username/your_repository
- DIRECT_RULE_FILE=rule/Custom_Direct.list
1) 创建工作目录并下载配置文件

```bash
mkdir -p /opt/Rule-Bot && cd /opt/Rule-Bot
wget https://raw.githubusercontent.com/Aethersailor/Rule-Bot/main/docker-compose.yml
```

2) 启动
1) 编辑配置文件

```bash
vim docker-compose.yml
```

修改以下必填参数(去掉 `#` 注释,填入你的实际值):

- `TELEGRAM_BOT_TOKEN`
- `GITHUB_TOKEN`
- `GITHUB_REPO`
- `DIRECT_RULE_FILE`

1) 启动容器

```bash
docker compose up -d
```

3) 查看日志
1) 查看日志
Comment on lines +61 to +87
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The numbering in the Quick Start section is incorrect. All steps are numbered as "1)" instead of being sequentially numbered (1, 2, 3, 4). This makes the documentation confusing to follow. The steps should be numbered: 1) 创建工作目录并下载配置文件, 2) 编辑配置文件, 3) 启动容器, 4) 查看日志

Copilot uses AI. Check for mistakes.

```bash
docker compose logs -f rule-bot
Expand Down Expand Up @@ -113,6 +118,7 @@ docker compose logs -f rule-bot
| `REQUIRED_GROUP_NAME` | 群组验证名称 | 空 |
| `REQUIRED_GROUP_LINK` | 群组验证链接 | 空 |
| `ALLOWED_GROUP_IDS` | 群组模式允许的群组 ID,逗号分隔 | 空 |
| `ADMIN_USER_IDS` | 管理员 Telegram 用户 ID,逗号分隔 | 空 |
| `TZ` | 时区 | `Asia/Shanghai` |

</details>
Expand Down Expand Up @@ -142,6 +148,15 @@ docker compose logs -f rule-bot

同时配置 `REQUIRED_GROUP_ID/NAME/LINK` 后生效,未通过或校验失败会拒绝访问(失败即拒绝)。

### 管理员模式(ADMIN_USER_IDS)

配置 `ADMIN_USER_IDS` 后,指定的管理员用户可以:

- 强制添加被系统检测拒绝的域名
- 获取调试辅助信息
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The README documentation mentions that admins can "获取调试辅助信息" (get debugging assistance information) at line 156, but this feature does not appear to be implemented in the codebase. Only the force-add functionality is implemented for admins. Either implement the debugging feature or remove this claim from the documentation to avoid confusion.

Copilot uses AI. Check for mistakes.

> 通过 @userinfobot 获取你的 Telegram 用户 ID。

## 📌 规则逻辑(简版)

1) 解析域名并提取二级域名
Expand All @@ -160,6 +175,7 @@ docker compose logs -f rule-bot
## 🧩 常见问题

**群组不响应消息**

1. 关闭 Privacy Mode
2. 重新添加机器人到群组
3. 仅在消息中 @ 机器人
Expand Down
8 changes: 7 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
rule-bot:
build: .
image: aethersailor/rule-bot:latest
container_name: rule-bot
restart: unless-stopped
environment:
Expand Down Expand Up @@ -52,6 +52,12 @@ services:
# 支持逗号分隔多个群组 ID,例如:-1001234567890,-1009876543210
# 留空则关闭此功能(仅支持私聊模式)
# - ALLOWED_GROUP_IDS=-1001234567890,-1009876543210

# 管理员配置 (可选: 指定管理员用户 ID,拥有强制添加域名的权限)
# 支持逗号分隔多个 Telegram 用户 ID,例如:123456789,987654321
# 管理员可以强制添加被系统检测拒绝的域名
# 留空则关闭此功能
# - ADMIN_USER_IDS=123456789,987654321
# ========================================

# ========== 系统配置 ==========
Expand Down
1 change: 1 addition & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def _register_handlers(self):
# 命令处理器
self.app.add_handler(CommandHandler("start", self.handler_manager.start_command))
self.app.add_handler(CommandHandler("help", self.handler_manager.help_command))
self.app.add_handler(CommandHandler("id", self.handler_manager.id_command))
self.app.add_handler(CommandHandler("query", self.handler_manager.query_command))
self.app.add_handler(CommandHandler("add", self.handler_manager.add_command))
self.app.add_handler(CommandHandler("delete", self.handler_manager.delete_command))
Expand Down
32 changes: 32 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import re
from typing import Optional, Dict
from loguru import logger

Expand Down Expand Up @@ -47,6 +48,14 @@ def __init__(self):
# 群组工作模式配置(允许机器人在这些群组中直接响应 @提及)
# 支持逗号分隔的多个群组 ID,例如:-1001234567890,-1009876543210
self.ALLOWED_GROUP_IDS = self._parse_group_ids(os.getenv("ALLOWED_GROUP_IDS", ""))

# 管理员配置(Telegram 用户 ID 列表)
# 支持逗号分隔的多个用户 ID,例如:123456789,987654321
self.ADMIN_USER_IDS = self._parse_user_ids(os.getenv("ADMIN_USER_IDS", ""))
if self.ADMIN_USER_IDS:
logger.info(f"已加载管理员 IDs: {self.ADMIN_USER_IDS}")
else:
logger.info("未配置管理员 IDs(ADMIN_USER_IDS)")

# 数据源URL
# 使用 Aethersailor GeoIP 数据库
Expand Down Expand Up @@ -120,6 +129,29 @@ def _parse_group_ids(self, ids_str: str) -> list:
logger.warning(f"无效的 ALLOWED_GROUP_IDS: {raw_id}")
return group_ids

def _parse_user_ids(self, ids_str: str) -> list:
"""解析用户 ID 列表

Args:
ids_str: 逗号分隔的用户 ID 字符串

Returns:
用户 ID 整数列表
"""
if not ids_str.strip():
return []

user_ids = []
parts = [part for part in re.split(r"[,\s;]+", ids_str.strip()) if part]
for raw_id in parts:
if not raw_id:
continue
try:
user_ids.append(int(raw_id))
except ValueError:
logger.warning(f"无效的 ADMIN_USER_IDS: {raw_id}")
return user_ids
Comment on lines +132 to +153
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The _parse_user_ids method uses a more sophisticated regex-based split pattern (re.split with multiple separators including commas, whitespace, and semicolons) compared to _parse_group_ids which only splits on commas. This creates an inconsistency in how the two similar configuration options are parsed. While the extra flexibility for user IDs might be intentional, it would be better to either: (1) make both methods use the same parsing logic for consistency, or (2) document why user IDs support more separator types than group IDs.

Copilot uses AI. Check for mistakes.

def _parse_required_group_id(self, group_id_raw: str) -> Optional[int]:
"""解析必需群组 ID"""
if not group_id_raw:
Expand Down
16 changes: 13 additions & 3 deletions src/handlers/group_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional
from loguru import logger

from telegram import Update, Message
from telegram import Update, Message, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import ContextTypes

from ..config import Config
Expand Down Expand Up @@ -220,6 +220,7 @@ async def _process_domain_request(
result = await self.handler_manager.check_and_add_domain_auto(domain, username)

# 根据结果回复
reply_markup = None
if result["action"] == "added":
# 记录用户添加历史
self.handler_manager.record_user_add(user_id)
Expand All @@ -241,13 +242,22 @@ async def _process_domain_request(
result_text = f"❌ **无法添加域名**\n\n"
result_text += f"📍 **域名:** `{domain}`\n"
result_text += f"📋 {result['message']}"
if self.handler_manager.is_admin(user_id):
result_text += "\n\n🛡️ **管理员可使用权限按钮强制添加。**"
keyboard = [
[InlineKeyboardButton(
"🛡️ 管理员权限添加",
callback_data=self.handler_manager.get_admin_force_add_callback(domain)
)]
]
reply_markup = InlineKeyboardMarkup(keyboard)

else: # error
result_text = f"❌ **处理失败**\n\n"
result_text += f"📍 **域名:** `{domain}`\n"
result_text += f"❌ {result['message']}"
await processing_msg.edit_text(result_text, parse_mode='Markdown')

await processing_msg.edit_text(result_text, reply_markup=reply_markup, parse_mode='Markdown')

except Exception as e:
logger.error(f"处理域名请求失败: {e}")
Expand Down
Loading
Loading