Skip to content

Automatically Remove Users from BigBrother Watch List on Perma Ban#821

Merged
sco1 merged 11 commits into
masterfrom
hemlock-perma-ban-watch-removal
Mar 20, 2020
Merged

Automatically Remove Users from BigBrother Watch List on Perma Ban#821
sco1 merged 11 commits into
masterfrom
hemlock-perma-ban-watch-removal

Conversation

@MrHemlock
Copy link
Copy Markdown
Member

@MrHemlock MrHemlock commented Mar 6, 2020

Previously we had the bot set up so that when a user was permanently banned it would be automatically unwatched by our "Big Brother" system. This originally worked just fine, but the issue was that there was no embed being sent telling us about this. However, after the big rewrite, that automated functionality was lost in the process. This PR is intended to restore it.

The discussed solution was to move most of the current unwatch command's functionality into a helper method and allow for a flag to be set when it's sent from a permanent ban. The watch command will also have its functionality moved to a helper method for consistency and ease of testing.

Closes #321

- 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 <browndj3@gmail.com>
@MrHemlock MrHemlock added t: bug Something isn't working a: moderation Related to community moderation functionality: (moderation, defcon, verification) p: 1 - high High Priority labels Mar 6, 2020
@MrHemlock MrHemlock self-assigned this Mar 6, 2020
@Akarys42 Akarys42 added the s: WIP Work In Progress label Mar 9, 2020
- 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 <browndj3@gmail.com>
@SebastiaanZ SebastiaanZ changed the base branch from master to unittest-utils March 10, 2020 15:07
@SebastiaanZ SebastiaanZ changed the base branch from unittest-utils to master March 10, 2020 15:08
Bugs fixed:
- Previously, the code would check to see if `'expires_at'` was in the kwargs, which after testing I came to find out that it is regardless of the duration of the ban.  It has sense been changed to use a `.get()` in order to do a proper comparison.

- Code previously attempted to load from the `"BigBrother"` cog which is the incorrect spelling.  Changed it to `"Big Brother"` to correct this.

Logging Added:
- Additional trace logs added to both the `infractions.py` file as well as `bigbrother.py` to assist with future debugging or testing.

Signed-off-by: Daniel Brown <browndj3@gmail.com>
Kaizen:
- Cut down on the size of the import line by changing the imports from bot.constants to instead just importing the constants.  This will help clarify where certain constants are coming from.

- The periodic checkpoint message will no longer ping `@everyone` or `@Admins` when the bot detects that it is being ran in a debug environment.  Message is now a simple confirmation that the periodic ping method successfully ran.

Signed-off-by: Daniel Brown <browndj3@gmail.com>
@MrHemlock MrHemlock marked this pull request as ready for review March 13, 2020 19:53
@MrHemlock MrHemlock requested a review from a team as a code owner March 13, 2020 19:53
@MrHemlock MrHemlock requested review from jb3 and jerbob and removed request for a team March 13, 2020 19:53
@MrHemlock MrHemlock added status: needs review and removed s: WIP Work In Progress labels Mar 13, 2020
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know two spaces after full stops was a practice. I can live with it but it isn't consistent with any of the other text in this project as far as I know.

Comment thread bot/cogs/moderation/infractions.py Outdated
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply_ban's docstring should mention that this happens.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in most recent commit

Comment thread bot/cogs/moderation/infractions.py Outdated
Comment thread bot/cogs/watchchannels/bigbrother.py Outdated
@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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more generic name like send_message would be better. Regardless, this parameter should be documented.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in most recent commit

Comment thread bot/cogs/watchchannels/bigbrother.py Outdated
Comment thread bot/cogs/watchchannels/bigbrother.py Outdated
Comment thread bot/cogs/watchchannels/bigbrother.py Outdated
Comment on lines +123 to +132
if not banned: # Prevents a message being sent to the channel if part of a permanent ban
log.trace("User is not banned. Sending message to channel")
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.")
log.trace("No active watches found for user.")
if not banned: # Prevents a message being sent to the channel if part of a permanent ban
log.trace("User is not perma banned. Send the error message.")
await ctx.send(":x: The specified user is currently not being watched.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be cleaner if the message is assigned to a parameter and sent at the very end, similar to what the apply_watch function does.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in most recent commit

Comment thread bot/cogs/moderation/infractions.py Outdated
MrHemlock and others added 4 commits March 14, 2020 16:42
Co-Authored-By: Mark <kozlovmark@gmail.com>
Co-Authored-By: Mark <kozlovmark@gmail.com>
Co-Authored-By: Mark <kozlovmark@gmail.com>
- Docstrings for `apply_ban()` have been edited to mention that the method also removes a banned user from the watch list.

- Parameter `banned` in `apply_unwatch()` was changed to `send_message` in order to be more general.  Boolean logic was swapped to coincide with that change.

- `apply_unwatch()`'s sent message moved to the bottom of the method for clarity.  Added `return`s to the method to exit early if no message needs to be sent.

Signed-off-by: Daniel Brown <browndj3@gmail.com>
@MrHemlock MrHemlock requested a review from MarkKoz March 20, 2020 19:52
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly.

Comment thread bot/cogs/moderation/infractions.py Outdated

bb_cog = self.bot.get_cog("Big Brother")
if not bb_cog:
log.trace(f"Big Brother cog not loaded; perma-banned user {user} won't be unwatched.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand that this is part of the trace logging flow, if this situation is encountered then this should be issued at the error level, not a trace.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected in the most recent commit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we want to be notified that the big brother cog isn't loaded?

Copy link
Copy Markdown
Member Author

@MrHemlock MrHemlock Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purpose of the trace flow it makes no difference if this is an error or a trace, but for the sake of knowing that something isn't quite right with one of our cogs, it makes total sense for it to be an error. I just didn't think about it when writing it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case then IMO a warning is more appropriate. If there's ever a legitimate reason to unload it, even temporarily, then it'd be strange to be greeted with an error when nothing is actually wrong with the code. If you don't want it to be unloaded, consider adding it to the blacklist in the extensions cog.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, a warning makes sense to me. @sco1 that work for you?

- Changed the log for when the big brother cog doesn't load in the `apply_ban()` method doesn't properly load from a trace to an error.
Copy link
Copy Markdown
Contributor

@sco1 sco1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool, works cool, very cool

@sco1 sco1 merged commit 44b33d5 into master Mar 20, 2020
@sco1 sco1 deleted the hemlock-perma-ban-watch-removal branch March 20, 2020 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: moderation Related to community moderation functionality: (moderation, defcon, verification) p: 1 - high High Priority t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No embed is send when a user gets "auto-unwatched" after a ban

4 participants