-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add /newchat command and topic precheck for groups #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Forum 群组安全设计 | ||
|
|
||
| ## 背景 | ||
|
|
||
| Bot 设计上依赖 Telegram Forum (Topics) 功能,需要确保: | ||
| 1. Bot 只在满足条件的群组中工作 | ||
| 2. 用户得到清晰的配置指引 | ||
|
|
||
| ## 安全策略 | ||
|
|
||
| ### 1. 用户白名单 (最高优先级) | ||
|
|
||
| 非白名单用户拉 Bot 进群 → 直接退群,不做任何处理。 | ||
|
|
||
| ```python | ||
| if should_leave_group(update, config.user_whitelist): | ||
| bot.leave_chat(chat_id) | ||
| return | ||
| ``` | ||
|
|
||
| ### 2. 入群预检 | ||
|
|
||
| 白名单用户拉 Bot 进群时,检查: | ||
| - `chat.is_forum` - 群组是否开启 Topics | ||
| - `can_manage_topics` - Bot 是否有 Topic 管理权限 | ||
|
|
||
| 预检失败时发送详细配置指引,但不退群(给用户配置时间)。 | ||
|
|
||
| ### 3. 消息过滤 (统一入口) | ||
|
|
||
| 非 Forum 群组的消息在 producer 入口处直接忽略: | ||
|
|
||
| ```python | ||
| # 群组消息:非 Forum 直接忽略 | ||
| if message.chat.type in ('group', 'supergroup') and not message.chat.is_forum: | ||
| return {'statusCode': 200} | ||
| ``` | ||
|
|
||
| **优点**: | ||
| - 一行代码,所有命令无需单独检查 | ||
| - 私聊不受影响 | ||
| - 用户已在入群时收到预检提示 | ||
|
|
||
| ## 处理流程 | ||
|
|
||
| ``` | ||
| Bot 被添加到群组 | ||
| ↓ | ||
| ┌─────────────────────┐ | ||
| │ 白名单检查 │ | ||
| └─────────────────────┘ | ||
| ↓ | ||
| 通过? ──No──→ 退群 | ||
| ↓ Yes | ||
| ┌─────────────────────┐ | ||
| │ Topic 预检 │ | ||
| │ - is_forum? │ | ||
| │ - can_manage_topics?│ | ||
| └─────────────────────┘ | ||
| ↓ | ||
| 通过? ──No──→ 发送配置指引 | ||
| ↓ Yes | ||
| 正常工作 | ||
|
|
||
| --- | ||
|
|
||
| 收到群组消息 | ||
| ↓ | ||
| ┌─────────────────────┐ | ||
| │ is_forum 检查 │ | ||
| └─────────────────────┘ | ||
| ↓ | ||
| 是 Forum? ──No──→ 静默忽略 | ||
| ↓ Yes | ||
| 正常处理命令 | ||
| ``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The config.toml adds
/newchatas a local command with response "创建新对话", but/newchatis not actually a local command - it requires async processing and SQS messaging. This is inconsistent with the implementation in handler.py where/newchatis handled specially before the local command check. The entry in local_commands may cause confusion or incorrect behavior if config.is_local_command() is called for/newchat. Consider removing this entry from local_commands or documenting why it's included.