From 7ff461132f6db84b36c7a50a15b40e41b2e9de1e Mon Sep 17 00:00:00 2001 From: Levi <57452819+l3v11@users.noreply.github.com> Date: Tue, 20 Dec 2022 19:28:57 +0600 Subject: [PATCH] Add Bookmark support for storing Destination Drive IDs into database - This improves the destination change support for cloning data by providing a bookmarked drive key - Change the authorize command of auth module from /authorize to /auth - Change the unauthorize command of auth module from /unauthorize to /unauth - Fix bugs - Tidy up --- .gitignore | 2 + bot/__init__.py | 4 +- bot/__main__.py | 28 +++++---- bot/helper/drive_utils/gdriveTools.py | 7 ++- bot/helper/ext_utils/bot_utils.py | 3 +- bot/helper/ext_utils/database.py | 43 +++++++++----- bot/helper/telegram_helper/bot_commands.py | 7 ++- bot/helper/telegram_helper/message_utils.py | 35 +++-------- bot/modules/archive.py | 32 +++++------ bot/modules/auth.py | 64 ++++++++------------- bot/modules/bookmark.py | 64 +++++++++++++++++++++ bot/modules/cancel.py | 2 +- bot/modules/clone.py | 13 +++-- bot/modules/count.py | 2 +- bot/modules/delete.py | 2 +- bot/modules/eval.py | 6 +- bot/modules/list.py | 2 +- bot/modules/permission.py | 2 +- bot/modules/shell.py | 6 +- bot/modules/status.py | 2 +- 20 files changed, 193 insertions(+), 133 deletions(-) create mode 100644 bot/modules/bookmark.py diff --git a/.gitignore b/.gitignore index e41ca5d0..fe424ca8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,10 @@ data* .idea *.json *.pickle +*.zip log.txt accounts/* drives.txt drive_list +fly.toml /temp.py diff --git a/bot/__init__.py b/bot/__init__.py index c4e93aa3..594fbb8d 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -47,6 +47,7 @@ DRIVE_IDS = [] INDEX_URLS = [] TELEGRAPH = [] +BOOKMARKS = {} download_dict_lock = Lock() status_reply_dict_lock = Lock() @@ -184,6 +185,7 @@ def create_account(sname): create_account(sname) LOGGER.info(f"Generated {TELEGRAPH_ACCS} telegraph tokens") -updater = tg.Updater(token=BOT_TOKEN, use_context=True) +tgDefaults = tg.Defaults(parse_mode='HTML', allow_sending_without_reply=True, disable_web_page_preview=True, run_async=True) +updater = tg.Updater(token=BOT_TOKEN, defaults=tgDefaults, use_context=True) bot = updater.bot dispatcher = updater.dispatcher diff --git a/bot/__main__.py b/bot/__main__.py index 9f9ff3c3..d41fe954 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -7,13 +7,13 @@ from telegram.ext import CommandHandler from bot import bot, LOGGER, botStartTime, TELEGRAPH, Interval, dispatcher, updater -from bot.modules import archive, auth, cancel, clone, count, delete, eval, list, permission, shell, status +from bot.modules import archive, auth, bookmark, cancel, clone, count, delete, eval, list, permission, shell, status from bot.helper.ext_utils.bot_utils import get_readable_file_size, get_readable_time from bot.helper.ext_utils.fs_utils import start_cleanup, clean_all, exit_clean_up from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.button_builder import ButtonMaker from bot.helper.telegram_helper.filters import CustomFilters -from bot.helper.telegram_helper.message_utils import sendMessage, sendMarkup, editMessage, sendLogFile +from bot.helper.telegram_helper.message_utils import sendMessage, editMessage, sendLogFile def start(update, context): if CustomFilters.authorized_user(update) or CustomFilters.authorized_chat(update): @@ -70,7 +70,7 @@ def restart(update, context):

/{BotCommands.ListCommand} <query>: Search data in Google Drive

-• /{BotCommands.CloneCommand} <url> <dest_id>: Clone data from Google Drive and GDToT (Destination ID optional) +• /{BotCommands.CloneCommand} <url> <drive_key>: Clone data from Google Drive and GDToT (Drive Key optional)

/{BotCommands.CompressCommand} <url>: Compress data from Google Drive and GDToT

@@ -82,6 +82,8 @@ def restart(update, context):

/{BotCommands.StatusCommand}: Get status of all tasks

+• /{BotCommands.BookmarksCommand}: Get the list of bookmarked destination drives +

/{BotCommands.PingCommand}: Ping the bot

/{BotCommands.StatsCommand}: Get the system statistics @@ -102,6 +104,10 @@ def restart(update, context):

/{BotCommands.DeleteCommand} <drive_url>: Delete data from Google Drive

+• /{BotCommands.AddBookmarkCommand} <drive_key> <drive_id>: Add bookmark of a destination drive +

+• /{BotCommands.RemBookmarkCommand} <drive_key>: Remove bookmark of a destination drive +

/{BotCommands.AuthorizeCommand}: Grant authorization of an user

/{BotCommands.UnauthorizeCommand}: Revoke authorization of an user @@ -131,7 +137,7 @@ def bot_help(update, context): button = ButtonMaker() button.build_button("User", f"https://graph.org/{help_user}") button.build_button("Admin", f"https://graph.org/{help_admin}") - sendMarkup(help_string, context.bot, update.message, button.build_menu(2)) + sendMessage(help_string, context.bot, update.message, button.build_menu(2)) def main(): start_cleanup() @@ -139,22 +145,22 @@ def main(): with open(".restartmsg") as f: chat_id, msg_id = map(int, f) try: - bot.editMessageText("Restarted successfully", chat_id, msg_id, parse_mode='HTML') + bot.editMessageText("Restarted successfully", chat_id, msg_id) except: pass os.remove(".restartmsg") - start_handler = CommandHandler(BotCommands.StartCommand, start, run_async=True) + start_handler = CommandHandler(BotCommands.StartCommand, start) ping_handler = CommandHandler(BotCommands.PingCommand, ping, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) stats_handler = CommandHandler(BotCommands.StatsCommand, stats, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) log_handler = CommandHandler(BotCommands.LogCommand, log, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) restart_handler = CommandHandler(BotCommands.RestartCommand, restart, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) help_handler = CommandHandler(BotCommands.HelpCommand, bot_help, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) dispatcher.add_handler(start_handler) dispatcher.add_handler(ping_handler) dispatcher.add_handler(stats_handler) diff --git a/bot/helper/drive_utils/gdriveTools.py b/bot/helper/drive_utils/gdriveTools.py index da9a56a1..4789284d 100644 --- a/bot/helper/drive_utils/gdriveTools.py +++ b/bot/helper/drive_utils/gdriveTools.py @@ -343,13 +343,12 @@ def __copyFile(self, file_id, dest_id): if reason in ['userRateLimitExceeded', 'dailyLimitExceeded']: if USE_SERVICE_ACCOUNTS: if self.__sa_count == SERVICE_ACCOUNTS_NUMBER: - self.__is_cancelled = True + LOGGER.info("SA switch limit exceeded") raise err else: self.__switchServiceAccount() return self.__copyFile(file_id, dest_id) else: - self.__is_cancelled = True LOGGER.error(f"Warning: {reason}") raise err else: @@ -621,6 +620,8 @@ def __download_file(self, file_id, path, filename, mime_type): filename = f"{filename[:245]}{ext}" if self.name.endswith(ext): self.name = filename + if self.__is_cancelled: + return fh = FileIO(f"{path}/{filename}", 'wb') downloader = MediaIoBaseDownload(fh, request, chunksize=50 * 1024 * 1024) done = False @@ -637,7 +638,7 @@ def __download_file(self, file_id, path, filename, mime_type): raise err if USE_SERVICE_ACCOUNTS: if self.__sa_count == SERVICE_ACCOUNTS_NUMBER: - self.__is_cancelled = True + LOGGER.info("SA switch limit exceeded") raise err else: self.__switchServiceAccount() diff --git a/bot/helper/ext_utils/bot_utils.py b/bot/helper/ext_utils/bot_utils.py index 5e0c9566..e0f12b7a 100644 --- a/bot/helper/ext_utils/bot_utils.py +++ b/bot/helper/ext_utils/bot_utils.py @@ -51,8 +51,7 @@ def get_progress_bar_string(status): cFull = p // 8 p_str = '⬤' * cFull p_str += '○' * (12 - cFull) - p_str = f"「{p_str}」" - return p_str + return f"「{p_str}」" def get_readable_message(): with download_dict_lock: diff --git a/bot/helper/ext_utils/database.py b/bot/helper/ext_utils/database.py index 4eccf76a..2dfd3e60 100644 --- a/bot/helper/ext_utils/database.py +++ b/bot/helper/ext_utils/database.py @@ -1,7 +1,7 @@ from pymongo import MongoClient from pymongo.errors import PyMongoError -from bot import LOGGER, AUTHORIZED_USERS, DATABASE_URL +from bot import LOGGER, AUTHORIZED_USERS, BOOKMARKS, DATABASE_URL class DatabaseHelper: @@ -9,39 +9,56 @@ def __init__(self): self.__err = False self.__client = None self.__db = None - self.__collection = None self.__connect() def __connect(self): try: self.__client = MongoClient(DATABASE_URL) self.__db = self.__client['SearchX'] - self.__collection = self.__db['users'] except PyMongoError as err: LOGGER.error(err) self.__err = True - def auth_user(self, user_id: int): + def load_db(self): if self.__err: return - self.__collection.insert_one({"user_id": user_id}) - return 'Authorization granted' + if self.__db.users.find_one(): + users_dict = self.__db.users.find().sort("user_id") + for user in users_dict: + AUTHORIZED_USERS.add(user["user_id"]) + if self.__db.bms.find_one(): + bms_dict = self.__db.bms.find().sort("drive_key") + for bm in bms_dict: + BOOKMARKS[bm["drive_key"]] = str(bm["drive_id"]) + self.__client.close() + + def auth_user(self, user_id): + if self.__err: + return + self.__db.users.insert_one({"user_id": user_id}) self.__client.close() + return 'Authorization granted' - def unauth_user(self, user_id: int): + def unauth_user(self, user_id): if self.__err: return - self.__collection.delete_many({"user_id": user_id}) + self.__db.users.delete_one({"user_id": user_id}) + self.__client.close() return 'Authorization revoked' + + def add_bm(self, drive_key, drive_id): + if self.__err: + return + self.__db.bms.insert_one({"drive_key": drive_key, "drive_id": drive_id}) self.__client.close() + return 'Bookmark added' - def load_users(self): + def remove_bm(self, drive_key): if self.__err: return - users = self.__collection.find().sort("user_id") - for user in users: - AUTHORIZED_USERS.add(user["user_id"]) + self.__db.bms.delete_one({"drive_key": drive_key}) self.__client.close() + return 'Bookmark removed' if DATABASE_URL is not None: - DatabaseHelper().load_users() + DatabaseHelper().load_db() diff --git a/bot/helper/telegram_helper/bot_commands.py b/bot/helper/telegram_helper/bot_commands.py index 81681b43..bcd9c646 100644 --- a/bot/helper/telegram_helper/bot_commands.py +++ b/bot/helper/telegram_helper/bot_commands.py @@ -11,8 +11,11 @@ def __init__(self): self.StatusCommand = 'status' self.PermissionCommand = 'share' self.DeleteCommand = 'del' - self.AuthorizeCommand = 'authorize' - self.UnauthorizeCommand = 'unauthorize' + self.AddBookmarkCommand = 'addbm' + self.RemBookmarkCommand = 'rembm' + self.BookmarksCommand = 'bookmarks' + self.AuthorizeCommand = 'auth' + self.UnauthorizeCommand = 'unauth' self.UsersCommand = 'users' self.ShellCommand = 'shell' self.EvalCommand = 'eval' diff --git a/bot/helper/telegram_helper/message_utils.py b/bot/helper/telegram_helper/message_utils.py index bad5bd18..4cd707f3 100644 --- a/bot/helper/telegram_helper/message_utils.py +++ b/bot/helper/telegram_helper/message_utils.py @@ -1,46 +1,29 @@ import time -from telegram import InlineKeyboardMarkup from telegram.error import RetryAfter from bot import bot, LOGGER, Interval, STATUS_UPDATE_INTERVAL, \ status_reply_dict, status_reply_dict_lock from bot.helper.ext_utils.bot_utils import SetInterval, get_readable_message -def sendMessage(text, bot, message): +def sendMessage(text, bot, message, reply_markup=None): try: - return bot.sendMessage(message.chat_id, + return bot.sendMessage(chat_id=message.chat_id, reply_to_message_id=message.message_id, - text=text, parse_mode='HTML', - disable_web_page_preview=True) + text=text, reply_markup=reply_markup) except RetryAfter as r: LOGGER.warning(str(r)) time.sleep(r.retry_after * 1.5) - return sendMessage(text, bot, message) - except Exception as err: - LOGGER.error(str(err)) - return - -def sendMarkup(text, bot, message, reply_markup: InlineKeyboardMarkup): - try: - return bot.sendMessage(message.chat_id, - reply_to_message_id=message.message_id, - text=text, reply_markup=reply_markup, - parse_mode='HTML', disable_web_page_preview=True) - except RetryAfter as r: - LOGGER.warning(str(r)) - time.sleep(r.retry_after * 1.5) - return sendMarkup(text, bot, message, reply_markup) + return sendMessage(text, bot, message, reply_markup) except Exception as err: LOGGER.error(str(err)) return def editMessage(text, message, reply_markup=None): try: - bot.editMessageText(text=text, message_id=message.message_id, - chat_id=message.chat.id, - reply_markup=reply_markup, parse_mode='HTML', - disable_web_page_preview=True) + bot.editMessageText(chat_id=message.chat.id, + message_id=message.message_id, + text=text, reply_markup=reply_markup) except RetryAfter as r: LOGGER.warning(str(r)) time.sleep(r.retry_after * 1.5) @@ -59,8 +42,8 @@ def deleteMessage(bot, message): def sendLogFile(bot, message): with open('log.txt', 'rb') as f: bot.sendDocument(document=f, filename=f.name, - reply_to_message_id=message.message_id, - chat_id=message.chat_id) + chat_id=message.chat_id, + reply_to_message_id=message.message_id) def delete_all_messages(): with status_reply_dict_lock: diff --git a/bot/modules/archive.py b/bot/modules/archive.py index ab5862cc..46b2c994 100644 --- a/bot/modules/archive.py +++ b/bot/modules/archive.py @@ -188,27 +188,25 @@ def onUploadError(self, error): def _archive(bot, message, is_compress=False, is_extract=False): mesg = message.text.split('\n') message_args = mesg[0].split(maxsplit=1) - name_arg = mesg[0].split('|', maxsplit=1) is_gdtot = False + link = '' if len(message_args) > 1: link = message_args[1].strip() - if link.startswith("pswd:"): + if link.startswith(('|', 'pswd:')): link = '' - else: - link = '' - if len(name_arg) > 1: - name = name_arg[1] - name = name.split(' pswd:')[0] - name = name.strip() + name = mesg[0].split('|', maxsplit=1) + if len(name) > 1: + if 'pswd:' in name[0]: + name = '' + else: + name = name[1].split('pswd:')[0].strip() else: name = '' - link = re.split(r"pswd:|\|", link)[0] - link = link.strip() - pswd_arg = mesg[0].split(' pswd: ') - if len(pswd_arg) > 1: - pswd = pswd_arg[1] - else: - pswd = None + pswd = mesg[0].split(' pswd: ') + pswd = pswd[1] if len(pswd) > 1 else None + if link != '': + link = re.split(r'pswd:|\|', link)[0] + link = link.strip() reply_to = message.reply_to_message if reply_to is not None: link = reply_to.text.split(maxsplit=1)[0].strip() @@ -241,8 +239,8 @@ def extract_data(update, context): _archive(context.bot, update.message, is_extract=True) compress_handler = CommandHandler(BotCommands.CompressCommand, compress_data, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) extract_handler = CommandHandler(BotCommands.ExtractCommand, extract_data, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) dispatcher.add_handler(compress_handler) dispatcher.add_handler(extract_handler) diff --git a/bot/modules/auth.py b/bot/modules/auth.py index a4755154..af6d35cf 100644 --- a/bot/modules/auth.py +++ b/bot/modules/auth.py @@ -13,25 +13,16 @@ def authorize(update, context): user_id = int(context.args[0]) elif reply_message: user_id = reply_message.from_user.id - if user_id: - if user_id in AUTHORIZED_USERS: - msg = 'Already authorized' - elif DATABASE_URL is not None: - msg = DatabaseHelper().auth_user(user_id) - AUTHORIZED_USERS.add(user_id) - else: - AUTHORIZED_USERS.add(user_id) - msg = 'Authorization granted' else: - chat_id = update.effective_chat.id - if chat_id in AUTHORIZED_USERS: - msg = 'Already authorized' - elif DATABASE_URL is not None: - msg = DatabaseHelper().auth_user(chat_id) - AUTHORIZED_USERS.add(chat_id) - else: - AUTHORIZED_USERS.add(chat_id) - msg = 'Authorization granted' + user_id = update.effective_chat.id + if user_id in AUTHORIZED_USERS: + msg = 'Already authorized' + elif DATABASE_URL is not None: + msg = DatabaseHelper().auth_user(user_id) + AUTHORIZED_USERS.add(user_id) + else: + AUTHORIZED_USERS.add(user_id) + msg = 'Authorization granted' sendMessage(msg, context.bot, update.message) def unauthorize(update, context): @@ -41,39 +32,30 @@ def unauthorize(update, context): user_id = int(context.args[0]) elif reply_message: user_id = reply_message.from_user.id - if user_id: - if user_id in AUTHORIZED_USERS: - if DATABASE_URL is not None: - msg = DatabaseHelper().unauth_user(user_id) - else: - msg = 'Authorization revoked' - AUTHORIZED_USERS.remove(user_id) - else: - msg = 'Already unauthorized' else: - chat_id = update.effective_chat.id - if chat_id in AUTHORIZED_USERS: - if DATABASE_URL is not None: - msg = DatabaseHelper().unauth_user(chat_id) - else: - msg = 'Authorization revoked' - AUTHORIZED_USERS.remove(chat_id) + user_id = update.effective_chat.id + if user_id in AUTHORIZED_USERS: + if DATABASE_URL is not None: + msg = DatabaseHelper().unauth_user(user_id) else: - msg = 'Already unauthorized' + msg = 'Authorization revoked' + AUTHORIZED_USERS.remove(user_id) + else: + msg = 'Already unauthorized' sendMessage(msg, context.bot, update.message) def auth_users(update, context): users = '' - users += '\n'.join(f"{user}" for user in AUTHORIZED_USERS) + users += 'None' if len(AUTHORIZED_USERS) == 0 else '\n'.join(f'{user}' for user in AUTHORIZED_USERS) msg = f'Authorized Users\n{users}' sendMessage(msg, context.bot, update.message) authorize_handler = CommandHandler(BotCommands.AuthorizeCommand, authorize, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) unauthorize_handler = CommandHandler(BotCommands.UnauthorizeCommand, unauthorize, - filters=CustomFilters.owner_filter, run_async=True) -auth_handler = CommandHandler(BotCommands.UsersCommand, auth_users, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) +users_handler = CommandHandler(BotCommands.UsersCommand, auth_users, + filters=CustomFilters.owner_filter) dispatcher.add_handler(authorize_handler) dispatcher.add_handler(unauthorize_handler) -dispatcher.add_handler(auth_handler) +dispatcher.add_handler(users_handler) diff --git a/bot/modules/bookmark.py b/bot/modules/bookmark.py new file mode 100644 index 00000000..42e72bb8 --- /dev/null +++ b/bot/modules/bookmark.py @@ -0,0 +1,64 @@ +from telegram.ext import CommandHandler + +from bot import dispatcher, BOOKMARKS, DATABASE_URL +from bot.helper.telegram_helper.bot_commands import BotCommands +from bot.helper.telegram_helper.filters import CustomFilters +from bot.helper.telegram_helper.message_utils import sendMessage +from bot.helper.ext_utils.database import DatabaseHelper + +def addbookmark(update, context): + args = update.message.text.split() + drive_key = '' + drive_id = '' + if len(args) > 2: + drive_key = args[1].strip() + drive_id = args[2].strip() + else: + sendMessage("Send a Drive Key and a Drive ID along with command", context.bot, update.message) + return + if drive_key in BOOKMARKS: + msg = 'Already added bookmark' + elif DATABASE_URL is not None: + msg = DatabaseHelper().add_bm(drive_key, drive_id) + BOOKMARKS[drive_key] = drive_id + else: + BOOKMARKS[drive_key] = drive_id + msg = 'Bookmark added' + sendMessage(msg, context.bot, update.message) + +def rembookmark(update, context): + args = update.message.text.split() + drive_key = '' + if len(args) > 1: + drive_key = args[1].strip() + else: + sendMessage("Send a Drive Key along with command", context.bot, update.message) + return + if drive_key in BOOKMARKS: + if DATABASE_URL is not None: + msg = DatabaseHelper().remove_bm(drive_key) + else: + msg = 'Bookmark removed' + del BOOKMARKS[drive_key] + else: + msg = 'Already removed bookmark' + sendMessage(msg, context.bot, update.message) + +def bookmarks(update, context): + drive_keys = '' + if len(BOOKMARKS) == 0: + drive_keys += 'None' + else: + drive_keys += '\n'.join(f'• {drive_key} - {BOOKMARKS[drive_key]}' for drive_key in BOOKMARKS) + msg = f'Bookmarks\n{drive_keys}' + sendMessage(msg, context.bot, update.message) + +addbm_handler = CommandHandler(BotCommands.AddBookmarkCommand, addbookmark, + filters=CustomFilters.owner_filter) +rembm_handler = CommandHandler(BotCommands.RemBookmarkCommand, rembookmark, + filters=CustomFilters.owner_filter) +bookmarks_handler = CommandHandler(BotCommands.BookmarksCommand, bookmarks, + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) +dispatcher.add_handler(addbm_handler) +dispatcher.add_handler(rembm_handler) +dispatcher.add_handler(bookmarks_handler) diff --git a/bot/modules/cancel.py b/bot/modules/cancel.py index 05f79ca1..58afcc32 100644 --- a/bot/modules/cancel.py +++ b/bot/modules/cancel.py @@ -33,5 +33,5 @@ def cancelNode(update, context): dl.download().cancel_task() cancel_handler = CommandHandler(BotCommands.CancelCommand, cancelNode, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) dispatcher.add_handler(cancel_handler) diff --git a/bot/modules/clone.py b/bot/modules/clone.py index 7b7a9210..e06c3919 100644 --- a/bot/modules/clone.py +++ b/bot/modules/clone.py @@ -3,13 +3,13 @@ from telegram.ext import CommandHandler -from bot import LOGGER, dispatcher, CLONE_LIMIT, download_dict, download_dict_lock, Interval +from bot import LOGGER, dispatcher, Interval, BOOKMARKS, CLONE_LIMIT, download_dict, download_dict_lock from bot.helper.download_utils.ddl_generator import gdtot from bot.helper.drive_utils.gdriveTools import GoogleDriveHelper from bot.helper.ext_utils.bot_utils import new_thread, get_readable_file_size, is_gdrive_link, is_gdtot_link from bot.helper.ext_utils.exceptions import DDLExceptionHandler from bot.helper.status_utils.clone_status import CloneStatus -from bot.helper.telegram_helper.message_utils import sendMessage, editMessage, deleteMessage, delete_all_messages, \ +from bot.helper.telegram_helper.message_utils import sendMessage, deleteMessage, delete_all_messages, \ update_all_messages, sendStatusMessage from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.filters import CustomFilters @@ -19,17 +19,20 @@ def cloneNode(update, context): args = update.message.text.split() reply_to = update.message.reply_to_message link = '' + key = '' dest_id = '' if len(args) > 1: link = args[1].strip() try: - dest_id = args[2].strip() + key = args[2].strip() + dest_id = BOOKMARKS[key] except IndexError: pass if reply_to: link = reply_to.text.split(maxsplit=1)[0].strip() try: - dest_id = args[1].strip() + key = args[1].strip() + dest_id = BOOKMARKS[key] except IndexError: pass is_gdtot = is_gdtot_link(link) @@ -94,5 +97,5 @@ def cloneNode(update, context): sendMessage(help_msg, context.bot, update.message) clone_handler = CommandHandler(BotCommands.CloneCommand, cloneNode, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) dispatcher.add_handler(clone_handler) diff --git a/bot/modules/count.py b/bot/modules/count.py index 2b3e1f42..d659ae32 100644 --- a/bot/modules/count.py +++ b/bot/modules/count.py @@ -26,5 +26,5 @@ def countNode(update, context): sendMessage("Send a Drive link along with command", context.bot, update.message) count_handler = CommandHandler(BotCommands.CountCommand, countNode, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) dispatcher.add_handler(count_handler) diff --git a/bot/modules/delete.py b/bot/modules/delete.py index 17f86374..590d36d4 100644 --- a/bot/modules/delete.py +++ b/bot/modules/delete.py @@ -26,5 +26,5 @@ def deleteNode(update, context): sendMessage("Send a Drive link along with command", context.bot, update.message) delete_handler = CommandHandler(BotCommands.DeleteCommand, deleteNode, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) dispatcher.add_handler(delete_handler) diff --git a/bot/modules/eval.py b/bot/modules/eval.py index 8635641f..6a9f8ac0 100644 --- a/bot/modules/eval.py +++ b/bot/modules/eval.py @@ -102,11 +102,11 @@ def clear(update, context): send("Cleared locals", bot, update) eval_handler = CommandHandler(BotCommands.EvalCommand, evaluate, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) exec_handler = CommandHandler(BotCommands.ExecCommand, execute, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) clear_handler = CommandHandler(BotCommands.ClearLocalsCommand, clear, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) dispatcher.add_handler(eval_handler) dispatcher.add_handler(exec_handler) diff --git a/bot/modules/list.py b/bot/modules/list.py index 83306090..02b3030c 100644 --- a/bot/modules/list.py +++ b/bot/modules/list.py @@ -31,5 +31,5 @@ def list_drive(update, context): sendMessage(help_msg, context.bot, update.message) list_handler = CommandHandler(BotCommands.ListCommand, list_drive, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) dispatcher.add_handler(list_handler) diff --git a/bot/modules/permission.py b/bot/modules/permission.py index 123424ff..277927f5 100644 --- a/bot/modules/permission.py +++ b/bot/modules/permission.py @@ -36,5 +36,5 @@ def permissionNode(update, context): sendMessage("Send a Drive link along with command", context.bot, update.message) permission_handler = CommandHandler(BotCommands.PermissionCommand, permissionNode, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) dispatcher.add_handler(permission_handler) diff --git a/bot/modules/shell.py b/bot/modules/shell.py index c6428ddf..c3181af1 100644 --- a/bot/modules/shell.py +++ b/bot/modules/shell.py @@ -28,13 +28,13 @@ def shell(update, context): context.bot.send_document( document=doc, filename=doc.name, - reply_to_message_id=message.message_id, - chat_id=message.chat_id) + chat_id=message.chat_id, + reply_to_message_id=message.message_id) elif len(reply) != 0: message.reply_text(reply, parse_mode='HTML') else: message.reply_text('Command executed', parse_mode='HTML') shell_handler = CommandHandler(BotCommands.ShellCommand, shell, - filters=CustomFilters.owner_filter, run_async=True) + filters=CustomFilters.owner_filter) dispatcher.add_handler(shell_handler) diff --git a/bot/modules/status.py b/bot/modules/status.py index 8c2dc201..b335d7d2 100644 --- a/bot/modules/status.py +++ b/bot/modules/status.py @@ -25,5 +25,5 @@ def statusNode(update, context): Interval.append(SetInterval(STATUS_UPDATE_INTERVAL, update_all_messages)) status_handler = CommandHandler(BotCommands.StatusCommand, statusNode, - filters=CustomFilters.authorized_user | CustomFilters.authorized_chat, run_async=True) + filters=CustomFilters.authorized_user | CustomFilters.authorized_chat) dispatcher.add_handler(status_handler)