Skip to content

Commit

Permalink
change: bot no longer DMs user, instead warning message is sent in ch…
Browse files Browse the repository at this point in the history
…annel and pings user.

change: expanded regex to include optional final `/`.
  • Loading branch information
namemcguffin committed Aug 6, 2021
1 parent 83d49be commit 2550921
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions cogs/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
# You should have received a copy of the GNU General Public License
# along with Canary. If not, see <https://www.gnu.org/licenses/>.

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_&=%\.\?-]+\/?"
)


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2550921

Please sign in to comment.