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

+154 -56
View File
@@ -27,69 +27,167 @@ public:
return;
}
std::stringstream msg;
msg << "\xf0\x9f\x93\x9c **Queue**\n";
// Parse page number from args (default to 1)
int page = 1;
if (!ctx.args.empty()) {
try {
page = std::stoi(std::string(ctx.args));
if (page < 1) {
page = 1;
}
} catch (...) {
page = 1;
}
}
// Current track
if (current && current->has_value()) {
const auto& track = current->value();
msg << std::format("\n**Now Playing:** {} by {}\n",
track.track.title,
track.track.artist);
}
constexpr int ITEMS_PER_PAGE = 10;
int totalPages =
(static_cast<int>(queue->size()) + ITEMS_PER_PAGE - 1) /
ITEMS_PER_PAGE;
if (totalPages == 0) {
totalPages = 1;
}
// Queue
if (queue->empty()) {
msg << "\nThe queue is empty. Add songs with [prefix]play!";
} else {
msg << std::format("\n**Up Next ({} tracks):**\n", queue->size());
for (size_t i = 0; i < queue->size() && i < 10; ++i) {
const auto& entry = (*queue)[i];
msg << std::format("{}. {}", i + 1, entry.track.title);
if (!entry.addedBy.empty()) {
msg << std::format(" (by {})", entry.addedBy);
}
msg << "\n";
}
if (queue->size() > 10) {
msg << std::format("\n... and {} more", queue->size() - 10);
}
}
// Clamp page to valid range
if (page > totalPages) {
page = totalPages;
}
// State indicators
if (state) {
msg << "\n\n";
if (state->isPaused) {
msg << "\xe2\x8f\xb8 Paused | ";
}
if (state->shuffle) {
msg << "\xf0\x9f\x94\x80 Shuffle | ";
}
if (state->repeat) {
msg << "\xf0\x9f\x94\x81 Repeat | ";
}
msg << std::format("Volume: {}%", static_cast<int>(state->volume * 100));
}
int startIdx = (page - 1) * ITEMS_PER_PAGE;
int endIdx = std::min(startIdx + ITEMS_PER_PAGE,
static_cast<int>(queue->size()));
ctx.reply(msg.str());
} catch (const std::exception& e) {
ECHOION_LOG_ERROR(std::format("Queue command exception: {}", e.what()));
ctx.reply("Something went wrong. Please try again.");
}
}
std::stringstream msg;
msg << "\xf0\x9f\x93\x9c **Queue** (Page " << page << "/"
<< totalPages << ")\n";
std::string_view getDescription() const override {
return "Shows the current queue and playback status.";
}
// Current track
if (current && current->has_value()) {
const auto& track = current->value();
const auto& trackInfo = track.track;
CommandCategory getCategory() const override {
return CommandCategory::Queue;
}
// Build time display: [current/total] or [total]
std::string timeStr;
if (trackInfo.duration.has_value() &&
trackInfo.duration->count() > 0) {
if (state) {
timeStr =
std::format(" [{}/{}]",
formatDuration(state->position),
formatDuration(*trackInfo.duration));
} else {
timeStr = std::format(
" [{}]", formatDuration(*trackInfo.duration));
}
}
std::vector<std::string_view> getAliases() const override {
return {"q", "list"};
}
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, timeStr)
: displayText + timeStr;
msg << std::format("\n**Now Playing:** {}\n", linkText);
}
// Queue
if (queue->empty()) {
msg << std::format(
"\nThe queue is empty. Add songs with {}play !",
ctx.prefix);
} else {
msg << std::format("\n**Up Next ({} tracks):**\n",
queue->size());
for (int i = startIdx; i < endIdx; ++i) {
const auto& entry = (*queue)[i];
const auto& trackInfo = entry.track;
std::string displayText = trackInfo.title;
if (!trackInfo.artist.empty()) {
displayText =
std::format("{} [{}] by {}", trackInfo.title,
formatDuration(*trackInfo.duration),
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);
if (!entry.addedBy.empty()) {
msg << std::format(" (by {})", entry.addedBy);
}
msg << "\n";
}
if (totalPages > 1) {
msg << std::format("\nUse {}queue <page> to see more "
"(page {} of {})",
ctx.prefix, page, totalPages);
}
}
// State indicators
if (state) {
msg << "\n\n";
if (state->isPaused) {
msg << "\xe2\x8f\xb8 Paused | ";
}
if (state->shuffle) {
msg << "\xf0\x9f\x94\x80 Shuffle | ";
}
if (state->repeat) {
msg << "\xf0\x9f\x94\x81 Repeat | ";
}
msg << std::format("Volume: {}%", static_cast<int>(state->volume * 100));
}
ctx.reply(msg.str());
} catch (const std::exception& e) {
ECHOION_LOG_ERROR(
std::format("Queue command exception: {}", e.what()));
ctx.reply("Something went wrong. Please try again.");
}
}
std::string_view getDescription() const override
{
return "Shows the current queue and playback status.";
}
std::string_view getUsage() const override { return "[page]"; }
CommandCategory getCategory() const override
{
return CommandCategory::Queue;
}
std::vector<std::string_view> getAliases() const override
{
return {"q", "list"};
}
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