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

46 lines
1.0 KiB
Python
Raw Normal View History

2023-05-23 15:14:50 +02:00
import contextlib
2023-04-01 14:25:41 +02:00
import logging
from os import getpid
from libbot.pyrogram.classes import PyroClient
2023-05-26 16:32:56 +02:00
from modules.scheduler import scheduler
2023-05-23 15:14:50 +02:00
2023-05-14 22:09:04 +02:00
# Uncomment this and the line below client declaration
# in order to use context manager in your commands.
2023-06-01 15:53:47 +02:00
# Don't forget to disable PyroClient workers if you want
# to use convopyro, because workers create more event loops.
2023-05-14 22:09:04 +02:00
# from convopyro import Conversation
2023-04-01 14:25:41 +02:00
logging.basicConfig(
level=logging.INFO,
format="%(name)s.%(funcName)s | %(levelname)s | %(message)s",
datefmt="[%X]",
)
logger = logging.getLogger(__name__)
2023-05-23 15:14:50 +02:00
with contextlib.suppress(ImportError):
2023-04-01 14:25:41 +02:00
import uvloop
uvloop.install()
2023-05-14 21:27:07 +02:00
def main():
client = PyroClient(scheduler=scheduler)
2023-05-14 22:09:04 +02:00
# Conversation(client)
2023-04-01 14:25:41 +02:00
try:
2023-05-14 21:27:07 +02:00
client.run()
2023-04-01 14:25:41 +02:00
except KeyboardInterrupt:
2023-05-23 15:14:50 +02:00
logger.warning("Forcefully shutting down with PID %s...", getpid())
2023-04-01 14:25:41 +02:00
finally:
if client.scheduler is not None:
client.scheduler.shutdown()
2023-05-14 21:27:07 +02:00
exit()
2023-04-01 14:25:41 +02:00
if __name__ == "__main__":
2023-05-14 21:29:23 +02:00
main()