Properly handle locked channel being deleted

This commit is contained in:
Zeva Rose 2022-04-19 12:05:15 -06:00
parent b8c64bae31
commit 7dcfd1aaf7

View file

@ -14,6 +14,7 @@ from jarvis_tasks.util import runat
async def _unlock(channel: GuildChannel, lock: Lock, logger: Logger) -> None:
logger.debug(f"Deactivating lock {lock.id}")
try:
overwrite = get(channel.permission_overwrites, id=lock.guild)
if overwrite and lock.original_perms:
overwrite.allow = lock.original_perms.allow
@ -23,13 +24,12 @@ async def _unlock(channel: GuildChannel, lock: Lock, logger: Logger) -> None:
except Exception:
logger.debug("Locked channel deleted, ignoring error")
elif overwrite and not lock.original_perms:
try:
await channel.delete_permission(target=overwrite, reason="Automatic unlock")
except Exception:
logger.debug("Locked channel deleted, ignoring error")
else:
logger.debug("Permission neither exists not existed")
lock.active = False
except Exception:
logger.debug("Locked channel deleted, ignoring error")
await lock.commit()