diff options
author | 2021-10-14 21:52:01 +0100 | |
---|---|---|
committer | 2021-10-14 20:52:01 +0000 | |
commit | 1f4b65d4d06d3f22f05253eccd1abd0468217811 (patch) | |
tree | 2dabc95a6d66445309a7197a8001bcd6e9d0871d | |
parent | Merge pull request #1860 from python-discord/fix-infract-then-dm (diff) |
Send `!defcon threshold` message in `channel` as well as #defcon. (#1856)
Co-authored-by: Xithrius <[email protected]>
-rw-r--r-- | bot/exts/moderation/defcon.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/bot/exts/moderation/defcon.py b/bot/exts/moderation/defcon.py index ac813d6ba..1d6dbb49a 100644 --- a/bot/exts/moderation/defcon.py +++ b/bot/exts/moderation/defcon.py @@ -8,7 +8,7 @@ from typing import Optional, Union from aioredis import RedisError from async_rediscache import RedisCache from dateutil.relativedelta import relativedelta -from discord import Colour, Embed, Forbidden, Member, User +from discord import Colour, Embed, Forbidden, Member, TextChannel, User from discord.ext import tasks from discord.ext.commands import Cog, Context, group, has_any_role @@ -176,7 +176,7 @@ class Defcon(Cog): """ if isinstance(threshold, int): threshold = relativedelta(days=threshold) - await self._update_threshold(ctx.author, threshold=threshold, expiry=expiry) + await self._update_threshold(ctx.author, ctx.channel, threshold, expiry) @defcon_group.command() @has_any_role(Roles.admins) @@ -208,7 +208,13 @@ class Defcon(Cog): scheduling.create_task(self.channel.edit(topic=new_topic)) @defcon_settings.atomic_transaction - async def _update_threshold(self, author: User, threshold: relativedelta, expiry: Optional[Expiry] = None) -> None: + async def _update_threshold( + self, + author: User, + channel: TextChannel, + threshold: relativedelta, + expiry: Optional[Expiry] = None + ) -> None: """Update the new threshold in the cog, cache, defcon channel, and logs, and additionally schedule expiry.""" self.threshold = threshold if threshold == relativedelta(days=0): # If the threshold is 0, we don't need to schedule anything @@ -248,9 +254,13 @@ class Defcon(Cog): else: channel_message = "removed" - await self.channel.send( - f"{action.value.emoji} DEFCON threshold {channel_message}{error}." - ) + message = f"{action.value.emoji} DEFCON threshold {channel_message}{error}." + await self.channel.send(message) + + # If invoked outside of #defcon send to `ctx.channel` too + if channel != self.channel: + await channel.send(message) + await self._send_defcon_log(action, author) self._update_channel_topic() @@ -258,7 +268,7 @@ class Defcon(Cog): async def _remove_threshold(self) -> None: """Resets the threshold back to 0.""" - await self._update_threshold(self.bot.user, relativedelta(days=0)) + await self._update_threshold(self.bot.user, self.channel, relativedelta(days=0)) @staticmethod def _stringify_relativedelta(delta: relativedelta) -> str: |