ban|mute|kick|zombies: stop calling get_cgat_member to check status, chat object sends chat perms.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user