Skip to content

Commit

Permalink
🐛 fix bot_config dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 9, 2024
1 parent 79b12f2 commit fd23bf9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit fd23bf9

Please sign in to comment.