Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/websites.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Optional, Self, Type, Iterable, Callable

import aiohttp
import discore

from database.models.Guild import *

Expand Down Expand Up @@ -115,10 +116,10 @@ async def render(self) -> Optional[str]:
return None
author_url, author_label = await self.get_author_url()
original_url, original_label = await self.get_original_url()
fixed_link = f"[{original_label}](<{original_url}>)"
fixed_link = markdown_link(original_label, original_url, embed=False)
if author_url:
fixed_link += f" • [{author_label}](<{author_url}>)"
fixed_link += f" • [{fixed_label}]({fixed_url})"
fixed_link += f" • {markdown_link(author_label, author_url)}"
fixed_link += f" • {markdown_link(fixed_label, fixed_url)}"
return fixed_link


Expand Down Expand Up @@ -270,6 +271,18 @@ async def get_original_url(self) -> tuple[Optional[str], Optional[str]]:
return original_url, self.hypertext_label


def markdown_link(label: str, url: str, embed=True) -> str:
"""
Create a markdown link with escaped label to prevent formatting issues.

:param label: The label text for the link
:param url: The URL for the link
:param embed: Whether the link is to be embedded (enclosed in <>) or not
:return: A markdown formatted link with escaped label
"""
return f"[{discore.utils.escape_markdown(label)}]({url if embed else f'<{url}>'})"


def generate_regex(domain_names: str|list[str], route: str, params: Optional[list[str]] = None) -> re.Pattern[str]:
"""
Generate a regex for the corresponding route, with named groups.
Expand Down