Skip to content

Commit 798946f

Browse files
committed
增加转发模式黑白名单
1 parent 178381c commit 798946f

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
- [x] **互通模式**:指定一个 QQ 群与一个 Telegram 群/频道双向互通,消息实时同步
2121
- [x] **转发模式**:将 QQ 所有接收到的消息单向转发到 Telegram 私聊/频道/群聊
22+
- [x] 转发模式黑白名单,仅允许/除了名单内的群/qq号转发
2223
- [x] 使用指令临时关闭单向互通
2324
- [x] 互通模式和转发模式可同时开启不会重复发送消息
2425
- [x] Telegram 图片/贴纸下载会自动走适配器配置的代理
@@ -133,6 +134,8 @@
133134
| 配置项 | 类型 | 默认值 | 说明 |
134135
|--------|------|--------|------|
135136
| `ONEBOT2TG_FORWARD_TARGET_CHAT_ID` | `str \| int` | `""` | 转发模式下,QQ 消息转发到 TG 的目标 chat_id 或 用户ID |
137+
| `onebot2tg_forward_filter_mode` | `str` | `"none"` | 可选"none","blacklist","whitelist" |
138+
| `onebot2tg_forward_filter_list` | `list` | `["12345678","123"]`| 按照filter_mode的参数配置白名单或黑名单 |
136139

137140
## 🎉 使用示例
138141

src/nonebot_plugin_onebot2tg/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ class Config(BaseModel):
2121
# 转发模式配置
2222
onebot2tg_forward_target_chat_id: str | int = ""
2323
"""转发模式下,QQ消息转发到TG的目标chat_id(私聊或群)"""
24+
25+
# 转发模式黑白名单
26+
onebot2tg_forward_filter_mode: str = "none"
27+
"""转发模式过滤方式:none(不过滤,默认)、blacklist(黑名单)、whitelist(白名单)"""
28+
29+
onebot2tg_forward_filter_list: list[str | int] = []
30+
"""转发模式过滤列表:QQ号或群号列表。黑名单模式下不转发这些来源的消息;白名单模式下只转发这些来源的消息"""

src/nonebot_plugin_onebot2tg/forwarder.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,18 @@ async def handle_ob11_message(event: OB11MessageEvent):
360360

361361
# ---------- 转发模式(QQ → TG 单向) ----------
362362
if config.onebot2tg_enable_forward and config.onebot2tg_forward_target_chat_id:
363+
user_id = str(event.user_id)
364+
365+
# 黑白名单过滤
366+
filter_mode = str(config.onebot2tg_forward_filter_mode).lower()
367+
filter_set = {str(x) for x in config.onebot2tg_forward_filter_list}
368+
if filter_mode == "blacklist":
369+
if user_id in filter_set or (is_group and group_id in filter_set):
370+
return
371+
elif filter_mode == "whitelist":
372+
if user_id not in filter_set and not (is_group and group_id in filter_set):
373+
return
374+
363375
if is_group:
364376
group_name = ""
365377
try:

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)