Example #1
0
def mirror_status(update: Update, context):
    message = get_readable_message()
    if len(message) == 0:
        message = "No active downloads"
        sendMessage(message, context, update)
        return
    index = update.effective_chat.id
    with status_reply_dict_lock:
        if index in status_reply_dict.keys():
            deleteMessage(context, status_reply_dict[index])
            del status_reply_dict[index]
    kill_thread = False
    while len(message) != 0:
        message = get_readable_message()
        with status_reply_dict_lock:
            if index in status_reply_dict.keys():
                if len(message) == 0:
                    message = "No active downloads"
                    editMessage(message, context, status_reply_dict[index])
                    break
                try:
                    editMessage(message, context, status_reply_dict[index])
                except BadRequest:
                    break
            else:
                # If the loop returns here 2nd time, it means the message
                # has been replaced by a new message due to a second /status command in the chat.
                # So we kill the thread by simply breaking the loop
                if kill_thread:
                    break
                status_reply_dict[index] = sendMessage(message, context,
                                                       update)
                kill_thread = True
        sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL)
Example #2
0
def sendStatusMessage(msg, bot):
    progress = get_readable_message()
    progress += f"๐Ÿธ๐Ÿธ๐Ÿธ๐Ÿธ๐Ÿธ๐Ÿธ๐Ÿธ๐Ÿธ"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        #dlspeed = get_readable_file_size(dlspeed_bytes)
        #ulspeed = get_readable_file_size(uldl_bytes)
        #progress += f"\n<b>DL: </b>{dlspeed}ps ๐Ÿ”ป| <b>UL: </b>{ulspeed}ps ๐Ÿ”บ\n"
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
                pass
        if len(progress) == 0:
            progress = "Starting DL"
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
Example #3
0
def sendStatusMessage(msg, bot):
    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)
    progress = get_readable_message()
    progress += f"๐—–๐—ฃ๐—จ ๐Ÿ“Ÿ: {psutil.cpu_percent()}%" \
           f" ๐——๐—œ๐—ฆ๐—ž๐Ÿ’ฟ: {psutil.disk_usage('/').percent}%" \
           f" ๐—ฅ๐—”๐—  ๐Ÿ’พ: {psutil.virtual_memory().percent}%" \
           f"\n๐—•๐—ผ๐˜ ๐—จ๐—ฝ๐˜๐—ถ๐—บ๐—ฒ : {currentTime} | ๐—™๐—ฟ๐—ฒ๐—ฒ ๐Ÿคฏ: {free}"
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
                pass
        if len(progress) == 0:
            progress = "Starting DL"
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
Example #4
0
def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>โœฅโ•โ•โ•โ• @TGFilmZone โ•โ•โ•โ•โœฅ</b>"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        #dlspeed = get_readable_file_size(dlspeed_bytes)
        #ulspeed = get_readable_file_size(uldl_bytes)
        #msg += f"\n<b>DL:</b> {dlspeed}ps ๐Ÿ”ป| <b>UL:</b> {ulspeed}ps ๐Ÿ”บ\n"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Starting DL"
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #5
0
def _mirror(update, context, isTar=False):
    message_args = update.message.text.split(' ')
    try:
        link = message_args[1]
    except IndexError:
        link = ''
    LOGGER.info(link)
    link = link.strip()

    if len(link) == 0:
        if update.message.reply_to_message is not None:
            document = update.message.reply_to_message.document
            if document is not None and document.mime_type == "application/x-bittorrent":
                link = document.get_file().file_path
            else:
                sendMessage('Only torrent files can be mirrored from telegram',
                            context, update)
                return
    if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
        sendMessage('No download source provided', context, update)
        return
    reply_msg = sendMessage('Starting Download', context, update)
    index = update.effective_chat.id
    with status_reply_dict_lock:
        if index in status_reply_dict.keys():
            try:
                deleteMessage(context, status_reply_dict[index])
            except BadRequest:
                pass
        status_reply_dict[index] = reply_msg
    listener = MirrorListener(context, update, reply_msg, isTar)
    aria = download_tools.DownloadHelper(listener)
    t = threading.Thread(target=aria.add_download, args=(link, ))
    t.start()
Example #6
0
def sendStatusMessage(msg, bot):
    progress = get_readable_message()
    progress += f"<b>CPU:</b> {psutil.cpu_percent()}%\n" \
           f"<b>RAM:</b> {psutil.virtual_memory().percent}%\n" \
           f"<b>DISK:</b> {psutil.disk_usage('/').percent}%\n"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        progress += f"\n<b>DL: </b>{dlspeed}ps รฐลธโ€ยป| <b>UL: </b>{ulspeed}ps รฐลธโ€ยบ\n"
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
Example #7
0
def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>CPU:</b> {psutil.cpu_percent()}%\n" \
           f"<b>RAM:</b> {psutil.virtual_memory().percent}%\n" \
           f"<b>DISK:</b> {psutil.disk_usage('/').percent}%\n"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        msg += f"\n<b>DL:</b> {dlspeed}ps รฐลธโ€ยป| <b>UL:</b> {ulspeed}ps รฐลธโ€ยบ\n"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Starting DL"
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #8
0
def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>๐Ÿ–ฅ๏ธCPU:</b> {psutil.cpu_percent()}%" \
           f" <b>๐Ÿ“€Penyimpanan:</b> {psutil.disk_usage('/').percent}%" \
           f" <b>๐Ÿ“RAM:</b> {psutil.virtual_memory().percent}%"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiloByte/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MegaByte/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KiloByte/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MegaByte/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        msg += f"\n<b>Kecepatan Downlod:</b>{dlspeed}ps โฌ| <b>Kecepatan Upload:</b>{ulspeed}ps โซ\n"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Bentar lagi download"
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #9
0
def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>๐‚๐๐”:</b> {psutil.cpu_percent()}%" \
           f" <b>๐ƒ๐ˆ๐’๐Š:</b> {psutil.disk_usage('/').percent}%" \
           f" <b>๐‘๐€๐Œ:</b> {psutil.virtual_memory().percent}%"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        msg += f"\n<b>๐ƒ๐‹:</b>{dlspeed}ps ๐Ÿ”ป| <b>๐”๐‹:</b>{ulspeed}ps ๐Ÿ”บ\n"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "๐Ÿš‰๐’๐ญ๐š๐ซ๐ญ๐ข๐ง๐  ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐..."
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #10
0
def update_all_messages():
    msg = get_readable_message()
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if msg != status_reply_dict[chat_id].text:
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except BadRequest as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #11
0
def update_all_messages():
    msg, buttons = get_readable_message()
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if buttons == "":
                    editMessage(msg, status_reply_dict[chat_id])
                else:
                    editMessage(msg, status_reply_dict[chat_id], buttons)
                status_reply_dict[chat_id].text = msg
Example #12
0
def update_all_messages():
    msg = get_readable_message()
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Starting DL"
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #13
0
def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>CPU:</b> {psutil.cpu_percent()}%" \
           f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \
           f" <b>RAM:</b> {psutil.virtual_memory().percent}%"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text:
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #14
0
def sendStatusMessage(msg, bot):
    progress = get_readable_message()
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as _error:
                LOGGER.error(str(_error))
                del status_reply_dict[msg.message.chat.id]
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
Example #15
0
def mirror_status(update, context):
    with download_dict_lock:
        if len(download_dict) == 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)
Example #16
0
def mirror_status(update,context):
    message = get_readable_message()
    if len(message) == 0:
        message = "โ›ฝ๐๐จ ๐€๐œ๐ญ๐ข๐ฏ๐ž ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐๐ฌ ๐…๐จ๐ฎ๐ง๐"
        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)
def mirror_status(update,context):
    message = get_readable_message()
    if len(message) == 0:
        message = "Khรดng cรณ tรกc vแปฅ tแบฃi xuแป‘ng nร o ฤ‘ang hoแบกt ฤ‘แป™ng!"
        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)
def mirror_status(update,context):
    message = get_readable_message()
    if len(message) == 0:
        message = "Lagi sepi ga ada download an nihh.."
        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)
Example #19
0
def mirror_status(client: Client, update: Message):
    message = get_readable_message()
    if len(message) == 0:
        message = "No active downloads"
        reply_message = sendMessage(message, client, update)
        threading.Thread(target=auto_delete_message, args=(client, update, reply_message)).start()
        return
    index = update.chat.id
    with status_reply_dict_lock:
        if index in status_reply_dict.keys():
            deleteMessage(status_reply_dict[index])
            del status_reply_dict[index]
    sendStatusMessage(update, client)
    deleteMessage(update)
def mirror_status(update, context):
    message = get_readable_message()
    if len(message) == 0:
        message = "ยญะฎะ‰ั…ยญะฎัšั™ ยญะฎัšั“ยญะฎัšั‘ยญะฎัšะ‹ยญะฎัšั–ยญะฎัšะŒยญะฎัšั” ยญะฎะ‰ะคยญะฎัšั™ยญะฎัšัžยญะฎัšะˆยญะฎัšะ‡ยญะฎัšั™ยญะฎัšั“ยญะฎัšะยญะฎัšั› ยญะฎะ‰ั„ยญะฎัšัœยญะฎัšะŠยญะฎัšะŠยญะฎัšั”ยญะฎัšะˆยญะฎัšะ‹ยญะฎัšะ‡ยญะฎัšัŸ ยญะชั†ะธ"
        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)
Example #21
0
def mirror_status(update, context):
    message = get_readable_message()
    if len(message) == 0:
        message = "โŒ๐™ฝ๐š˜ ๐šŠ๐šŒ๐š๐š’๐šŸ๐šŽ ๐š๐š˜๐š ๐š—๐š•๐š˜๐šŠ๐š๐šœโŒ"
        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)
Example #22
0
def sendStatusMessage(msg, bot):
    progress = get_readable_message()
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
                pass
        if len(progress) == 0:
            progress = "Starting DL"
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
Example #23
0
def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>๐Ÿ“‰ Performance Usage ๐Ÿ“ˆ</b>\n\n" \
           f"<b>๐Ÿ–ฅ๏ธ CPU : {psutil.cpu_percent()}%</b>\n" \
           f"<b>๐Ÿ—ƒ๏ธ DISK : {psutil.disk_usage('/').percent}%</b>\n" \
           f"<b>๐ŸŽ›๏ธ RAM : {psutil.virtual_memory().percent}%</b>"
    with download_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Starting Download ๐Ÿ“ฅ"
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
def sendStatusMessage(msg, bot):
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
    total, used, free = shutil.disk_usage('.')
    free = get_readable_file_size(free)
    currentTime = get_readable_time(time.time() - botStartTime)
    progress, buttons = get_readable_message()
    if progress is None:
        progress, buttons = get_readable_message()
    progress += f"<b>CPU:</b> <code>{psutil.cpu_percent()}%</code>" \
           f" <b>RAM:</b> <code>{psutil.virtual_memory().percent}%</code>" \
           f" <b>DISK:</b> <code>{psutil.disk_usage('/').percent}%</code>"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'K' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'M' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        progress += f"\n<b>FREE:</b> <code>{free}</code> | <b>UPTIME:</b> <code>{currentTime}</code>\n<b>DL:</b> <code>{dlspeed}/s</code> รฐลธโ€ยป | <b>UL:</b> <code>{ulspeed}/s</code> รฐลธโ€ยบ\n"
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
                pass
        if buttons == "":
            message = sendMessage(progress, bot, msg)
        else:
            message = sendMarkup(progress, bot, msg, buttons)
        status_reply_dict[msg.message.chat.id] = message
Example #25
0
def sendStatusMessage(msg, bot):
    progress = get_readable_message()
    progress += f"<b>CPU:</b> {psutil.cpu_percent()}%" \
           f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \
           f" <b>RAM:</b> {psutil.virtual_memory().percent}%"
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
                pass
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
Example #26
0
def sendStatusMessage(msg, bot):
    if len(Interval) == 0:
        Interval.append(
            setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
    progress, buttons = get_readable_message()
    with status_reply_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
        if buttons == "":
            message = sendMessage(progress, bot, msg)
        else:
            message = sendMarkup(progress, bot, msg, buttons)
        status_reply_dict[msg.message.chat.id] = message
Example #27
0
def update_all_messages():
    msg = get_readable_message()
    msg += f"<b>CPU:</b> {psutil.cpu_percent()}%" \
           f" <b>DISK:</b> {psutil.disk_usage('/').percent}%" \
           f" <b>RAM:</b> {psutil.virtual_memory().percent}%"
    with download_dict_lock:
        dlspeed_bytes = 0
        uldl_bytes = 0
        for download in list(download_dict.values()):
            speedy = download.speed()
            if download.status() == MirrorStatus.STATUS_DOWNLOADING:
                if 'KiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MiB/s' in speedy:
                    dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
            if download.status() == MirrorStatus.STATUS_UPLOADING:
                if 'KB/s' in speedy:
                    uldl_bytes += float(speedy.split('K')[0]) * 1024
                elif 'MB/s' in speedy:
                    uldl_bytes += float(speedy.split('M')[0]) * 1048576
        dlspeed = get_readable_file_size(dlspeed_bytes)
        ulspeed = get_readable_file_size(uldl_bytes)
        msg += f"\n<b>DL:</b> {dlspeed}ps ๐Ÿ”ป| <b>UL:</b> {ulspeed}ps ๐Ÿ”บ\n"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                if len(msg) == 0:
                    msg = "Starting DL"
                try:
                    keyboard = [[
                        InlineKeyboardButton("๐Ÿ”„ REFRESH ๐Ÿ”„",
                                             callback_data=str(ONE)),
                        InlineKeyboardButton("โŒ CLOSE โŒ",
                                             callback_data=str(TWO)),
                    ]]
                    editMessage(msg,
                                status_reply_dict[chat_id],
                                reply_markup=InlineKeyboardMarkup(keyboard))
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #28
0
def update_all_messages():
    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)
    msg = get_readable_message()
    msg += f"๐—–๐—ฃ๐—จ : {psutil.cpu_percent()}%" \
           f" ๐——๐—œ๐—ฆ๐—ž : {psutil.disk_usage('/').percent}%" \
           f" ๐—ฅ๐—”๐—  : {psutil.virtual_memory().percent}%" \
           f"\n๐—•๐—ผ๐˜ ๐—จ๐—ฝ๐˜๐—ถ๐—บ๐—ฒ : {currentTime} | ๐—™๐—ฟ๐—ฒ๐—ฒ๐Ÿคฏ: {free}"
    with status_reply_dict_lock:
        for chat_id in list(status_reply_dict.keys()):
            if status_reply_dict[
                    chat_id] and msg != status_reply_dict[chat_id].text:
                try:
                    editMessage(msg, status_reply_dict[chat_id])
                except Exception as e:
                    LOGGER.error(str(e))
                status_reply_dict[chat_id].text = msg
Example #29
0
def sendStatusMessage(msg, bot):
    progress = get_readable_message()
    progress += f"<b>๐Ÿ“‰ Performance Usage ๐Ÿ“ˆ</b>\n\n" \
           f"<b>๐Ÿ–ฅ๏ธ CPU : {psutil.cpu_percent()}%</b>\n" \
           f"<b>๐Ÿ—ƒ๏ธ DISK : {psutil.disk_usage('/').percent}%</b>\n" \
           f"<b>๐ŸŽ›๏ธ RAM : {psutil.virtual_memory().percent}%</b>"
    with download_dict_lock:
        if msg.message.chat.id in list(status_reply_dict.keys()):
            try:
                message = status_reply_dict[msg.message.chat.id]
                deleteMessage(bot, message)
                del status_reply_dict[msg.message.chat.id]
            except Exception as e:
                LOGGER.error(str(e))
                del status_reply_dict[msg.message.chat.id]
                pass
        if len(progress) == 0:
            progress = "Starting Download ๐Ÿ“ฅ"
        message = sendMessage(progress, bot, msg)
        status_reply_dict[msg.message.chat.id] = message
Example #30
0
def mirror_status(update, context):
    with download_dict_lock:
        if len(download_dict) == 0:
            currentTime = get_readable_time(time() - botStartTime)
            total, used, free, _ = disk_usage('.')
            free = get_readable_file_size(free)
            message = 'No Active Downloads !\n___________________________'
            message += f"\n<b>CPU:</b> {cpu_percent()}% | <b>FREE:</b> {free}" \
                       f"\n<b>RAM:</b> {virtual_memory().percent}% | <b>UPTIME:</b> {currentTime}"
            reply_message = sendMessage(message, context.bot, update)
            Thread(target=auto_delete_message,
                   args=(context.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(context.bot, status_reply_dict[index])
            del status_reply_dict[index]
    sendStatusMessage(update, context.bot)
    deleteMessage(context.bot, update.message)