many different fixes

This commit is contained in:
faumaray committed 2026-02-03 05:07:15 +03:00
1 parent a583c17916
commit 53801f2b53
36 files changed
+5149 -1291

No files matched your search

@@ -24,22 +24,39 @@ public:
}
if (!current->has_value()) {
ctx.reply("Nothing is currently playing. Add something with [prefix]play!");
return;
ctx.reply(std::format(
"Nothing is currently playing. Add something with {}play !",
ctx.prefix));
return;
}
const auto& track = current->value();
std::string msg = std::format("\xf0\x9f\x8e\xb5 **{}** by **{}**",
track.track.title,
track.track.artist);
if (track.track.duration > std::chrono::seconds(0)) {
auto mins = std::chrono::minutes(track.track.duration->count()).count();
auto secs = std::chrono::seconds(track.track.duration->count()).count() % 60;
msg += std::format(" [{}:{:02}]", mins, secs);
}
if (!track.addedBy.empty()) {
const auto& trackInfo = track.track;
std::string displayText = trackInfo.title;
if (!trackInfo.artist.empty()) {
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);
// Show current position / total duration
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(" [{}/{}]",
formatDuration(position),
formatDuration(*trackInfo.duration));
} else if (trackInfo.duration.has_value() && trackInfo.duration->count() > 0) {
msg += std::format(" [{}]", formatDuration(*trackInfo.duration));
}
if (!track.addedBy.empty()) {
msg += std::format(" (requested by {})", track.addedBy);
}
@@ -61,6 +78,21 @@ public:
std::vector<std::string_view> getAliases() const override {
return {"np", "current", "playing"};
}
private:
static std::string formatDuration(std::chrono::milliseconds duration)
{
auto totalSeconds = duration.count() / 1000;
auto hours = totalSeconds / 3600;
auto mins = (totalSeconds % 3600) / 60;
auto secs = totalSeconds % 60;
if (hours > 0) {
return std::format("{}:{:02}:{:02}", hours, mins, secs);
}
return std::format("{}:{:02}", mins, secs);
}
};
} // namespace Echoion::Core