if chat_id in AUTHORIZED_CHATS: AUTHORIZED_CHATS.remove(chat_id) msg = 'Chat unauthorized' else: msg = 'Already unauthorized chat' else: # Trying to authorize someone in specific user_id = reply_message.from_user.id if user_id in AUTHORIZED_CHATS: AUTHORIZED_CHATS.remove(user_id) msg = 'Person unauthorized to use the bot!' else: msg = 'Person already unauthorized!' with open('authorized_chats.txt', 'a') as file: file.truncate(0) for i in AUTHORIZED_CHATS: file.write(f'{i}\n') sendMessage(msg, context.bot, update) authorize_handler = CommandHandler(command=BotCommands.AuthorizeCommand, callback=authorize, filters=CustomFilters.owner_filter & Filters.group) unauthorize_handler = CommandHandler(command=BotCommands.UnAuthorizeCommand, callback=unauthorize, filters=CustomFilters.owner_filter & Filters.group) dispatcher.add_handler(authorize_handler) dispatcher.add_handler(unauthorize_handler)
except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, isTar, tag, extract) ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) def mirror(update, context): _mirror(context.bot, update) def tar_mirror(update, context): _mirror(context.bot, update, isTar=True) def unzip_mirror(update, context): _mirror(context.bot, update, extract=True) mirror_handler = CommandHandler(BotCommands.MirrorCommand, mirror, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) tar_mirror_handler = CommandHandler(BotCommands.TarMirrorCommand, tar_mirror, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) unzip_mirror_handler = CommandHandler(BotCommands.UnzipMirrorCommand, unzip_mirror, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) dispatcher.add_handler(mirror_handler) dispatcher.add_handler(tar_mirror_handler) dispatcher.add_handler(unzip_mirror_handler)
from tgmb.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper from tgmb.helper.telegram_helper.message_utils import * from tgmb.helper.telegram_helper.filters import CustomFilters from tgmb.helper.telegram_helper.bot_commands import BotCommands from tgmb import dispatcher def cloneNode(update, context): args = update.message.text.split(" ", maxsplit=1) if len(args) > 1: link = args[1] msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update) gd = GoogleDriveHelper() result, button = gd.clone(link) deleteMessage(context.bot, msg) if button == "": sendMessage(result, context.bot, update) else: sendMarkup(result, context.bot, update, button) else: sendMessage("Provide G-Drive Shareable Link to Clone.", context.bot, update) clone_handler = CommandHandler(BotCommands.CloneCommand, cloneNode, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) dispatcher.add_handler(clone_handler)
from telegram.ext import CommandHandler from tgmb import dispatcher, status_reply_dict, DOWNLOAD_STATUS_UPDATE_INTERVAL, status_reply_dict_lock from tgmb.helper.telegram_helper.message_utils import * from time import sleep from tgmb.helper.ext_utils.bot_utils import get_readable_message from telegram.error import BadRequest from tgmb.helper.telegram_helper.filters import CustomFilters from tgmb.helper.telegram_helper.bot_commands import BotCommands import threading def mirror_status(update, context): message = get_readable_message() if len(message) == 0: message = "No active downloads" 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 with status_reply_dict_lock: if index in status_reply_dict.keys(): deleteMessage(bot, status_reply_dict[index]) del status_reply_dict[index] sendStatusMessage(update, context.bot) deleteMessage(context.bot, update.message) mirror_status_handler = CommandHandler(BotCommands.StatusCommand, mirror_status, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) dispatcher.add_handler(mirror_status_handler)
def list_drive(update, context): if update.message.text == f'/{BotCommands.ListCommand}': sendMessage( f'Send a search key along with {BotCommands.ListCommand} command', context.bot, update) else: search = update.message.text.split(' ', maxsplit=1)[1] LOGGER.info(f"Searching: '{search}'...") reply = sendMessage('Searching.....\nPlease Wait!', context.bot, update) gdrive = GoogleDriveHelper(None) msg, button = gdrive.drive_list(search) if msg: if button: editMessage(msg, reply, button) else: editMessage(msg, reply) else: editMessage('No results found', reply) # if not USE_TELEGRAPH: # threading.Thread(target=auto_delete_message, args=(context.bot, update.message, reply)).start() list_handler = CommandHandler(BotCommands.ListCommand, list_drive, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) dispatcher.add_handler(list_handler)
sendMessage("Upload in Progress, Don't Cancel it.", context.bot, update) return elif dl.status() == "Archiving": sendMessage("Archival in Progress, Don't Cancel it.", context.bot, update) return else: dl.download().cancel_download() sleep(1) # Wait a Second For Aria2 To free Resources. clean_download(f'{DOWNLOAD_DIR}{mirror_message.message_id}/') @run_async def cancel_all(update, context): with download_dict_lock: count = 0 for dlDetails in list(download_dict.values()): if dlDetails.status() == MirrorStatus.STATUS_DOWNLOADING \ or dlDetails.status() == MirrorStatus.STATUS_WAITING: dlDetails.download().cancel_download() count += 1 delete_all_messages() sendMessage(f'Cancelled {count} downloads!', context.bot, update) cancel_mirror_handler = CommandHandler(BotCommands.CancelMirrorCommand, cancel_mirror, filters=(CustomFilters.authorized_chat | CustomFilters.authorized_user) & CustomFilters.mirror_owner_filter) cancel_all_handler = CommandHandler(BotCommands.CancelAllCommand, cancel_all, filters=CustomFilters.owner_filter) dispatcher.add_handler(cancel_all_handler) dispatcher.add_handler(cancel_mirror_handler)
from tgmb.helper.telegram_helper.filters import CustomFilters from tgmb.helper.telegram_helper.bot_commands import BotCommands from tgmb.helper.mirror_utils.upload_utils import gdriveTools @run_async def deletefile(update, context): msg_args = update.message.text.split(None, 1) msg = '' try: link = msg_args[1] LOGGER.info(msg_args[1]) except IndexError: msg = 'send a link along with command' if msg == '': drive = gdriveTools.GoogleDriveHelper() msg = drive.deletefile(link) LOGGER.info(f"this is msg : {msg}") reply_message = sendMessage(msg, context.bot, update) threading.Thread(target=auto_delete_message, args=(context.bot, update.message, reply_message)).start() delete_handler = CommandHandler(command=BotCommands.DeleteCommand, callback=deletefile, filters=CustomFilters.owner_filter) dispatcher.add_handler(delete_handler)