sh_discord_bot/src/bot/main.py

49 lines
1.3 KiB
Python
Raw Normal View History

2022-07-14 16:32:46 +02:00
import asyncio
2022-07-16 19:47:04 +02:00
from typing import Optional
2022-07-14 16:32:46 +02:00
from cpl_core.application import ApplicationBuilder
from bot.application import Application
from bot.startup import Startup
from bot.startup_discord_extension import StartupDiscordExtension
from bot.startup_migration_extension import StartupMigrationExtension
from modules.boot_log.boot_log_extension import BootLogExtension
from modules.database.database_extension import DatabaseExtension
2022-07-14 16:32:46 +02:00
2022-07-16 19:47:04 +02:00
class Main:
def __init__(self):
2022-07-16 19:55:22 +02:00
self._app: Optional[Application] = None
2022-07-16 19:47:04 +02:00
async def main(self):
app_builder = ApplicationBuilder(Application)
app_builder.use_extension(StartupDiscordExtension)
app_builder.use_extension(StartupMigrationExtension)
app_builder.use_extension(BootLogExtension)
app_builder.use_extension(DatabaseExtension)
2022-07-16 19:47:04 +02:00
app_builder.use_startup(Startup)
2022-07-16 19:55:22 +02:00
self._app: Application = await app_builder.build_async()
await self._app.run_async()
2022-07-16 19:47:04 +02:00
async def stop(self):
2022-07-16 19:55:22 +02:00
await self._app.stop_async()
2022-07-14 16:32:46 +02:00
if __name__ == '__main__':
2022-07-16 19:47:04 +02:00
main = Main()
try:
asyncio.run(main.main())
except KeyboardInterrupt:
asyncio.run(main.stop())
# ((
# ( `)
# ; / ,
# / \/
# / |
# / ~/
# / ) ) ~ edraft
# ___// | /
# `--' \_~-,