This repository has been archived on 2024-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
TelegramBot/main.py

62 lines
1.4 KiB
Python
Raw Permalink Normal View History

2023-08-27 23:43:16 +03:00
import contextlib
import logging
from argparse import ArgumentParser
from os import getpid
from pathlib import Path
2024-08-10 15:10:59 +03:00
from aiohttp import ClientSession
2023-08-27 23:43:16 +03:00
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(
2023-10-15 23:20:12 +03:00
level=logging.DEBUG if sync.config_get("debug") else logging.INFO,
2023-08-27 23:43:16 +03:00
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():
2024-05-26 23:56:30 +03:00
if args.migrate:
migrate_database()
logger.info("Migration finished. Exiting...")
exit()
2023-08-27 23:43:16 +03:00
client = PyroClient(
2024-08-10 15:10:59 +03:00
scheduler=scheduler,
commands_source=sync.json_read(Path("commands.json")),
2023-08-27 23:43:16 +03:00
)
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()