diff --git a/app/extra_config.py b/app/extra_config.py
index 62dd835..9d4e8cc 100644
--- a/app/extra_config.py
+++ b/app/extra_config.py
@@ -1,7 +1,11 @@
from os import environ
+from pyrogram.enums import ChatMemberStatus
+
ALIVE_MEDIA: str = environ.get("ALIVE_MEDIA", "https://telegra.ph/file/a1d35a86c7f54a96188a9.png")
+ADMIN_STATUS = {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}
+
BOT_NAME = environ.get("BOT_NAME", "PLAIN-UB")
DISABLED_SUPERUSERS: list[int] = []
@@ -22,6 +26,10 @@ PM_GUARD: bool = False
PM_LOGGER: bool = False
+PM_LOGGER_THREAD_ID: int = int(environ.get("PM_LOGGER_THREAD_ID", 0)) or None
+
TAG_LOGGER: bool = False
+TAG_LOGGER_THREAD_ID: int = int(environ.get("TAG_LOGGER_THREAD_ID", 0)) or None
+
UPSTREAM_REPO: str = environ.get("UPSTREAM_REPO", "https://github.com/thedragonsinn/plain-ub")
diff --git a/app/plugins/tg_tools/pm_n_tag_logger.py b/app/plugins/tg_tools/pm_n_tag_logger.py
index 9124d82..825a5ff 100644
--- a/app/plugins/tg_tools/pm_n_tag_logger.py
+++ b/app/plugins/tg_tools/pm_n_tag_logger.py
@@ -33,19 +33,23 @@ async def logger_switch(bot: BOT, message: Message):
"""
text = "pm" if message.cmd == "pmlogger" else "tag"
conf_str = f"{text.upper()}_LOGGER"
+
if "-c" in message.flags:
await message.reply(
text=f"{text.capitalize()} Logger is enabled: {getattr(extra_config, conf_str)}!",
del_in=8,
)
return
+
value: bool = not getattr(extra_config, conf_str)
setattr(extra_config, conf_str, value)
+
await asyncio.gather(
LOGGER.add_data({"_id": f"{text}_logger_switch", "value": value}),
message.reply(text=f"{text.capitalize()} Logger is enabled: {value}!", del_in=8),
bot.log_text(text=f"#{text.capitalize()}Logger is enabled: {value}!", type="info"),
)
+
for task in Config.BACKGROUND_TASKS:
if task.get_name() == "pm_tag_logger" and task.done():
Config.BACKGROUND_TASKS.append(asyncio.create_task(runner(), name="pm_tag_logger"))
@@ -65,8 +69,6 @@ BASIC_FILTERS = (
filters=BASIC_FILTERS
& filters.private
& filters.create(lambda _, __, ___: extra_config.PM_LOGGER),
- group=2,
- is_command=False,
)
async def pm_logger(bot: BOT, message: Message):
cache_message(message)
@@ -77,8 +79,6 @@ TAG_FILTER = filters.create(lambda _, __, ___: extra_config.TAG_LOGGER)
@bot.on_message(
filters=(BASIC_FILTERS & filters.reply & TAG_FILTER) & ~filters.private,
- group=2,
- is_command=False,
)
async def reply_logger(bot: BOT, message: Message):
if (
@@ -92,8 +92,6 @@ async def reply_logger(bot: BOT, message: Message):
@bot.on_message(
filters=(BASIC_FILTERS & filters.mentioned & TAG_FILTER) & ~filters.private,
- group=2,
- is_command=False,
)
async def mention_logger(bot: BOT, message: Message):
for entity in message.entities or []:
@@ -104,8 +102,6 @@ async def mention_logger(bot: BOT, message: Message):
@bot.on_message(
filters=(BASIC_FILTERS & (filters.text | filters.media) & TAG_FILTER) & ~filters.private,
- group=2,
- is_command=False,
)
async def username_logger(bot: BOT, message: Message):
text = message.text or message.caption or ""
@@ -179,7 +175,7 @@ async def log_pm(message: Message, log_info: bool):
f"\n\n---\n\n"
f"Caption:\n{message.caption or 'No Caption in media.'}"
)
- await log_message(message=message, notice=notice)
+ await log_message(message=message, notice=notice, thread_id=extra_config.PM_LOGGER_THREAD_ID)
async def log_chat(message: Message):
@@ -196,21 +192,31 @@ async def log_chat(message: Message):
)
if message.reply_to_message:
- await log_message(message.reply_to_message)
+ await log_message(message.reply_to_message, thread_id=extra_config.TAG_LOGGER_THREAD_ID)
await log_message(
message=message,
notice=notice,
extra_info=f"#TAG\n{mention} [{u_id}]\nMessage: \n{message.chat.title} ({message.chat.id})",
+ thread_id=extra_config.TAG_LOGGER_THREAD_ID,
)
-async def log_message(message: Message, notice: str | None = None, extra_info: str | None = None):
+async def log_message(
+ message: Message,
+ notice: str | None = None,
+ extra_info: str | None = None,
+ thread_id: int = None,
+):
try:
- logged_message: Message = await message.forward(extra_config.MESSAGE_LOGGER_CHAT)
+ logged_message: Message = await message.forward(
+ extra_config.MESSAGE_LOGGER_CHAT, message_thread_id=thread_id
+ )
if extra_info:
await logged_message.reply(extra_info, parse_mode=ParseMode.HTML)
except MessageIdInvalid:
- logged_message = await message.copy(extra_config.MESSAGE_LOGGER_CHAT)
+ logged_message = await message.copy(
+ extra_config.MESSAGE_LOGGER_CHAT, message_thread_id=thread_id
+ )
if notice:
await logged_message.reply(notice, parse_mode=ParseMode.HTML)
diff --git a/sample-config.env b/sample-config.env
index 52f8c3b..dd1f5c0 100644
--- a/sample-config.env
+++ b/sample-config.env
@@ -43,9 +43,19 @@ LOG_CHAT=
# Bot logs chat/channel
+# LOG_CHAT_THREAD_ID=
+# if you want to log to a specific topic.
+
+
# MESSAGE_LOGGER_CHAT=
# For PM and Tag logger
-# Defaults to sending in Log Channel Above
+# Defaults to sending in Log Channel Above.
+
+
+# PM_LOGGER_THREAD_ID=
+# TAG_LOGGER_THREAD_ID=
+# Extra customisation for separated logging.
+# To be used with the var above.
OWNER_ID=
@@ -60,9 +70,5 @@ SUDO_TRIGGER=!
# Sudo Trigger for bot
-# MESSAGE_LOGGER_CHAT=
-# PM and Tag Logger chat.
-
-
UPSTREAM_REPO=https://github.com/thedragonsinn/plain-ub
# Keep default unless you maintain your own fork.