From adac8e8eb687f2c36c8d9ee55b25e51aa95a1d0b Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 14 Jun 2022 22:52:52 +0100 Subject: Always prepend guild name to guild invite filters. Some guild invites are autoban filters, which require the mod to set a comment which includes [autoban]. Having the guild name in the comment is still useful when reviewing filter list, so prepend it to the set comment in case some mod forgets. Co-authored-by: Alex Noel <66466249+LiquidPulsar@users.noreply.github.com> --- bot/exts/filters/filter_lists.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bot/exts/filters/filter_lists.py b/bot/exts/filters/filter_lists.py index fc9cfbeca..cc3a61212 100644 --- a/bot/exts/filters/filter_lists.py +++ b/bot/exts/filters/filter_lists.py @@ -55,17 +55,20 @@ class FilterLists(Cog): """Add an item to a filterlist.""" allow_type = "whitelist" if allowed else "blacklist" - # If this is a server invite, we gotta validate it. + # If this is a guild invite, we gotta validate it. if list_type == "GUILD_INVITE": guild_data = await self._validate_guild_invite(ctx, content) content = guild_data.get("id") - # Unless the user has specified another comment, let's - # use the server name as the comment so that the list - # of guild IDs will be more easily readable when we - # display it. - if not comment: - comment = guild_data.get("name") + # Some guild invites are autoban filters, which require the mod + # to set a comment which includes [autoban]. + # Having the guild name in the comment is still useful when reviewing + # filter list, so prepend it to the set comment in case some mod forgets. + comment = " - ".join( + comment_part + for comment_part in (guild_data.get("name", ""), comment) + if comment_part + ) # If it's a file format, let's make sure it has a leading dot. elif list_type == "FILE_FORMAT" and not content.startswith("."): -- cgit v1.2.3 From 19f67db0f18c7d49ff5e0a01b4cc9b569c992689 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 15 Jun 2022 13:06:26 +0100 Subject: Include the list type when telling mods a new autoban filter was added --- bot/exts/filters/filter_lists.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/exts/filters/filter_lists.py b/bot/exts/filters/filter_lists.py index cc3a61212..fe7a71e09 100644 --- a/bot/exts/filters/filter_lists.py +++ b/bot/exts/filters/filter_lists.py @@ -118,7 +118,8 @@ class FilterLists(Cog): # If it is an autoban trigger we send a warning in #mod-meta if comment and "[autoban]" in comment: await self.bot.get_channel(Channels.mod_meta).send( - f":warning: Heads-up! The new filter `{content}` (`{comment}`) will automatically ban users." + f":warning: Heads-up! The new `{list_type}` filter " + f"`{content}` (`{comment}`) will automatically ban users." ) # Insert the item into the cache -- cgit v1.2.3 From 111db69c9f697ed1ff90296aa6d9ab37a11dcd9c Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 15 Jun 2022 15:35:33 +0100 Subject: Don't ping mods for autoban filters --- bot/exts/filters/filtering.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 13035c0c8..d974a147e 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -387,9 +387,9 @@ class Filtering(Cog): log.trace(f"Offensive message {msg.id} will be deleted on {delete_date}") stats = self._add_stats(filter_name, match, msg.content) - await self._send_log(filter_name, _filter, msg, stats, reason) - # If the filter reason contains `[autoban]`, we want to auto-ban the user + # If the filter reason contains `[autoban]`, we want to auto-ban the user. + # Also pass this to _send_log so mods are not pinged filter matches that are auto-actioned autoban = reason and "[autoban]" in reason.lower() if not autoban and filter_name == "filter_invites" and isinstance(result, dict): autoban = any( @@ -397,6 +397,9 @@ class Filtering(Cog): for invite_info in result.values() if invite_info.get("reason") ) + + await self._send_log(filter_name, _filter, msg, stats, reason, autoban=autoban) + if autoban: # Create a new context, with the author as is the bot, and the channel as #mod-alerts. # This sends the ban confirmation directly under watchlist trigger embed, to inform @@ -425,6 +428,7 @@ class Filtering(Cog): reason: Optional[str] = None, *, is_eval: bool = False, + auto_ban: bool = False, ) -> None: """Send a mod log for a triggered filter.""" if msg.channel.type is ChannelType.private: @@ -438,7 +442,7 @@ class Filtering(Cog): content = str(msg.author.id) # quality-of-life improvement for mobile moderators # If we are going to autoban, we don't want to ping and don't need the user ID - if reason and "[autoban]" in reason: + if auto_ban: ping_everyone = False content = None -- cgit v1.2.3 From af4339e1436bf554188205341a7b82becb573af1 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 22 Jun 2022 14:17:49 +0100 Subject: Improved output format of guild autoban notifications --- bot/exts/filters/filter_lists.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/exts/filters/filter_lists.py b/bot/exts/filters/filter_lists.py index fe7a71e09..c643f9a84 100644 --- a/bot/exts/filters/filter_lists.py +++ b/bot/exts/filters/filter_lists.py @@ -64,9 +64,11 @@ class FilterLists(Cog): # to set a comment which includes [autoban]. # Having the guild name in the comment is still useful when reviewing # filter list, so prepend it to the set comment in case some mod forgets. + guild_name_part = f'Guild "{guild_data["name"]}"' if "name" in guild_data else None + comment = " - ".join( comment_part - for comment_part in (guild_data.get("name", ""), comment) + for comment_part in (guild_name_part, comment) if comment_part ) -- cgit v1.2.3 From 11f329f6847c0e5f97dac248507bbd2970804f43 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 22 Jun 2022 14:18:43 +0100 Subject: Rename filtering send log kwarg for consistency with where it's sent from --- bot/exts/filters/filtering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index d974a147e..ca6ad0064 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -428,7 +428,7 @@ class Filtering(Cog): reason: Optional[str] = None, *, is_eval: bool = False, - auto_ban: bool = False, + autoban: bool = False, ) -> None: """Send a mod log for a triggered filter.""" if msg.channel.type is ChannelType.private: @@ -442,7 +442,7 @@ class Filtering(Cog): content = str(msg.author.id) # quality-of-life improvement for mobile moderators # If we are going to autoban, we don't want to ping and don't need the user ID - if auto_ban: + if autoban: ping_everyone = False content = None -- cgit v1.2.3