|
47 | 47 | build_mod_alert, |
48 | 48 | format_response_error, |
49 | 49 | ) |
50 | | -from bot.exts.filtering._utils import past_tense, repr_equals, starting_value, to_serializable |
| 50 | +from bot.exts.filtering._utils import past_tense, repr_equals, resolve_mention, starting_value, to_serializable |
51 | 51 | from bot.exts.moderation.infraction.infractions import COMP_BAN_DURATION, COMP_BAN_REASON |
52 | 52 | from bot.exts.utils.snekbox._io import FileAttachment |
53 | 53 | from bot.log import get_logger |
|
66 | 66 | WEEKLY_REPORT_ISO_DAY = 3 # 1=Monday, 7=Sunday |
67 | 67 |
|
68 | 68 |
|
| 69 | +def _clean_ban_mentions(mentions: set[str]) -> set[str]: |
| 70 | + """Remove broad pings and moderators role pings from ban alerts.""" |
| 71 | + blocked_mentions = {f"<@&{Roles.moderators}>", "@here", "@everyone"} |
| 72 | + cleaned_mentions = set() |
| 73 | + |
| 74 | + for mention in mentions: |
| 75 | + if mention.casefold() == "moderators": |
| 76 | + continue |
| 77 | + if resolve_mention(mention) in blocked_mentions: |
| 78 | + continue |
| 79 | + cleaned_mentions.add(mention) |
| 80 | + |
| 81 | + return cleaned_mentions |
| 82 | + |
| 83 | + |
69 | 84 | async def _extract_text_file_content(att: discord.Attachment) -> str: |
70 | 85 | """Extract up to the first 30 lines or first 2000 characters (whichever is shorter) of an attachment.""" |
71 | 86 | file_encoding = re.search(r"charset=(\S+)", att.content_type).group(1) |
@@ -981,7 +996,9 @@ async def _resolve_action( |
981 | 996 | # If the action is a ban, mods don't want to be pinged. |
982 | 997 | if infr_action := result_actions.get("infraction_and_notification"): |
983 | 998 | if infr_action.infraction_type == Infraction.BAN: |
984 | | - result_actions.pop("mentions", None) |
| 999 | + if mentions := result_actions.get("mentions"): |
| 1000 | + mentions.guild_pings = _clean_ban_mentions(mentions.guild_pings) |
| 1001 | + mentions.dm_pings = _clean_ban_mentions(mentions.dm_pings) |
985 | 1002 | return result_actions, messages, triggers |
986 | 1003 |
|
987 | 1004 | async def _send_alert(self, ctx: FilterContext, triggered_filters: dict[FilterList, Iterable[str]]) -> None: |
|
0 commit comments