1
Fork 0
mirror of https://github.com/RGBCube/minearchy-bot synced 2025-07-26 16:37:46 +00:00

feat: async Bot run

This commit is contained in:
RGBCube 2025-04-07 01:26:43 +03:00
parent efb078fef9
commit fb63e83312
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M
2 changed files with 14 additions and 17 deletions

View file

@ -2,7 +2,6 @@ from __future__ import annotations
__all__ = ("MinearchyBot",) __all__ = ("MinearchyBot",)
import asyncio
from inspect import cleandoc as strip from inspect import cleandoc as strip
from itertools import chain from itertools import chain
from pathlib import Path from pathlib import Path
@ -83,16 +82,10 @@ class MinearchyBot(CommandsBot):
except (ExtensionFailed, NoEntryPointError): except (ExtensionFailed, NoEntryPointError):
print(f"Couldn't load {file_name}:\n{format_exception()}") print(f"Couldn't load {file_name}:\n{format_exception()}")
def run(self) -> None: async def run(self) -> None:
async def runner() -> None: async with self, AIOHTTPSession() as self.session:
async with self, AIOHTTPSession() as self.session: self.log_webhook = Webhook.from_url(
self.log_webhook = Webhook.from_url( self.webhook_url, session = self.session, bot_token = self.token
self.webhook_url, session = self.session, bot_token = self.token )
) await self.load_extensions()
await self.load_extensions() await self.start(self.token)
await self.start(self.token)
try:
asyncio.run(runner())
except KeyboardInterrupt:
pass

View file

@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
import asyncio
import json import json
from os import environ as env from os import environ as env
from pathlib import Path from pathlib import Path
@ -7,7 +8,7 @@ from pathlib import Path
from . import MinearchyBot from . import MinearchyBot
def main() -> None: async def main() -> None:
config = json.loads( config = json.loads(
( (
Path(__file__).parent / "config.json" Path(__file__).parent / "config.json"
@ -22,7 +23,10 @@ def main() -> None:
webhook_url = config["WEBHOOK_URL"] webhook_url = config["WEBHOOK_URL"]
) )
bot.run() await bot.run()
if __name__ == "__main__": if __name__ == "__main__":
main() try:
asyncio.run(main())
except KeyboardInterrupt:
pass