Automatically fix twitter links
All checks were successful
Build and Publish / build_and_publish (push) Successful in 5m32s

This commit is contained in:
Nexus 2024-07-23 16:24:01 +01:00
parent 27b23d3e3a
commit 0bbe0a65a5
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -14,6 +14,7 @@ import shutil
import tempfile
import time
import typing
import urllib.parse
import warnings
from pathlib import Path
@ -497,6 +498,20 @@ class NetworkCog(commands.Cog):
files=files,
)
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
content = message.content.split()
for section in content:
if section.startswith("<") and section.endswith(">"):
continue
if section.startswith("http://") or section.startswith("https://"):
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)
def setup(bot):
bot.add_cog(NetworkCog(bot))