aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2021-10-30 10:36:26 +0100
committerGravatar GitHub <[email protected]>2021-10-30 10:36:26 +0100
commit4b27cdff48ee82852fa18be00384e98148a7685d (patch)
tree3de9c3b0b32a35b6a0da7667386f87b6512c8cf6
parentRemove channel limitation with time range (diff)
parentMerge pull request #1909 from python-discord/pin-consistency (diff)
Merge branch 'main' into cleanrework
-rw-r--r--bot/constants.py1
-rw-r--r--bot/exts/filters/filter_lists.py7
-rw-r--r--bot/exts/filters/filtering.py39
-rw-r--r--bot/exts/help_channels/_cog.py6
-rw-r--r--bot/exts/help_channels/_message.py6
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py14
-rw-r--r--config-default.yml1
7 files changed, 64 insertions, 10 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..022b4ab02 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,24 @@ 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.guild = self.bot.get_guild(Guild.id)
+ context.author = context.guild.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 +403,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/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index 3c6cf7f26..0905cb23d 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -376,6 +376,12 @@ class HelpChannels(commands.Cog):
log.trace(f"Moving #{channel} ({channel.id}) to the Available category.")
+ # Unpin any previously stuck pins
+ log.trace(f"Looking for pins stuck in #{channel} ({channel.id}).")
+ for message in await channel.pins():
+ await _message.pin_wrapper(message.id, channel, pin=False)
+ log.debug(f"Removed a stuck pin from #{channel} ({channel.id}). ID: {message.id}")
+
await _channel.move_to_bottom(
channel=channel,
category_id=constants.Categories.help_available,
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
index a52c67570..241dd606c 100644
--- a/bot/exts/help_channels/_message.py
+++ b/bot/exts/help_channels/_message.py
@@ -174,7 +174,7 @@ async def notify(channel: discord.TextChannel, last_notification: t.Optional[Arr
async def pin(message: discord.Message) -> None:
"""Pin an initial question `message` and store it in a cache."""
- if await _pin_wrapper(message.id, message.channel, pin=True):
+ if await pin_wrapper(message.id, message.channel, pin=True):
await _caches.question_messages.set(message.channel.id, message.id)
@@ -205,7 +205,7 @@ async def unpin(channel: discord.TextChannel) -> None:
if msg_id is None:
log.debug(f"#{channel} ({channel.id}) doesn't have a message pinned.")
else:
- await _pin_wrapper(msg_id, channel, pin=False)
+ await pin_wrapper(msg_id, channel, pin=False)
def _match_bot_embed(message: t.Optional[discord.Message], description: str) -> bool:
@@ -220,7 +220,7 @@ def _match_bot_embed(message: t.Optional[discord.Message], description: str) ->
return message.author == bot.instance.user and bot_msg_desc.strip() == description.strip()
-async def _pin_wrapper(msg_id: int, channel: discord.TextChannel, *, pin: bool) -> bool:
+async def pin_wrapper(msg_id: int, channel: discord.TextChannel, *, pin: bool) -> bool:
"""
Pin message `msg_id` in `channel` if `pin` is True or unpin if it's False.
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