Example #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")
Example #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)
Example #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))
Example #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)
Example #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()
Example #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)
Example #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)
Example #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)
Example #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))
Example #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)
Example #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)
Example #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))
Example #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)
Example #14
0
File: list.py Project: 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)
Example #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))
Example #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}/')
Example #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)
Example #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)
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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)