diff --git a/src/libbot/pycord/classes/bot.py b/src/libbot/pycord/classes/bot.py index 829961b..aac613f 100644 --- a/src/libbot/pycord/classes/bot.py +++ b/src/libbot/pycord/classes/bot.py @@ -59,3 +59,15 @@ class PycordBot(Bot): self.in_every_locale = self.bot_locale.in_every_locale self.scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = scheduler + + async def start(self, token: str, reconnect: bool = True, scheduler_start: bool = True) -> None: + if self.scheduler is not None and scheduler_start: + self.scheduler.start() + + await super().start(token, reconnect=reconnect) + + async def close(self, scheduler_shutdown: bool = True, scheduler_wait: bool = True) -> None: + if self.scheduler is not None and scheduler_shutdown: + self.scheduler.shutdown(scheduler_wait) + + await super().close() diff --git a/src/libbot/pyrogram/classes/client.py b/src/libbot/pyrogram/classes/client.py index 450aa13..33af849 100644 --- a/src/libbot/pyrogram/classes/client.py +++ b/src/libbot/pyrogram/classes/client.py @@ -125,7 +125,7 @@ class PyroClient(Client): self.i18n_bot_info: bool = i18n_bot_info - async def start(self, register_commands: bool = True) -> None: + async def start(self, register_commands: bool = True, scheduler_start: bool = True) -> None: await super().start() self.start_time = time() @@ -209,9 +209,12 @@ class PyroClient(Client): kwargs={"command_sets": await self.collect_commands()}, ) - self.scheduler.start() + if scheduler_start: + self.scheduler.start() - async def stop(self, exit_completely: bool = True) -> None: + async def stop( + self, exit_completely: bool = True, scheduler_shutdown: bool = True, scheduler_wait: bool = True + ) -> None: try: await self.send_message( chat_id=self.owner @@ -223,6 +226,9 @@ class PyroClient(Client): except BadRequest: logger.warning("Unable to send message to report chat.") + if self.scheduler is not None and scheduler_shutdown: + self.scheduler.shutdown(scheduler_wait) + await super().stop() logger.warning("Bot stopped with PID %s.", getpid())