Skip to content

Commit 253dfd8

Browse files
Merge pull request #4 from CMHopeSunshine/plugin-blacklist
2 parents c2b68d4 + 22e3ac5 commit 253dfd8

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ nb plugin install nonebot-plugin-follow-withdraw
6060
| follow_withdraw_interval | 0.5 | 多条消息时的撤回间隔(单位秒),以防止一瞬间撤回过多消息导致风控( |
6161
| follow_withdraw_enable_adapters | ["OneBot V11", "OneBot V12", "QQ Guild", "Discord", "Kaiheila"] | 启用的适配器类型列表,默认为所有已支持的适配器,可选值请看默认值 |
6262
| follow_withdraw_bot_blacklist | [] | 不启用跟随撤回的Bot列表,填写Bot的bot_id |
63+
| follow_withdraw_plugin_blacklist | [] | 不启用跟随撤回的插件列表 |
6364

6465
此外,本插件还提供了一个仅超级用户可使用的命令`清除消息记录`,来清除本插件记录的消息ID数据。

nonebot_plugin_follow_withdraw/__init__.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from nonebot.permission import SUPERUSER
77
from nonebot import on_notice, on_command
88
from nonebot.plugin import PluginMetadata
9-
from nonebot.internal.matcher import current_event
9+
from nonebot.internal.matcher import current_event, current_matcher
1010

1111
from . import adapters as adapters_module
1212
from .config import Config, withdraw_config
@@ -64,14 +64,23 @@ async def handle_save_message(
6464
if exception:
6565
return
6666
if bot.self_id in withdraw_config.follow_withdraw_bot_blacklist:
67-
return False
67+
return
68+
try:
69+
matcher = current_matcher.get()
70+
if matcher.plugin_name in withdraw_config.follow_withdraw_plugin_blacklist:
71+
return
72+
except LookupError:
73+
pass
74+
6875
adapter_name = bot.adapter.get_name()
6976
if adapter_name not in withdraw_config.follow_withdraw_enable_adapters:
7077
return
7178
if not check_allow_api(adapter_name, api):
7279
return
73-
74-
event = current_event.get()
80+
try:
81+
event = current_event.get()
82+
except LookupError:
83+
return
7584
if (message := get_message(result, adapter_name)) and (
7685
origin_message := get_origin_message(event, adapter_name)
7786
):

nonebot_plugin_follow_withdraw/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Config(BaseModel):
1717
"Kaiheila",
1818
]
1919
follow_withdraw_bot_blacklist: List[str] = []
20+
follow_withdraw_plugin_blacklist: List[str] = []
2021

2122

2223
driver = get_driver()

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nonebot-plugin-follow-withdraw"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
description = "A plugin for nonebot2 that follows the user's withdraw of a command."
55
authors = ["CMHopeSunshine <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)