Feature: 移除内置响应规则事件类型限制 (#1824)

This commit is contained in:
Ju4tCode
2023-03-19 15:45:32 +08:00
committed by GitHub
parent f65127e655
commit 36e99bc3ea
4 changed files with 26 additions and 19 deletions

View File

@ -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):
"""匹配当前事件属于指定会话