import contextlib import logging from argparse import ArgumentParser from os import getpid from pathlib import Path from aiohttp import ClientSession from convopyro import Conversation from libbot import sync from classes.pyroclient import PyroClient from modules.migrator import migrate_database from modules.scheduler import scheduler logging.basicConfig( level=logging.DEBUG if sync.config_get("debug") else logging.INFO, format="%(name)s.%(funcName)s | %(levelname)s | %(message)s", datefmt="[%X]", ) logger = logging.getLogger(__name__) parser = ArgumentParser( prog="GarbageCollection", description="Bot that notifies about upcoming garbage collection", ) parser.add_argument("--migrate", action="store_true") args = parser.parse_args() with contextlib.suppress(ImportError): import uvloop uvloop.install() def main(): if args.migrate: migrate_database() logger.info("Migration finished. Exiting...") exit() client = PyroClient( scheduler=scheduler, commands_source=sync.json_read(Path("commands.json")), ) Conversation(client) try: client.run() except KeyboardInterrupt: logger.warning("Forcefully shutting down with PID %s...", getpid()) finally: if client.scheduler is not None: client.scheduler.shutdown() exit() if __name__ == "__main__": main()