aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Ryu18 <[email protected]>2021-08-07 00:52:52 +0200
committerGravatar Ryu18 <[email protected]>2021-08-07 00:52:52 +0200
commit1a952752de4b2d9d472f385d3598eb357be0abcd (patch)
tree619d06c5ef8cb79271543ecb24a1fa3e5e0d9a29
parentMerge pull request #1709 from python-discord/bug/bot-1jd/backend/wait-for-del... (diff)
added escape markdown in PythonNews
-rw-r--r--bot/exts/info/python_news.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/bot/exts/info/python_news.py b/bot/exts/info/python_news.py
index a7837c93a..651a33d02 100644
--- a/bot/exts/info/python_news.py
+++ b/bot/exts/info/python_news.py
@@ -1,6 +1,7 @@
import logging
import typing as t
from datetime import date, datetime
+import re
import discord
import feedparser
@@ -72,6 +73,12 @@ class PythonNews(Cog):
if mail["name"].split("@")[0] in constants.PythonNews.mail_lists:
self.webhook_names[mail["name"].split("@")[0]] = mail["display_name"]
+ @staticmethod
+ def escape_markdown(content: str) -> str:
+ """Escape the markdown underlines"""
+ # taken from discord.utils.escape_markdown
+ return re.sub(r'[_\\~|]', lambda match: '\\' + match[0], content, 0, re.MULTILINE)
+
async def post_pep_news(self) -> None:
"""Fetch new PEPs and when they don't have announcement in #python-news, create it."""
# Wait until everything is ready and http_session available
@@ -103,7 +110,7 @@ class PythonNews(Cog):
# Build an embed and send a webhook
embed = discord.Embed(
title=new["title"],
- description=new["summary"],
+ description=self.escape_markdown(new["summary"]),
timestamp=new_datetime,
url=new["link"],
colour=constants.Colours.soft_green
@@ -167,7 +174,7 @@ class PythonNews(Cog):
):
continue
- content = email_information["content"]
+ content = self.escape_markdown(email_information["content"])
link = THREAD_URL.format(id=thread["href"].split("/")[-2], list=maillist)
# Build an embed and send a message to the webhook