diff options
| author | 2022-11-26 15:53:42 +0200 | |
|---|---|---|
| committer | 2022-11-26 15:53:42 +0200 | |
| commit | 2fab8c1962666934d42cea1aa7b7bb79fe3b5a09 (patch) | |
| tree | dfcd4e3eed84d4c4069910855ff49b1e09daf633 | |
| parent | Bring back snekbox result filtering (diff) | |
Phishing filter add command
A shortcut command to autoban a compromised account if it posts a given content.
| -rw-r--r-- | bot/exts/filtering/_settings_types/actions/infraction_and_notification.py | 2 | ||||
| -rw-r--r-- | bot/exts/filtering/_settings_types/actions/remove_context.py | 2 | ||||
| -rw-r--r-- | bot/exts/filtering/_utils.py | 2 | ||||
| -rw-r--r-- | bot/exts/filtering/filtering.py | 22 |
4 files changed, 26 insertions, 2 deletions
diff --git a/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py b/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py index f29aee571..ed08362de 100644 --- a/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py +++ b/bot/exts/filtering/_settings_types/actions/infraction_and_notification.py @@ -50,7 +50,7 @@ class Infraction(Enum): log.warning(f":warning: Could not apply {command_name} to {user.mention}: command not found.") return - ctx = FakeContext(channel) + ctx = FakeContext(channel, command) if self.name in ("KICK", "WARNING", "WATCH", "NOTE"): await command(ctx, user, reason=reason or None) else: diff --git a/bot/exts/filtering/_settings_types/actions/remove_context.py b/bot/exts/filtering/_settings_types/actions/remove_context.py index 7eb3db6c4..2ba731309 100644 --- a/bot/exts/filtering/_settings_types/actions/remove_context.py +++ b/bot/exts/filtering/_settings_types/actions/remove_context.py @@ -102,7 +102,7 @@ class RemoveContext(ActionEntry): ctx.action_descriptions.append("failed to superstar") return - await command(FakeContext(alerts_channel), ctx.author, None, reason=SUPERSTAR_REASON) + await command(FakeContext(alerts_channel, command), ctx.author, None, reason=SUPERSTAR_REASON) ctx.action_descriptions.append("superstar") def __or__(self, other: ActionEntry): diff --git a/bot/exts/filtering/_utils.py b/bot/exts/filtering/_utils.py index bd56c1260..5abb2240b 100644 --- a/bot/exts/filtering/_utils.py +++ b/bot/exts/filtering/_utils.py @@ -10,6 +10,7 @@ from typing import Any, Iterable, TypeVar, Union import discord import regex +from discord.ext.commands import Command import bot from bot.bot import Bot @@ -199,6 +200,7 @@ class FakeContext: """ channel: discord.abc.Messageable + command: Command | None bot: Bot | None = None guild: discord.Guild | None = None author: discord.Member | discord.User | None = None diff --git a/bot/exts/filtering/filtering.py b/bot/exts/filtering/filtering.py index 81348ca1e..673b5487c 100644 --- a/bot/exts/filtering/filtering.py +++ b/bot/exts/filtering/filtering.py @@ -39,6 +39,7 @@ from bot.exts.filtering._ui.ui import ( ArgumentCompletionView, DeleteConfirmationView, build_mod_alert, format_response_error ) from bot.exts.filtering._utils import past_tense, repr_equals, starting_value, to_serializable +from bot.exts.moderation.infraction.infractions import COMP_BAN_DURATION, COMP_BAN_REASON from bot.log import get_logger from bot.pagination import LinePaginator from bot.utils.channel import is_mod_channel @@ -671,6 +672,27 @@ class Filtering(Cog): ) await ctx.send(embed=embed, reference=ctx.message, view=view) + @filter.command(root_aliases=("compfilter", "compf")) + async def compadd( + self, ctx: Context, list_name: Optional[str], content: str, *, description: Optional[str] = "Phishing" + ) -> None: + """Add a filter to detect a compromised account. Will apply the equivalent of a compban if triggered.""" + result = await self._resolve_list_type_and_name(ctx, ListType.DENY, list_name, exclude="list_type") + if result is None: + return + list_type, filter_list = result + + settings = ( + "remove_context=True " + "dm_pings=Moderators " + "infraction_type=BAN " + "infraction_channel=1 " # Post the ban in #mod-alerts + f"infraction_duration={COMP_BAN_DURATION.total_seconds()} " + f"infraction_reason={COMP_BAN_REASON}" + ) + description_and_settings = f"{description} {settings}" + await self._add_filter(ctx, "noui", list_type, filter_list, content, description_and_settings) + # endregion # region: filterlist group |