import logging import os import threading import time import aria2p import telegram.ext as tg from dotenv import load_dotenv from pyrogram import Client from telegraph import Telegraph import socket socket.setdefaulttimeout(600) botStartTime = time.time() if os.path.exists('log.txt'): with open('log.txt', 'r+') as f: f.truncate(0) logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[logging.FileHandler('log.txt'), logging.StreamHandler()], level=logging.INFO) load_dotenv('config.env') Interval = [] def getConfig(name: str): return os.environ[name] LOGGER = logging.getLogger(__name__) try: if bool(getConfig('_____REMOVE_THIS_LINE_____')): logging.error('The README.md file there to be read! Exiting now!') exit() except KeyError: pass aria2 = aria2p.API( aria2p.Client( host="http://localhost", port=6800, secret="", ) ) DOWNLOAD_DIR = None BOT_TOKEN = None download_dict_lock = threading.Lock() status_reply_dict_lock = threading.Lock() # Key: update.effective_chat.id # Value: telegram.Message status_reply_dict = {} # Key: update.message.message_id # Value: An object of Status download_dict = {} # Stores list of users and chats the bot is authorized to use in AUTHORIZED_CHATS = set() if os.path.exists('authorized_chats.txt'): with open('authorized_chats.txt', 'r+') as f: lines = f.readlines() for line in lines: # LOGGER.info(line.split()) AUTHORIZED_CHATS.add(int(line.split()[0])) try: achats = getConfig('AUTHORIZED_CHATS') achats = achats.split(" ") for chats in achats: AUTHORIZED_CHATS.add(int(chats)) except: pass try: BOT_TOKEN = getConfig('BOT_TOKEN') parent_id = getConfig('GDRIVE_FOLDER_ID') DOWNLOAD_DIR = getConfig('DOWNLOAD_DIR') if DOWNLOAD_DIR[-1] != '/' or DOWNLOAD_DIR[-1] != '\\': DOWNLOAD_DIR = DOWNLOAD_DIR + '/' DOWNLOAD_STATUS_UPDATE_INTERVAL = int(getConfig('DOWNLOAD_STATUS_UPDATE_INTERVAL')) OWNER_ID = int(getConfig('OWNER_ID')) AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION')) TELEGRAM_API = getConfig('TELEGRAM_API') TELEGRAM_HASH = getConfig('TELEGRAM_HASH') except KeyError as e: LOGGER.error("One or more env variables missing! Exiting now") exit(1) try: MEGA_API_KEY = getConfig('MEGA_API_KEY') except KeyError: LOGGER.warning('MEGA API KEY not provided!') MEGA_API_KEY = None try: MEGA_EMAIL_ID = getConfig('MEGA_EMAIL_ID') MEGA_PASSWORD = getConfig('MEGA_PASSWORD') if len(MEGA_EMAIL_ID) == 0 or len(MEGA_PASSWORD) == 0: raise KeyError except KeyError: LOGGER.warning('MEGA Credentials not provided!') MEGA_EMAIL_ID = None MEGA_PASSWORD = None LOGGER.info("Generating USER_SESSION_STRING") with Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN) as app: USER_SESSION_STRING = app.export_session_string() #Generate Telegraph Token LOGGER.info("Generating Telegraph Token") telegraph = Telegraph() telegraph.create_account(short_name="mirror_bot") telegraph_token = telegraph.get_access_token() try: INDEX_URL = getConfig('INDEX_URL') if len(INDEX_URL) == 0: INDEX_URL = None except KeyError: INDEX_URL = None try: IS_TEAM_DRIVE = getConfig('IS_TEAM_DRIVE') if IS_TEAM_DRIVE.lower() == 'true': IS_TEAM_DRIVE = True else: IS_TEAM_DRIVE = False except KeyError: IS_TEAM_DRIVE = False try: USE_SERVICE_ACCOUNTS = getConfig('USE_SERVICE_ACCOUNTS') if USE_SERVICE_ACCOUNTS.lower() == 'true': USE_SERVICE_ACCOUNTS = True else: USE_SERVICE_ACCOUNTS = False except KeyError: USE_SERVICE_ACCOUNTS = False try: BLOCK_MEGA_LINKS = getConfig('BLOCK_MEGA_LINKS') if BLOCK_MEGA_LINKS.lower() == 'true': BLOCK_MEGA_LINKS = True else: BLOCK_MEGA_LINKS = False except KeyError: BLOCK_MEGA_LINKS = False app = Client('slam', api_id=TELEGRAM_API, api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN) updater = tg.Updater(token=BOT_TOKEN,use_context=True) bot = updater.bot dispatcher = updater.dispatcher