diff --git a/anjani/language/en.yml b/anjani/language/en.yml index 2c00ad990..4ab549b58 100644 --- a/anjani/language/en.yml +++ b/anjani/language/en.yml @@ -628,6 +628,7 @@ lockings-failed-to-delete: "'`{lock_type}`' is locked but i can't delete the mes lockings-admin-required: | This method requires admin rights to work.\n -> __{message}__ +lockings-not-modified: "The chat lock setting has not been modified.\nIt appears that you have set the same setting as before." unlockings-type-required: Please provide a type of unlock. unlockings-type-unlocked: "'`{unlock_type}`' is not locked." unlockings-type-invalid: "'`{unlock_type}`' invalid unlock type." diff --git a/anjani/language/id.yml b/anjani/language/id.yml index 3dd7ffe76..38c4ee2e4 100644 --- a/anjani/language/id.yml +++ b/anjani/language/id.yml @@ -649,6 +649,7 @@ lockings-failed-to-delete: "'`{lock_type}`' dikunci tetapi saya tidak bisa mengh lockings-admin-required: | Metode ini membutuhkan hak administrator untuk mengunci tipe pesan/hak.\n -> __{message}__ +lockings-not-modified: "Pengaturan kunci tidak diubah.\nTampaknya anda mengatur pengaturan yang sama seperti sebelumnya." unlockings-type-required: Tolong sediakan tipe pesan yang ingin dikunci. unlockings-type-unlocked: "'`{unlock_type}`' tidak terkunci." unlockings-type-invalid: "'`{unlock_type}`' tipe pesan tidak sah." diff --git a/anjani/plugins/lockings.py b/anjani/plugins/lockings.py index 06f5c7981..e4591ea28 100644 --- a/anjani/plugins/lockings.py +++ b/anjani/plugins/lockings.py @@ -1,4 +1,5 @@ """Lock/Unlock group Plugin""" + # Copyright (C) 2020 - 2023 UserbotIndo Team, # # This program is free software: you can redistribute it and/or modify @@ -37,6 +38,7 @@ from pyrogram.errors import ( ChannelPrivate, ChatAdminRequired, + ChatNotModified, MessageDeleteForbidden, MessageIdInvalid, PeerIdInvalid, @@ -161,9 +163,9 @@ async def on_message(self, message: Message) -> None: locked = await self.get_chat_restrictions(chat.id) for lock_type in locked: try: - func: Union[ - str, Callable[[Client, Message], Coroutine[Any, Any, bool]] - ] = LOCK_TYPES[lock_type] + func: Union[str, Callable[[Client, Message], Coroutine[Any, Any, bool]]] = ( + LOCK_TYPES[lock_type] + ) if not callable(func): continue @@ -342,10 +344,14 @@ async def cmd_lock(self, ctx: command.Context, lock_type: Optional[str] = None) except ChatAdminRequired as e: return await ctx.get_text( "lockings-admin-required", - message=e.MESSAGE.split()[-1].strip(")").split(".")[-1].strip('"') - if e.MESSAGE - else "", + message=( + e.MESSAGE.split()[-1].strip(")").split(".")[-1].strip('"') + if e.MESSAGE + else "" + ), ) + except ChatNotModified: + return await ctx.get_text("lockings-not-modified") elif lock_type in LOCK_TYPES: locked = await self.get_chat_restrictions(chat.id) if lock_type in locked: @@ -380,10 +386,14 @@ async def cmd_unlock(self, ctx: command.Context, unlock_type: Optional[str] = No ): return await ctx.get_text("unlockings-type-unlocked", unlock_type=unlock_type) - await self.bot.client.set_chat_permissions( - chat_id=chat.id, - permissions=self.unpack_permissions(permissions, "unlock", unlock_type), - ) + try: + await self.bot.client.set_chat_permissions( + chat_id=chat.id, + permissions=self.unpack_permissions(permissions, "unlock", unlock_type), + ) + except ChatNotModified: + return await ctx.get_text("lockings-not-modified") + elif unlock_type in LOCK_TYPES: locked = await self.get_chat_restrictions(chat.id) if not locked or unlock_type not in locked: