Automatically fix twitter links
All checks were successful
Build and Publish / build_and_publish (push) Successful in 5m32s
All checks were successful
Build and Publish / build_and_publish (push) Successful in 5m32s
This commit is contained in:
parent
27b23d3e3a
commit
0bbe0a65a5
1 changed files with 15 additions and 0 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue