From dfb10b419ef19715ab63867b9c8be1c70f44773e Mon Sep 17 00:00:00 2001 From: thedragonsinn <98635854+thedragonsinn@users.noreply.github.com> Date: Sat, 26 Apr 2025 15:23:55 +0530 Subject: [PATCH] `ban|mute|kick|zombies`: stop calling get_cgat_member to check status, chat object sends chat perms. --- app/plugins/admin/ban.py | 4 ++++ app/plugins/admin/fbans.py | 3 +-- app/plugins/admin/kicks.py | 6 ++---- app/plugins/admin/mute.py | 4 ++++ app/plugins/admin/promote.py | 7 +++---- app/plugins/admin/zombies.py | 7 ++----- app/plugins/tg_tools/respond.py | 1 + 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/plugins/admin/ban.py b/app/plugins/admin/ban.py index 4db5a35..c645d99 100644 --- a/app/plugins/admin/ban.py +++ b/app/plugins/admin/ban.py @@ -5,6 +5,10 @@ from app import BOT, Message @BOT.add_cmd(cmd=["ban", "unban", "unmute"]) async def ban_or_unban(bot: BOT, message: Message) -> None: + if not message.chat._raw.admin_rights: + await message.reply("Cannot perform action without being admin.") + return + user, reason = await message.extract_user_n_reason() if not isinstance(user, User): diff --git a/app/plugins/admin/fbans.py b/app/plugins/admin/fbans.py index 2716d65..ba61f82 100644 --- a/app/plugins/admin/fbans.py +++ b/app/plugins/admin/fbans.py @@ -129,8 +129,7 @@ async def fed_ban(bot: BOT, message: Message): if message.replied and message.chat.type != ChatType.PRIVATE: try: - me = await bot.get_chat_member(chat_id=message.chat.id, user_id="me") - if me.status in {ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR}: + if message.chat._raw.admin_rights: await message.replied.reply( text=f"!dban {reason}", disable_preview=True, del_in=3, block=False ) diff --git a/app/plugins/admin/kicks.py b/app/plugins/admin/kicks.py index 863cc19..11dba44 100644 --- a/app/plugins/admin/kicks.py +++ b/app/plugins/admin/kicks.py @@ -4,8 +4,7 @@ from datetime import UTC, datetime, timedelta from pyrogram.types import User from app import BOT, Message - -from .zombies import ADMIN_STATUS +from app.extra_config import ADMIN_STATUS @BOT.add_cmd(cmd="kick") @@ -31,8 +30,7 @@ async def kick_inactive_members(bot: BOT, message: Message): INFO: Kick inactive members with message count less than 10 """ - me = await bot.get_chat_member(message.chat.id, bot.me.id) - if me.status not in ADMIN_STATUS: + if not message.chat._raw.admin_rights: await message.reply("Cannot kick members without being admin.") return diff --git a/app/plugins/admin/mute.py b/app/plugins/admin/mute.py index 21e9ab2..3ee03b5 100644 --- a/app/plugins/admin/mute.py +++ b/app/plugins/admin/mute.py @@ -5,6 +5,10 @@ from app import BOT, Message @BOT.add_cmd(cmd="mute") async def mute_or_unmute(bot: BOT, message: Message): + if not message.chat._raw.admin_rights: + await message.reply("Cannot mute members without being admin.") + return + user, reason = await message.extract_user_n_reason() if not isinstance(user, User): diff --git a/app/plugins/admin/promote.py b/app/plugins/admin/promote.py index a78f061..5923283 100644 --- a/app/plugins/admin/promote.py +++ b/app/plugins/admin/promote.py @@ -5,6 +5,7 @@ from pyrogram.errors import FloodWait from pyrogram.types import ChatPrivileges, User from app import BOT, Message +from app.extra_config import ADMIN_STATUS DEMOTE_PRIVILEGES = ChatPrivileges(can_manage_chat=False) @@ -35,12 +36,10 @@ async def promote_or_demote(bot: BOT, message: Message) -> None: response: Message = await message.reply(f"Trying to {message.cmd.capitalize()}.....") my_status = await bot.get_chat_member(chat_id=message.chat.id, user_id=bot.me.id) + my_privileges = my_status.privileges - if not ( - my_status.status in {ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR} - and my_privileges.can_promote_members - ): + if not (my_status.status in ADMIN_STATUS and my_privileges.can_promote_members): await response.edit("You don't to have enough rights to do this.") return diff --git a/app/plugins/admin/zombies.py b/app/plugins/admin/zombies.py index 58b15cb..6ce7463 100644 --- a/app/plugins/admin/zombies.py +++ b/app/plugins/admin/zombies.py @@ -1,18 +1,15 @@ import asyncio from datetime import UTC, datetime, timedelta -from pyrogram.enums import ChatMemberStatus from pyrogram.errors import FloodWait from app import BOT, Message - -ADMIN_STATUS = {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER} +from app.extra_config import ADMIN_STATUS @BOT.add_cmd(cmd="zombies") async def clean_zombies(bot: BOT, message: Message): - me = await bot.get_chat_member(message.chat.id, bot.me.id) - if me.status not in ADMIN_STATUS: + if not message.chat._raw.admin_rights: await message.reply("Cannot clean zombies without being admin.") return diff --git a/app/plugins/tg_tools/respond.py b/app/plugins/tg_tools/respond.py index e3ada3e..1c95b0c 100644 --- a/app/plugins/tg_tools/respond.py +++ b/app/plugins/tg_tools/respond.py @@ -23,4 +23,5 @@ async def respond(bot: BOT, message: Message): else: await message.reply("Unable to extract chat_id and text.") return + await bot.send_message(chat_id=int(chat_id), text=text, disable_preview=True)