Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bot/cogs/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from bot.bot import Bot
from bot.cogs.token_remover import TokenRemover
from bot.cogs.webhook_remover import WEBHOOK_URL_RE
from bot.constants import Categories, Channels, DEBUG_MODE, Guild, MODERATION_ROLES, Roles, URLs
from bot.decorators import with_role
from bot.utils.messages import wait_for_deletion
Expand Down Expand Up @@ -240,6 +241,7 @@ async def on_message(self, msg: Message) -> None:
and not msg.author.bot
and len(msg.content.splitlines()) > 3
and not TokenRemover.find_token_in_message(msg)
and not WEBHOOK_URL_RE.search(msg.content)
)

if parse_codeblock: # no token in the msg
Expand Down
10 changes: 7 additions & 3 deletions bot/cogs/watchchannels/watchchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from bot.api import ResponseCodeError
from bot.bot import Bot
from bot.cogs.moderation import ModLog
from bot.cogs.token_remover import TokenRemover
from bot.cogs.webhook_remover import WEBHOOK_URL_RE
from bot.constants import BigBrother as BigBrotherConfig, Guild as GuildConfig, Icons
from bot.pagination import LinePaginator
from bot.utils import CogABCMeta, messages
Expand Down Expand Up @@ -226,14 +228,16 @@ async def relay_message(self, msg: Message) -> None:

await self.send_header(msg)

cleaned_content = msg.clean_content

if cleaned_content:
if TokenRemover.find_token_in_message(msg) 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):
if url not in media_urls:
cleaned_content = cleaned_content.replace(url, f"`{url}`")

if cleaned_content:
await self.webhook_send(
cleaned_content,
username=msg.author.display_name,
Expand Down