diff --git a/bot/core/handlers.py b/bot/core/handlers.py index 86cc3f468..e4b83bbe2 100644 --- a/bot/core/handlers.py +++ b/bot/core/handlers.py @@ -213,6 +213,7 @@ def add_handlers(): "^help": arg_usage, "^status": status_pages, "^botrestart": confirm_restart, + "^log": log_callback, } for regex_filter, handler_func in regex_filters.items(): diff --git a/bot/helper/mirror_leech_utils/telegram_uploader.py b/bot/helper/mirror_leech_utils/telegram_uploader.py index d9e3a3d90..8c8ba3a93 100644 --- a/bot/helper/mirror_leech_utils/telegram_uploader.py +++ b/bot/helper/mirror_leech_utils/telegram_uploader.py @@ -587,7 +587,8 @@ async def _copy(target, retries=3): LOGGER.error(f"Failed to copy message after {retries} attempts") # if self.dm_mode: - await _copy(self._user_id) + if self._sent_msg.chat.id != self._user_id: + await _copy(self._user_id) # if self._user_dump: # await _copy(self._user_dump) diff --git a/bot/modules/__init__.py b/bot/modules/__init__.py index 3783280e6..23408f5c4 100644 --- a/bot/modules/__init__.py +++ b/bot/modules/__init__.py @@ -23,7 +23,7 @@ ) from .rss import get_rss_menu, rss_listener from .search import initiate_search_tools, torrent_search, torrent_search_update -from .services import log, ping, start +from .services import log, ping, start, log_callback from .shell import run_shell from .speedtest import speedtest from .stats import bot_stats, get_packages_version @@ -63,6 +63,7 @@ "initiate_search_tools", "leech", "log", + "log_callback", "mediainfo", "mirror", "ping", diff --git a/bot/modules/mirror_leech.py b/bot/modules/mirror_leech.py index f7eff09bd..4d5e46a9a 100644 --- a/bot/modules/mirror_leech.py +++ b/bot/modules/mirror_leech.py @@ -374,30 +374,26 @@ async def new_event(self): session, ), ) - return None - if isinstance(self.link, dict): + elif isinstance(self.link, dict): create_task(add_direct_download(self, path)) - return None - if self.is_qbit: + elif self.is_qbit: create_task(add_qb_torrent(self, path, ratio, seed_time)) - return None - if is_rclone_path(self.link): + elif is_rclone_path(self.link): create_task(add_rclone_download(self, f"{path}/")) - return None - if is_mega_link(self.link): + elif is_mega_link(self.link): create_task(add_mega_download(self, f"{path}/")) - return None - if is_gdrive_link(self.link) or is_gdrive_id(self.link): + elif is_gdrive_link(self.link) or is_gdrive_id(self.link): create_task(add_gd_download(self, path)) - return None - ussr = args["-au"] - pssw = args["-ap"] - if ussr or pssw: - auth = f"{ussr}:{pssw}" - headers += ( - f" authorization: Basic {b64encode(auth.encode()).decode('ascii')}" - ) - create_task(add_aria2c_download(self, path, headers, ratio, seed_time)) + else: + ussr = args["-au"] + pssw = args["-ap"] + if ussr or pssw: + auth = f"{ussr}:{pssw}" + headers += ( + f" authorization: Basic {b64encode(auth.encode()).decode('ascii')}" + ) + create_task(add_aria2c_download(self, path, headers, ratio, seed_time)) + await delete_links(self.message) return None diff --git a/bot/modules/services.py b/bot/modules/services.py index 6025ad7cb..238a262f1 100644 --- a/bot/modules/services.py +++ b/bot/modules/services.py @@ -1,18 +1,22 @@ from time import time from uuid import uuid4 +from html import escape +from aiofiles import open as aiopen -from bot import user_data +from bot import user_data, LOGGER from bot.core.config_manager import Config from bot.helper.ext_utils.bot_utils import new_task from bot.helper.ext_utils.db_handler import database from bot.helper.ext_utils.status_utils import get_readable_time from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.filters import CustomFilters +from bot.helper.telegram_helper.button_build import ButtonMaker from bot.helper.telegram_helper.message_utils import ( delete_message, edit_message, send_file, send_message, + five_minute_del, ) @@ -74,4 +78,52 @@ async def ping(_, message): @new_task async def log(_, message): - await send_file(message, "log.txt") + buttons = ButtonMaker() + buttons.data_button("Log display", f"log {message.from_user.id}") + reply_message = await send_file( + message, + "log.txt", + buttons=buttons.build_menu(1), + ) + await delete_message(message) + await five_minute_del(reply_message) + + +@new_task +async def log_callback(_, query): + message = query.message + user_id = query.from_user.id + data = query.data.split() + if user_id != int(data[1]): + return await query.answer(text="This message not your's!", show_alert=True) + await query.answer() + async with aiopen("log.txt") as f: + log_file_lines = (await f.read()).splitlines() + + def parseline(line): + try: + return line.split("] ", 1)[1] + except IndexError: + return line + + ind, log_lines = 1, "" + try: + while len(log_lines) <= 3500: + log_lines = parseline(log_file_lines[-ind]) + "\n" + log_lines + if ind == len(log_file_lines): + break + ind += 1 + start_line = "
"
+        end_line = "
" + btn = ButtonMaker() + btn.data_button("Close", f"aeon {user_id} close") + reply_message = await send_message( + message, + start_line + escape(log_lines) + end_line, + btn.build_menu(1), + ) + await query.edit_message_reply_markup(None) + await delete_message(message) + await five_minute_del(reply_message) + except Exception as err: + LOGGER.error(f"TG Log Display : {err!s}") \ No newline at end of file