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 asyncio
import inspect import inspect
import operator import operator
import re
from asyncio.subprocess import Process from asyncio.subprocess import Process
from functools import partial, partialmethod from functools import partial, partialmethod
from typing import Any from typing import Any
@ -28,6 +29,9 @@ from redbot.core.utils.views import SimpleMenu
def md(soup: BeautifulSoup, **options) -> Any | str: def md(soup: BeautifulSoup, **options) -> Any | str:
return MarkdownConverter(**options).convert_soup(soup) 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): class SeaUtils(commands.Cog):
"""A collection of random utilities.""" """A collection of random utilities."""
@ -204,15 +208,16 @@ class SeaUtils(commands.Cog):
pre_tags = soup.find_all('pre') pre_tags = soup.find_all('pre')
content = [] content = []
for pre_tag in pre_tags: for pre_tag in pre_tags:
text = convert_rfc_references(md(pre_tag))
if await ctx.embed_requested(): if await ctx.embed_requested():
embed = Embed( embed = Embed(
title="RFC Document", title="RFC Document",
description=md(pre_tag), description=text,
color=await ctx.embed_color() color=await ctx.embed_color()
) )
content.append(embed) content.append(embed)
else: else:
content.append(md(pre_tag)) content.append(text)
await SimpleMenu(pages=content, disable_after_timeout=True, timeout=300).start(ctx) await SimpleMenu(pages=content, disable_after_timeout=True, timeout=300).start(ctx)
else: else:
await ctx.maybe_send_embed(content=cf.error(f"An error occurred while fetching RFC {number}. Status code: {response.status}.")) await ctx.maybe_send_embed(content=cf.error(f"An error occurred while fetching RFC {number}. Status code: {response.status}."))