mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-07 04:26:45 +00:00
✨ Feature: 移除内置响应规则事件类型限制 (#1824)
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from typing_extensions import Self
|
||||
from contextlib import AsyncExitStack
|
||||
from typing import Set, Tuple, Union, NoReturn, Optional
|
||||
|
||||
@ -140,6 +141,22 @@ class User:
|
||||
session in self.users and (self.perm is None or await self.perm(bot, event))
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_event(cls, event: Event, perm: Optional[Permission] = None) -> Self:
|
||||
"""从事件中获取会话 ID
|
||||
|
||||
参数:
|
||||
event: Event 对象
|
||||
perm: 需同时满足的权限
|
||||
"""
|
||||
if (
|
||||
perm
|
||||
and len(perm.checkers) == 1
|
||||
and isinstance(user_perm := tuple(perm.checkers)[0].call, cls)
|
||||
):
|
||||
perm = user_perm.perm
|
||||
return cls((event.get_session_id(),), perm)
|
||||
|
||||
|
||||
def USER(*users: str, perm: Optional[Permission] = None):
|
||||
"""匹配当前事件属于指定会话
|
||||
|
Reference in New Issue
Block a user