|
| 1 | +"""Initialise the directory.""" |
| 2 | + |
| 3 | +from datetime import datetime |
| 4 | +from logging import INFO, WARNING, FileHandler, StreamHandler, basicConfig, getLogger |
| 5 | +from os import environ, mkdir, path |
| 6 | +from sys import exit as sysexit |
| 7 | +from sys import stdout, version_info |
| 8 | + |
| 9 | +LOG_DATETIME = datetime.now().strftime("%d_%m_%Y-%H_%M_%S") |
| 10 | +LOGDIR = f"{__name__}/logs" |
| 11 | + |
| 12 | +# Make Logs directory if it does not exixts |
| 13 | +if not path.isdir(LOGDIR): |
| 14 | + mkdir(LOGDIR) |
| 15 | + |
| 16 | +LOGFILE = f"{LOGDIR}/{__name__}_{LOG_DATETIME}.txt" |
| 17 | + |
| 18 | +file_handler = FileHandler(filename=LOGFILE) |
| 19 | +stdout_handler = StreamHandler(stdout) |
| 20 | + |
| 21 | +basicConfig( |
| 22 | + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", |
| 23 | + level=INFO, |
| 24 | + handlers=[file_handler, stdout_handler], |
| 25 | +) |
| 26 | + |
| 27 | +getLogger("pyrogram").setLevel(WARNING) |
| 28 | +LOGGER = getLogger(__name__) |
| 29 | + |
| 30 | +# if version < 3.6, stop bot. |
| 31 | +if version_info[0] < 3 or version_info[1] < 7: |
| 32 | + LOGGER.error( |
| 33 | + ( |
| 34 | + "You MUST have a Python Version of at least 3.7!\n" |
| 35 | + "Multiple features depend on this. Bot quitting." |
| 36 | + ), |
| 37 | + ) |
| 38 | + sysexit(1) # Quit the Script |
| 39 | + |
| 40 | +# the secret configuration specific things |
| 41 | +try: |
| 42 | + if environ.get("ENV"): |
| 43 | + from .vars import Config |
| 44 | + else: |
| 45 | + from .vars import Development as Config |
| 46 | +except BaseException as ef: |
| 47 | + LOGGER.error(ef) # Print Error |
| 48 | + sysexit(1) |
| 49 | + |
| 50 | + |
| 51 | +TOKEN = Config.TOKEN |
| 52 | +APP_ID = Config.APP_ID |
| 53 | +API_HASH = Config.API_HASH |
| 54 | +TOKEN = Config.TOKEN |
| 55 | +APP_ID = Config.APP_ID |
| 56 | +API_HASH = Config.API_HASH |
| 57 | +OWNER_ID = Config.OWNER_ID |
| 58 | +PREFIX_HANDLER = Config.PREFIX_HANDLER |
| 59 | +WORKERS = Config.WORKERS |
0 commit comments