Skip to content

Commit

Permalink
fix(lockings): handle unmodified permission
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMissx committed Feb 20, 2024
1 parent 6a970eb commit b6a52b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions anjani/language/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions anjani/language/id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
30 changes: 20 additions & 10 deletions anjani/plugins/lockings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Lock/Unlock group Plugin"""

# Copyright (C) 2020 - 2023 UserbotIndo Team, <https://github.com/userbotindo.git>
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -37,6 +38,7 @@
from pyrogram.errors import (
ChannelPrivate,
ChatAdminRequired,
ChatNotModified,
MessageDeleteForbidden,
MessageIdInvalid,
PeerIdInvalid,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b6a52b1

Please sign in to comment.