update song.py as per code, add missing vars in sample config, fix pm/tag logger bug.

This commit is contained in:
thedragonsinn
2024-06-28 18:35:44 +05:30
parent 6d0e463101
commit 43f320e598
4 changed files with 42 additions and 34 deletions

View File

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

View File

@@ -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<a href='{message.link}'>{message.chat.title or message.chat.first_name}</a> ({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<a href='{message.link}'>{message.chat.title or message.chat.first_name}</a> ({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<a href='{message.link}'>{message.chat.title}</a> ({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<a href='{message.link}'>{message.chat.title}</a> ({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)

View File

@@ -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),
)

View File

@@ -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