Skip to content

Commit

Permalink
delete_links work properly, log display, file dont send in dm twice
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jan 5, 2025
1 parent 4766296 commit 91d8cab
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 23 deletions.
1 change: 1 addition & 0 deletions bot/core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion bot/helper/mirror_leech_utils/telegram_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion bot/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,6 +63,7 @@
"initiate_search_tools",
"leech",
"log",
"log_callback",
"mediainfo",
"mirror",
"ping",
Expand Down
34 changes: 15 additions & 19 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
56 changes: 54 additions & 2 deletions bot/modules/services.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down Expand Up @@ -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 = "<pre language='python'>"
end_line = "</pre>"
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}")

0 comments on commit 91d8cab

Please sign in to comment.