Compare commits
No commits in common. "069ea800db9c71dd684290cadc52b81fe3e1c859" and "b9f0dbf98a5272d81e39c8c62788ccc47cda36dc" have entirely different histories.
069ea800db
...
b9f0dbf98a
1 changed files with 3 additions and 14 deletions
|
@ -29,7 +29,7 @@ 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 format_rfx_text(text: str, number: int) -> str:
|
def convert_rfc_references(text: str, number: int) -> str:
|
||||||
one = re.sub(r"\(\.\/rfc(\d+)", r"(https://www.rfc-editor.org/rfc/rfc\1.html", text)
|
one = re.sub(r"\(\.\/rfc(\d+)", r"(https://www.rfc-editor.org/rfc/rfc\1.html", text)
|
||||||
two = re.sub(r"\((#(?:section|page)-\d+(?:.\d+)?)\)", f"(https://www.rfc-editor.org/rfc/rfc{number}.html\1)", one)
|
two = re.sub(r"\((#(?:section|page)-\d+(?:.\d+)?)\)", f"(https://www.rfc-editor.org/rfc/rfc{number}.html\1)", one)
|
||||||
three: str = re.sub(r"\n{3,}", "\n\n", two)
|
three: str = re.sub(r"\n{3,}", "\n\n", two)
|
||||||
|
@ -201,18 +201,7 @@ class SeaUtils(commands.Cog):
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def rfc(self, ctx: commands.Context, number: int) -> None:
|
async def rfc(self, ctx: commands.Context, number: int) -> None:
|
||||||
"""Retrieve the text of an RFC document.
|
"""Retrieve the text of an RFC document."""
|
||||||
|
|
||||||
This command uses the [RFC Editor website](https://www.rfc-editor.org/) to fetch the text of an RFC document.
|
|
||||||
`number` refers to the number of the RFC document you wish to retrieve.
|
|
||||||
Modified excerpt from the RFC Editor website:
|
|
||||||
>>> The RFC Series (ISSN 2070-1721) contains technical and organizational documents about the Internet,
|
|
||||||
including the specifications and policy documents produced by five streams:
|
|
||||||
- [Internet Engineering Task Force](https://www.ietf.org/)
|
|
||||||
- [Internet Research Task Force](https://www.irtf.org/)
|
|
||||||
- [Internet Architecture Board](https://www.iab.org/)
|
|
||||||
- [Independent Submissions](https://www.rfc-editor.org/independent)
|
|
||||||
- [Editorial](https://www.rfc-editor.org/info/rfc9280)"""
|
|
||||||
url = f"https://www.rfc-editor.org/rfc/rfc{number}.html"
|
url = f"https://www.rfc-editor.org/rfc/rfc{number}.html"
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(url=url) as response:
|
async with session.get(url=url) as response:
|
||||||
|
@ -222,7 +211,7 @@ class SeaUtils(commands.Cog):
|
||||||
pre_tags = soup.find_all('pre')
|
pre_tags = soup.find_all('pre')
|
||||||
content: list[Embed | str] = []
|
content: list[Embed | str] = []
|
||||||
for pre_tag in pre_tags:
|
for pre_tag in pre_tags:
|
||||||
text = format_rfx_text(md(pre_tag), number)
|
text = convert_rfc_references(md(pre_tag), number)
|
||||||
if len(text) > 4096:
|
if len(text) > 4096:
|
||||||
pagified_text = cf.pagify(text, delims=["\n\n"], page_length=4096)
|
pagified_text = cf.pagify(text, delims=["\n\n"], page_length=4096)
|
||||||
for page in pagified_text:
|
for page in pagified_text:
|
||||||
|
|
Loading…
Add table
Reference in a new issue