From c5e727129647bbb2433f2aa7c786eb841b0cfa08 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 6 Sep 2021 11:44:19 +0200 Subject: [PATCH] repost message when a tiktok link is detected for embed compatibility --- src/cogs/internet.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cogs/internet.py b/src/cogs/internet.py index a98c81f..1c052da 100644 --- a/src/cogs/internet.py +++ b/src/cogs/internet.py @@ -4,6 +4,7 @@ from discord.ext import commands from random import choice from asyncpraw import Reddit from discord_slash import cog_ext +from re import findall from utils.core import randomImage, isSlash, mySendHidden, load, addReaction def setup(client): @@ -198,3 +199,17 @@ class Internet(commands.Cog): return await self._news(ctx, True) else: return await self._news(ctx, source, True) + + @commands.Cog.listener() + async def on_message(self, message): + """Triggered a message is received for tiktok""" + if message.author.bot: + return + urls = findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', message.content) + for url in urls: + url_embed = url.replace("tiktok.com", "dstn.to") + if message.content == url.replace(' ',''): + await message.channel.send(url_embed) + await message.delete() + else: + await message.reply(url_embed, mention_author = False)