aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-10-19 11:17:31 +0000
committerGravatar GitHub <[email protected]>2021-10-19 11:17:31 +0000
commitacc79870d55ca257a234a9dc49bfa4a7c85da2ca (patch)
treea4bce9cca2118d1f286c331e0d7210040fbbc5c4
parentMerge pull request #1871 from python-discord/modlog-ingore-channels-mods-can'... (diff)
Filtering: add autoban on specific reasons
Due to the increase in typo-squatting based phishing, we want to automatically ban users sending specific domain names. For that, this commit will automatically ban any user that trigger a filter which has `[autoban]` in its reason. That's it!
-rw-r--r--bot/exts/filters/filtering.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py
index 7faf063b9..ad67f3469 100644
--- a/bot/exts/filters/filtering.py
+++ b/bot/exts/filters/filtering.py
@@ -42,6 +42,10 @@ ZALGO_RE = regex.compile(rf"[\p{{NONSPACING MARK}}\p{{ENCLOSING MARK}}--[{VARIAT
# Other constants.
DAYS_BETWEEN_ALERTS = 3
OFFENSIVE_MSG_DELETE_TIME = timedelta(days=Filter.offensive_msg_delete_days)
+AUTO_BAN_REASON = (
+ "Your account seem to be compromised (%s). "
+ "Please appeal this ban once you have regained control of your account."
+)
FilterMatch = Union[re.Match, dict, bool, List[discord.Embed]]
@@ -346,6 +350,26 @@ class Filtering(Cog):
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 indeed ban
+ if "[autoban]" in reason.lower():
+ # We create a new context from that message and make sure the staffer is the bot
+ # and the feeback message is sent in #mod-alert
+ context = await self.bot.get_context(msg)
+ context.author = self.bot.user
+ context.channel = self.bot.get_channel(Channels.mod_alerts)
+
+ # We need to convert the user to a member if we are inside a DM channel
+ if msg.guild is None:
+ user = self.bot.get_guild(Guild.id).get_member(msg.author.id)
+ else:
+ user = msg.author
+
+ await context.invoke(
+ self.bot.get_command("ban"),
+ user,
+ reason=AUTO_BAN_REASON % reason.lower().replace("[autoban]", "").strip()
+ )
+
break # We don't want multiple filters to trigger
async def _send_log(
@@ -367,6 +391,10 @@ class Filtering(Cog):
# Allow specific filters to override ping_everyone
ping_everyone = Filter.ping_everyone and _filter.get("ping_everyone", True)
+ # If we are going to autoban, we don't want to ping
+ if "[autoban]" in reason:
+ ping_everyone = False
+
eval_msg = "using !eval " if is_eval else ""
footer = f"Reason: {reason}" if reason else None
message = (