bugfix unmute: unmuted users remained in restricted section, changed logic to remome them

This commit is contained in:
thedragonsinn
2024-11-05 15:15:39 +05:30
parent 1bfca2cff0
commit ac8ccbc4f9
2 changed files with 22 additions and 39 deletions

View File

@@ -1,41 +1,25 @@
import asyncio
from pyrogram.types import User
from app import BOT, Message
@BOT.add_cmd(cmd=["ban", "unban"])
@BOT.add_cmd(cmd=["ban", "unban", "unmute"])
async def ban_or_unban(bot: BOT, message: Message) -> None:
user, reason = await message.extract_user_n_reason()
if not isinstance(user, User):
await message.reply(user, del_in=10)
return
action = bot.ban_chat_member if message.cmd == "ban" else bot.unban_chat_member
if message.cmd == "unmute":
action_str = "Unmuted"
else:
action_str = f"{message.cmd.capitalize()}ned"
try:
await action(chat_id=message.chat.id, user_id=user.id) # NOQA
await message.reply(
text=f"{message.cmd.capitalize()}ned: {user.mention}\nReason: {reason}"
)
except Exception as e:
await message.reply(text=e, del_in=10)
@BOT.add_cmd(cmd="kick")
async def kick_user(bot: BOT, message: Message):
user, reason = await message.extract_user_n_reason()
if not isinstance(user, User):
await message.reply(user, del_in=10)
return
try:
await bot.ban_chat_member(chat_id=message.chat.id, user_id=user.id)
await asyncio.sleep(2)
await bot.unban_chat_member(chat_id=message.chat.id, user_id=user.id)
await message.reply(
text=f"{message.cmd.capitalize()}ed: {user.mention}\nReason: {reason}"
)
await message.reply(text=f"{action_str}: {user.mention}\nReason: {reason}")
except Exception as e:
await message.reply(text=e, del_in=10)

View File

@@ -3,29 +3,28 @@ from pyrogram.types import ChatPermissions, User
from app import BOT, Message
@BOT.add_cmd(cmd=["mute", "unmute"])
@BOT.add_cmd(cmd="mute")
async def mute_or_unmute(bot: BOT, message: Message):
user, reason = await message.extract_user_n_reason()
if not isinstance(user, User):
await message.reply(user, del_in=10)
return
perms = message.chat.permissions
if message.cmd == "mute":
perms = ChatPermissions(
can_send_messages=False,
can_pin_messages=False,
can_invite_users=False,
can_change_info=False,
can_send_media_messages=False,
can_send_polls=False,
can_send_other_messages=False,
can_add_web_page_previews=False,
)
try:
await bot.restrict_chat_member(
chat_id=message.chat.id, user_id=user.id, permissions=perms
chat_id=message.chat.id,
user_id=user.id,
permissions=ChatPermissions(
can_send_messages=False,
can_pin_messages=False,
can_invite_users=False,
can_change_info=False,
can_send_media_messages=False,
can_send_polls=False,
can_send_other_messages=False,
can_add_web_page_previews=False,
),
)
await message.reply(
text=f"{message.cmd.capitalize()}d: {user.mention}\nReason: {reason}"