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)
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
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
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
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()
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
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
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
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
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
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
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
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
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
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)
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)
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)
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 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
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
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
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
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
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
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
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)