From 43f320e5985f982906a22e7573819e7c32a92b2e Mon Sep 17 00:00:00 2001
From: thedragonsinn <98635854+thedragonsinn@users.noreply.github.com>
Date: Fri, 28 Jun 2024 18:35:44 +0530
Subject: [PATCH] update song.py as per code, add missing vars in sample
config, fix pm/tag logger bug.
---
app/plugins/misc/song.py | 9 ++---
app/plugins/tg_tools/pm_n_tag_logger.py | 51 +++++++++++++------------
app/plugins/tg_tools/pm_permit.py | 6 +--
sample-config.env | 10 +++++
4 files changed, 42 insertions(+), 34 deletions(-)
diff --git a/app/plugins/misc/song.py b/app/plugins/misc/song.py
index a0e84de..3820e49 100644
--- a/app/plugins/misc/song.py
+++ b/app/plugins/misc/song.py
@@ -89,13 +89,10 @@ async def get_download_info(query: str, path: str):
f"'{query}'"
)
try:
+ song_info = (await run_shell_cmd(download_cmd)).strip()
- async with asyncio.timeout(30):
-
- song_info = (await run_shell_cmd(download_cmd)).strip()
-
- serialised_json = json.loads(song_info)
- return serialised_json
+ serialised_json = json.loads(song_info)
+ return serialised_json
except asyncio.TimeoutError:
shutil.rmtree(path=path, ignore_errors=True)
diff --git a/app/plugins/tg_tools/pm_n_tag_logger.py b/app/plugins/tg_tools/pm_n_tag_logger.py
index 32b85d3..a5afa3e 100644
--- a/app/plugins/tg_tools/pm_n_tag_logger.py
+++ b/app/plugins/tg_tools/pm_n_tag_logger.py
@@ -52,7 +52,7 @@ async def logger_switch(bot: BOT, message: Message):
),
)
for task in Config.BACKGROUND_TASKS:
- if task.get_name() == "pm_tag_logger" and not task.done():
+ if task.get_name() == "pm_tag_logger" and task.done():
Config.BACKGROUND_TASKS.append(
asyncio.create_task(runner(), name="pm_tag_logger")
)
@@ -187,18 +187,14 @@ async def log_pm(message: Message, log_info: bool):
chat_id=extra_config.MESSAGE_LOGGER_CHAT,
text=f"#PM\n{message.from_user.mention} [{message.from_user.id}]",
)
- try:
- await message.forward(extra_config.MESSAGE_LOGGER_CHAT)
- except MessageIdInvalid:
- notice = (
- f"{message.from_user.mention} [{message.from_user.id}] deleted this message."
- f"\n\n---\n\n"
- f"Message: \n{message.chat.title or message.chat.first_name} ({message.chat.id})"
- f"\n\n---\n\n"
- f"Caption:\n{message.caption or 'No Caption in media.'}"
- )
-
- await message.copy(extra_config.MESSAGE_LOGGER_CHAT, caption=notice)
+ notice = (
+ f"{message.from_user.mention} [{message.from_user.id}] deleted this message."
+ f"\n\n---\n\n"
+ f"Message: \n{message.chat.title or message.chat.first_name} ({message.chat.id})"
+ f"\n\n---\n\n"
+ f"Caption:\n{message.caption or 'No Caption in media.'}"
+ )
+ await log_message(message=message, notice=notice)
async def log_chat(message: Message):
@@ -215,16 +211,23 @@ async def log_chat(message: Message):
)
if message.reply_to_message:
- try:
- await message.reply_to_message.forward(extra_config.MESSAGE_LOGGER_CHAT)
- except MessageIdInvalid:
- await message.reply_to_message.copy(
- extra_config.MESSAGE_LOGGER_CHAT, caption=notice
- )
+ await log_message(message.reply_to_message)
+
+ await log_message(
+ message=message,
+ notice=notice,
+ extra_info=f"#TAG\n{mention} [{u_id}]\nMessage: \n{message.chat.title} ({message.chat.id})",
+ )
+
+
+async def log_message(
+ message: Message, notice: str | None = None, extra_info: str | None = None
+):
try:
- logged = await message.forward(extra_config.MESSAGE_LOGGER_CHAT)
- await logged.reply(
- text=f"#TAG\n{mention} [{u_id}]\nMessage: \n{message.chat.title} ({message.chat.id})"
- )
+ logged_message = await message.forward(extra_config.MESSAGE_LOGGER_CHAT)
+ if extra_info:
+ await logged_message.reply(extra_info)
except MessageIdInvalid:
- await message.copy(extra_config.MESSAGE_LOGGER_CHAT, caption=notice)
+ logged_message = await message.copy(extra_config.MESSAGE_LOGGER_CHAT)
+ if notice:
+ await logged_message.reply(notice)
diff --git a/app/plugins/tg_tools/pm_permit.py b/app/plugins/tg_tools/pm_permit.py
index d8f70a1..7b55868 100644
--- a/app/plugins/tg_tools/pm_permit.py
+++ b/app/plugins/tg_tools/pm_permit.py
@@ -56,9 +56,7 @@ async def handle_new_pm(bot: BOT, message: Message):
)
return
if RECENT_USERS[user_id] % 2:
- await message.reply(
- "You are not authorised to PM.\nWait until you get authorised."
- )
+ await message.reply("You are not authorised to PM.")
@bot.on_message(
@@ -73,7 +71,7 @@ async def auto_approve(bot: BOT, message: Message):
ALLOWED_USERS.append(message.chat.id)
await asyncio.gather(
PM_USERS.insert_one({"_id": message.chat.id}),
- message.reply("Auto-Approved to PM.", del_in=5),
+ message.reply(text="Auto-Approved to PM.", del_in=5),
)
diff --git a/sample-config.env b/sample-config.env
index df7da58..52f8c3b 100644
--- a/sample-config.env
+++ b/sample-config.env
@@ -20,6 +20,11 @@ DB_URL=
# Mongo DB cluster URL
+# EXTRA_MODULES_REPO=
+# To add extra modules or mini bots that require stuff in ub.
+# Only For Advance Users.
+
+
# FBAN_LOG_CHANNEL=
# Optional FedBan Proof and logs.
@@ -38,6 +43,11 @@ LOG_CHAT=
# Bot logs chat/channel
+# MESSAGE_LOGGER_CHAT=
+# For PM and Tag logger
+# Defaults to sending in Log Channel Above
+
+
OWNER_ID=
# Your user ID