diff options
| author | 2020-03-10 23:38:53 +0100 | |
|---|---|---|
| committer | 2020-03-10 23:38:53 +0100 | |
| commit | 39b2319bff31a7b3e2cb17154bcbdad0a0e71fc7 (patch) | |
| tree | 5a488635acb187c4e7a4fd8a7a7a7c9947a917e1 | |
| parent | Remove `channel` arg from commands. (diff) | |
Add alert with silenced channels on `cog_unload`.
| -rw-r--r-- | bot/cogs/moderation/silence.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/bot/cogs/moderation/silence.py b/bot/cogs/moderation/silence.py index 0fe720882..76c5a171d 100644 --- a/bot/cogs/moderation/silence.py +++ b/bot/cogs/moderation/silence.py @@ -72,6 +72,7 @@ class Silence(commands.Cog): def __init__(self, bot: Bot): self.bot = bot + self.muted_channels = set() self.bot.loop.create_task(self._get_instance_vars()) async def _get_instance_vars(self) -> None: @@ -131,6 +132,7 @@ class Silence(commands.Cog): self.notifier.add_channel(channel) return True + self.muted_channels.add(channel) log.debug(f"Silenced #{channel} ({channel.id}) for {duration} minute(s).") return True @@ -149,10 +151,19 @@ class Silence(commands.Cog): ) log.debug(f"Unsilenced channel #{channel} ({channel.id}).") self.notifier.remove_channel(channel) + with suppress(KeyError): + self.muted_channels.remove(channel) return True log.debug(f"Tried to unsilence channel #{channel} ({channel.id}) but the channel was not silenced.") return False + def cog_unload(self) -> None: + """Send alert with silenced channels on unload.""" + if self.muted_channels: + channels_string = ''.join(channel.mention for channel in self.muted_channels) + message = f"<@&{Roles.moderators}> channels left silenced on cog unload: {channels_string}" + asyncio.create_task(self._mod_alerts_channel.send(message)) + # This cannot be static (must have a __func__ attribute). def cog_check(self, ctx: Context) -> bool: """Only allow moderators to invoke the commands in this cog.""" |