From f9f064eb5b61075ef697306558e6ad2210ac7cc9 Mon Sep 17 00:00:00 2001 From: Abhi <85984486+AbhiTheModder@users.noreply.github.com> Date: Thu, 4 Jan 2024 22:51:46 +0000 Subject: [PATCH] Fix: antipm.py Add PM_PERMIT feature insteade of clearing full chat of users --- Dockerfile | 5 ++++ install.sh | 10 +++++++ modules/antipm.py | 66 ++++++++++++++++++++++++++++++++++++++++++++--- termux-install.sh | 10 +++++++ utils/config.py | 2 ++ 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a4fc0e3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.11 +WORKDIR /app +COPY . /app +RUN pip install -r requirements.txt +CMD ["bash", "install.sh"] \ No newline at end of file diff --git a/install.sh b/install.sh index ae8417a..22d8cbb 100644 --- a/install.sh +++ b/install.sh @@ -44,6 +44,15 @@ else read -r -p "API_HASH > " api_hash fi +echo +echo "SET PM PERMIT warn limit" +read -r -p "PM_LIMIT warn limit > " pm_limit + +if [[ $pm_limit = "" ]]; then + pm_limit="3" + echo "limit not provided by user set to default" +fi + echo echo "Enter APIFLASH_KEY for webshot plugin" echo "You can get it here -> https://apiflash.com/dashboard/access_keys" @@ -141,6 +150,7 @@ RMBG_KEY=${rmbg_key} VT_KEY=${vt_key} GEMINI_KEY=${gemini_key} VCA_API_KEY=${vca_api_key} +PM_LIMIT=${pm_limit} EOL chown -R $SUDO_USER:$SUDO_USER . diff --git a/modules/antipm.py b/modules/antipm.py index 7619562..112c7af 100644 --- a/modules/antipm.py +++ b/modules/antipm.py @@ -20,6 +20,7 @@ from pyrogram.types import Message from utils.db import db from utils.misc import modules_help, prefix +from utils.config import pm_limit anti_pm_enabled = filters.create( lambda _, __, ___: db.get("core.antipm", "status", False) @@ -32,6 +33,8 @@ in_contact_list = filters.create( is_support = filters.create(lambda _, __, message: message.chat.is_support) +message_counts = {} + @Client.on_message( filters.private & ~filters.me @@ -41,14 +44,48 @@ is_support = filters.create(lambda _, __, message: message.chat.is_support) & anti_pm_enabled ) async def anti_pm_handler(client: Client, message: Message): + m_n = 0 + warns = db.get("core.antipm", "warns") + user_id = message.from_user.id + id = message.chat.id + b_f = await client.get_me() + u_n = b_f.username + user = await client.get_users(id) + u_f = user.first_name user_info = await client.resolve_peer(message.chat.id) + default_text = f"""Hello, {u_f}! +This is the Assistant Of {u_n}. +My Boss is away or busy as of now, You can wait for him to respond. +Do not spam further messages else I may have to block you! + +This is an automated message by the assistant. +Currently You Have {warns} Warnings. +""" if db.get("core.antipm", "spamrep", False): await client.invoke(functions.messages.ReportSpam(peer=user_info)) if db.get("core.antipm", "block", False): await client.invoke(functions.contacts.Block(id=user_info)) - await client.invoke( - functions.messages.DeleteHistory(peer=user_info, max_id=0, revoke=True) - ) + await client.send_message(message.chat.id, f"{default_text}") + + if user_id in message_counts: + message_counts[user_id] += 1 + m_n = db.get("core.antipm", "warns") + m_n_n = m_n + 1 + db.set("core.antipm", "warns", m_n_n) + else: + message_counts[user_id] = 1 + m_n_n = 1 + db.set("core.antipm", "warns", m_n_n) + + if message_counts[user_id] > pm_limit: + await client.send_message(message.chat.id, f"Ehm...! That was your Last warn, Bye Bye see you L0L") + await client.invoke(functions.contacts.Block(id=user_info)) + del message_counts[user_id] + db.set("core.antipm", "warns", 0) + # await client.delete_messages(message.chat.id, message.id) + # await client.invoke( + # functions.messages.DeleteHistory(peer=user_info, max_id=0, revoke=True) + # ) @Client.on_message(filters.command(["antipm", "anti_pm"], prefix) & filters.me) @@ -124,8 +161,29 @@ async def antipm_block(_, message: Message): ) +@Client.on_message(filters.command(["a"], prefix) & filters.me) +async def add_contact(client: Client, message: Message): + # Extract the phone number from the message text + id = message.chat.id + + user = await client.get_users(id) + # Add the contact + await client.add_contact(id, user.first_name) + await message.edit("User Approved!") + +@Client.on_message(filters.command(["d"], prefix) & filters.me) +async def del_contact(client: Client, message: Message): + # Extract the phone number from the message text + id = message.chat.id + + # Add the contact + await client.delete_contacts(id) + await message.edit("User DisApproved!") + modules_help["antipm"] = { - "antipm [enable|disable]*": "When enabled, deletes all messages from users who are not in the contact book", + "antipm [enable|disable]*": "Enable Pm permit", "antipm_report [enable|disable]*": "Enable spam reporting", "antipm_block [enable|disable]*": "Enable user blocking", + "a": "Approve User", + "d": "DisApprove User" } \ No newline at end of file diff --git a/termux-install.sh b/termux-install.sh index 74fa3b1..196f8b1 100644 --- a/termux-install.sh +++ b/termux-install.sh @@ -40,6 +40,15 @@ else read -r -p "API_HASH > " api_hash fi +echo +echo "SET PM PERMIT warn limit" +read -r -p "PM_LIMIT warn limit > " pm_limit + +if [[ $pm_limit = "" ]]; then + pm_limit="3" + echo "limit not provided by user set to default" +fi + echo echo "Enter APIFLASH_KEY for webshot plugin" echo "You can get it here -> https://apiflash.com/dashboard/access_keys" @@ -120,6 +129,7 @@ RMBG_KEY=${rmbg_key} VT_KEY=${vt_key} GEMINI_KEY=${gemini_key} VCA_API_KEY=${vca_api_key} +PM_LIMIT=${pm_limit} EOL python3 install.py 3 || exit 3 diff --git a/utils/config.py b/utils/config.py index c9fc643..ea31857 100644 --- a/utils/config.py +++ b/utils/config.py @@ -16,5 +16,7 @@ vt_key = env.str("VT_KEY") gemini_key = env.str("GEMINI_KEY") vca_api_key = env.str("VCA_API_KEY") +pm_limit = env.int("PM_LIMIT") + test_server = env.bool("TEST_SERVER", False) modules_repo_branch = env.str("MODULES_REPO_BRANCH", "master") \ No newline at end of file