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

+19 -20
View File
@@ -72,18 +72,19 @@ namespace Echoion::Core
const auto& track = current->value();
const auto& trackInfo = track.track;
// Build time display: [current/total] or [total]
// Build time display: · current/total or · total
// (no [] — TeamSpeak parses it as a link reference).
std::string timeStr;
if (trackInfo.duration.has_value() &&
trackInfo.duration->count() > 0) {
if (state) {
timeStr = std::format(
" [{}/{}]",
" {} {}/{}", kDot,
formatDuration(state->position),
formatDuration(*trackInfo.duration));
} else {
timeStr = std::format(
" [{}]",
" {} {}", kDot,
formatDuration(*trackInfo.duration));
}
}
@@ -93,13 +94,10 @@ namespace Echoion::Core
displayText = std::format(
"{} by {}", trackInfo.title, trackInfo.artist);
}
std::string linkText =
trackInfo.shortenedUrl.has_value() &&
!trackInfo.shortenedUrl->empty()
? std::format("[{}]({}){}", displayText,
*trackInfo.shortenedUrl, timeStr)
: displayText + timeStr;
msg << std::format("\n**Now Playing:** {}\n", linkText);
msg << std::format(
"\n**Now Playing:** {}{}\n",
markdownLink(displayText, trackInfo.shortenedUrl),
timeStr);
}
// Queue
@@ -119,17 +117,18 @@ namespace Echoion::Core
std::format("{} by {}", trackInfo.title,
trackInfo.artist);
}
std::string linkText =
trackInfo.shortenedUrl.has_value() &&
!trackInfo.shortenedUrl->empty()
? std::format(
"[{}]({}) [{}]", displayText,
*trackInfo.shortenedUrl,
formatDuration(*trackInfo.duration))
: displayText;
msg << std::format("{}. {}", i + 1, linkText);
msg << std::format(
"{}. {}", i + 1,
markdownLink(displayText,
trackInfo.shortenedUrl));
if (trackInfo.duration.has_value()) {
msg << std::format(
" {} {}", kDot,
formatDuration(*trackInfo.duration));
}
if (!entry.addedBy.empty()) {
msg << std::format(" (by {})", entry.addedBy);
msg << std::format(
" (by {})", escapeMarkdown(entry.addedBy));
}
msg << "\n";
}