commands: fix result/queue formatting for TeamSpeak markdown

The reply lists rendered badly: durations written as [0:00] were parsed as
Markdown link references (brackets stripped), and titles containing Markdown
punctuation broke the surrounding [title](url) link so it showed raw.

Add shared escapeMarkdown()/markdownLink() helpers (Command.hpp) and reformat
search, play, nowplaying and queue replies to:
  N. [escaped title](shortUrl) · duration
Titles/nicknames are Markdown-escaped so '[', '*', '_', etc. can't break the
link; the duration follows a middot separator instead of [..]. Also guard a
possible nullopt duration deref in the queue list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-26 03:05:38 +03:00
1 parent 352101e657
commit b9c6c5dbc9
5 files changed
+91 -64

No files matched your search

@@ -53,29 +53,24 @@ namespace Echoion::Core
manager->storePendingSearch(ctx.clientId, result->tracks);
std::stringstream msg;
msg << "\xf0\x9f\x94\x8d Search results for \"" << ctx.args
<< "\":\n\n";
msg << "Search results for \"" << ctx.args << "\":\n\n";
for (size_t i = 0; i < result->tracks.size() && i < 5;
++i) {
const auto& track = result->tracks[i];
// Format as [Title by Artist](shortenedUrl) with
// duration
std::string displayText = track.title;
if (!track.artist.empty()) {
displayText = std::format("{} by {}", track.title,
track.artist);
}
std::string linkText =
track.shortenedUrl.has_value() &&
!track.shortenedUrl->empty()
? std::format("[{}]({})", displayText,
*track.shortenedUrl)
: displayText;
msg << std::format("{}. {}", i + 1, linkText);
// [escaped title](url) · duration (no [] around the
// duration: TeamSpeak parses [..] as a link reference).
msg << std::format(
"{}. {}", i + 1,
markdownLink(displayText, track.shortenedUrl));
if (track.duration.has_value()) {
msg << std::format(" [{}]",
formatDuration(*track.duration));
msg << " " << kDot << " "
<< formatDuration(*track.duration);
}
msg << "\n";
}