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

70 lines
1.7 KiB
Python

import contextlib
import logging
from argparse import ArgumentParser
from os import getpid
from pathlib import Path
from libbot import sync
from classes.pyroclient import PyroClient
# Main uses MongoDB implementation of DB
# but you can also select SQLite one below
# from modules.migrator_sqlite import migrate_database
from modules.migrator_mongo import migrate_database
from modules.scheduler import scheduler
# Uncomment this and the line below client declaration
# in order to use context manager in your commands.
# Don't forget to disable PyroClient workers if you want
# to use convopyro, because workers create more event loops.
# from convopyro import Conversation
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="__name__",
description="__description__",
)
# Remove if no database is being used
parser.add_argument("--migrate", action="store_true")
args = parser.parse_args()
with contextlib.suppress(ImportError):
import uvloop
uvloop.install()
def main():
client = PyroClient(
scheduler=scheduler, commands_source=sync.json_read(Path("commands.json"))
)
# Conversation(client)
# Remove if no database is being used
if args.migrate:
migrate_database()
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()