diff options
| author | 2020-03-06 14:35:17 -0600 | |
|---|---|---|
| committer | 2020-03-06 14:35:17 -0600 | |
| commit | 76a9a03a7b4334fd9606f0940c78111f3cfec9ea (patch) | |
| tree | f29f178d6d17d9b947c7eb31a3fe390a69ee6139 | |
| parent | Merge pull request #820 from python-discord/feat/ci/pre-commit-tweaks (diff) | |
Added BigBrother Helper Methods
- Added apply_unwatch() and migrated the code from the unwatch command to it. This will give us more control regarding testing and also determining when unwatches trigger.
- Added apply_watch() and migrated the code from the watch command to it. Again, this will assist with testing and could make it easier to automate adding to the watch list if need be.
- Added unwatch call to apply_ban. User will only be removed from the watch list if they were permanently banned. They will not be removed if it was only temporary.
Signed-off-by: Daniel Brown <[email protected]>
| -rw-r--r-- | bot/cogs/moderation/infractions.py | 13 | ||||
| -rw-r--r-- | bot/cogs/watchchannels/bigbrother.py | 22 |
2 files changed, 28 insertions, 7 deletions
diff --git a/bot/cogs/moderation/infractions.py b/bot/cogs/moderation/infractions.py index 9ea17b2b3..9bab38e23 100644 --- a/bot/cogs/moderation/infractions.py +++ b/bot/cogs/moderation/infractions.py @@ -67,7 +67,7 @@ class Infractions(InfractionScheduler, commands.Cog): @command() async def ban(self, ctx: Context, user: FetchedMember, *, reason: str = None) -> None: - """Permanently ban a user for the given reason.""" + """Permanently ban a user for the given reason. Also removes them from the BigBrother watch list.""" await self.apply_ban(ctx, user, reason) # endregion @@ -243,6 +243,17 @@ class Infractions(InfractionScheduler, commands.Cog): action = ctx.guild.ban(user, reason=reason, delete_message_days=0) await self.apply_infraction(ctx, infraction, user, action) + # Remove perma banned users from the watch list + if 'expires_at' not in kwargs: + bb_cog = self.bot.get_cog("BigBrother") + if bb_cog: + await bb_cog.apply_unwatch( + ctx, + user, + "User has been permanently banned from the server. Automatically removed.", + banned=True + ) + # endregion # region: Base pardon functions diff --git a/bot/cogs/watchchannels/bigbrother.py b/bot/cogs/watchchannels/bigbrother.py index c601e0d4d..75b66839e 100644 --- a/bot/cogs/watchchannels/bigbrother.py +++ b/bot/cogs/watchchannels/bigbrother.py @@ -52,6 +52,16 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"): A `reason` for adding the user to Big Brother is required and will be displayed in the header when relaying messages of this user to the watchchannel. """ + await self.apply_watch(ctx, user, reason) + + @bigbrother_group.command(name='unwatch', aliases=('uw',)) + @with_role(*MODERATION_ROLES) + async def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None: + """Stop relaying messages by the given `user`.""" + await self.apply_unwatch(ctx, user, reason) + + async def apply_watch(self, ctx: Context, user: FetchedMember, reason: str) -> None: + """Handles adding a user to the watch list.""" if user.bot: await ctx.send(f":x: I'm sorry {ctx.author}, I'm afraid I can't do that. I only watch humans.") return @@ -90,10 +100,8 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"): await ctx.send(msg) - @bigbrother_group.command(name='unwatch', aliases=('uw',)) - @with_role(*MODERATION_ROLES) - async def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None: - """Stop relaying messages by the given `user`.""" + async def apply_unwatch(self, ctx: Context, user: FetchedMember, reason: str, banned: bool = False) -> None: + """Handles the actual user removal from the watch list.""" active_watches = await self.bot.api_client.get( self.api_endpoint, params=ChainMap( @@ -111,8 +119,10 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"): await post_infraction(ctx, user, 'watch', f"Unwatched: {reason}", hidden=True, active=False) - await ctx.send(f":white_check_mark: Messages sent by {user} will no longer be relayed.") + if not banned: # Prevents a message being sent to the channel if part of a permanent ban + await ctx.send(f":white_check_mark: Messages sent by {user} will no longer be relayed.") self._remove_user(user.id) else: - await ctx.send(":x: The specified user is currently not being watched.") + if not banned: # Prevents a message being sent to the channel if part of a permanent ban + await ctx.send(":x: The specified user is currently not being watched.") |