diff options
author | 2021-10-25 23:42:05 +0300 | |
---|---|---|
committer | 2021-10-25 23:42:05 +0300 | |
commit | ca634c93ef377a21ad987006703654d0ed5c952f (patch) | |
tree | eb7c5e4fc71674e64d4936de6dda9cb7b99e437c | |
parent | Merge pull request #1908 from python-discord/fix-tz-issue (diff) | |
parent | Filtering: remove dangling empty quote (diff) |
Merge pull request #1893 from python-discord/filters/autoban
Filtering: add autoban on specific reasons
-rw-r--r-- | bot/constants.py | 1 | ||||
-rw-r--r-- | bot/exts/filters/filter_lists.py | 7 | ||||
-rw-r--r-- | bot/exts/filters/filtering.py | 38 | ||||
-rw-r--r-- | bot/exts/moderation/infraction/_scheduler.py | 14 | ||||
-rw-r--r-- | config-default.yml | 1 |
5 files changed, 54 insertions, 7 deletions
diff --git a/bot/constants.py b/bot/constants.py index f704c9e6a..e3846fb3d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -444,6 +444,7 @@ class Channels(metaclass=YAMLGetter): incidents: int incidents_archive: int mod_alerts: int + mod_meta: int nominations: int nomination_voting: int organisation: int diff --git a/bot/exts/filters/filter_lists.py b/bot/exts/filters/filter_lists.py index 4b5200684..ee5bd89f3 100644 --- a/bot/exts/filters/filter_lists.py +++ b/bot/exts/filters/filter_lists.py @@ -6,6 +6,7 @@ from discord.ext.commands import BadArgument, Cog, Context, IDConverter, group, from bot import constants from bot.api import ResponseCodeError from bot.bot import Bot +from bot.constants import Channels from bot.converters import ValidDiscordServerInvite, ValidFilterListType from bot.log import get_logger from bot.pagination import LinePaginator @@ -100,6 +101,12 @@ class FilterLists(Cog): ) raise + # 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." + ) + # Insert the item into the cache self.bot.insert_item_into_filter_list_cache(item) await ctx.message.add_reaction("✅") diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 6df78f550..b7a7e8093 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -44,6 +44,23 @@ ZALGO_RE = regex.compile(rf"[\p{{NONSPACING MARK}}\p{{ENCLOSING MARK}}--[{VARIAT DAYS_BETWEEN_ALERTS = 3 OFFENSIVE_MSG_DELETE_TIME = timedelta(days=Filter.offensive_msg_delete_days) +# Autoban +LINK_PASSWORD = "https://support.discord.com/hc/en-us/articles/218410947-I-forgot-my-Password-Where-can-I-set-a-new-one" +LINK_2FA = "https://support.discord.com/hc/en-us/articles/219576828-Setting-up-Two-Factor-Authentication" +AUTO_BAN_REASON = ( + "Your account has been used to send links to a phishing website. You have been automatically banned. " + "If you are not aware of sending them, that means your account has been compromised.\n\n" + + f"Here is a guide from Discord on [how to change your password]({LINK_PASSWORD}).\n\n" + + f"We also highly recommend that you [enable 2 factor authentication on your account]({LINK_2FA}), " + "for heightened security.\n\n" + + "Once you have changed your password, feel free to follow the instructions at the bottom of " + "this message to appeal your ban." +) +AUTO_BAN_DURATION = timedelta(days=4) + FilterMatch = Union[re.Match, dict, bool, List[discord.Embed]] @@ -347,6 +364,23 @@ 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 auto-ban the user + if reason and "[autoban]" in reason.lower(): + # 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 + # mods that the user was auto-banned for the message. + context = await self.bot.get_context(msg) + context.author = self.bot.get_guild(Guild.id).get_member(self.bot.user.id) + context.channel = self.bot.get_channel(Channels.mod_alerts) + context.command = self.bot.get_command("tempban") + + await context.invoke( + context.command, + msg.author, + arrow.utcnow() + AUTO_BAN_DURATION, + reason=AUTO_BAN_REASON + ) + break # We don't want multiple filters to trigger async def _send_log( @@ -368,6 +402,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 reason and "[autoban]" in reason: + ping_everyone = False + eval_msg = "using !eval " if is_eval else "" footer = f"Reason: {reason}" if reason else None message = ( diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index 74a987808..762eb6afa 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -175,13 +175,7 @@ class InfractionScheduler: dm_log_text = "\nDM: Sent" end_msg = "" - if infraction["actor"] == self.bot.user.id: - log.trace( - f"Infraction #{id_} actor is bot; including the reason in the confirmation message." - ) - if reason: - end_msg = f" (reason: {textwrap.shorten(reason, width=1500, placeholder='...')})" - elif is_mod_channel(ctx.channel): + if is_mod_channel(ctx.channel): log.trace(f"Fetching total infraction count for {user}.") infractions = await self.bot.api_client.get( @@ -190,6 +184,12 @@ class InfractionScheduler: ) total = len(infractions) end_msg = f" (#{id_} ; {total} infraction{ngettext('', 's', total)} total)" + elif infraction["actor"] == self.bot.user.id: + log.trace( + f"Infraction #{id_} actor is bot; including the reason in the confirmation message." + ) + if reason: + end_msg = f" (reason: {textwrap.shorten(reason, width=1500, placeholder='...')})" purge = infraction.get("purge", "") diff --git a/config-default.yml b/config-default.yml index b61d9c99c..4a85ccc56 100644 --- a/config-default.yml +++ b/config-default.yml @@ -207,6 +207,7 @@ guild: incidents_archive: 720668923636351037 mod_alerts: 473092532147060736 mods: &MODS 305126844661760000 + mod_meta: 775412552795947058 nominations: 822920136150745168 nomination_voting: 822853512709931008 organisation: &ORGANISATION 551789653284356126 |