diff --git a/minearchy_bot/__init__.py b/minearchy_bot/__init__.py index eef64b5..39b351d 100644 --- a/minearchy_bot/__init__.py +++ b/minearchy_bot/__init__.py @@ -2,7 +2,6 @@ from __future__ import annotations __all__ = ("MinearchyBot",) -import asyncio from inspect import cleandoc as strip from itertools import chain from pathlib import Path @@ -83,16 +82,10 @@ class MinearchyBot(CommandsBot): except (ExtensionFailed, NoEntryPointError): print(f"Couldn't load {file_name}:\n{format_exception()}") - def run(self) -> None: - async def runner() -> None: - async with self, AIOHTTPSession() as self.session: - self.log_webhook = Webhook.from_url( - self.webhook_url, session = self.session, bot_token = self.token - ) - await self.load_extensions() - await self.start(self.token) - - try: - asyncio.run(runner()) - except KeyboardInterrupt: - pass + async def run(self) -> None: + async with self, AIOHTTPSession() as self.session: + self.log_webhook = Webhook.from_url( + self.webhook_url, session = self.session, bot_token = self.token + ) + await self.load_extensions() + await self.start(self.token) diff --git a/minearchy_bot/__main__.py b/minearchy_bot/__main__.py index 4eb4442..cb1cbe0 100644 --- a/minearchy_bot/__main__.py +++ b/minearchy_bot/__main__.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio import json from os import environ as env from pathlib import Path @@ -7,7 +8,7 @@ from pathlib import Path from . import MinearchyBot -def main() -> None: +async def main() -> None: config = json.loads( ( Path(__file__).parent / "config.json" @@ -22,7 +23,10 @@ def main() -> None: webhook_url = config["WEBHOOK_URL"] ) - bot.run() + await bot.run() if __name__ == "__main__": - main() + try: + asyncio.run(main()) + except KeyboardInterrupt: + pass