diff --git a/misskaty/core/misskaty_patch/bound/message.py b/misskaty/core/misskaty_patch/bound/message.py index 8083e80d..53e3bb89 100644 --- a/misskaty/core/misskaty_patch/bound/message.py +++ b/misskaty/core/misskaty_patch/bound/message.py @@ -88,6 +88,7 @@ async def reply_text( await asleep(del_in) return bool(await msg.delete_msg()) except FloodWait as e: + LOGGER.warning(f"Got floodwait in {self.chat.id} for {e.value}'s.") await asleep(e.value) return await reply_text(self, text, *args, **kwargs) except TopicClosed: @@ -134,7 +135,7 @@ async def edit_text( await asleep(del_in) return bool(await msg.delete_msg()) except FloodWait as e: - LOGGER.warning(str(e)) + LOGGER.warning(f"Got floodwait in {self.chat.id} for {e.value}'s.") await asleep(e.value) return await edit_text(self, text, *args, **kwargs) except MessageNotModified: diff --git a/misskaty/plugins/admin.py b/misskaty/plugins/admin.py index 9d89fc7f..e7e50e8d 100644 --- a/misskaty/plugins/admin.py +++ b/misskaty/plugins/admin.py @@ -28,7 +28,7 @@ from logging import getLogger from time import time from pyrogram import Client, enums, filters -from pyrogram.errors import ChatAdminRequired, FloodWait, PeerIdInvalid +from pyrogram.errors import ChatAdminRequired, FloodWait, PeerIdInvalid, UsernameNotOccupied from pyrogram.types import ChatPermissions, ChatPrivileges, Message from database.warn_db import add_warn, get_warn, remove_warns @@ -573,7 +573,10 @@ async def unmute(_, message, strings): @ratelimiter @use_chat_lang() async def warn_user(client, message, strings): - user_id, reason = await extract_user_and_reason(message) + try: + user_id, reason = await extract_user_and_reason(message) + except UsernameNotOccupied: + return await message.reply_msg("Sorry, i didn't know that user.") chat_id = message.chat.id if not user_id: return await message.reply_text(strings("user_not_found")) diff --git a/misskaty/plugins/locks.py b/misskaty/plugins/locks.py index 746a8b05..04f7061e 100644 --- a/misskaty/plugins/locks.py +++ b/misskaty/plugins/locks.py @@ -24,7 +24,7 @@ SOFTWARE. import asyncio from pyrogram import filters -from pyrogram.errors import ChatNotModified, FloodWait +from pyrogram.errors import ChatNotModified, FloodWait, ChatAdminRequired from pyrogram.types import ChatPermissions from misskaty import app @@ -120,7 +120,7 @@ async def tg_lock(message, permissions: list, perm: str, lock: bool): @adminsOnly("can_restrict_members") async def locks_func(_, message): if len(message.command) != 2: - return await message.reply_text(incorrect_parameters) + return await message.reply_msg(incorrect_parameters) chat_id = message.chat.id parameter = message.text.strip().split(None, 1)[1].lower() @@ -134,24 +134,30 @@ async def locks_func(_, message): if parameter in data: await tg_lock(message, permissions, data[parameter], state == "lock") elif parameter == "all" and state == "lock": - await app.set_chat_permissions(chat_id, ChatPermissions()) - await message.reply_text(f"Locked Everything in {message.chat.title}") + try: + await app.set_chat_permissions(chat_id, ChatPermissions()) + await message.reply_text(f"Locked Everything in {message.chat.title}") + except ChatAdminRequired: + await message.reply_msg("Give me proper admin permission to use this command.") elif parameter == "all" and state == "unlock": - await app.set_chat_permissions( - chat_id, - ChatPermissions( - can_send_messages=True, - can_send_media_messages=True, - can_send_other_messages=True, - can_add_web_page_previews=True, - can_send_polls=True, - can_change_info=False, - can_invite_users=True, - can_pin_messages=False, - ), - ) - await message.reply(f"Unlocked Everything in {message.chat.title}") + try: + await app.set_chat_permissions( + chat_id, + ChatPermissions( + can_send_messages=True, + can_send_media_messages=True, + can_send_other_messages=True, + can_add_web_page_previews=True, + can_send_polls=True, + can_change_info=False, + can_invite_users=True, + can_pin_messages=False, + ), + ) + await message.reply(f"Unlocked Everything in {message.chat.title}") + except ChatAdminRequired: + await message.reply_msg("Give me full admin permission to use this command.") @app.on_message(filters.command("locks", COMMAND_HANDLER) & ~filters.private)