many different fixes
This commit is contained in:
1 parent
a583c17916
commit
53801f2b53
36 files changed
+5149
-1291
No files matched your search
@@ -19,25 +19,67 @@ public:
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: seek <seconds>\nExample: seek 60 (jumps to 1 minute)");
|
||||
ctx.reply("Usage: seek <+/-seconds>\nExamples:\n seek +30 (skip forward 30s)\n seek -10 (skip back 10s)\n seek 60 (jump to 1 minute mark)");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the seek argument (supports +30, -10, or absolute 60)
|
||||
std::string_view arg = ctx.args;
|
||||
bool relative = false;
|
||||
bool forward = true;
|
||||
|
||||
if (arg.starts_with('+')) {
|
||||
relative = true;
|
||||
forward = true;
|
||||
arg = arg.substr(1);
|
||||
} else if (arg.starts_with('-')) {
|
||||
relative = true;
|
||||
forward = false;
|
||||
arg = arg.substr(1);
|
||||
}
|
||||
|
||||
int seconds = 0;
|
||||
auto parseResult = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
auto parseResult = std::from_chars(arg.data(),
|
||||
arg.data() + arg.size(),
|
||||
seconds);
|
||||
if (parseResult.ec != std::errc()) {
|
||||
ctx.reply("Please provide a valid number of seconds.");
|
||||
if (parseResult.ec != std::errc() || seconds < 0) {
|
||||
ctx.reply("Please provide a valid number of seconds.\nExamples: seek +30, seek -10, seek 60");
|
||||
return;
|
||||
}
|
||||
|
||||
if (seconds < 0) {
|
||||
ctx.reply("Time must be a positive number.");
|
||||
return;
|
||||
std::chrono::milliseconds targetPosition;
|
||||
std::string positionStr;
|
||||
|
||||
if (relative) {
|
||||
// Get current position from playback state
|
||||
auto state = manager->getPlaybackState();
|
||||
if (!state) {
|
||||
ctx.reply("Unable to get current playback position.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto currentPos = state->position;
|
||||
if (forward) {
|
||||
targetPosition = currentPos + std::chrono::seconds(seconds);
|
||||
positionStr = std::format("+{}s", seconds);
|
||||
} else {
|
||||
// Seek backward
|
||||
if (currentPos.count() < seconds * 1000) {
|
||||
targetPosition = std::chrono::milliseconds(0);
|
||||
} else {
|
||||
targetPosition = currentPos - std::chrono::seconds(seconds);
|
||||
}
|
||||
positionStr = std::format("-{}s", seconds);
|
||||
}
|
||||
} else {
|
||||
// Absolute seek (legacy behavior)
|
||||
targetPosition = std::chrono::seconds(seconds);
|
||||
auto mins = seconds / 60;
|
||||
auto secs = seconds % 60;
|
||||
positionStr = std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
|
||||
auto result = manager->seek(std::chrono::seconds(seconds));
|
||||
auto result = manager->seek(targetPosition);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Seek command failed: {}", result.error().message));
|
||||
|
||||
@@ -51,12 +93,10 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
auto mins = seconds / 60;
|
||||
auto secs = seconds % 60;
|
||||
if (mins > 0) {
|
||||
ctx.reply(std::format("Seeked to {}:{:02}.", mins, secs));
|
||||
if (relative) {
|
||||
ctx.reply(std::format("Seeked {} from current position.", positionStr));
|
||||
} else {
|
||||
ctx.reply(std::format("Seeked to {} seconds.", seconds));
|
||||
ctx.reply(std::format("Seeked to position {}.", positionStr));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Seek command exception: {}", e.what()));
|
||||
@@ -65,11 +105,11 @@ public:
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Seeks to a position in the current track.";
|
||||
return "Seeks to a position in the current track. Use +seconds to skip forward, -seconds to skip backward.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<seconds>";
|
||||
return "<+/-seconds>";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
|
||||
Reference in new issue
Block a user