Exemplo n.º 1
0
def restart(update, context):
    restart_message = sendMessage("Restarting, Please wait!", context.bot,
                                  update)
    # Save restart message ID and chat ID in order to edit it after restarting
    with open(".restartmsg", "w") as f:
        f.truncate(0)
        f.write(f"{restart_message.chat.id}\n{restart_message.message_id}\n")
    fs_utils.clean_all()
    os.execl(executable, executable, "-m", "bot")
Exemplo n.º 2
0
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..... Please 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)
Exemplo n.º 3
0
def _watch(bot: Bot, update: Update, args: list, isTar=False):
    try:
        link = args[0]
    except IndexError:
        sendMessage(
            f'/{BotCommands.WatchCommand} [yt_dl supported link] to mirror with youtube_dl',
            bot, update)
        return
    reply_to = update.message.reply_to_message
    tag = reply_to.from_user.username if reply_to is not None else None
    listener = MirrorListener(bot, update, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}')).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Exemplo n.º 4
0
def authorize(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        user_id = int(message_[1])
        if user_id in AUTHORIZED_CHATS:
            msg = 'User Already Authorized!'
        elif DB_URI is not None:
            msg = DbManger().user_auth(user_id)
            AUTHORIZED_CHATS.add(user_id)
        else:
            AUTHORIZED_CHATS.add(user_id)
            with open('authorized_chats.txt', 'a') as file:
                file.write(f'{user_id}\n')
                msg = 'User Authorized'
    elif reply_message is None:
        # Trying to authorize a chat
        chat_id = update.effective_chat.id
        if chat_id in AUTHORIZED_CHATS:
            msg = 'Chat Already Authorized!'
        elif DB_URI is not None:
            msg = DbManger().user_auth(chat_id)
            AUTHORIZED_CHATS.add(chat_id)
        else:
            AUTHORIZED_CHATS.add(chat_id)
            with open('authorized_chats.txt', 'a') as file:
                file.write(f'{chat_id}\n')
                msg = 'Chat Authorized'
    else:
        # Trying to authorize someone by replying
        user_id = reply_message.from_user.id
        if user_id in AUTHORIZED_CHATS:
            msg = 'User Already Authorized!'
        elif DB_URI is not None:
            msg = DbManger().user_auth(user_id)
            AUTHORIZED_CHATS.add(user_id)
        else:
            AUTHORIZED_CHATS.add(user_id)
            with open('authorized_chats.txt', 'a') as file:
                file.write(f'{user_id}\n')
                msg = 'User Authorized'
    sendMessage(msg, context.bot, update)
Exemplo n.º 5
0
def list_drive(update, context):
    try:
        file_paths = [
            os.path.join(DOWNLOAD_DIR, i) for i in os.listdir(DOWNLOAD_DIR)
        ]
        mes = ''.join([
            f'<code>{os.path.split(i)[-1]}</code> {get_FileSize(i)} {get_FileModifyTime(i)}\n'
            for i in file_paths
        ])
    except Exception as e:
        mes = None
    if mes:
        reply_message = sendMessage(mes, context.bot, update)
    else:
        reply_message = sendMessage('There is no file', context.bot, update)

    threading.Thread(target=auto_delete_message,
                     args=(context.bot, update.message,
                           reply_message)).start()
Exemplo n.º 6
0
def countNode(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    if len(args) > 1:
        link = args[1]
        msg = sendMessage(f"📚 Counting : <code>{link}</code>", context.bot,
                          update)
        gd = GoogleDriveHelper()
        result = gd.count(link)
        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\n👤 𝗖𝗼𝘂𝗻𝘁𝗲𝗿 : {uname}\n\n🔥 𝗣𝗿𝗶𝗶𝗶𝗶𝘆𝗼 𝗠𝗶𝗿𝗿𝗼𝗿 𝗭𝗼𝗻𝗘\n\n🔥 𝗚𝗿𝗼𝘂𝗽 : @PriiiiyoMirror\n\n▫️#Uploaded To Team Drive ✓ \n\n🚫 𝗗𝗼 𝗡𝗼𝘁 𝗦𝗵𝗮𝗿𝗲 𝗜𝗻𝗱𝗲𝘅 𝗟𝗶𝗻𝗸 \n\n✅ 𝗣𝗼𝘄𝗲𝗿𝗲𝗱 𝗕𝘆 : @PriiiiyoBOTs'
        sendMessage(result + cc, context.bot, update)
    else:
        sendMessage("Provide G-Drive Shareable Link to Count.", context.bot,
                    update)
Exemplo n.º 7
0
def unauthorize(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        user_id = int(message_[1])
        if user_id in AUTHORIZED_CHATS:
            if DB_URI is not None:
                msg = DbManger().db_unauth(user_id)
            else:
                AUTHORIZED_CHATS.remove(user_id)
                msg = '❎ User Unauthorized'
        else:
            msg = '❎ User Already Unauthorized'
    else:
        if reply_message is None:
            # Trying to unauthorize a chat
            chat_id = update.effective_chat.id
            if chat_id in AUTHORIZED_CHATS:
                if DB_URI is not None:
                    msg = DbManger().db_unauth(chat_id)
                else:
                    AUTHORIZED_CHATS.remove(chat_id)
                    msg = '❎ Chat Unauthorized'
            else:
                msg = '❎ Chat Already Unauthorized'
        else:
            # Trying to authorize someone by replying
            user_id = reply_message.from_user.id
            if user_id in AUTHORIZED_CHATS:
                if DB_URI is not None:
                    msg = DbManger().db_unauth(user_id)
                else:
                    AUTHORIZED_CHATS.remove(user_id)
                    msg = '❎ User Unauthorized'
            else:
                msg = '❎ User 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)
Exemplo n.º 8
0
def list_buttons(update, context):
    user_id = update.message.from_user.id
    if len(update.message.text.split(" ", maxsplit=1)) < 2:
        return sendMessage('Send a search key along with command', context.bot, update)
    buttons = button_build.ButtonMaker()
    buttons.sbutton("Drive Root", f"types {user_id} root")
    buttons.sbutton("Recursive", f"types {user_id} recu")
    buttons.sbutton("Cancel", f"types {user_id} cancel")
    button = InlineKeyboardMarkup(buttons.build_menu(2))
    sendMarkup('Choose option to list.', context.bot, update, button)
Exemplo n.º 9
0
def _watch(bot: Bot, update, isZip=False):
    mssg = update.message.text
    message_args = mssg.split(" ")
    name_args = mssg.split("|")
    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [yt_dl supported link] [quality] |[CustomName] to mirror with youtube_dl.\n\n"
        msg += "<b>Note :- Quality and custom name are optional</b>\n\nExample of quality :- audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\nIf you want to use custom filename, plz enter it after |"
        msg += f"\n\nExample :-\n<code>/{BotCommands.WatchCommand} https://youtu.be/ocX2FN1nguA 720 |My video bro</code>\n\n"
        msg += "This file will be downloaded in 720p quality and it's name will be <b>My video bro</b>"
        sendMessage(msg, bot, update)
        return
    try:
        if "|" in mssg:
            mssg = mssg.split("|")
            qual = mssg[0].split(" ")[2]
            if qual == "":
                raise IndexError
        else:
            qual = message_args[2]
        if qual != "audio":
            qual = f"bestvideo[height<={qual}]+bestaudio/best[height<={qual}]"
    except IndexError:
        qual = "bestvideo+bestaudio/best"
    try:
        name = name_args[1]
    except IndexError:
        name = ""
    reply_to = update.message.reply_to_message
    tag = reply_to.from_user.username if reply_to is not None else None
    pswd = ""
    listener = MirrorListener(bot, update, pswd, isZip, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(
        target=ydl.add_download,
        args=(link, f"{DOWNLOAD_DIR}{listener.uid}", qual, name),
    ).start()
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Exemplo n.º 10
0
def countNode(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    if len(args) > 1:
        link = args[1]
        msg = sendMessage(f"Counting: <code>{link}</code>", context.bot,
                          update)
        gd = GoogleDriveHelper()
        result = gd.count(link)
        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\n<b>cc:</b> {uname}'
        sendMessage(result + cc, context.bot, update)
    else:
        sendMessage("Provide G-Drive Shareable Link to Count.", context.bot,
                    update)
Exemplo n.º 11
0
def list_drive(update, context):
    try:
        search = update.message.text.split(' ', maxsplit=1)[1]
        LOGGER.info(f"Searching: {search}")
        reply = sendMessage('Searching..... Please wait!', context.bot, update)
        gdrive = GoogleDriveHelper(None)
        msg, button = gdrive.drive_list(search)

        if button:
            editMessage(msg, reply, button)
        else:
            editMessage(
                '😬Error!! Please Go To https://testing.bunny.workers.dev/0: To Search🤪',
                reply, button)

    except IndexError:
        sendMessage(
            '😬Error!! Please Go To https://testing.bunny.workers.dev/0: To Search🤪',
            context.bot, update)
Exemplo n.º 12
0
def _watch(bot: Bot, update, isTar=False):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|')
    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [yt_dl supported link] [quality] |[CustomName] to mirror with youtube_dl.\n\n"
        msg += "<b>Note :- Quality and custom name are optional</b>\n\nExample of quality :- audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\nIf you want to use custom filename, plz enter it after |"
        msg += f"\n\nExample :-\n<code>/{BotCommands.WatchCommand} https://youtu.be/Pk_TthHfLeE 720 |Slam</code>\n\n"
        msg += "This file will be downloaded in 720p quality and it's name will be <b>Slam</b>"
        sendMessage(msg, bot, update)
        return
    try:
      if "|" in mssg:
        mssg = mssg.split("|")
        qual = mssg[0].split(" ")[2]
        if qual == "":
          raise IndexError
      else:
        qual = message_args[2]
      if qual != "audio":
        qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
      qual = "bestvideo+bestaudio/best"
    try:
      name = name_args[1]
    except IndexError:
      name = ""
    reply_to = update.message.reply_to_message
    if reply_to is not None:
        tag = reply_to.from_user.username
    else:
        tag = None
    pswd = ""
    listener = MirrorListener(bot, update, pswd, isTar, tag)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual, name)).start()
    sendMessage(f"<b>★Your YTDL Link Has Been Added To Download Queue.\n☆ Obey Rules On Pinned Message To Avoid Being Banned.\n★ Check Status To See Current Progress</b> /{BotCommands.StatusCommand}", bot, update)
    if len(Interval) == 0:
        Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
Exemplo n.º 13
0
def list_drive(update, context):
    try:
        search = update.message.text.split(' ', maxsplit=1)[1]
        LOGGER.info(f"Searching: {search}")
        reply = sendMessage('<b>🔍Sᴇᴀʀᴄʜɪɴɢ...Pʟᴇᴀsᴇ Wᴀɪᴛ!</b>', context.bot,
                            update)
        gdrive = GoogleDriveHelper(None)
        msg, button = gdrive.drive_list(search)

        if button:
            editMessage(msg, reply, button)
        else:
            editMessage(
                '<b>➼Nᴏ Rᴇsᴜʟᴛs Fᴏᴜɴᴅ Fᴏʀ Yᴏᴜʀ Fɪʟᴇ Nᴀᴍᴇ Kᴇʏᴡᴏʀᴅ :(</b>',
                reply, button)

    except IndexError:
        sendMessage(
            '<b>➼Sᴇɴᴅ ᴀ Fɪʟᴇ Nᴀᴍᴇ As Kᴇʏᴡᴏʀᴅ Tᴏ Sᴇᴀʀᴄʜ., Aʟᴏɴɢ Wɪᴛʜ</b> <b>/list</b> <b>Cᴏᴍᴍᴀɴᴅ</b>',
            context.bot, update)
Exemplo n.º 14
0
Arquivo: list.py Projeto: TGExplore/td
def list_drive(update, context):
    try:
        search = update.message.text.split(' ', maxsplit=1)[1]
        if "'" in search:
            search = search.replace("'", "\\'")
    except IndexError:
        sendMessage(
            '<b>⛽Bᴏᴛ: ➼Sᴇɴᴅ ᴀ Fɪʟᴇ Kᴇʏᴡᴏʀᴅ Tᴏ Sᴇᴀʀᴄʜ, Aʟᴏɴɢ Wɪᴛʜ /search Cᴏᴍᴍᴀɴᴅ</b>',
            context.bot, update)
        return

    reply = sendMessage('<b>🔍Sᴇᴀʀᴄʜɪɴɢ...Pʟᴇᴀsᴇ Wᴀɪᴛ!</b>', context.bot,
                        update)

    LOGGER.info(f"Searching: {search}")

    gdrive = GoogleDriveHelper(None)
    msg, button = gdrive.drive_list(search)

    editMessage(msg, reply, button)
Exemplo n.º 15
0
def mirrorcf(update, context):

    bot = context.bot
    message_args = update.message.text.split(' ')
    try:
        link = message_args[1]
    except IndexError:
        link = ''

    LOGGER.info(link)
    link = link.strip()
    tag = None
    if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
        sendMessage('No download source provided', bot, update)
        return

    parsed_link = urlparse(link)
    headers = {"Content-Type": "application/json"}
    data = {
        "cmd": "request.get",
        "url": f"{parsed_link.scheme}://{parsed_link.netloc}",
        "maxTimeout": 60000
    }
    r = requests.post('http://localhost:8191/v1', headers=headers, json=data)
    solution = r.json()['solution']
    cf_clearance = solution['cookies'][0]
    cookie_string = f"{cf_clearance['name']}={cf_clearance['value']};"

    aria_options = {
        "header": f"Cookie:{cookie_string}",
        "user-agent": solution['userAgent']
    }

    listener = MirrorListener(bot, update, False, tag)
    ariaDlManager.add_download(f'{DOWNLOAD_DIR}/{listener.uid}/', [link],
                               listener, aria_options)
    sendStatusMessage(update, bot)
    if len(Interval) == 0:
        Interval.append(
            bot_utils.setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL,
                                  update_all_messages))
Exemplo n.º 16
0
def cancel_mirror(update, context):
    args = update.message.text.split(" ", maxsplit=1)
    mirror_message = None
    if len(args) > 1:
        gid = args[1]
        dl = getDownloadByGid(gid)
        if not dl:
            sendMessage(f"GID: <code>{gid}</code> not found.", context.bot,
                        update)
            return
        with download_dict_lock:
            keys = list(download_dict.keys())
        mirror_message = dl.message
    elif update.message.reply_to_message:
        mirror_message = update.message.reply_to_message
        with download_dict_lock:
            keys = list(download_dict.keys())
            dl = download_dict[mirror_message.message_id]
    if len(args) == 1:
        if mirror_message is None or mirror_message.message_id not in keys:
            if BotCommands.MirrorCommand in mirror_message.text or \
                    BotCommands.TarMirrorCommand in mirror_message.text:
                msg = "Mirror already have been cancelled"
                sendMessage(msg, context.bot, update)
                return
            else:
                msg = "Please reply to the /mirror message which was used to start the download or /cancel gid to cancel it!"
                sendMessage(msg, context.bot, update)
                return
    if dl.status() == "Uploading":
        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}/')
Exemplo n.º 17
0
def add_gd_download(link, listener, is_gdtot):
    res, size, name, files = GoogleDriveHelper().helper(link)
    if res != "":
        return sendMessage(res, listener.bot, listener.update)
    if STOP_DUPLICATE and not listener.isLeech:
        LOGGER.info('Checking File/Folder if already in Drive...')
        if listener.isZip:
            gname = name + ".zip"
        elif listener.extract:
            try:
                gname = get_base_name(name)
            except:
                gname = None
        if gname is not None:
            gmsg, button = GoogleDriveHelper().drive_list(gname, True)
            if gmsg:
                msg = "File/Folder is already available in Drive.\nHere are the search results:"
                return sendMarkup(msg, listener.bot, listener.update, button)
    if STORAGE_THRESHOLD is not None:
        acpt = check_storage_threshold(size, True)
        if not acpt:
            msg = f'You must leave {STORAGE_THRESHOLD}GB free storage.'
            msg += f'\nYour File/Folder size is {get_readable_file_size(size)}'
            return sendMessage(msg, listener.bot, listener.update)
    if ZIP_UNZIP_LIMIT is not None:
        LOGGER.info('Checking File/Folder Size...')
        if size > ZIP_UNZIP_LIMIT * 1024**3:
            msg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(size)}.'
            return sendMessage(msg, listener.bot, listener.update)
    LOGGER.info(f"Download Name: {name}")
    drive = GoogleDriveHelper(name, listener)
    gid = ''.join(random.SystemRandom().choices(string.ascii_letters +
                                                string.digits,
                                                k=12))
    download_status = GdDownloadStatus(drive, size, listener, gid)
    with download_dict_lock:
        download_dict[listener.uid] = download_status
    sendStatusMessage(listener.update, listener.bot)
    drive.download(link)
    if is_gdtot:
        drive.deletefile(link)
Exemplo n.º 18
0
def _watch(bot: Bot, update, isTar=False):
    mssg = update.message.text
    message_args = mssg.split(' ')
    name_args = mssg.split('|')

    try:
        link = message_args[1]
    except IndexError:
        msg = f"/{BotCommands.WatchCommand} [youtube-dl supported link] [quality] |[CustomName] to mirror with youtube-dl.\n\n"
        msg += "<b>Note: Quality and custom name are optional</b>\n\nExample of quality: audio, 144, 240, 360, 480, 720, 1080, 2160."
        msg += "\n\nIf you want to use custom filename, enter it after |"
        msg += f"\n\nExample:\n<code>/{BotCommands.WatchCommand} https://youtu.be/Pk_TthHfLeE 720 |Slam</code>\n\n"
        msg += "This file will be downloaded in 720p quality and it's name will be <b>Slam</b>"
        sendMessage(msg, bot, update)
        return

    try:
        if "|" in mssg:
            mssg = mssg.split("|")
            qual = mssg[0].split(" ")[2]
            if qual == "":
                raise IndexError
        else:
            qual = message_args[2]
        if qual != "audio":
            qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
    except IndexError:
        qual = "bestvideo+bestaudio/best"

    try:
        name = name_args[1]
    except IndexError:
        name = ""

    pswd = ""
    listener = MirrorListener(bot, update, pswd, isTar)
    ydl = YoutubeDLHelper(listener)
    threading.Thread(target=ydl.add_download,
                     args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual,
                           name)).start()
    sendStatusMessage(update, bot)
Exemplo n.º 19
0
def removeSudo(update,context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ') 
    if len(message_) == 2:
        chat_id = int(message_[1])
        if chat_id in SUDO_USERS:
            msg = DbManger().db_rmsudo(chat_id)
        else:
            msg = 'Not a Sudo'
    else:
        if reply_message is None:
            msg = "Give ID or Reply To message of whom you want to remove from Sudo"
        else:
            user_id = reply_message.from_user.id
            if user_id in SUDO_USERS:
                msg = DbManger().db_rmsudo(user_id)
            else:
                msg = 'Not a Sudo'
    sendMessage(msg, context.bot, update)
Exemplo n.º 20
0
def addSudo(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        chat_id = int(message_[1])
        if chat_id not in SUDO_USERS:
            msg = DbManger().db_addsudo(chat_id)
        else:
            msg = 'Already Sudo'
    elif reply_message is None:
        msg = "Give ID or Reply To message of whom you want to Promote"
    else:
        # Trying to authorize someone in specific
        user_id = reply_message.from_user.id
        if user_id not in SUDO_USERS:
            msg = DbManger().db_addsudo(user_id)
        else:
            msg = 'Already Sudo'
    sendMessage(msg, context.bot, update)
Exemplo n.º 21
0
def removeSudo(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        chat_id = int(message_[1])
        if chat_id in SUDO_USERS:
            msg = DbManger().db_rmsudo(chat_id)
        else:
            msg = 'Not a Sudo'
    else:
        if reply_message is None:
            msg = "𝙶𝚒𝚟𝚎 𝙸𝙳 𝚘𝚛 𝚁𝚎𝚙𝚕𝚢 𝚃𝚘 𝚖𝚎𝚜𝚜𝚊𝚐𝚎 𝚘𝚏 𝚠𝚑𝚘𝚖 𝚢𝚘𝚞 𝚠𝚊𝚗𝚝 𝚝𝚘 𝚛𝚎𝚖𝚘𝚟𝚎 𝚏𝚛𝚘𝚖 𝚂𝚞𝚍𝚘"
        else:
            user_id = reply_message.from_user.id
            if user_id in SUDO_USERS:
                msg = DbManger().db_rmsudo(user_id)
            else:
                msg = '𝙽𝚘𝚝 𝚊 𝚂𝚞𝚍𝚘'
    sendMessage(msg, context.bot, update)
Exemplo n.º 22
0
def removeSudo(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        chat_id = int(message_[1])
        if chat_id in SUDO_USERS:
            msg = DbManger().db_rmsudo(chat_id)
        else:
            msg = '<b>Nᴏᴛ ᴀ Sᴜᴅᴏ!</b>'
    else:
        if reply_message is None:
            msg = "<b>Gɪᴠᴇ ID Oꜰ Usᴇʀ Oʀ Rᴇᴘʟʏ Tᴏ Mᴇssᴀɢᴇ Oꜰ Usᴇʀ Wʜᴏᴍ Yᴏᴜ Wᴀɴᴛ Tᴏ Rᴇᴍᴏᴠᴇ Fʀᴏᴍ Sᴜᴅᴏ</b>"
        else:
            user_id = reply_message.from_user.id
            if user_id in SUDO_USERS:
                msg = DbManger().db_rmsudo(user_id)
            else:
                msg = '<b>Nᴏᴛ ᴀ Sᴜᴅᴏ!</b>'
    sendMessage(msg, context.bot, update)
Exemplo n.º 23
0
def setThumb(update, context):
    user_id = update.message.from_user.id
    reply_to = update.message.reply_to_message
    if reply_to is not None and reply_to.photo:
        path = "Thumbnails/"
        if not ospath.isdir(path):
            mkdir(path)
        photo_msg = app.get_messages(
            update.message.chat.id,
            reply_to_message_ids=update.message.message_id)
        photo_dir = app.download_media(photo_msg, file_name=path)
        des_dir = ospath.join(path, str(user_id) + ".jpg")
        Image.open(photo_dir).convert("RGB").save(des_dir, "JPEG")
        osremove(photo_dir)
        if DB_URI is not None:
            DbManger().user_save_thumb(user_id, des_dir)
        msg = f"Custom thumbnail saved for <a href='tg://user?id={user_id}'>{update.message.from_user.full_name}</a>."
        sendMessage(msg, context.bot, update)
    else:
        sendMessage("Reply to a photo to save custom thumbnail.", context.bot,
                    update)
Exemplo n.º 24
0
def stats(update, context):
    currentTime = get_readable_time(time.time() - botStartTime)
    total, used, free = shutil.disk_usage(".")
    total = get_readable_file_size(total)
    used = get_readable_file_size(used)
    free = get_readable_file_size(free)
    sent = get_readable_file_size(psutil.net_io_counters().bytes_sent)
    recv = get_readable_file_size(psutil.net_io_counters().bytes_recv)
    cpuUsage = psutil.cpu_percent(interval=0.5)
    memory = psutil.virtual_memory().percent
    disk = psutil.disk_usage("/").percent
    stats = (f"<b>Bot Uptime:</b> {currentTime}\n"
             f"<b>Total disk space:</b> {total}\n"
             f"<b>Used:</b> {used}  "
             f"<b>Free:</b> {free}\n\n"
             f"Data Usage\n<b>Upload:</b> {sent}\n"
             f"<b>Down:</b> {recv}\n\n"
             f"<b>CPU:</b> {cpuUsage}% "
             f"<b>RAM:</b> {memory}% "
             f"<b>Disk:</b> {disk}%")
    sendMessage(stats, context.bot, update)
Exemplo n.º 25
0
def torser(update, context):
    user_id = update.message.from_user.id
    try:
        key = update.message.text.split(" ", maxsplit=1)[1]
    except IndexError:
        return sendMessage("Send a search key along with command", context.bot, update)
    if SEARCH_API_LINK is not None and SEARCH_PLUGINS is not None:
        buttons = button_build.ButtonMaker()
        buttons.sbutton('Api', f"torser {user_id} api")
        buttons.sbutton('Plugins', f"torser {user_id} plugin")
        buttons.sbutton("Cancel", f"torser {user_id} cancel")
        button = InlineKeyboardMarkup(buttons.build_menu(2))
        sendMarkup('Choose tool to search:', context.bot, update, button)
    elif SEARCH_API_LINK is not None and SEARCH_PLUGINS is None:
        button = _api_buttons(user_id)
        sendMarkup('Choose site to search:', context.bot, update, button)
    elif SEARCH_API_LINK is None and SEARCH_PLUGINS is not None:
        button = _plugin_buttons(user_id)
        sendMarkup('Choose site to search:', context.bot, update, button)
    else:
        return sendMessage("No API link or search PLUGINS added for this function", context.bot, update)
Exemplo n.º 26
0
def addSudo(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        user_id = int(message_[1])
        if user_id not in SUDO_USERS:
            if DB_URI is not None:
                msg = DbManger().db_addsudo(user_id)
            else:
                with open('authorized_chats.txt', 'a') as file:
                    file.write(f'{user_id}\n')
                    AUTHORIZED_CHATS.add(user_id)
                with open('sudo_users.txt', 'a') as file:
                    file.write(f'{user_id}\n')
                    SUDO_USERS.add(user_id)
                    msg = 'Promoted as Sudo'
        else:
            msg = 'Already Sudo'
    else:
        if reply_message is None:
            msg = "Give ID or Reply To message of whom you want to Promote"
        else:
            # Trying to authorize someone by replying
            user_id = reply_message.from_user.id
            if user_id not in SUDO_USERS:
                if DB_URI is not None:
                    msg = DbManger().db_addsudo(user_id)
                else:
                    with open('authorized_chats.txt', 'a') as file:
                        file.write(f'{user_id}\n')
                        AUTHORIZED_CHATS.add(user_id)
                    with open('sudo_users.txt', 'a') as file:
                        file.write(f'{user_id}\n')
                        SUDO_USERS.add(user_id)
                        msg = 'Promoted as Sudo'
            else:
                msg = 'Already Sudo'
    sendMessage(msg, context.bot, update)
Exemplo n.º 27
0
def removeSudo(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        user_id = int(message_[1])
        if user_id in SUDO_USERS:
            if DB_URI is not None:
                msg = DbManger().db_rmsudo(user_id)
            else:
                AUTHORIZED_CHATS.remove(user_id)
                SUDO_USERS.remove(user_id)
                msg = 'Demoted'
        else:
            msg = 'Not a Sudo'
    else:
        if reply_message is None:
            msg = "Give ID or Reply To message of whom you want to remove from Sudo"
        else:
            user_id = reply_message.from_user.id
            if user_id in SUDO_USERS:
                if DB_URI is not None:
                    msg = DbManger().db_rmsudo(user_id)
                else:
                    AUTHORIZED_CHATS.remove(user_id)
                    SUDO_USERS.remove(user_id)
                    msg = 'Demoted'
            else:
                msg = 'Not a Sudo'
    if DB_URI is None:
        with open('authorized_chats.txt', 'a') as file:
            file.truncate(0)
            for i in AUTHORIZED_CHATS:
                file.write(f'{i}\n')
        with open('sudo_users.txt', 'a') as file:
            file.truncate(0)
            for i in SUDO_USERS:
                file.write(f'{i}\n')
    sendMessage(msg, context.bot, update)
Exemplo n.º 28
0
def addSudo(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        chat_id = int(message_[1])
        if chat_id not in SUDO_USERS:
            msg = DbManger().db_addsudo(chat_id)
        else:
            msg = '<b>Aʟʀᴇᴀᴅʏ Sᴜᴅᴏ!</b>'
    else:
        if reply_message is None:
            msg = "<b>Gɪᴠᴇ ID Oꜰ Usᴇʀ Oʀ Rᴇᴘʟʏ Tᴏ Mᴇssᴀɢᴇ Oꜰ Usᴇʀ Wʜᴏᴍ Yᴏᴜ Wᴀɴᴛ Tᴏ Pʀᴏᴍᴏᴛᴇ</b>"
        else:
            # Trying to authorize someone in specific
            user_id = reply_message.from_user.id
            if user_id not in SUDO_USERS:
                msg = DbManger().db_addsudo(user_id)
            else:
                msg = '<b>Aʟʀᴇᴀᴅʏ Sᴜᴅᴏ!</b>'
    sendMessage(msg, context.bot, update)
Exemplo n.º 29
0
def addSudo(update, context):
    reply_message = None
    message_ = None
    reply_message = update.message.reply_to_message
    message_ = update.message.text.split(' ')
    if len(message_) == 2:
        chat_id = int(message_[1])
        if chat_id not in SUDO_USERS:
            msg = DbManger().db_addsudo(chat_id)
        else:
            msg = '𝙰𝚕𝚛𝚎𝚊𝚍𝚢 𝚂𝚞𝚍𝚘'
    else:
        if reply_message is None:
            msg = "𝙶𝚒𝚟𝚎 𝙸𝙳 𝚘𝚛 𝚁𝚎𝚙𝚕𝚢 𝚃𝚘 𝚖𝚎𝚜𝚜𝚊𝚐𝚎 𝚘𝚏 𝚠𝚑𝚘𝚖 𝚢𝚘𝚞 𝚠𝚊𝚗𝚝 𝚝𝚘 𝙿𝚛𝚘𝚖𝚘𝚝𝚎"
        else:
            # Trying to authorize someone in specific
            user_id = reply_message.from_user.id
            if user_id not in SUDO_USERS:
                msg = DbManger().db_addsudo(user_id)
            else:
                msg = '𝙰𝚕𝚛𝚎𝚊𝚍𝚢 𝚂𝚞𝚍𝚘'
    sendMessage(msg, context.bot, update)
Exemplo n.º 30
0
def unauthorize(bot, update):
    reply_message = update.message.reply_to_message
    if reply_message is None:
        # Trying to unauthorize a chat
        chat_id = update.effective_chat.id
        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, bot, update)