Improve twitter fix
All checks were successful
Build and Publish / build_and_publish (push) Successful in 57s
All checks were successful
Build and Publish / build_and_publish (push) Successful in 57s
This commit is contained in:
parent
0bbe0a65a5
commit
8264680e21
1 changed files with 15 additions and 3 deletions
|
@ -501,6 +501,7 @@ class NetworkCog(commands.Cog):
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
content = message.content.split()
|
content = message.content.split()
|
||||||
|
new_links = []
|
||||||
for section in content:
|
for section in content:
|
||||||
if section.startswith("<") and section.endswith(">"):
|
if section.startswith("<") and section.endswith(">"):
|
||||||
continue
|
continue
|
||||||
|
@ -508,9 +509,20 @@ class NetworkCog(commands.Cog):
|
||||||
parsed = urllib.parse.urlparse(section)
|
parsed = urllib.parse.urlparse(section)
|
||||||
if parsed.netloc in ("x.com", "twitter.com"):
|
if parsed.netloc in ("x.com", "twitter.com"):
|
||||||
parsed = parsed._replace(netloc="fixupx.com")
|
parsed = parsed._replace(netloc="fixupx.com")
|
||||||
await message.channel.send(parsed.geturl(), reference=message)
|
new_links.append(parsed.geturl())
|
||||||
if message.channel.permissions_for(message.guild.me).manage_messages:
|
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.edit(suppress=True)
|
||||||
|
await message.channel.send(
|
||||||
|
" | ".join(new_links),
|
||||||
|
allowed_mentions=discord.AllowedMentions.none(),
|
||||||
|
reference=message
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
Loading…
Reference in a new issue