-
Notifications
You must be signed in to change notification settings - Fork 605
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
🎨 notice响应期添加rule #1682
🎨 notice响应期添加rule #1682
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from nonebot.adapters import Bot, Event | ||
from nonebot.internal.rule import Rule | ||
from nonebot.adapters import Bot, Event | ||
from nonebot.permission import SUPERUSER | ||
from nonebot_plugin_session import EventSession, SessionLevel | ||
|
||
|
@@ -24,7 +24,7 @@ async def _rule(bot: Bot, event: Event, session: EventSession) -> bool: | |
return True | ||
if session.id1 and session.id2: | ||
level = a | ||
if type(a) == str and key: | ||
if isinstance(a, str) and key: | ||
level = Config.get_config(a, key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (performance): 考虑优化 在 Original comment in Englishsuggestion (performance): Consider optimizing the In the |
||
if level is not None: | ||
return bool( | ||
|
@@ -59,3 +59,26 @@ def ensure_private(session: EventSession) -> bool: | |
bool: bool | ||
""" | ||
return not session.id3 and not session.id2 | ||
|
||
|
||
def notice_rule(event_type: type | list[type]) -> Rule: | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): 考虑重构 notice_rule 函数以简化其实现并提高效率。
def notice_rule(event_types: type | tuple[type, ...]) -> Rule:
if not isinstance(event_types, tuple):
event_types = (event_types,)
def _rule(event: Event) -> bool:
return isinstance(event, event_types)
return Rule(_rule) 此重构解决了几个问题:
此实现更简单、更高效且更易于理解,同时保持了原有功能。使用带有类型元组的 Original comment in Englishissue (complexity): Consider refactoring the notice_rule function to simplify its implementation and improve efficiency. The def notice_rule(event_types: type | tuple[type, ...]) -> Rule:
if not isinstance(event_types, tuple):
event_types = (event_types,)
def _rule(event: Event) -> bool:
return isinstance(event, event_types)
return Rule(_rule) This refactoring addresses several issues:
This implementation is simpler, more efficient, and easier to understand while maintaining the original functionality. The use of |
||
Notice限制 | ||
|
||
参数: | ||
event_type: Event类型 | ||
|
||
返回: | ||
Rule: Rule | ||
""" | ||
|
||
async def _rule(event: Event) -> bool: | ||
if isinstance(event_type, list): | ||
for et in event_type: | ||
if isinstance(event, et): | ||
return True | ||
else: | ||
return isinstance(event, event_type) | ||
return False | ||
|
||
return Rule(_rule) |
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.
issue (bug_risk): 修正 group_decrease_handle 的事件类型
group_decrease_handle
使用的是GroupMemberIncreaseEvent
而不是GroupDecreaseNoticeEvent
。这似乎是一个复制粘贴错误,可能导致意外行为。请验证并更正事件类型。Original comment in English
issue (bug_risk): Correct event type for group_decrease_handle
The
group_decrease_handle
is usingGroupMemberIncreaseEvent
instead ofGroupDecreaseNoticeEvent
. This appears to be a copy-paste error and could lead to unexpected behavior. Please verify and correct the event types.