diff --git a/src/mab/bot/bot.py b/src/mab/bot/bot.py index 81a3611..b454e2a 100644 --- a/src/mab/bot/bot.py +++ b/src/mab/bot/bot.py @@ -1,3 +1,4 @@ +import asyncio import logging from typing import Callable, Coroutine, Any @@ -97,6 +98,20 @@ class MatrixBot: """ await self._client_manager.stop() + async def run(self) -> None: + """ + Start bot operation in foreground. You may cancel task running this + method to stop the bot. + + Warning: calling `stop()` is not a supported way to stop the bot. You + should cancel this task instead. + """ + await self.start() + try: + await asyncio.Event().wait() + finally: + await self.stop() + def get_client(self) -> AsyncClient: """ Get AsyncClient.