Improve twitter fix
All checks were successful
Build and Publish / build_and_publish (push) Successful in 57s

This commit is contained in:
Nexus 2024-07-23 16:37:40 +01:00
parent 0bbe0a65a5
commit 8264680e21
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -501,6 +501,7 @@ class NetworkCog(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
content = message.content.split()
new_links = []
for section in content:
if section.startswith("<") and section.endswith(">"):
continue
@ -508,9 +509,20 @@ class NetworkCog(commands.Cog):
parsed = urllib.parse.urlparse(section)
if parsed.netloc in ("x.com", "twitter.com"):
parsed = parsed._replace(netloc="fixupx.com")
await message.channel.send(parsed.geturl(), reference=message)
if message.channel.permissions_for(message.guild.me).manage_messages:
await message.edit(suppress=True)
new_links.append(parsed.geturl())
if len(content) == 1: # just link
await message.delete(delay=0.1, reason="Fixed twitter link")
await message.channel.send(
f"**{message.author.mention}**:\n" + " | ".join(new_links),
allowed_mentions=discord.AllowedMentions.none(),
)
else:
await message.edit(suppress=True)
await message.channel.send(
" | ".join(new_links),
allowed_mentions=discord.AllowedMentions.none(),
reference=message
)
def setup(bot):