diff --git a/bot/__init__.py b/bot/__init__.py index 8cca93a..1f5cf40 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -103,6 +103,6 @@ try: except KeyError: USE_SERVICE_ACCOUNTS = False -updater = tg.Updater(token=BOT_TOKEN) +updater = tg.Updater(token=BOT_TOKEN,use_context=True) bot = updater.bot dispatcher = updater.dispatcher diff --git a/bot/__main__.py b/bot/__main__.py index efdaf4d..695b654 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -13,7 +13,7 @@ from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clon @run_async -def stats(bot, update): +def stats(update,context): currentTime = get_readable_time((time.time() - botStartTime)) total, used, free = shutil.disk_usage('.') total = get_readable_file_size(total) @@ -21,32 +21,32 @@ def stats(bot, update): free = get_readable_file_size(free) stats = f'Bot Uptime: {currentTime}\n' \ f'Total disk space: {total}\n' \ - f'Used: {used}\n' \ - f'Free: {free}' - sendMessage(stats, bot, update) + f'Used: {used}\n' \ + f'Free: {free}' + sendMessage(stats, context.bot, update) @run_async -def start(bot, update): +def start(update,context): sendMessage("This is a bot which can mirror all your links to Google drive!\n" - "Type /help to get a list of available commands", bot, update) + "Type /help to get a list of available commands", context.bot, update) @run_async -def ping(bot, update): +def ping(update, context): start_time = int(round(time.time() * 1000)) - reply = sendMessage("Starting Ping", bot, update) + reply = sendMessage("Starting Ping", context.bot, update) end_time = int(round(time.time() * 1000)) editMessage(f'{end_time - start_time} ms', reply) @run_async -def log(bot, update): - sendLogFile(bot, update) +def log(update, context): + sendLogFile(context.bot, update) @run_async -def bot_help(bot, update): +def bot_help(update, context): help_string = f''' /{BotCommands.HelpCommand}: To get this message @@ -71,7 +71,7 @@ def bot_help(bot, update): /{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports ''' - sendMessage(help_string, bot, update) + sendMessage(help_string, context.bot, update) def main(): diff --git a/bot/helper/mirror_utils/upload_utils/gdriveTools.py b/bot/helper/mirror_utils/upload_utils/gdriveTools.py index ad7c8ef..d367c0a 100644 --- a/bot/helper/mirror_utils/upload_utils/gdriveTools.py +++ b/bot/helper/mirror_utils/upload_utils/gdriveTools.py @@ -175,6 +175,8 @@ class GoogleDriveHelper: return download_url def upload(self, file_name: str): + if USE_SERVICE_ACCOUNTS: + self.service_account_count = len(os.listdir("accounts")) self.__listener.onUploadStarted() file_dir = f"{DOWNLOAD_DIR}{self.__listener.message.message_id}" file_path = f"{file_dir}/{file_name}" diff --git a/bot/modules/authorize.py b/bot/modules/authorize.py index de254f0..fedb4d1 100644 --- a/bot/modules/authorize.py +++ b/bot/modules/authorize.py @@ -9,7 +9,7 @@ from bot.helper.telegram_helper.bot_commands import BotCommands @run_async -def authorize(bot, update): +def authorize(update,context): reply_message = update.message.reply_to_message msg = '' with open('authorized_chats.txt', 'a') as file: @@ -31,11 +31,11 @@ def authorize(bot, update): msg = 'Person Authorized to use the bot!' else: msg = 'Person already authorized' - sendMessage(msg, bot, update) + sendMessage(msg, context.bot, update) @run_async -def unauthorize(bot,update): +def unauthorize(update,context): reply_message = update.message.reply_to_message if reply_message is None: # Trying to unauthorize a chat @@ -57,7 +57,7 @@ def unauthorize(bot,update): file.truncate(0) for i in AUTHORIZED_CHATS: file.write(f'{i}\n') - sendMessage(msg, bot, update) + sendMessage(msg, context.bot, update) authorize_handler = CommandHandler(command=BotCommands.AuthorizeCommand, callback=authorize, diff --git a/bot/modules/cancel_mirror.py b/bot/modules/cancel_mirror.py index 53ccdfc..c25c460 100644 --- a/bot/modules/cancel_mirror.py +++ b/bot/modules/cancel_mirror.py @@ -11,14 +11,14 @@ from bot.helper.ext_utils.bot_utils import getDownloadByGid, MirrorStatus @run_async -def cancel_mirror(bot, update): - args = update.message.text.split(" ", maxsplit=1) +def cancel_mirror(update,context): + args = update.message.text.split(" ",maxsplit=1) mirror_message = None if len(args) > 1: gid = args[1] dl = getDownloadByGid(gid) if not dl: - sendMessage(f"GID: {gid} not found.", bot, update) + sendMessage(f"GID: {gid} not found.",context.bot,update) return with download_dict_lock: keys = list(download_dict.keys()) @@ -33,18 +33,17 @@ def cancel_mirror(bot, update): if BotCommands.MirrorCommand in mirror_message.text or \ BotCommands.TarMirrorCommand in mirror_message.text: msg = "Mirror already have been cancelled" - sendMessage(msg, bot, update) + sendMessage(msg,context.bot,update) return else: - msg = "Please reply to the /mirror message which was " \ - "used to start the download or /cancel gid to cancel it!" - sendMessage(msg, bot, update) + msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!" + sendMessage(msg,context.bot,update) return - if dl.status() == MirrorStatus.STATUS_UPLOADING: - sendMessage("Upload in Progress, Don't Cancel it.", bot, update) + if dl.status() == "Uploading": + sendMessage("Upload in Progress, Don't Cancel it.", context.bot, update) return - elif dl.status() == MirrorStatus.STATUS_ARCHIVING: - sendMessage("Archival in Progress, Don't Cancel it.", bot, update) + elif dl.status() == "Archiving": + sendMessage("Archival in Progress, Don't Cancel it.", context.bot, update) return else: dl.download().cancel_download() @@ -53,7 +52,7 @@ def cancel_mirror(bot, update): @run_async -def cancel_all(update, bot): +def cancel_all(update, context): with download_dict_lock: count = 0 for dlDetails in list(download_dict.values()): @@ -62,7 +61,7 @@ def cancel_all(update, bot): dlDetails.download().cancel_download() count += 1 delete_all_messages() - sendMessage(f'Cancelled {count} downloads!', update, bot) + sendMessage(f'Cancelled {count} downloads!', context.bot,update) cancel_mirror_handler = CommandHandler(BotCommands.CancelMirror, cancel_mirror, diff --git a/bot/modules/clone.py b/bot/modules/clone.py index fa33233..407e353 100644 --- a/bot/modules/clone.py +++ b/bot/modules/clone.py @@ -7,15 +7,15 @@ from bot import dispatcher @run_async -def cloneNode(bot,update): +def cloneNode(update,context): args = update.message.text.split(" ",maxsplit=1) if len(args) > 1: link = args[1] - msg = sendMessage(f"Cloning: {link}",bot,update) + msg = sendMessage(f"Cloning: {link}",context.bot,update) gd = GoogleDriveHelper() result = gd.clone(link) - deleteMessage(bot,msg) - sendMessage(result,bot,update) + deleteMessage(context.bot,msg) + sendMessage(result,context.bot,update) else: sendMessage("Provide G-Drive Shareable Link to Clone.",bot,update) diff --git a/bot/modules/list.py b/bot/modules/list.py index bef678c..24a641c 100644 --- a/bot/modules/list.py +++ b/bot/modules/list.py @@ -7,18 +7,18 @@ import threading from bot.helper.telegram_helper.bot_commands import BotCommands @run_async -def list_drive(bot,update): +def list_drive(update,context): message = update.message.text search = message.split(' ',maxsplit=1)[1] LOGGER.info(f"Searching: {search}") gdrive = GoogleDriveHelper(None) msg = gdrive.drive_list(search) if msg: - reply_message = sendMessage(msg, bot, update) + reply_message = sendMessage(msg, context.bot, update) else: - reply_message = sendMessage('No result found', bot, update) + reply_message = sendMessage('No result found', context.bot, update) - threading.Thread(target=auto_delete_message, args=(bot, update.message, reply_message)).start() + threading.Thread(target=auto_delete_message, args=(context.bot, update.message, reply_message)).start() list_handler = CommandHandler(BotCommands.ListCommand, list_drive,filters=CustomFilters.authorized_chat | CustomFilters.authorized_user) diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index a7718ee..b9539c3 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -194,13 +194,13 @@ def _mirror(bot, update, isTar=False): @run_async -def mirror(bot, update): - _mirror(bot, update) +def mirror(update, context): + _mirror(context.bot, update) @run_async -def tar_mirror(update, bot): - _mirror(update, bot, True) +def tar_mirror(update, context): + _mirror(context.bot, update, True) mirror_handler = CommandHandler(BotCommands.MirrorCommand, mirror, diff --git a/bot/modules/mirror_status.py b/bot/modules/mirror_status.py index bc2a913..e4ae324 100644 --- a/bot/modules/mirror_status.py +++ b/bot/modules/mirror_status.py @@ -9,11 +9,11 @@ from bot.helper.telegram_helper.bot_commands import BotCommands import threading @run_async -def mirror_status(bot,update): +def mirror_status(update,context): message = get_readable_message() if len(message) == 0: message = "No active downloads" - reply_message = sendMessage(message, bot, update) + reply_message = sendMessage(message, context.bot, update) threading.Thread(target=auto_delete_message, args=(bot, update.message, reply_message)).start() return index = update.effective_chat.id @@ -21,8 +21,8 @@ def mirror_status(bot,update): if index in status_reply_dict.keys(): deleteMessage(bot, status_reply_dict[index]) del status_reply_dict[index] - sendStatusMessage(update,bot) - deleteMessage(bot,update.message) + sendStatusMessage(update,context.bot) + deleteMessage(context.bot,update.message) mirror_status_handler = CommandHandler(BotCommands.StatusCommand, mirror_status, diff --git a/requirements.txt b/requirements.txt index 69fbbe1..1699c9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ requests -python-telegram-bot==12.2.0 +python-telegram-bot==12.6.1 google-api-python-client>=1.7.11,<1.7.20 google-auth-httplib2>=0.0.3,<0.1.0 google-auth-oauthlib>=0.4.1,<0.10.0 @@ -10,4 +10,4 @@ python-magic beautifulsoup4>=4.8.2,<4.8.10 Pyrogram>=0.16.0,<0.16.10 TgCrypto>=1.1.1,<1.1.10 -youtube-dl \ No newline at end of file +youtube-dl