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

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

View file

@ -500,6 +500,8 @@ class NetworkCog(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.author.bot:
return
content = message.content.split()
new_links = []
for section in content:
@ -510,19 +512,20 @@ class NetworkCog(commands.Cog):
if parsed.netloc in ("x.com", "twitter.com"):
parsed = parsed._replace(netloc="fixupx.com")
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
)
if new_links:
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):