From efb6c07fdd59044943d0a3253331213b8f456175 Mon Sep 17 00:00:00 2001 From: Hafitz Setya <71178188+breakdowns@users.noreply.github.com> Date: Sat, 5 Jun 2021 17:48:44 +0700 Subject: [PATCH] v4.8.3 - Added uptime in /status - Added cc in /count - Fix error if not field IMAGE_URL in config.env - Tidying up --- README.md | 2 +- bot/__init__.py | 2 ++ bot/helper/mirror_utils/upload_utils/gdriveTools.py | 8 ++++---- bot/helper/telegram_helper/message_utils.py | 12 ++++++------ bot/modules/count.py | 8 +++++++- bot/modules/mirror.py | 4 ++-- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4fc75d201d8..a323e7739d5 100644 --- a/README.md +++ b/README.md @@ -283,7 +283,7 @@ Where host is the name of extractor (eg. Youtube, Twitch). Multiple accounts of # Credits Thanks to: -- [out386](https://github.com/out386) heavily inspired from telegram bot which is written in JS +- [out386](https://github.com/out386) heavily inspired from Telegram Bot which is written in JS - [Izzy12](https://github.com/lzzy12/) for original repo - [Dank-del](https://github.com/Dank-del/) for base repo - [magneto261290](https://github.com/magneto261290/) for some features diff --git a/bot/__init__.py b/bot/__init__.py index 109ced91311..721238e3e02 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -256,6 +256,8 @@ def mktable(): SHORTENER_API = None try: IMAGE_URL = getConfig('IMAGE_URL') + if len(IMAGE_URL) == 0: + IMAGE_URL = 'https://telegra.ph/file/89a98d9634d296e516961.jpg' except KeyError: IMAGE_URL = 'https://telegra.ph/file/db03910496f06094f1f7a.jpg' diff --git a/bot/helper/mirror_utils/upload_utils/gdriveTools.py b/bot/helper/mirror_utils/upload_utils/gdriveTools.py index 962d78c4af3..fb889861409 100644 --- a/bot/helper/mirror_utils/upload_utils/gdriveTools.py +++ b/bot/helper/mirror_utils/upload_utils/gdriveTools.py @@ -332,7 +332,7 @@ def clone(self, link): dir_id = self.create_directory(meta.get('name'), parent_id) result = self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_id) msg += f'Filename: {meta.get("name")}\nSize: {get_readable_file_size(self.transferred_size)}' - msg += f'\n\nType: Folder' + msg += f'\nType: Folder' msg += f'\nSubFolders: {self.total_folders}' msg += f'\nFiles: {self.total_files}' durl = self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id) @@ -372,7 +372,7 @@ def clone(self, link): typeee = 'File' try: msg += f'\nSize: {get_readable_file_size(int(meta.get("size")))}' - msg += f'\n\nType: {typeee}' + msg += f'\nType: {typeee}' except TypeError: pass if INDEX_URL is not None: @@ -625,7 +625,7 @@ def count(self, link): self.gDrive_directory(**drive_file) msg += f'Filename: {name}' msg += f'\nSize: {get_readable_file_size(self.total_bytes)}' - msg += f'\n\nType: Folder' + msg += f'\nType: Folder' msg += f'\nSubFolders: {self.total_folders}' msg += f'\nFiles: {self.total_files}' else: @@ -638,7 +638,7 @@ def count(self, link): self.total_files += 1 self.gDrive_file(**drive_file) msg += f'\nSize: {get_readable_file_size(self.total_bytes)}' - msg += f'\n\nType: {typee}' + msg += f'\nType: {typee}' msg += f'\nFiles: {self.total_files}' except TypeError: pass diff --git a/bot/helper/telegram_helper/message_utils.py b/bot/helper/telegram_helper/message_utils.py index ebff623ea73..36a0d3d0e2f 100644 --- a/bot/helper/telegram_helper/message_utils.py +++ b/bot/helper/telegram_helper/message_utils.py @@ -4,8 +4,8 @@ import psutil, shutil import time from bot import AUTO_DELETE_MESSAGE_DURATION, LOGGER, bot, \ - status_reply_dict, status_reply_dict_lock, download_dict, download_dict_lock -from bot.helper.ext_utils.bot_utils import get_readable_message, get_readable_file_size, MirrorStatus + status_reply_dict, status_reply_dict_lock, download_dict, download_dict_lock, botStartTime +from bot.helper.ext_utils.bot_utils import get_readable_message, get_readable_file_size, get_readable_time, MirrorStatus from telegram.error import TimedOut, BadRequest @@ -68,8 +68,8 @@ def delete_all_messages(): def update_all_messages(): total, used, free = shutil.disk_usage('.') - used = get_readable_file_size(used) free = get_readable_file_size(free) + currentTime = get_readable_time(time.time() - botStartTime) msg = get_readable_message() msg += f"CPU: {psutil.cpu_percent()}%" \ f" RAM: {psutil.virtual_memory().percent}%" \ @@ -91,7 +91,7 @@ def update_all_messages(): uldl_bytes += float(speedy.split('M')[0]) * 1048576 dlspeed = get_readable_file_size(dlspeed_bytes) ulspeed = get_readable_file_size(uldl_bytes) - msg += f"\nUSED: {used} | FREE: {free}\nDL: {dlspeed}ps 🔻 | UL: {ulspeed}ps 🔺\n" + msg += f"\nFREE: {free} | UPTIME: {currentTime}\nDL: {dlspeed}ps 🔻 | UL: {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: @@ -106,8 +106,8 @@ def update_all_messages(): def sendStatusMessage(msg, bot): total, used, free = shutil.disk_usage('.') - used = get_readable_file_size(used) free = get_readable_file_size(free) + currentTime = get_readable_time(time.time() - botStartTime) progress = get_readable_message() progress += f"CPU: {psutil.cpu_percent()}%" \ f" RAM: {psutil.virtual_memory().percent}%" \ @@ -129,7 +129,7 @@ def sendStatusMessage(msg, bot): uldl_bytes += float(speedy.split('M')[0]) * 1048576 dlspeed = get_readable_file_size(dlspeed_bytes) ulspeed = get_readable_file_size(uldl_bytes) - progress += f"\nUSED: {used} | FREE: {free}\nDL: {dlspeed}ps 🔻 | UL: {ulspeed}ps 🔺\n" + progress += f"\nFREE: {free} | UPTIME: {currentTime}\nDL: {dlspeed}ps 🔻 | UL: {ulspeed}ps 🔺\n" with status_reply_dict_lock: if msg.message.chat.id in list(status_reply_dict.keys()): try: diff --git a/bot/modules/count.py b/bot/modules/count.py index 8782c662e57..76d942fb4e9 100644 --- a/bot/modules/count.py +++ b/bot/modules/count.py @@ -9,13 +9,19 @@ @run_async def countNode(update, context): args = update.message.text.split(" ", maxsplit=1) + if update.message.from_user.username: + uname = f"@{update.message.from_user.username}" + else: + uname = f'{update.message.from_user.first_name}' + if uname is not None: + cc = f'\n\ncc: {uname}' if len(args) > 1: link = args[1] msg = sendMessage(f"Counting: {link}", context.bot, update) gd = GoogleDriveHelper() result = gd.count(link) deleteMessage(context.bot, msg) - sendMessage(result, context.bot, update) + sendMessage(result + cc, context.bot, update) else: sendMessage("Provide G-Drive Shareable Link to Count.", context.bot, update) diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index c69dee9e690..023b03a48f0 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -150,11 +150,11 @@ def onUploadComplete(self, link: str, size, files, folders, typ): with download_dict_lock: msg = f'Filename: {download_dict[self.uid].name()}\nSize: {size}' if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'): - msg += '\n\nType: Folder' + msg += '\nType: Folder' msg += f'\nSubFolders: {folders}' msg += f'\nFiles: {files}' else: - msg += f'\n\nType: {typ}' + msg += f'\nType: {typ}' buttons = button_build.ButtonMaker() if SHORTENER is not None and SHORTENER_API is not None: surl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, link)).text