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

+12 -19
View File
@@ -98,13 +98,9 @@ namespace Echoion::Core
displayText = std::format("{} by {}", track.title,
track.artist);
}
std::string linkText =
track.shortenedUrl.has_value() &&
!track.shortenedUrl->empty()
? std::format("[{}]({})", displayText,
*track.shortenedUrl)
: displayText;
ctx.reply(std::format("Added to queue: {}", linkText));
ctx.reply(std::format(
"Added to queue: {}",
markdownLink(displayText, track.shortenedUrl)));
return;
}
@@ -112,10 +108,9 @@ namespace Echoion::Core
manager->storePendingSearch(ctx.clientId,
searchResult->tracks);
std::string msg =
std::format("\xf0\x9f\x94\x8d Multiple results "
"found. Use {}select <number>:\n",
ctx.prefix);
std::string msg = std::format(
"Multiple results \xe2\x80\x94 use {}select <number>:\n\n",
ctx.prefix);
for (size_t i = 0; i < searchResult->tracks.size() && i < 5;
++i) {
const auto& track = searchResult->tracks[i];
@@ -124,15 +119,13 @@ namespace Echoion::Core
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(" [{}]",
msg += std::format(" {} {}", kDot,
formatDuration(*track.duration));
}
msg += "\n";