From 2550921f9b3c86859dfe55e53a6ae5584e1f43fe Mon Sep 17 00:00:00 2001 From: "namemcguffin@not-a-tower" <52169277+namemcguffin@users.noreply.github.com> Date: Fri, 6 Aug 2021 17:54:21 -0400 Subject: [PATCH] change: bot no longer DMs user, instead warning message is sent in channel and pings user. change: expanded regex to include optional final `/`. --- cogs/sanitizer.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/cogs/sanitizer.py b/cogs/sanitizer.py index 3459b908..93014166 100644 --- a/cogs/sanitizer.py +++ b/cogs/sanitizer.py @@ -15,17 +15,16 @@ # You should have received a copy of the GNU General Public License # along with Canary. If not, see . -import discord -from discord import utils +import asyncio from discord.ext import commands import re import requests -TIKTOK_SHORTLINK = re.compile(r"https?:\/\/vm\.tiktok\.com\/[A-Za-z0-9]+") +TIKTOK_SHORTLINK = re.compile(r"https?:\/\/vm\.tiktok\.com\/[A-Za-z0-9]+\/?") TIKTOK_MOBILE = re.compile( - r"(https?:\/\/m\.tiktok\.com\/v\/[0-9]+)\.html\?[A-Za-z0-9_&=%\.\?-]+") + r"(https?:\/\/m\.tiktok\.com\/v\/[0-9]+)\.html\?[A-Za-z0-9_&=%\.\?-]+\/?") TIKTOK_DESKTOP = re.compile( - r"(https?:\/\/www\.tiktok\.com\/@[A-Za-z0-9_\.]+\/video\/[0-9]+)\?[A-Za-z0-9_&=%\.\?-]+" + r"(https?:\/\/www\.tiktok\.com\/@[A-Za-z0-9_\.]+\/video\/[0-9]+)\?[A-Za-z0-9_&=%\.\?-]+\/?" ) @@ -59,13 +58,24 @@ async def tiktok_link_sanitizer(self, msg): replace = True if replace: await msg.delete() - await msg.channel.send(f"> from: `{msg.author}`\n{msg_txt}") - dm_channel = msg.author.dm_channel or await msg.author.create_dm() - await dm_channel.send( - f"⚠️***WARNING*** ⚠️:\na message you sent contained " + warning_msg = await msg.channel.send( + f"<@{msg.author.id}> ⚠️***WARNING*** ⚠️:\na message you sent contained " "a tiktok link that could potentially reveal sensitive information." "\nas such, it has been deleted and a sanitized " "version of the message was resent by this discord bot.") + await msg.channel.send( + f"> from: <@{msg.author.id}>\n{msg_txt}" + ) + await warning_msg.add_reaction("🗑️") + try: + await self.bot.wait_for( + "reaction_add", + timeout=30, + check=lambda r, u: u == msg.author and r.message == + warning_msg and str(r.emoji) == "🗑️") + await warning_msg.delete() + except asyncio.TimeoutError: + await warning_msg.delete() def setup(bot):