def cloneNode(update, context): args = update.message.text.split(" ", maxsplit=1) if len(args) > 1: link = args[1] gd = gdriveTools.GoogleDriveHelper() res, size, name, files = gd.clonehelper(link) if res != "": sendMessage(res, context.bot, update) return if STOP_DUPLICATE: LOGGER.info('Checking File/Folder if already in Drive...') smsg, button = gd.drive_list(name) if smsg: msg3 = "File/Folder is already available in Drive.\nHere are the search results:" sendMarkup(msg3, context.bot, update, button) return if CLONE_LIMIT is not None: result = check_limit(size, CLONE_LIMIT) if result: msg2 = f'Failed, Clone limit is {CLONE_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}.' sendMessage(msg2, context.bot, update) return if files < 15: msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update) result, button = gd.clone(link) deleteMessage(context.bot, msg) else: drive = gdriveTools.GoogleDriveHelper(name) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) clone_status = CloneStatus(drive, size, update, gid) with download_dict_lock: download_dict[update.message.message_id] = clone_status sendStatusMessage(update, context.bot) result, button = drive.clone(link) with download_dict_lock: del download_dict[update.message.message_id] count = len(download_dict) try: if count == 0: Interval[0].cancel() del Interval[0] delete_all_messages() else: update_all_messages() except IndexError: pass 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}' men = f'{uname} ' if button in ["cancelled", ""]: sendMessage(men + result, context.bot, update) else: sendMarkup(result + cc, context.bot, update, button) else: sendMessage('Provide G-Drive Shareable Link to Clone.', context.bot, update)
def cloneNode(update, context): args = update.message.text.split(" ", maxsplit=1) reply_to = update.message.reply_to_message if len(args) > 1: link = args[1] if update.message.from_user.username: tag = f"@{update.message.from_user.username}" else: tag = update.message.from_user.mention_html( update.message.from_user.first_name) elif reply_to is not None: link = reply_to.text if reply_to.from_user.username: tag = f"@{reply_to.from_user.username}" else: tag = reply_to.from_user.mention_html( reply_to.from_user.first_name) else: link = '' gdtot_link = is_gdtot_link(link) if gdtot_link: try: msg = sendMessage(f"Processing: <code>{link}</code>", context.bot, update) link = gdtot(link) deleteMessage(context.bot, msg) except DirectDownloadLinkException as e: deleteMessage(context.bot, msg) return sendMessage(str(e), context.bot, update) if is_gdrive_link(link): gd = GoogleDriveHelper() res, size, name, files = gd.helper(link) if res != "": return sendMessage(res, context.bot, update) if STOP_DUPLICATE: LOGGER.info('Checking File/Folder if already in Drive...') smsg, button = gd.drive_list(name, True, True) if smsg: msg3 = "File/Folder is already available in Drive.\nHere are the search results:" sendMarkup(msg3, context.bot, update, button) if gdtot_link: gd.deletefile(link) return if CLONE_LIMIT is not None: LOGGER.info('Checking File/Folder Size...') if size > CLONE_LIMIT * 1024**3: msg2 = f'Failed, Clone limit is {CLONE_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(size)}.' return sendMessage(msg2, context.bot, update) if files <= 10: msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update) result, button = gd.clone(link) deleteMessage(context.bot, msg) else: drive = GoogleDriveHelper(name) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) clone_status = CloneStatus(drive, size, update, gid) with download_dict_lock: download_dict[update.message.message_id] = clone_status sendStatusMessage(update, context.bot) result, button = drive.clone(link) with download_dict_lock: del download_dict[update.message.message_id] count = len(download_dict) try: if count == 0: Interval[0].cancel() del Interval[0] delete_all_messages() else: update_all_messages() except IndexError: pass cc = f'\n\n<b>cc: </b>{tag}' if button in ["cancelled", ""]: sendMessage(f"{tag} {result}", context.bot, update) else: sendMarkup(result + cc, context.bot, update, button) if gdtot_link: gd.deletefile(link) else: sendMessage( 'Send Gdrive or gdtot link along with command or by replying to the link by command', context.bot, update)
def cloneNode(update, context): args = update.message.text.split(" ", maxsplit=1) if len(args) > 1: link = args[1] gd = gdriveTools.GoogleDriveHelper() res, clonesize, name, files = gd.clonehelper(link) if res != "": sendMessage(res, context.bot, update) return if STOP_DUPLICATE_CLONE: LOGGER.info(f"Checking File/Folder if already in Drive...") smsg, button = gd.drive_list(name) if smsg: msg3 = "File/Folder is already available in Drive.\nHere are the search results:" sendMarkup(msg3, context.bot, update, button) return if CLONE_LIMIT is not None: LOGGER.info(f"Checking File/Folder Size...") limit = CLONE_LIMIT limit = limit.split(' ', maxsplit=1) limitint = int(limit[0]) msg2 = f'Failed, Clone limit is {CLONE_LIMIT}.\nYour File/Folder size is {get_readable_file_size(clonesize)}.' if 'G' in limit[1] or 'g' in limit[1]: if clonesize > limitint * 1024**3: sendMessage(msg2, context.bot, update) return elif 'T' in limit[1] or 't' in limit[1]: if clonesize > limitint * 1024**4: sendMessage(msg2, context.bot, update) return if files < 15: msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update) result, button = gd.clone(link) deleteMessage(context.bot, msg) else: drive = gdriveTools.GoogleDriveHelper(name) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) clone_status = CloneStatus(drive, clonesize, update, gid) with download_dict_lock: download_dict[update.message.message_id] = clone_status if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) sendStatusMessage(update, context.bot) result, button = drive.clone(link) 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}' men = f'{uname} ' if button == "cancelled": sendMessage(men + result, context.bot, update) elif button == "": sendMessage(men + result, context.bot, update) else: sendMarkup(result + cc, context.bot, update, button) try: with download_dict_lock: del download_dict[update.message.message_id] count = len(download_dict) if count == 0: Interval[0].cancel() del Interval[0] delete_all_messages() else: update_all_messages() except IndexError, KeyError: pass