clone limit option (#142)

This commit is contained in:
Anas 2021-06-08 02:05:36 +03:00 committed by GitHub
parent a5cadd222e
commit 5ec9688b12
Signed by untrusted user: GitHub
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 24 deletions

View File

@ -182,6 +182,12 @@ try:
INDEX_URL = None INDEX_URL = None
except KeyError: except KeyError:
INDEX_URL = None INDEX_URL = None
try:
CLONE_LIMIT = getConfig('CLONE_LIMIT')
if len(CLONE_LIMIT) == 0:
CLONE_LIMIT = None
except KeyError:
CLONE_LIMIT = None
try: try:
BUTTON_FOUR_NAME = getConfig('BUTTON_FOUR_NAME') BUTTON_FOUR_NAME = getConfig('BUTTON_FOUR_NAME')
BUTTON_FOUR_URL = getConfig('BUTTON_FOUR_URL') BUTTON_FOUR_URL = getConfig('BUTTON_FOUR_URL')

View File

@ -619,7 +619,7 @@ class GoogleDriveHelper:
file_id = self.getIdFromUrl(link) file_id = self.getIdFromUrl(link)
except (KeyError,IndexError): except (KeyError,IndexError):
msg = "Google drive ID could not be found in the provided link" msg = "Google drive ID could not be found in the provided link"
return msg return msg, ""
msg = "" msg = ""
LOGGER.info(f"File ID: {file_id}") LOGGER.info(f"File ID: {file_id}")
try: try:
@ -634,6 +634,7 @@ class GoogleDriveHelper:
msg += f'\n<b>Type: </b>Folder' msg += f'\n<b>Type: </b>Folder'
msg += f'\n<b>SubFolders: </b>{self.total_folders}' msg += f'\n<b>SubFolders: </b>{self.total_folders}'
msg += f'\n<b>Files: </b>{self.total_files}' msg += f'\n<b>Files: </b>{self.total_files}'
clonesizelimit = self.total_bytes
else: else:
msg += f'<b>Filename: </b><code>{name}</code>' msg += f'<b>Filename: </b><code>{name}</code>'
try: try:
@ -646,6 +647,7 @@ class GoogleDriveHelper:
msg += f'\n<b>Size: </b><code>{get_readable_file_size(self.total_bytes)}</code>' msg += f'\n<b>Size: </b><code>{get_readable_file_size(self.total_bytes)}</code>'
msg += f'\n<b>Type: </b>{typee}' msg += f'\n<b>Type: </b>{typee}'
msg += f'\n<b>Files: </b>{self.total_files}' msg += f'\n<b>Files: </b>{self.total_files}'
clonesizelimit = self.total_bytes
except TypeError: except TypeError:
pass pass
except Exception as err: except Exception as err:
@ -654,8 +656,12 @@ class GoogleDriveHelper:
err = err.last_attempt.exception() err = err.last_attempt.exception()
err = str(err).replace('>', '').replace('<', '') err = str(err).replace('>', '').replace('<', '')
LOGGER.error(err) LOGGER.error(err)
return err if "File not found" in str(err):
return msg msg = "File not found."
else:
msg = f"Error.\n{err}"
return msg, ""
return msg, clonesizelimit
def gDrive_file(self, **kwargs): def gDrive_file(self, **kwargs):
try: try:

View File

@ -1,33 +1,58 @@
from telegram.ext import CommandHandler from telegram.ext import CommandHandler, run_async
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
from bot.helper.telegram_helper.message_utils import * from bot.helper.telegram_helper.message_utils import sendMarkup, deleteMessage, sendMessage
from bot.helper.telegram_helper.filters import CustomFilters from bot.helper.telegram_helper.filters import CustomFilters
from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.ext_utils.bot_utils import new_thread from bot import dispatcher, CLONE_LIMIT
from bot import dispatcher
@new_thread @run_async
def cloneNode(update, context): def cloneNode(update, context):
args = update.message.text.split(" ", maxsplit=1) args = update.message.text.split(" ", maxsplit=1)
if update.message.from_user.username:
uname = f"@{update.message.from_user.username}"
else:
uname = f'<a href="tg://user?id={update.message.from_user.id}">{update.message.from_user.first_name}</a>'
if uname is not None:
cc = f'\n\ncc: {uname}'
if len(args) > 1: if len(args) > 1:
link = args[1] link = args[1]
msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update)
gd = GoogleDriveHelper() gd = GoogleDriveHelper()
if CLONE_LIMIT is not None:
mssg = sendMessage(f"Checking The Size...", context.bot, update)
limit = CLONE_LIMIT
limit = limit.split(' ', maxsplit=1)
limitint = int(limit[0])
res, clonesizelimit = gd.count(link)
if clonesizelimit != "":
msgg = f'Failed, clone limit is {CLONE_LIMIT}'
if 'GB' in limit or 'gb' in limit:
if clonesizelimit > limitint * 1024**3:
deleteMessage(context.bot, mssg)
sendMessage(msgg, context.bot, update)
return
else:
deleteMessage(context.bot, mssg)
elif 'TB' in limit or 'tb' in limit:
if clonesizelimit > limitint * 1024**4:
deleteMessage(context.bot, mssg)
sendMessage(msgg, context.bot, update)
return
else:
deleteMessage(context.bot, mssg)
else:
deleteMessage(context.bot, mssg)
sendMessage(res, context.bot, update)
return
msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update)
result, button = gd.clone(link) result, button = gd.clone(link)
deleteMessage(context.bot,msg) deleteMessage(context.bot, msg)
if button == "": if button == "":
sendMessage(result, context.bot, update) sendMessage(result, context.bot, update)
else: else:
if update.message.from_user.username:
uname = f'@{update.message.from_user.username}'
else:
uname = f'<a href="tg://user?id={update.message.from_user.id}">{update.message.from_user.first_name}</a>'
if uname is not None:
cc = f'\n\n#cc: {uname}'
sendMarkup(result + cc, context.bot, update, button) sendMarkup(result + cc, context.bot, update, button)
else: else:
sendMessage("Provide G-Drive Shareable Link to Clone.", context.bot, update) sendMessage('Provide G-Drive Shareable Link to Clone.', context.bot, update)
clone_handler = CommandHandler(BotCommands.CloneCommand, cloneNode, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user) clone_handler = CommandHandler(BotCommands.CloneCommand, cloneNode, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
dispatcher.add_handler(clone_handler) dispatcher.add_handler(clone_handler)

View File

@ -9,18 +9,18 @@ from bot import dispatcher
@run_async @run_async
def countNode(update, context): def countNode(update, context):
args = update.message.text.split(" ", maxsplit=1) args = update.message.text.split(" ", maxsplit=1)
if update.message.from_user.username:
uname = f"@{update.message.from_user.username}"
else:
uname = f'<a href="tg://user?id={update.message.from_user.id}">{update.message.from_user.first_name}</a>'
if uname is not None:
cc = f'\n\ncc: {uname}'
if len(args) > 1: if len(args) > 1:
link = args[1] link = args[1]
msg = sendMessage(f"Counting: <code>{link}</code>", context.bot, update) msg = sendMessage(f"Counting: <code>{link}</code>", context.bot, update)
gd = GoogleDriveHelper() gd = GoogleDriveHelper()
result = gd.count(link) result, empty = gd.count(link)
deleteMessage(context.bot, msg) deleteMessage(context.bot, msg)
if update.message.from_user.username:
uname = f'@{update.message.from_user.username}'
else:
uname = f'<a href="tg://user?id={update.message.from_user.id}">{update.message.from_user.first_name}</a>'
if uname is not None:
cc = f'\n\ncc: {uname}'
sendMessage(result + cc, context.bot, update) sendMessage(result + cc, context.bot, update)
else: else:
sendMessage("Provide G-Drive Shareable Link to Count.", context.bot, update) sendMessage("Provide G-Drive Shareable Link to Count.", context.bot, update)

View File

@ -25,6 +25,7 @@ BLOCK_MEGA_LINKS = ""
STOP_DUPLICATE_MIRROR = "" STOP_DUPLICATE_MIRROR = ""
SHORTENER = "" SHORTENER = ""
SHORTENER_API = "" SHORTENER_API = ""
CLONE_LIMIT = "" #leave space between number and unit (tb or gb only)
IMAGE_URL = "https://telegra.ph/file/db03910496f06094f1f7a.jpg" IMAGE_URL = "https://telegra.ph/file/db03910496f06094f1f7a.jpg"
# Change ENABLE_FILESIZE_LIMIT = True if you want to use MAX_TORRENT_SIZE # Change ENABLE_FILESIZE_LIMIT = True if you want to use MAX_TORRENT_SIZE
ENABLE_FILESIZE_LIMIT = false ENABLE_FILESIZE_LIMIT = false