feat(seautils): add correct formatting for masked links
Some checks failed
Actions / Build Documentation (MkDocs) (push) Successful in 26s
Actions / Lint Code (Ruff & Pylint) (push) Failing after 39s

This commit is contained in:
Seaswimmer 2024-05-28 20:35:25 -04:00
parent 28246121a6
commit 99cd13ccf1
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -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}."))