🐛 fix missing cache in session updater (#1807)

This commit is contained in:
Ju4tCode 2023-03-16 15:51:48 +08:00 committed by GitHub
parent fee16082e0
commit 3462295562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ from typing import (
Union, Union,
TypeVar, TypeVar,
Callable, Callable,
ClassVar,
Iterable, Iterable,
NoReturn, NoReturn,
Optional, Optional,
@ -89,38 +90,38 @@ class MatcherMeta(type):
class Matcher(metaclass=MatcherMeta): class Matcher(metaclass=MatcherMeta):
"""事件响应器类""" """事件响应器类"""
plugin: Optional["Plugin"] = None plugin: ClassVar[Optional["Plugin"]] = None
"""事件响应器所在插件""" """事件响应器所在插件"""
module: Optional[ModuleType] = None module: ClassVar[Optional[ModuleType]] = None
"""事件响应器所在插件模块""" """事件响应器所在插件模块"""
plugin_name: Optional[str] = None plugin_name: ClassVar[Optional[str]] = None
"""事件响应器所在插件名""" """事件响应器所在插件名"""
module_name: Optional[str] = None module_name: ClassVar[Optional[str]] = None
"""事件响应器所在点分割插件模块路径""" """事件响应器所在点分割插件模块路径"""
type: str = "" type: ClassVar[str] = ""
"""事件响应器类型""" """事件响应器类型"""
rule: Rule = Rule() rule: ClassVar[Rule] = Rule()
"""事件响应器匹配规则""" """事件响应器匹配规则"""
permission: Permission = Permission() permission: ClassVar[Permission] = Permission()
"""事件响应器触发权限""" """事件响应器触发权限"""
handlers: List[Dependent[Any]] = [] handlers: List[Dependent[Any]] = []
"""事件响应器拥有的事件处理函数列表""" """事件响应器拥有的事件处理函数列表"""
priority: int = 1 priority: ClassVar[int] = 1
"""事件响应器优先级""" """事件响应器优先级"""
block: bool = False block: bool = False
"""事件响应器是否阻止事件传播""" """事件响应器是否阻止事件传播"""
temp: bool = False temp: ClassVar[bool] = False
"""事件响应器是否为临时""" """事件响应器是否为临时"""
expire_time: Optional[datetime] = None expire_time: ClassVar[Optional[datetime]] = None
"""事件响应器过期时间点""" """事件响应器过期时间点"""
_default_state: T_State = {} _default_state: ClassVar[T_State] = {}
"""事件响应器默认状态""" """事件响应器默认状态"""
_default_type_updater: Optional[Dependent[str]] = None _default_type_updater: ClassVar[Optional[Dependent[str]]] = None
"""事件响应器类型更新函数""" """事件响应器类型更新函数"""
_default_permission_updater: Optional[Dependent[Permission]] = None _default_permission_updater: ClassVar[Optional[Dependent[Permission]]] = None
"""事件响应器权限更新函数""" """事件响应器权限更新函数"""
HANDLER_PARAM_TYPES = ( HANDLER_PARAM_TYPES = (
@ -643,17 +644,43 @@ class Matcher(metaclass=MatcherMeta):
"""阻止事件传播""" """阻止事件传播"""
self.block = True self.block = True
async def update_type(self, bot: Bot, event: Event) -> str: async def update_type(
self,
bot: Bot,
event: Event,
stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None,
) -> str:
updater = self.__class__._default_type_updater updater = self.__class__._default_type_updater
return ( return (
await updater(bot=bot, event=event, state=self.state, matcher=self) await updater(
bot=bot,
event=event,
state=self.state,
matcher=self,
stack=stack,
dependency_cache=dependency_cache,
)
if updater if updater
else "message" else "message"
) )
async def update_permission(self, bot: Bot, event: Event) -> Permission: async def update_permission(
self,
bot: Bot,
event: Event,
stack: Optional[AsyncExitStack] = None,
dependency_cache: Optional[T_DependencyCache] = None,
) -> Permission:
if updater := self.__class__._default_permission_updater: if updater := self.__class__._default_permission_updater:
return await updater(bot=bot, event=event, state=self.state, matcher=self) return await updater(
bot=bot,
event=event,
state=self.state,
matcher=self,
stack=stack,
dependency_cache=dependency_cache,
)
permission = self.permission permission = self.permission
if len(permission.checkers) == 1 and isinstance( if len(permission.checkers) == 1 and isinstance(
user_perm := tuple(permission.checkers)[0].call, User user_perm := tuple(permission.checkers)[0].call, User
@ -731,8 +758,10 @@ class Matcher(metaclass=MatcherMeta):
except RejectedException: except RejectedException:
await self.resolve_reject() await self.resolve_reject()
type_ = await self.update_type(bot, event) type_ = await self.update_type(bot, event, stack, dependency_cache)
permission = await self.update_permission(bot, event) permission = await self.update_permission(
bot, event, stack, dependency_cache
)
Matcher.new( Matcher.new(
type_, type_,
@ -750,8 +779,10 @@ class Matcher(metaclass=MatcherMeta):
default_permission_updater=self.__class__._default_permission_updater, default_permission_updater=self.__class__._default_permission_updater,
) )
except PausedException: except PausedException:
type_ = await self.update_type(bot, event) type_ = await self.update_type(bot, event, stack, dependency_cache)
permission = await self.update_permission(bot, event) permission = await self.update_permission(
bot, event, stack, dependency_cache
)
Matcher.new( Matcher.new(
type_, type_,