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:
1 parent
352101e657
commit
b9c6c5dbc9
5 files changed
+91
-64
No files matched your search
@@ -44,33 +44,30 @@ 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)
|
||||
: displayText;
|
||||
std::string msg =
|
||||
std::format("\xf0\x9f\x8e\xb5 {}", linkText);
|
||||
std::string msg = std::format(
|
||||
"\xf0\x9f\x8e\xb5 {}",
|
||||
markdownLink(displayText, trackInfo.shortenedUrl));
|
||||
|
||||
// Show current position / total duration
|
||||
// Show current position / total duration after a middot
|
||||
// (no [] — TeamSpeak parses it as a link reference).
|
||||
auto playbackState = manager->getPlaybackState();
|
||||
if (playbackState &&
|
||||
playbackState->currentTrack.has_value() &&
|
||||
trackInfo.duration.has_value() &&
|
||||
trackInfo.duration->count() > 0) {
|
||||
auto position = playbackState->position;
|
||||
msg += std::format(" [{}/{}]",
|
||||
msg += std::format(" {} {}/{}", kDot,
|
||||
formatDuration(position),
|
||||
formatDuration(*trackInfo.duration));
|
||||
} else if (trackInfo.duration.has_value() &&
|
||||
trackInfo.duration->count() > 0) {
|
||||
msg += std::format(" [{}]",
|
||||
msg += std::format(" {} {}", kDot,
|
||||
formatDuration(*trackInfo.duration));
|
||||
}
|
||||
|
||||
if (!track.addedBy.empty()) {
|
||||
msg += std::format(" (requested by {})", track.addedBy);
|
||||
msg += std::format(" (requested by {})",
|
||||
escapeMarkdown(track.addedBy));
|
||||
}
|
||||
|
||||
ctx.reply(msg);
|
||||
|
||||
Reference in new issue
Block a user