feat(seautils): add correct formatting for masked links
This commit is contained in:
parent
28246121a6
commit
99cd13ccf1
1 changed files with 7 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
import asyncio
|
||||
import inspect
|
||||
import operator
|
||||
import re
|
||||
from asyncio.subprocess import Process
|
||||
from functools import partial, partialmethod
|
||||
from typing import Any
|
||||
|
@ -28,6 +29,9 @@ from redbot.core.utils.views import SimpleMenu
|
|||
def md(soup: BeautifulSoup, **options) -> Any | str:
|
||||
return MarkdownConverter(**options).convert_soup(soup)
|
||||
|
||||
def convert_rfc_references(text: str):
|
||||
return re.sub(r"\(RFC\s(\d+)\)", r"(https://www.rfc-editor.org/rfc/rfc\1.html)", text)
|
||||
|
||||
class SeaUtils(commands.Cog):
|
||||
"""A collection of random utilities."""
|
||||
|
||||
|
@ -204,15 +208,16 @@ class SeaUtils(commands.Cog):
|
|||
pre_tags = soup.find_all('pre')
|
||||
content = []
|
||||
for pre_tag in pre_tags:
|
||||
text = convert_rfc_references(md(pre_tag))
|
||||
if await ctx.embed_requested():
|
||||
embed = Embed(
|
||||
title="RFC Document",
|
||||
description=md(pre_tag),
|
||||
description=text,
|
||||
color=await ctx.embed_color()
|
||||
)
|
||||
content.append(embed)
|
||||
else:
|
||||
content.append(md(pre_tag))
|
||||
content.append(text)
|
||||
await SimpleMenu(pages=content, disable_after_timeout=True, timeout=300).start(ctx)
|
||||
else:
|
||||
await ctx.maybe_send_embed(content=cf.error(f"An error occurred while fetching RFC {number}. Status code: {response.status}."))
|
||||
|
|
Loading…
Reference in a new issue