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 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}."))
|
||||||
|
|
Loading…
Reference in a new issue