From d28ae9cc4101284b11f8bda22daff2f512d1884a Mon Sep 17 00:00:00 2001
From: Levi <57452819+l3v11@users.noreply.github.com>
Date: Tue, 13 Sep 2022 21:09:20 +0600
Subject: [PATCH] Fix bot getting stuck while cloning folders
- This fixes an issue where the bot was getting stuck when authorizing with token.json file while cloning folders having 20+ files
- Rename compress module to archive module
- Change the compression data command of archive module from /archive to /compress
- Tidy up
---
README.md | 7 ++-
bot/__init__.py | 8 +--
bot/__main__.py | 4 +-
bot/helper/download_utils/gd_downloader.py | 8 +--
bot/helper/drive_utils/gdriveTools.py | 19 +++----
bot/helper/ext_utils/bot_utils.py | 2 +-
bot/helper/ext_utils/exceptions.py | 2 +-
bot/helper/ext_utils/fs_utils.py | 6 +-
.../{archive_status.py => compress_status.py} | 8 +--
bot/helper/status_utils/extract_status.py | 2 +-
bot/helper/telegram_helper/bot_commands.py | 2 +-
bot/helper/telegram_helper/message_utils.py | 24 ++++----
bot/modules/{compress.py => archive.py} | 56 +++++++++----------
bot/modules/auth.py | 12 ++--
bot/modules/clone.py | 6 +-
bot/modules/list.py | 4 +-
config_sample.env | 2 +-
17 files changed, 86 insertions(+), 86 deletions(-)
rename bot/helper/status_utils/{archive_status.py => compress_status.py} (88%)
rename bot/modules/{compress.py => archive.py} (86%)
diff --git a/README.md b/README.md
index ef6b25ab..7c595b20 100644
--- a/README.md
+++ b/README.md
@@ -18,12 +18,13 @@ SearchX is a multipurpose Telegram bot written in Python for Google Drive
- Search data in Google Drive
- Clone data from Google Drive, AppDrive and GDToT
-- Archive data from Google Drive, AppDrive and GDToT
+- Compress data from Google Drive, AppDrive and GDToT
- Extract data from Google Drive, AppDrive and GDToT
- Count data from Google Drive
- Delete data from Google Drive
- Set data permission in Google Drive
-- Size Limit support for Clone, Archive and Extraction tasks
+- Size Limit support for Clone, Compression and Extraction tasks
+- Destination change support for Clone tasks
- MongoDB support for storing the list of authorized users
- Index Link support
- Multi-token telegraph support
@@ -54,7 +55,7 @@ This list of commands is supported by the bot
start - Start the bot
find - Search data in Google Drive
clone - Clone data to Google Drive
-archive - Archive data to Google Drive
+compress - Compress data to Google Drive
extract - Extract data to Google Drive
count - Count data from Google Drive
cancel - Cancel a task
diff --git a/bot/__init__.py b/bot/__init__.py
index b566a488..bbf12f8b 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -151,12 +151,12 @@ def get_config(name: str):
CLONE_LIMIT = None
try:
- COMPRESS_LIMIT = get_config('COMPRESS_LIMIT')
- if len(COMPRESS_LIMIT) == 0:
+ ARCHIVE_LIMIT = get_config('ARCHIVE_LIMIT')
+ if len(ARCHIVE_LIMIT) == 0:
raise KeyError
- COMPRESS_LIMIT = float(COMPRESS_LIMIT)
+ ARCHIVE_LIMIT = float(ARCHIVE_LIMIT)
except:
- COMPRESS_LIMIT = None
+ ARCHIVE_LIMIT = None
try:
TOKEN_JSON_URL = get_config('TOKEN_JSON_URL')
diff --git a/bot/__main__.py b/bot/__main__.py
index f7c83a8e..002d17a5 100644
--- a/bot/__main__.py
+++ b/bot/__main__.py
@@ -7,7 +7,7 @@
from telegram.ext import CommandHandler
from bot import bot, LOGGER, botStartTime, AUTHORIZED_CHATS, TELEGRAPH, Interval, dispatcher, updater
-from bot.modules import auth, cancel, clone, compress, count, delete, eval, list, permission, shell, status
+from bot.modules import archive, auth, 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
@@ -72,7 +72,7 @@ def restart(update, context):
• /{BotCommands.CloneCommand} <url> <dest_id>: Clone data from Google Drive, AppDrive and GDToT (Destination ID optional)
-• /{BotCommands.ArchiveCommand} <url>: Archive data from Google Drive, AppDrive and GDToT
+• /{BotCommands.CompressCommand} <url>: Compress data from Google Drive, AppDrive and GDToT
• /{BotCommands.ExtractCommand} <url>: Extract data from Google Drive, AppDrive and GDToT
diff --git a/bot/helper/download_utils/gd_downloader.py b/bot/helper/download_utils/gd_downloader.py
index 567013f3..a4eab4d0 100644
--- a/bot/helper/download_utils/gd_downloader.py
+++ b/bot/helper/download_utils/gd_downloader.py
@@ -1,7 +1,7 @@
import random
import string
-from bot import LOGGER, COMPRESS_LIMIT, download_dict, download_dict_lock
+from bot import LOGGER, ARCHIVE_LIMIT, download_dict, download_dict_lock
from bot.helper.drive_utils.gdriveTools import GoogleDriveHelper
from bot.helper.status_utils.download_status import DownloadStatus
from bot.helper.telegram_helper.message_utils import sendMessage, deleteMessage, sendStatusMessage
@@ -17,11 +17,11 @@ def add_gd_download(link, path, listener, customname, is_appdrive, appdict, is_g
return sendMessage(res, listener.bot, listener.message)
if customname:
name = customname
- if COMPRESS_LIMIT is not None:
- if size > COMPRESS_LIMIT * 1024**3:
+ if ARCHIVE_LIMIT is not None:
+ if size > ARCHIVE_LIMIT * 1024**3:
msg2 = f"Name: {name}
"
msg2 += f"\nSize: {get_readable_file_size(size)}"
- msg2 += f"\nLimit: {COMPRESS_LIMIT} GB"
+ msg2 += f"\nLimit: {ARCHIVE_LIMIT} GB"
msg2 += "\n\n⚠️ Task failed"
return sendMessage(msg2, listener.bot, listener.message)
LOGGER.info(f"Downloading: {name}")
diff --git a/bot/helper/drive_utils/gdriveTools.py b/bot/helper/drive_utils/gdriveTools.py
index 0d115043..f639df97 100644
--- a/bot/helper/drive_utils/gdriveTools.py
+++ b/bot/helper/drive_utils/gdriveTools.py
@@ -432,7 +432,7 @@ def clone(self, link, dest_id):
token_service = self.__alt_authorize()
if token_service is not None:
self.__service = token_service
- return self.clone(link, key)
+ return self.clone(link, dest_id)
msg = "File not found"
else:
msg = err
@@ -591,7 +591,7 @@ def upload(self, file_name: str):
if isinstance(err, RetryError):
LOGGER.info(f"Total attempts: {err.last_attempt.attempt_number}")
err = err.last_attempt.exception()
- self.__listener.onUploadError(str(err))
+ self.__listener.onUploadError(err)
self.__is_errored = True
finally:
self.__updater.cancel()
@@ -724,9 +724,9 @@ def __create_page(self, acc, content):
author_name="Levi",
author_url="https://t.me/l3v11",
html_content=content)['path'])
- except RetryAfterError as e:
- LOGGER.info(f"Cooldown: {e.retry_after} seconds")
- time.sleep(e.retry_after)
+ except RetryAfterError as err:
+ LOGGER.info(f"Cooldown: {err.retry_after} seconds")
+ time.sleep(err.retry_after)
self.__create_page(acc, content)
def __edit_page(self, acc, content, path):
@@ -737,13 +737,12 @@ def __edit_page(self, acc, content, path):
author_name="Levi",
author_url="https://t.me/l3v11",
html_content=content)
- except RetryAfterError as e:
- LOGGER.info(f"Cooldown: {e.retry_after} seconds")
- time.sleep(e.retry_after)
+ except RetryAfterError as err:
+ LOGGER.info(f"Cooldown: {err.retry_after} seconds")
+ time.sleep(err.retry_after)
self.__edit_page(acc, content, path)
def __receive_callback(self, request_id, response, exception):
- # request_id = order number of request = shared drive index (1 based)
if exception is not None:
exception = str(exception).replace('>', '').replace('<', '')
LOGGER.error(exception)
@@ -809,7 +808,7 @@ def drive_list(self, file_name):
msg = f'
{file.get('name')}
(folder){escape(name)}
'
msg += f'\nSize: {size}'
- msg += f'\nType: {typ}'
+ msg += f'\nType: {typ}'
if typ == "Folder":
msg += f'\nSubFolders: {folders}'
msg += f'\nFiles: {files}'
@@ -144,8 +144,8 @@ def onUploadComplete(self, link: str, size, files, folders, typ, name):
with download_dict_lock:
try:
del download_dict[self.uid]
- except Exception as e:
- LOGGER.error(str(e))
+ except Exception as err:
+ LOGGER.error(err)
count = len(download_dict)
if count == 0:
self.clean()
@@ -158,8 +158,8 @@ def onDownloadError(self, error):
with download_dict_lock:
try:
del download_dict[self.uid]
- except Exception as e:
- LOGGER.error(str(e))
+ except Exception as err:
+ LOGGER.error(err)
count = len(download_dict)
sendMessage(error, self.bot, self.message)
if count == 0:
@@ -173,8 +173,8 @@ def onUploadError(self, error):
with download_dict_lock:
try:
del download_dict[self.uid]
- except Exception as e:
- LOGGER.error(str(e))
+ except Exception as err:
+ LOGGER.error(err)
count = len(download_dict)
sendMessage(error, self.bot, self.message)
if count == 0:
@@ -182,7 +182,7 @@ def onUploadError(self, error):
else:
update_all_messages()
-def _compress(bot, message, is_archive=False, is_extract=False, pswd=None):
+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)
@@ -223,11 +223,11 @@ def _compress(bot, message, is_archive=False, is_extract=False, pswd=None):
if is_gdtot:
link = gdtot(link)
deleteMessage(bot, msg)
- except DDLExceptionHandler as e:
+ except DDLExceptionHandler as err:
deleteMessage(bot, msg)
- LOGGER.error(str(e))
- return sendMessage(str(e), bot, message)
- listener = CompressListener(bot, message, is_archive, is_extract, pswd)
+ LOGGER.error(err)
+ return sendMessage(str(err), bot, message)
+ listener = ArchiveListener(bot, message, is_compress, is_extract, pswd)
if is_gdrive_link(link):
threading.Thread(target=add_gd_download, args=(link, f'{DOWNLOAD_DIR}{listener.uid}', listener, name, is_appdrive, appdict, is_gdtot)).start()
else:
@@ -238,15 +238,15 @@ def _compress(bot, message, is_archive=False, is_extract=False, pswd=None):
sendMessage(help_msg, bot, message)
-def archive_data(update, context):
- _compress(context.bot, update.message, is_archive=True)
+def compress_data(update, context):
+ _archive(context.bot, update.message, is_compress=True)
def extract_data(update, context):
- _compress(context.bot, update.message, is_extract=True)
+ _archive(context.bot, update.message, is_extract=True)
-archive_handler = CommandHandler(BotCommands.ArchiveCommand, archive_data,
- filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)
+compress_handler = CommandHandler(BotCommands.CompressCommand, compress_data,
+ filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)
extract_handler = CommandHandler(BotCommands.ExtractCommand, extract_data,
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)
-dispatcher.add_handler(archive_handler)
+dispatcher.add_handler(compress_handler)
dispatcher.add_handler(extract_handler)
diff --git a/bot/modules/auth.py b/bot/modules/auth.py
index 65b76495..e13fbfbc 100644
--- a/bot/modules/auth.py
+++ b/bot/modules/auth.py
@@ -7,7 +7,7 @@
from bot.helper.ext_utils.database import DatabaseHelper
def authorize(update, context):
- user_id = ""
+ user_id = ''
reply_message = update.message.reply_to_message
if len(context.args) == 1:
user_id = int(context.args[0])
@@ -35,7 +35,7 @@ def authorize(update, context):
sendMessage(msg, context.bot, update.message)
def unauthorize(update, context):
- user_id = ""
+ user_id = ''
reply_message = update.message.reply_to_message
if len(context.args) == 1:
user_id = int(context.args[0])
@@ -62,17 +62,17 @@ def unauthorize(update, context):
msg = 'Already unauthorized'
sendMessage(msg, context.bot, update.message)
-def auth_chats(update, context):
+def auth_users(update, context):
users = ''
users += '\n'.join(f"{uid}
" for uid in AUTHORIZED_CHATS)
- msg = f'Authorized Chats\n{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)
unauthorize_handler = CommandHandler(BotCommands.UnauthorizeCommand, unauthorize,
- filters=CustomFilters.owner_filter, run_async=True)
-auth_handler = CommandHandler(BotCommands.UsersCommand, auth_chats,
+ filters=CustomFilters.owner_filter, run_async=True)
+auth_handler = CommandHandler(BotCommands.UsersCommand, auth_users,
filters=CustomFilters.owner_filter, run_async=True)
dispatcher.add_handler(authorize_handler)
dispatcher.add_handler(unauthorize_handler)
diff --git a/bot/modules/clone.py b/bot/modules/clone.py
index dacbbeb9..e992f0c1 100644
--- a/bot/modules/clone.py
+++ b/bot/modules/clone.py
@@ -45,10 +45,10 @@ def cloneNode(update, context):
if is_gdtot:
link = gdtot(link)
deleteMessage(context.bot, msg)
- except DDLExceptionHandler as e:
+ except DDLExceptionHandler as err:
deleteMessage(context.bot, msg)
- LOGGER.error(str(e))
- return sendMessage(str(e), context.bot, update.message)
+ LOGGER.error(err)
+ return sendMessage(str(err), context.bot, update.message)
if is_gdrive_link(link):
msg = sendMessage(f"Checking: {link}
", context.bot, update.message)
LOGGER.info(f"Checking: {link}")
diff --git a/bot/modules/list.py b/bot/modules/list.py
index 82d9c0d7..c70e5cd3 100644
--- a/bot/modules/list.py
+++ b/bot/modules/list.py
@@ -20,9 +20,9 @@ def list_drive(update, context):
gd = GoogleDriveHelper()
try:
msg, button = gd.drive_list(query)
- except Exception as e:
+ except Exception as err:
msg, button = "Internal error", None
- LOGGER.exception(e)
+ LOGGER.error(err)
editMessage(msg, reply, button)
else:
help_msg = 'Instructions\nSend a Query along with command'
diff --git a/config_sample.env b/config_sample.env
index e9411480..0f480668 100644
--- a/config_sample.env
+++ b/config_sample.env
@@ -12,7 +12,7 @@ STATUS_UPDATE_INTERVAL=
TELEGRAPH_ACCS=
INDEX_URL=
CLONE_LIMIT=
-COMPRESS_LIMIT=
+ARCHIVE_LIMIT=
TOKEN_JSON_URL=
ACCOUNTS_ZIP_URL=
DRIVE_LIST_URL=