Remove [https:// from markdown link

This commit is contained in:
2024-07-26 21:53:58 +02:00
parent 3514f3606e
commit f14c1215d7
3 changed files with 25 additions and 2 deletions

View File

@ -1,3 +1,10 @@
{
"cSpell.words": ["botuser", "Genshins", "levelname", "markdownify", "pipx"]
"cSpell.words": [
"botuser",
"Genshins",
"levelname",
"markdownify",
"pipx",
"thead"
]
}

View File

@ -71,6 +71,14 @@ def replace_tags_in_text_message(entry: Entry) -> str:
summary = markdownify(summary, strip=["img", "table", "td", "tr", "tbody", "thead"])
content = markdownify(content, strip=["img", "table", "td", "tr", "tbody", "thead"])
if "[https://" in content or "[https://www." in content:
content = content.replace("[https://", "[")
content = content.replace("[https://www.", "[")
if "[https://" in summary or "[https://www." in summary:
summary = summary.replace("[https://", "[")
summary = summary.replace("[https://www.", "[")
list_of_replacements = [
{"{{feed_author}}": feed.author},
{"{{feed_added}}": feed.added},
@ -167,6 +175,14 @@ def replace_tags_in_embed(feed: Feed, entry: Entry) -> CustomEmbed:
summary = markdownify(summary, strip=["img", "table", "td", "tr", "tbody", "thead"])
content = markdownify(content, strip=["img", "table", "td", "tr", "tbody", "thead"])
if "[https://" in content or "[https://www." in content:
content = content.replace("[https://", "[")
content = content.replace("[https://www.", "[")
if "[https://" in summary or "[https://www." in summary:
summary = summary.replace("[https://", "[")
summary = summary.replace("[https://www.", "[")
feed_added: str = feed.added.strftime("%Y-%m-%d %H:%M:%S") if feed.added else "Never"
feed_last_updated: str = feed.last_updated.strftime("%Y-%m-%d %H:%M:%S") if feed.last_updated else "Never"
feed_updated: str = feed.updated.strftime("%Y-%m-%d %H:%M:%S") if feed.updated else "Never"

View File

@ -41,7 +41,7 @@ def send_entry_to_discord(entry: Entry, custom_reader: Reader | None = None) ->
# Try to get the custom message for the feed. If the user has none, we will use the default message.
# This has to be a string for some reason so don't change it to "not custom_message.get_custom_message()"
if custom_message.get_custom_message(reader, entry.feed) != "": # noqa: PLC1901
webhook_message = custom_message.replace_tags_in_text_message(entry=entry)
webhook_message: str = custom_message.replace_tags_in_text_message(entry=entry)
if not webhook_message:
webhook_message = "No message found."