From b2f5f936036afe9356891ae0a82a0aca0205a3aa Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 31 May 2021 21:54:17 +0800 Subject: [PATCH] :bug: fix error inherit state in session when using state_factory --- nonebot/matcher.py | 14 +++++++------- pages/changelog.md | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nonebot/matcher.py b/nonebot/matcher.py index e3f894c4..3202c3ee 100644 --- a/nonebot/matcher.py +++ b/nonebot/matcher.py @@ -575,13 +575,13 @@ class Matcher(metaclass=MatcherMeta): e_t = current_event.set(event) try: # Refresh preprocess state - state_ = await self._default_state_factory( + self.state = await self._default_state_factory( bot, event) if self._default_state_factory else self.state - state_.update(state) + self.state.update(state) for _ in range(len(self.handlers)): handler = self.handlers.pop(0) - await handler(self, bot, event, state_) + await handler(self, bot, event, self.state) except RejectedException: self.handlers.insert(0, handler) # type: ignore @@ -590,7 +590,7 @@ class Matcher(metaclass=MatcherMeta): type_ = await updater( bot, event, - state_, # type: ignore + self.state, # type: ignore self.type) else: type_ = "message" @@ -600,7 +600,7 @@ class Matcher(metaclass=MatcherMeta): permission = await updater( bot, event, - state_, # type: ignore + self.state, # type: ignore self.permission) else: permission = USER(event.get_session_id(), perm=self.permission) @@ -626,7 +626,7 @@ class Matcher(metaclass=MatcherMeta): type_ = await updater( bot, event, - state_, # type: ignore + self.state, # type: ignore self.type) else: type_ = "message" @@ -636,7 +636,7 @@ class Matcher(metaclass=MatcherMeta): permission = await updater( bot, event, - state_, # type: ignore + self.state, # type: ignore self.permission) else: permission = USER(event.get_session_id(), perm=self.permission) diff --git a/pages/changelog.md b/pages/changelog.md index 8831578c..63c58c72 100644 --- a/pages/changelog.md +++ b/pages/changelog.md @@ -13,6 +13,7 @@ sidebar: auto - 移除 `bot.call_api` 参数 `self_id` 切换机器人支持 - 修复 `type_updater` `permission_updater` 未传递的错误 - 修复 `type_updater` `permission_updater` 参数 `state` 错误 +- 修复使用 `state_factory` 后导致无法在 session 内传递 `state` ## v2.0.0a13.post1