Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Final

from discord import Embed
from discord.utils import format_dt
from discord.utils import escape_markdown, format_dt

from europython_discord.program_notifications.models import Session, Speaker

Expand All @@ -29,7 +29,7 @@ def create_session_embed(session: Session, livestream_url: str | None) -> Embed:
:return: A Discord embed for this session
"""
embed = Embed(
title=_format_title(session.title),
title=_format_title(escape_markdown(session.title)),
description=_create_description(session),
url=session.website_url,
color=_get_color(session.level),
Expand Down Expand Up @@ -79,7 +79,7 @@ def _create_description(session: Session) -> str | None:
"""
if not session.tweet:
return None
tweet_short = textwrap.shorten(session.tweet, width=_TWEET_WIDTH)
tweet_short = textwrap.shorten(escape_markdown(session.tweet), width=_TWEET_WIDTH)
return f"{tweet_short}\n\n[Read more about this session]({session.website_url})"


Expand Down
15 changes: 15 additions & 0 deletions tests/program_notifications/test_session_to_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def test_embed_title_long(session: Session) -> None:
)


def test_embed_title_with_markdown(session: Session) -> None:
session.title = "A talk about __slots__ and *things*."
embed = session_to_embed.create_session_embed(session, None)
assert embed.title == "A talk about \\_\\_slots\\_\\_ and \\*things\\*."


def test_embed_description_short(session: Session) -> None:
"""Test the description (tweet) of the embed with a short description."""
session.tweet = "Short tweet."
Expand Down Expand Up @@ -103,6 +109,15 @@ def test_embed_description_empty(session: Session) -> None:
assert embed.description is None


def test_embed_description_with_markdown(session: Session) -> None:
session.tweet = "A talk about __slots__ and *things*."
embed = session_to_embed.create_session_embed(session, None)
assert embed.description == (
"A talk about \\_\\_slots\\_\\_ and \\*things\\*.\n\n"
f"[Read more about this session]({session.website_url})"
)


def test_embed_url(session: Session) -> None:
"""Test the URL of the embed."""
embed = session_to_embed.create_session_embed(session, None)
Expand Down