diff options
author | 2020-08-15 19:18:24 -0700 | |
---|---|---|
committer | 2020-08-15 19:24:17 -0700 | |
commit | 68f2fbcb5afd474bc06c50267655177cf3617c5f (patch) | |
tree | 684de4cb63c2bdf32f02102dc283ee32f3643530 | |
parent | Silence: abort silence if there's already a scheduled task (diff) |
Silence: notify admins if previous overwrites were not cached
Admins will have to manually check the default values used and adjust
them if they aren't the desired values for that particular channel.
-rw-r--r-- | bot/cogs/moderation/silence.py | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/bot/cogs/moderation/silence.py b/bot/cogs/moderation/silence.py index 0f64301c4..ea2f51574 100644 --- a/bot/cogs/moderation/silence.py +++ b/bot/cogs/moderation/silence.py @@ -146,26 +146,39 @@ class Silence(commands.Cog): """ Unsilence `channel`. - Check if `channel` is silenced through a `PermissionOverwrite`, - if it is unsilence it and remove it from the notifier. + If `channel` has a silence task scheduled or has its previous overwrites cached, unsilence + it, cancel the task, and remove it from the notifier. Notify admins if it has a task but + not cached overwrites. + Return `True` if channel permissions were changed, `False` otherwise. """ prev_overwrites = await self.muted_channel_perms.get(channel.id) - if prev_overwrites is not None: - overwrite = channel.overwrites_for(self._verified_role) + if channel.id not in self.scheduler and prev_overwrites is None: + log.info(f"Tried to unsilence channel #{channel} ({channel.id}) but the channel was not silenced.") + return False + + overwrite = channel.overwrites_for(self._verified_role) + if prev_overwrites is None: + log.info(f"Missing previous overwrites for #{channel} ({channel.id}); defaulting to None.") + overwrite.update(send_messages=None, add_reactions=None) + else: overwrite.update(**json.loads(prev_overwrites)) - await channel.set_permissions(self._verified_role, overwrite=overwrite) - log.info(f"Unsilenced channel #{channel} ({channel.id}).") + await channel.set_permissions(self._verified_role, overwrite=overwrite) + log.info(f"Unsilenced channel #{channel} ({channel.id}).") - self.scheduler.cancel(channel.id) - self.notifier.remove_channel(channel) - await self.muted_channel_perms.delete(channel.id) + self.scheduler.cancel(channel.id) + self.notifier.remove_channel(channel) + await self.muted_channel_perms.delete(channel.id) - return True + if prev_overwrites is None: + await self._mod_alerts_channel.send( + f"<@&{Roles.admins}> Restored overwrites with default values after unsilencing " + f"{channel.mention}. Please check that the `Send Messages` and `Add Reactions` " + f"overwrites for {self._verified_role.mention} are at their desired values." + ) - log.info(f"Tried to unsilence channel #{channel} ({channel.id}) but the channel was not silenced.") - return False + return True def cog_unload(self) -> None: """Send alert with silenced channels and cancel scheduled tasks on unload.""" |