From fd23bf9b93fa05688030b7503f7913af083be8a6 Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt Date: Sun, 10 Nov 2024 06:55:42 +0800 Subject: [PATCH] :bug: fix bot_config dispatch --- app/core.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/core.py b/app/core.py index eaf10ee..1437677 100644 --- a/app/core.py +++ b/app/core.py @@ -138,6 +138,13 @@ class RaianBotDispatcher(BaseDispatcher): def __init__(self, service: RaianBotService): self.service = service + async def beforeExecution(self, interface: DispatcherInterface): + context: Context = await interface.lookup_param("context", Context, None) + if context: + interface.local_storage["bot_config"] = next( + (bot for bot in self.service.config.bots if bot.ensure(context.account)), None # type: ignore + ) + async def catch(self, interface: DispatcherInterface): if interface.annotation is RaianBotService: return self.service @@ -150,11 +157,7 @@ async def catch(self, interface: DispatcherInterface): if issubclass(interface.annotation, BasePluginConfig): return self.service.config.plugin.get(interface.annotation) if issubclass(interface.annotation, BotConfig): - context: Context = await interface.lookup_param("context", Context, None) - if context: - return next( - (bot for bot in self.service.config.bots if bot.ensure(context.account)), None # type: ignore - ) + return interface.local_storage.get("bot_config") async def afterExecution( self,