diff options
author | 2023-02-28 14:30:09 +0200 | |
---|---|---|
committer | 2023-02-28 14:30:09 +0200 | |
commit | bd5c0f88851bfd074773d2ef69732e667a9e39d8 (patch) | |
tree | a9306294824332795255ff2846f7f8e1ed68c82f | |
parent | Correct type hint (diff) |
Re-add webhook and discord token check in other cogs
Co-authored-by: wookie184 <[email protected]>
-rw-r--r-- | bot/exts/filtering/_filters/unique/discord_token.py | 2 | ||||
-rw-r--r-- | bot/exts/info/codeblock/_cog.py | 4 | ||||
-rw-r--r-- | bot/exts/moderation/watchchannels/_watchchannel.py | 6 |
3 files changed, 10 insertions, 2 deletions
diff --git a/bot/exts/filtering/_filters/unique/discord_token.py b/bot/exts/filtering/_filters/unique/discord_token.py index 731df198c..b2ac43cdb 100644 --- a/bot/exts/filtering/_filters/unique/discord_token.py +++ b/bot/exts/filtering/_filters/unique/discord_token.py @@ -143,7 +143,7 @@ class DiscordTokenFilter(UniqueFilter): @classmethod def find_token_in_message(cls, content: str) -> Token | None: - """Return a seemingly valid token found in `msg` or `None` if no token is found.""" + """Return a seemingly valid token found in `content` or `None` if no token is found.""" # Use finditer rather than search to guard against method calls prematurely returning the # token check (e.g. `message.channel.send` also matches our token pattern) for match in TOKEN_RE.finditer(content): diff --git a/bot/exts/info/codeblock/_cog.py b/bot/exts/info/codeblock/_cog.py index cc5862131..95ea54761 100644 --- a/bot/exts/info/codeblock/_cog.py +++ b/bot/exts/info/codeblock/_cog.py @@ -8,6 +8,8 @@ from discord.ext.commands import Cog from bot import constants from bot.bot import Bot +from bot.exts.filtering._filters.unique.discord_token import DiscordTokenFilter +from bot.exts.filtering._filters.unique.webhook import WEBHOOK_URL_RE from bot.exts.info.codeblock._instructions import get_instructions from bot.log import get_logger from bot.utils import has_lines @@ -133,6 +135,8 @@ class CodeBlockCog(Cog, name="Code Block"): not message.author.bot and self.is_valid_channel(message.channel) and has_lines(message.content, constants.CodeBlock.minimum_lines) + and not DiscordTokenFilter.find_token_in_message(message.content) + and not WEBHOOK_URL_RE.search(message.content) ) @Cog.listener() diff --git a/bot/exts/moderation/watchchannels/_watchchannel.py b/bot/exts/moderation/watchchannels/_watchchannel.py index dc73aeef0..8701320de 100644 --- a/bot/exts/moderation/watchchannels/_watchchannel.py +++ b/bot/exts/moderation/watchchannels/_watchchannel.py @@ -14,6 +14,8 @@ from discord.ext.commands import Cog, Context from bot.bot import Bot from bot.constants import BigBrother as BigBrotherConfig, Guild as GuildConfig, Icons +from bot.exts.filtering._filters.unique.discord_token import DiscordTokenFilter +from bot.exts.filtering._filters.unique.webhook import WEBHOOK_URL_RE from bot.exts.moderation.modlog import ModLog from bot.log import CustomLogger, get_logger from bot.pagination import LinePaginator @@ -233,7 +235,9 @@ class WatchChannel(metaclass=CogABCMeta): await self.send_header(msg) - if cleaned_content := msg.clean_content: + if DiscordTokenFilter.find_token_in_message(msg.content) or WEBHOOK_URL_RE.search(msg.content): + cleaned_content = "Content is censored because it contains a bot or webhook token." + elif cleaned_content := msg.clean_content: # Put all non-media URLs in a code block to prevent embeds media_urls = {embed.url for embed in msg.embeds if embed.type in ("image", "video")} for url in URL_RE.findall(cleaned_content): |