Migrate core infrastructure to VoidLibrary
This commit is contained in:
1 parent
53801f2b53
commit
2bdb63766d
65 files changed
+16109
-12011
No files matched your search
@@ -4,43 +4,55 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class ClearCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class ClearCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->clearQueue();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Clear command failed: {}", result.error().message));
|
||||
ctx.reply("Couldn't clear the queue. Please try again.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Queue cleared!");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Clear command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->clearQueue();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Clear command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't clear the queue. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Clears all tracks from the queue.";
|
||||
}
|
||||
ctx.reply("Queue cleared!");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Clear command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Clears all tracks from the queue.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"clr", "empty"};
|
||||
}
|
||||
};
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"clr", "empty"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -1,106 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
#include <echoion/api.hpp>
|
||||
#include "echoion/core/MusicManager.hpp"
|
||||
#include <ConfigTypes.hpp>
|
||||
#include <Types.hpp>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include "echoion/core/MusicManager.hpp"
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class MusicManager;
|
||||
class MusicManager;
|
||||
|
||||
enum class CommandCategory {
|
||||
Music,
|
||||
Queue,
|
||||
Playback,
|
||||
Utility,
|
||||
Admin
|
||||
};
|
||||
enum class CommandCategory { Music, Queue, Playback, Utility, Admin };
|
||||
|
||||
inline std::string toString(CommandCategory category) {
|
||||
switch (category) {
|
||||
case CommandCategory::Music:
|
||||
return "Music";
|
||||
case CommandCategory::Queue:
|
||||
return "Queue";
|
||||
case CommandCategory::Playback:
|
||||
return "Playback";
|
||||
case CommandCategory::Utility:
|
||||
return "Utility";
|
||||
case CommandCategory::Admin:
|
||||
return "Admin";
|
||||
}
|
||||
return "Utility";
|
||||
}
|
||||
inline std::string toString(CommandCategory category)
|
||||
{
|
||||
switch (category) {
|
||||
case CommandCategory::Music:
|
||||
return "Music";
|
||||
case CommandCategory::Queue:
|
||||
return "Queue";
|
||||
case CommandCategory::Playback:
|
||||
return "Playback";
|
||||
case CommandCategory::Utility:
|
||||
return "Utility";
|
||||
case CommandCategory::Admin:
|
||||
return "Admin";
|
||||
}
|
||||
return "Utility";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Context passed to every command execution.
|
||||
* Wraps all dependencies required to perform an action.
|
||||
*/
|
||||
struct CommandContext {
|
||||
uint64_t clientId = 0;
|
||||
std::string prefix;
|
||||
std::string args; // Arguments excluding the command name
|
||||
std::string_view invokerName;
|
||||
|
||||
// Dependencies
|
||||
std::weak_ptr<MusicManager> musicManager;
|
||||
|
||||
// Reply callback - set by CommandManager
|
||||
std::function<void(std::string_view)> replyCallback;
|
||||
|
||||
// Helper to reply to the user
|
||||
void reply(std::string_view message) const {
|
||||
if (replyCallback) {
|
||||
replyCallback(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Context passed to every command execution.
|
||||
* Wraps all dependencies required to perform an action.
|
||||
*/
|
||||
struct CommandContext {
|
||||
uint64_t clientId = 0;
|
||||
std::string prefix;
|
||||
std::string args; // Arguments excluding the command name
|
||||
std::string_view invokerName;
|
||||
|
||||
/**
|
||||
* @brief Interface that all commands must implement.
|
||||
*/
|
||||
class Command {
|
||||
public:
|
||||
virtual ~Command() = default;
|
||||
// Dependencies
|
||||
std::weak_ptr<MusicManager> musicManager;
|
||||
|
||||
/**
|
||||
* @brief The logic of the command.
|
||||
*/
|
||||
virtual void execute(const CommandContext& ctx) = 0;
|
||||
// Reply callback - set by CommandManager
|
||||
std::function<void(std::string_view)> replyCallback;
|
||||
|
||||
/**
|
||||
* @brief Returns the description used for help generation.
|
||||
*/
|
||||
virtual std::string_view getDescription() const = 0;
|
||||
// Helper to reply to the user
|
||||
void reply(std::string_view message) const
|
||||
{
|
||||
if (replyCallback) {
|
||||
replyCallback(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Returns usage syntax (e.g., "<url>").
|
||||
*/
|
||||
virtual std::string_view getUsage() const { return ""; }
|
||||
/**
|
||||
* @brief Interface that all commands must implement.
|
||||
*/
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Returns the command category for grouping in help.
|
||||
*/
|
||||
virtual CommandCategory getCategory() const {
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
virtual ~Command() = default;
|
||||
|
||||
/**
|
||||
* @brief Returns aliases for this command.
|
||||
*/
|
||||
virtual std::vector<std::string_view> getAliases() const { return {}; }
|
||||
|
||||
/**
|
||||
* @brief Returns whether this command requires admin privileges.
|
||||
*/
|
||||
virtual bool requiresAdmin() const { return false; }
|
||||
};
|
||||
/**
|
||||
* @brief The logic of the command.
|
||||
*/
|
||||
virtual void execute(const CommandContext& ctx) = 0;
|
||||
|
||||
using CommandPtr = std::shared_ptr<Command>;
|
||||
/**
|
||||
* @brief Returns the description used for help generation.
|
||||
*/
|
||||
virtual std::string_view getDescription() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Returns usage syntax (e.g., "<url>").
|
||||
*/
|
||||
virtual std::string_view getUsage() const { return ""; }
|
||||
|
||||
/**
|
||||
* @brief Returns the command category for grouping in help.
|
||||
*/
|
||||
virtual CommandCategory getCategory() const
|
||||
{
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns aliases for this command.
|
||||
*/
|
||||
virtual std::vector<std::string_view> getAliases() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns whether this command requires admin privileges.
|
||||
*/
|
||||
virtual bool requiresAdmin() const { return false; }
|
||||
};
|
||||
|
||||
using CommandPtr = std::shared_ptr<Command>;
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -1,28 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
// New command system - header-only commands
|
||||
#include "Command.hpp"
|
||||
#include "PlayCommand.hpp"
|
||||
#include "SelectCommand.hpp"
|
||||
#include "PauseCommand.hpp"
|
||||
#include "ResumeCommand.hpp"
|
||||
#include "StopCommand.hpp"
|
||||
#include "SkipCommand.hpp"
|
||||
#include "SeekCommand.hpp"
|
||||
#include "VolumeCommand.hpp"
|
||||
#include "QueueCommand.hpp"
|
||||
#include "RemoveCommand.hpp"
|
||||
#include "ClearCommand.hpp"
|
||||
#include "Command.hpp"
|
||||
#include "MoveCommand.hpp"
|
||||
#include "ShuffleCommand.hpp"
|
||||
#include "RepeatCommand.hpp"
|
||||
#include "PlaylistCommand.hpp"
|
||||
#include "NowPlayingCommand.hpp"
|
||||
#include "SearchCommand.hpp"
|
||||
#include "PauseCommand.hpp"
|
||||
#include "PlayCommand.hpp"
|
||||
#include "PlaylistCommand.hpp"
|
||||
#include "QueueCommand.hpp"
|
||||
#include "ReloadCommand.hpp"
|
||||
#include "ReloadConfigCommand.hpp"
|
||||
#include "RemoveCommand.hpp"
|
||||
#include "RepeatCommand.hpp"
|
||||
#include "ResumeCommand.hpp"
|
||||
#include "RpcInfoCommand.hpp"
|
||||
#include "SearchCommand.hpp"
|
||||
#include "SeekCommand.hpp"
|
||||
#include "SelectCommand.hpp"
|
||||
#include "ShuffleCommand.hpp"
|
||||
#include "SkipCommand.hpp"
|
||||
#include "StopCommand.hpp"
|
||||
#include "SubscribeCommand.hpp"
|
||||
#include "UnsubscribeCommand.hpp"
|
||||
#include "SubscribersCommand.hpp"
|
||||
#include "UnsubscribeIdCommand.hpp"
|
||||
#include "UnsubscribeAllCommand.hpp"
|
||||
#include "UnsubscribeCommand.hpp"
|
||||
#include "UnsubscribeIdCommand.hpp"
|
||||
#include "VolumeCommand.hpp"
|
||||
@@ -2,81 +2,98 @@
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class MoveCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class MoveCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: move <from> <to>\nExample: move 5 1 (moves track 5 to position 1)");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse arguments: from and to positions
|
||||
uint32_t from = 0, to = 0;
|
||||
|
||||
auto spacePos = ctx.args.find(' ');
|
||||
if (spacePos == std::string::npos) {
|
||||
ctx.reply("Please provide both from and to positions.");
|
||||
return;
|
||||
}
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: move <from> <to>\nExample: move 5 1 "
|
||||
"(moves track 5 to position 1)");
|
||||
return;
|
||||
}
|
||||
|
||||
auto result1 = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + spacePos,
|
||||
from);
|
||||
auto result2 = std::from_chars(ctx.args.data() + spacePos + 1,
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
to);
|
||||
// Parse arguments: from and to positions
|
||||
uint32_t from = 0, to = 0;
|
||||
|
||||
if (result1.ec != std::errc() || result2.ec != std::errc() || from == 0 || to == 0) {
|
||||
ctx.reply("Please provide valid position numbers (starting from 1).");
|
||||
return;
|
||||
}
|
||||
auto spacePos = ctx.args.find(' ');
|
||||
if (spacePos == std::string::npos) {
|
||||
ctx.reply("Please provide both from and to positions.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto moveResult = manager->moveInQueue(from - 1, to - 1); // Convert to 0-based
|
||||
if (!moveResult) {
|
||||
ECHOION_LOG_ERROR(std::format("Move command failed: {}", moveResult.error().message));
|
||||
|
||||
if (moveResult.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply("One of those positions doesn't exist in the queue.");
|
||||
} else {
|
||||
ctx.reply("Couldn't move that track. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto result1 = std::from_chars(
|
||||
ctx.args.data(), ctx.args.data() + spacePos, from);
|
||||
auto result2 =
|
||||
std::from_chars(ctx.args.data() + spacePos + 1,
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
to);
|
||||
|
||||
ctx.reply(std::format("Moved track from position {} to {}.", from, to));
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Move command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
if (result1.ec != std::errc() ||
|
||||
result2.ec != std::errc() || from == 0 || to == 0) {
|
||||
ctx.reply("Please provide valid position numbers "
|
||||
"(starting from 1).");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Moves a track to a different position in the queue.";
|
||||
}
|
||||
auto moveResult = manager->moveInQueue(
|
||||
from - 1, to - 1); // Convert to 0-based
|
||||
if (!moveResult) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Move command failed: {}",
|
||||
moveResult.error().message));
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<from> <to>";
|
||||
}
|
||||
if (moveResult.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply("One of those positions doesn't exist in "
|
||||
"the queue.");
|
||||
} else {
|
||||
ctx.reply(
|
||||
"Couldn't move that track. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
ctx.reply(std::format(
|
||||
"Moved track from position {} to {}.", from, to));
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Move command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"mv"};
|
||||
}
|
||||
};
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Moves a track to a different position in the queue.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override { return "<from> <to>"; }
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"mv"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,95 +4,113 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class NowPlayingCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto current = manager->getCurrentTrack();
|
||||
if (!current) {
|
||||
ECHOION_LOG_ERROR(std::format("NowPlaying command failed: {}", current.error().message));
|
||||
ctx.reply("Couldn't get current track information.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!current->has_value()) {
|
||||
ctx.reply(std::format(
|
||||
"Nothing is currently playing. Add something with {}play !",
|
||||
ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& track = current->value();
|
||||
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);
|
||||
}
|
||||
|
||||
ctx.reply(msg);
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("NowPlaying command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Shows the currently playing track.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"np", "current", "playing"};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static std::string formatDuration(std::chrono::milliseconds duration)
|
||||
class NowPlayingCommand : public Command
|
||||
{
|
||||
auto totalSeconds = duration.count() / 1000;
|
||||
auto hours = totalSeconds / 3600;
|
||||
auto mins = (totalSeconds % 3600) / 60;
|
||||
auto secs = totalSeconds % 60;
|
||||
public:
|
||||
|
||||
if (hours > 0) {
|
||||
return std::format("{}:{:02}:{:02}", hours, mins, secs);
|
||||
}
|
||||
return std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
};
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto current = manager->getCurrentTrack();
|
||||
if (!current) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("NowPlaying command failed: {}",
|
||||
current.error().message));
|
||||
ctx.reply("Couldn't get current track information.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!current->has_value()) {
|
||||
ctx.reply(std::format("Nothing is currently playing. "
|
||||
"Add something with {}play !",
|
||||
ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& track = current->value();
|
||||
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);
|
||||
}
|
||||
|
||||
ctx.reply(msg);
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"NowPlaying command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Shows the currently playing track.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -4,48 +4,61 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class PauseCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class PauseCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->pause();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Pause command failed: {}", result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Nothing is playing right now.");
|
||||
} else {
|
||||
ctx.reply("Couldn't pause playback. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Playback paused.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Pause command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->pause();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Pause command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Pauses the current playback.";
|
||||
}
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Nothing is playing right now.");
|
||||
} else {
|
||||
ctx.reply(
|
||||
"Couldn't pause playback. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
ctx.reply("Playback paused.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Pause command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Pauses the current playback.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,158 +4,186 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class PlayCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable. Please try again later.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: play <url or search query>\nExample: play never gonna give you up");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it's a direct URL
|
||||
if (ctx.args.find("http") == 0) {
|
||||
auto result = manager->play(ctx.args, ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Play URL failed '{}': {}",
|
||||
ctx.args, result.error().message));
|
||||
|
||||
switch (result.error().code) {
|
||||
case Api::ErrorCode::NetworkError:
|
||||
ctx.reply("Couldn't connect to that URL. Please check and try again.");
|
||||
break;
|
||||
case Api::ErrorCode::InvalidUrl:
|
||||
ctx.reply("That doesn't look like a valid URL.");
|
||||
break;
|
||||
default:
|
||||
ctx.reply("Couldn't play that URL. Please try again.");
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// result contains the track title
|
||||
ctx.reply(std::format("Added to queue: {}", *result));
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, treat as search query
|
||||
auto searchResult = manager->search(ctx.args);
|
||||
if (!searchResult) {
|
||||
ECHOION_LOG_ERROR(std::format("Search failed for '{}': {}",
|
||||
ctx.args, searchResult.error().message));
|
||||
|
||||
if (searchResult.error().code == Api::ErrorCode::NetworkError) {
|
||||
ctx.reply("Couldn't connect to search service. Please check your connection.");
|
||||
} else {
|
||||
ctx.reply("Search failed. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchResult->tracks.empty()) {
|
||||
ctx.reply("No results found. Try different keywords.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Single result - play immediately
|
||||
if (searchResult->tracks.size() == 1) {
|
||||
const auto& track = searchResult->tracks[0];
|
||||
auto playResult = manager->queueTrack(track, ctx.clientId);
|
||||
if (!playResult) {
|
||||
ECHOION_LOG_ERROR(std::format("Queue failed: {}", playResult.error().message));
|
||||
ctx.reply("Couldn't add that track. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string displayText = track.title;
|
||||
if (!track.artist.empty()) {
|
||||
displayText =
|
||||
std::format("{} by {}", track.title, track.artist);
|
||||
}
|
||||
std::string linkText =
|
||||
track.shortenedUrl.has_value() &&
|
||||
!track.shortenedUrl->empty()
|
||||
? std::format("[{}]({})", displayText,
|
||||
*track.shortenedUrl)
|
||||
: displayText;
|
||||
ctx.reply(std::format("Added to queue: {}", linkText));
|
||||
return;
|
||||
}
|
||||
|
||||
// Multiple results - store and show list
|
||||
manager->storePendingSearch(ctx.clientId, searchResult->tracks);
|
||||
|
||||
std::string msg = std::format("\xf0\x9f\x94\x8d Multiple results "
|
||||
"found. Use {}select <number>:\n",
|
||||
ctx.prefix);
|
||||
for (size_t i = 0; i < searchResult->tracks.size() && i < 5; ++i) {
|
||||
const auto& track = searchResult->tracks[i];
|
||||
std::string displayText = track.title;
|
||||
if (!track.artist.empty()) {
|
||||
displayText =
|
||||
std::format("{} by {}", track.title, track.artist);
|
||||
}
|
||||
std::string linkText =
|
||||
track.shortenedUrl.has_value() &&
|
||||
!track.shortenedUrl->empty()
|
||||
? std::format("[{}]({})", displayText,
|
||||
*track.shortenedUrl)
|
||||
: displayText;
|
||||
msg += std::format("{}. {}", i + 1, linkText);
|
||||
if (track.duration.has_value()) {
|
||||
msg +=
|
||||
std::format(" [{}]", formatDuration(*track.duration));
|
||||
}
|
||||
msg += "\n";
|
||||
}
|
||||
|
||||
ctx.reply(msg);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Play command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong while trying to play. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Plays a track from URL or searches and lets you select.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<url or search query>";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"p", "add"};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static std::string formatDuration(std::chrono::milliseconds duration)
|
||||
class PlayCommand : public Command
|
||||
{
|
||||
auto totalSeconds = duration.count() / 1000;
|
||||
auto hours = totalSeconds / 3600;
|
||||
auto mins = (totalSeconds % 3600) / 60;
|
||||
auto secs = totalSeconds % 60;
|
||||
public:
|
||||
|
||||
if (hours > 0) {
|
||||
return std::format("{}:{:02}:{:02}", hours, mins, secs);
|
||||
}
|
||||
return std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
};
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable. "
|
||||
"Please try again later.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: play <url or search query>\nExample: "
|
||||
"play never gonna give you up");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it's a direct URL
|
||||
if (ctx.args.find("http") == 0) {
|
||||
auto result = manager->play(ctx.args, ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Play URL failed '{}': {}",
|
||||
ctx.args, result.error().message));
|
||||
|
||||
switch (result.error().code) {
|
||||
case Api::ErrorCode::NetworkError:
|
||||
ctx.reply("Couldn't connect to that URL. "
|
||||
"Please check and try again.");
|
||||
break;
|
||||
case Api::ErrorCode::InvalidUrl:
|
||||
ctx.reply(
|
||||
"That doesn't look like a valid URL.");
|
||||
break;
|
||||
default:
|
||||
ctx.reply("Couldn't play that URL. Please "
|
||||
"try again.");
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// result contains the track title
|
||||
ctx.reply(std::format("Added to queue: {}", *result));
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, treat as search query
|
||||
auto searchResult = manager->search(ctx.args);
|
||||
if (!searchResult) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Search failed for '{}': {}", ctx.args,
|
||||
searchResult.error().message));
|
||||
|
||||
if (searchResult.error().code ==
|
||||
Api::ErrorCode::NetworkError) {
|
||||
ctx.reply("Couldn't connect to search service. "
|
||||
"Please check your connection.");
|
||||
} else {
|
||||
ctx.reply("Search failed. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchResult->tracks.empty()) {
|
||||
ctx.reply("No results found. Try different keywords.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Single result - play immediately
|
||||
if (searchResult->tracks.size() == 1) {
|
||||
const auto& track = searchResult->tracks[0];
|
||||
auto playResult =
|
||||
manager->queueTrack(track, ctx.clientId);
|
||||
if (!playResult) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Queue failed: {}",
|
||||
playResult.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't add that track. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string displayText = track.title;
|
||||
if (!track.artist.empty()) {
|
||||
displayText = std::format("{} by {}", track.title,
|
||||
track.artist);
|
||||
}
|
||||
std::string linkText =
|
||||
track.shortenedUrl.has_value() &&
|
||||
!track.shortenedUrl->empty()
|
||||
? std::format("[{}]({})", displayText,
|
||||
*track.shortenedUrl)
|
||||
: displayText;
|
||||
ctx.reply(std::format("Added to queue: {}", linkText));
|
||||
return;
|
||||
}
|
||||
|
||||
// Multiple results - store and show list
|
||||
manager->storePendingSearch(ctx.clientId,
|
||||
searchResult->tracks);
|
||||
|
||||
std::string msg =
|
||||
std::format("\xf0\x9f\x94\x8d Multiple results "
|
||||
"found. Use {}select <number>:\n",
|
||||
ctx.prefix);
|
||||
for (size_t i = 0; i < searchResult->tracks.size() && i < 5;
|
||||
++i) {
|
||||
const auto& track = searchResult->tracks[i];
|
||||
std::string displayText = track.title;
|
||||
if (!track.artist.empty()) {
|
||||
displayText = std::format("{} by {}", track.title,
|
||||
track.artist);
|
||||
}
|
||||
std::string linkText =
|
||||
track.shortenedUrl.has_value() &&
|
||||
!track.shortenedUrl->empty()
|
||||
? std::format("[{}]({})", displayText,
|
||||
*track.shortenedUrl)
|
||||
: displayText;
|
||||
msg += std::format("{}. {}", i + 1, linkText);
|
||||
if (track.duration.has_value()) {
|
||||
msg += std::format(" [{}]",
|
||||
formatDuration(*track.duration));
|
||||
}
|
||||
msg += "\n";
|
||||
}
|
||||
|
||||
ctx.reply(msg);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Play command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong while trying to play. "
|
||||
"Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Plays a track from URL or searches and lets you "
|
||||
"select.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override
|
||||
{
|
||||
return "<url or search query>";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"p", "add"};
|
||||
}
|
||||
|
||||
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
|
||||
@@ -5,76 +5,97 @@
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class PlaylistCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class PlaylistCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
// List playlists
|
||||
auto playlists = manager->getPlaylists();
|
||||
if (!playlists) {
|
||||
ECHOION_LOG_ERROR(std::format("Playlist list failed: {}", playlists.error().message));
|
||||
ctx.reply("Couldn't retrieve playlists.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (playlists->empty()) {
|
||||
ctx.reply("No playlists available.");
|
||||
return;
|
||||
}
|
||||
if (ctx.args.empty()) {
|
||||
// List playlists
|
||||
auto playlists = manager->getPlaylists();
|
||||
if (!playlists) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Playlist list failed: {}",
|
||||
playlists.error().message));
|
||||
ctx.reply("Couldn't retrieve playlists.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x81 Available playlists:\n";
|
||||
for (const auto& pl : *playlists) {
|
||||
msg << std::format("- {} ({} tracks)\n", pl.name, pl.tracks.size());
|
||||
}
|
||||
if (playlists->empty()) {
|
||||
ctx.reply("No playlists available.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(msg.str());
|
||||
} else {
|
||||
// Load playlist
|
||||
auto result = manager->loadPlaylist(std::string(ctx.args), ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Playlist load failed: {}", result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply("That playlist doesn't exist.");
|
||||
} else {
|
||||
ctx.reply("Couldn't load the playlist. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x81 Available playlists:\n";
|
||||
for (const auto& pl : *playlists) {
|
||||
msg << std::format("- {} ({} tracks)\n", pl.name,
|
||||
pl.tracks.size());
|
||||
}
|
||||
|
||||
ctx.reply(std::format("Loading playlist '{}'... Tracks will be added to the queue as they are resolved.", ctx.args));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Playlist command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
ctx.reply(msg.str());
|
||||
} else {
|
||||
// Load playlist
|
||||
auto result = manager->loadPlaylist(
|
||||
std::string(ctx.args), ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Playlist load failed: {}",
|
||||
result.error().message));
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Lists or loads a playlist.";
|
||||
}
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply("That playlist doesn't exist.");
|
||||
} else {
|
||||
ctx.reply("Couldn't load the playlist. Please "
|
||||
"try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "[playlist name]";
|
||||
}
|
||||
ctx.reply(std::format(
|
||||
"Loading playlist '{}'... Tracks will be added to "
|
||||
"the queue as they are resolved.",
|
||||
ctx.args));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"Playlist command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Lists or loads a playlist.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"pl"};
|
||||
}
|
||||
};
|
||||
std::string_view getUsage() const override
|
||||
{
|
||||
return "[playlist name]";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"pl"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -5,189 +5,200 @@
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class QueueCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class QueueCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto current = manager->getCurrentTrack();
|
||||
auto queue = manager->getQueue();
|
||||
auto state = manager->getPlaybackState();
|
||||
|
||||
if (!queue) {
|
||||
ECHOION_LOG_ERROR(std::format("Queue command failed: {}", queue.error().message));
|
||||
ctx.reply("Couldn't get queue information.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse page number from args (default to 1)
|
||||
int page = 1;
|
||||
if (!ctx.args.empty()) {
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
page = std::stoi(std::string(ctx.args));
|
||||
if (page < 1) {
|
||||
page = 1;
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
} catch (...) {
|
||||
page = 1;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
auto current = manager->getCurrentTrack();
|
||||
auto queue = manager->getQueue();
|
||||
auto state = manager->getPlaybackState();
|
||||
|
||||
// Clamp page to valid range
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
if (!queue) {
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"Queue command failed: {}", queue.error().message));
|
||||
ctx.reply("Couldn't get queue information.");
|
||||
return;
|
||||
}
|
||||
|
||||
int startIdx = (page - 1) * ITEMS_PER_PAGE;
|
||||
int endIdx = std::min(startIdx + ITEMS_PER_PAGE,
|
||||
static_cast<int>(queue->size()));
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x9c **Queue** (Page " << page << "/"
|
||||
<< totalPages << ")\n";
|
||||
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;
|
||||
}
|
||||
|
||||
// Current track
|
||||
if (current && current->has_value()) {
|
||||
const auto& track = current->value();
|
||||
const auto& trackInfo = track.track;
|
||||
// Clamp page to valid range
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
|
||||
// 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));
|
||||
int startIdx = (page - 1) * ITEMS_PER_PAGE;
|
||||
int endIdx = std::min(startIdx + ITEMS_PER_PAGE,
|
||||
static_cast<int>(queue->size()));
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x9c **Queue** (Page " << page << "/"
|
||||
<< totalPages << ")\n";
|
||||
|
||||
// Current track
|
||||
if (current && current->has_value()) {
|
||||
const auto& track = current->value();
|
||||
const auto& trackInfo = track.track;
|
||||
|
||||
// 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::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 {
|
||||
timeStr = std::format(
|
||||
" [{}]", formatDuration(*trackInfo.duration));
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
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,
|
||||
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);
|
||||
: 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);
|
||||
}
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
// 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));
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Shows the current queue and playback status.";
|
||||
}
|
||||
|
||||
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 getUsage() const override { return "[page]"; }
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Shows the current queue and playback status.";
|
||||
}
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override { return "[page]"; }
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"q", "list"};
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
private:
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"q", "list"};
|
||||
}
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
if (hours > 0) {
|
||||
return std::format("{}:{:02}:{:02}", hours, mins, secs);
|
||||
}
|
||||
return std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,31 +4,38 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class ReloadCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
// This is a placeholder - actual reload is handled by the plugin
|
||||
ECHOION_LOG_INFO("Reload requested by user");
|
||||
ctx.reply("Reload is handled automatically by the plugin. Use the TS3 plugin menu to reload the core.");
|
||||
}
|
||||
class ReloadCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Shows information about reloading the bot.";
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
// This is a placeholder - actual reload is handled by the
|
||||
// plugin
|
||||
ECHOION_LOG_INFO("Reload requested by user");
|
||||
ctx.reply("Reload is handled automatically by the plugin. Use "
|
||||
"the TS3 plugin menu to reload the core.");
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Admin;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Shows information about reloading the bot.";
|
||||
}
|
||||
|
||||
bool requiresAdmin() const override {
|
||||
return true;
|
||||
}
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Admin;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"restart", "r"};
|
||||
}
|
||||
};
|
||||
bool requiresAdmin() const override { return true; }
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"restart", "r"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -1,42 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Core.hpp" // For Core::reloadConfig
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include "echoion/core/Core.hpp" // For Core::reloadConfig
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class ReloadConfigCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
// Note: ctx.core is not directly accessible, we need to use the MusicManager's core reference
|
||||
// For now, reply with instructions
|
||||
ctx.reply("Config reload: Please use !reload command or restart the bot for config changes to take effect.");
|
||||
|
||||
// TODO: Add core reference to CommandContext so commands can call Core methods
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("ReloadConfig command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
class ReloadConfigCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Reloads the bot configuration from file.";
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
// Note: ctx.core is not directly accessible, we need to use
|
||||
// the MusicManager's core reference For now, reply with
|
||||
// instructions
|
||||
ctx.reply(
|
||||
"Config reload: Please use !reload command or restart "
|
||||
"the bot for config changes to take effect.");
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Admin;
|
||||
}
|
||||
// TODO: Add core reference to CommandContext so commands
|
||||
// can call Core methods
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"ReloadConfig command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
bool requiresAdmin() const override {
|
||||
return true;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Reloads the bot configuration from file.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"reloadcfg", "rlcfg"};
|
||||
}
|
||||
};
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Admin;
|
||||
}
|
||||
|
||||
bool requiresAdmin() const override { return true; }
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"reloadcfg", "rlcfg"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -2,71 +2,88 @@
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class RemoveCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class RemoveCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply(std::format("Usage: remove <position>\nUse {}queue "
|
||||
"to see track positions.",
|
||||
ctx.prefix));
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t position = 0;
|
||||
auto result = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
position);
|
||||
if (result.ec != std::errc() || position == 0) {
|
||||
ctx.reply("Please provide a valid position number (starting from 1).");
|
||||
return;
|
||||
}
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply(
|
||||
std::format("Usage: remove <position>\nUse {}queue "
|
||||
"to see track positions.",
|
||||
ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
auto remResult = manager->removeFromQueue(position - 1); // Convert to 0-based
|
||||
if (!remResult) {
|
||||
ECHOION_LOG_ERROR(std::format("Remove command failed: {}", remResult.error().message));
|
||||
|
||||
if (remResult.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply("That position doesn't exist in the queue.");
|
||||
} else {
|
||||
ctx.reply("Couldn't remove that track. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
uint32_t position = 0;
|
||||
auto result =
|
||||
std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
position);
|
||||
if (result.ec != std::errc() || position == 0) {
|
||||
ctx.reply("Please provide a valid position number "
|
||||
"(starting from 1).");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(std::format("Removed track at position {}.", position));
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Remove command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto remResult = manager->removeFromQueue(
|
||||
position - 1); // Convert to 0-based
|
||||
if (!remResult) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Remove command failed: {}",
|
||||
remResult.error().message));
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Removes a track from the queue by position.";
|
||||
}
|
||||
if (remResult.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply(
|
||||
"That position doesn't exist in the queue.");
|
||||
} else {
|
||||
ctx.reply("Couldn't remove that track. Please try "
|
||||
"again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<position>";
|
||||
}
|
||||
ctx.reply(
|
||||
std::format("Removed track at position {}.", position));
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Remove command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Removes a track from the queue by position.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"rm", "delete", "del"};
|
||||
}
|
||||
};
|
||||
std::string_view getUsage() const override { return "<position>"; }
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"rm", "delete", "del"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,43 +4,55 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class RepeatCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class RepeatCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->toggleRepeat();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Repeat command failed: {}", result.error().message));
|
||||
ctx.reply("Couldn't toggle repeat. Please try again.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result ? "\xf0\x9f\x94\x81 Repeat is now ON." : "Repeat is now OFF.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Repeat command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->toggleRepeat();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Repeat command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply("Couldn't toggle repeat. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Toggles repeat mode for the current track.";
|
||||
}
|
||||
ctx.reply(*result ? "\xf0\x9f\x94\x81 Repeat is now ON."
|
||||
: "Repeat is now OFF.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Repeat command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Toggles repeat mode for the current track.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"loop"};
|
||||
}
|
||||
};
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"loop"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,48 +4,61 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class ResumeCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class ResumeCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->resume();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Resume command failed: {}", result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Playback isn't paused right now.");
|
||||
} else {
|
||||
ctx.reply("Couldn't resume playback. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Playback resumed.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Resume command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->resume();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Resume command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Resumes the paused playback.";
|
||||
}
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Playback isn't paused right now.");
|
||||
} else {
|
||||
ctx.reply(
|
||||
"Couldn't resume playback. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
ctx.reply("Playback resumed.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Resume command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"unpause", "continue"};
|
||||
}
|
||||
};
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Resumes the paused playback.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"unpause", "continue"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class RpcInfoCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
void execute(const CommandContext& ctx) override;
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Get RPC server connection information";
|
||||
}
|
||||
std::string_view getUsage() const override { return ""; }
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"rpc", "api", "remote"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -5,110 +5,126 @@
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class SearchCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: search <query>\nExample: search never gonna give you up");
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->search(ctx.args);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Search failed for '{}': {}",
|
||||
ctx.args, result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::NetworkError) {
|
||||
ctx.reply("Couldn't connect to search service. Please check your connection.");
|
||||
} else {
|
||||
ctx.reply("Search failed. Please try again later.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result->tracks.empty()) {
|
||||
ctx.reply("No results found. Try different keywords.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Store results for this client so they can use select
|
||||
manager->storePendingSearch(ctx.clientId, result->tracks);
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x94\x8d Search results for \"" << ctx.args << "\":\n\n";
|
||||
|
||||
for (size_t i = 0; i < result->tracks.size() && i < 5; ++i) {
|
||||
const auto& track = result->tracks[i];
|
||||
// Format as [Title by Artist](shortenedUrl) with duration
|
||||
std::string displayText = track.title;
|
||||
if (!track.artist.empty()) {
|
||||
displayText =
|
||||
std::format("{} by {}", track.title, track.artist);
|
||||
}
|
||||
std::string linkText =
|
||||
track.shortenedUrl.has_value() &&
|
||||
!track.shortenedUrl->empty()
|
||||
? std::format("[{}]({})", displayText,
|
||||
*track.shortenedUrl)
|
||||
: displayText;
|
||||
msg << std::format("{}. {}", i + 1, linkText);
|
||||
if (track.duration.has_value()) {
|
||||
msg << std::format(" [{}]",
|
||||
formatDuration(*track.duration));
|
||||
}
|
||||
msg << "\n";
|
||||
}
|
||||
|
||||
msg << std::format("\nUse {}select <number> to play a result.",
|
||||
ctx.prefix);
|
||||
|
||||
ctx.reply(msg.str());
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Search command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Searches for tracks and shows results.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<query>";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"find", "s"};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static std::string formatDuration(std::chrono::milliseconds duration)
|
||||
class SearchCommand : public Command
|
||||
{
|
||||
auto totalSeconds = duration.count() / 1000;
|
||||
auto hours = totalSeconds / 3600;
|
||||
auto mins = (totalSeconds % 3600) / 60;
|
||||
auto secs = totalSeconds % 60;
|
||||
public:
|
||||
|
||||
if (hours > 0) {
|
||||
return std::format("{}:{:02}:{:02}", hours, mins, secs);
|
||||
}
|
||||
return std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
};
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: search <query>\nExample: search "
|
||||
"never gonna give you up");
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->search(ctx.args);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Search failed for '{}': {}", ctx.args,
|
||||
result.error().message));
|
||||
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::NetworkError) {
|
||||
ctx.reply("Couldn't connect to search service. "
|
||||
"Please check your connection.");
|
||||
} else {
|
||||
ctx.reply("Search failed. Please try again later.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result->tracks.empty()) {
|
||||
ctx.reply("No results found. Try different keywords.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Store results for this client so they can use select
|
||||
manager->storePendingSearch(ctx.clientId, result->tracks);
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x94\x8d Search results for \"" << ctx.args
|
||||
<< "\":\n\n";
|
||||
|
||||
for (size_t i = 0; i < result->tracks.size() && i < 5;
|
||||
++i) {
|
||||
const auto& track = result->tracks[i];
|
||||
// Format as [Title by Artist](shortenedUrl) with
|
||||
// duration
|
||||
std::string displayText = track.title;
|
||||
if (!track.artist.empty()) {
|
||||
displayText = std::format("{} by {}", track.title,
|
||||
track.artist);
|
||||
}
|
||||
std::string linkText =
|
||||
track.shortenedUrl.has_value() &&
|
||||
!track.shortenedUrl->empty()
|
||||
? std::format("[{}]({})", displayText,
|
||||
*track.shortenedUrl)
|
||||
: displayText;
|
||||
msg << std::format("{}. {}", i + 1, linkText);
|
||||
if (track.duration.has_value()) {
|
||||
msg << std::format(" [{}]",
|
||||
formatDuration(*track.duration));
|
||||
}
|
||||
msg << "\n";
|
||||
}
|
||||
|
||||
msg << std::format(
|
||||
"\nUse {}select <number> to play a result.",
|
||||
ctx.prefix);
|
||||
|
||||
ctx.reply(msg.str());
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Search command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Searches for tracks and shows results.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override { return "<query>"; }
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"find", "s"};
|
||||
}
|
||||
|
||||
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
|
||||
@@ -2,123 +2,147 @@
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <chrono>
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class SeekCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class SeekCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
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;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
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);
|
||||
}
|
||||
if (ctx.args.empty()) {
|
||||
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;
|
||||
}
|
||||
|
||||
int seconds = 0;
|
||||
auto parseResult = std::from_chars(arg.data(),
|
||||
arg.data() + arg.size(),
|
||||
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;
|
||||
}
|
||||
// Parse the seek argument (supports +30, -10, or absolute
|
||||
// 60)
|
||||
std::string_view arg = ctx.args;
|
||||
bool relative = false;
|
||||
bool forward = true;
|
||||
|
||||
std::chrono::milliseconds targetPosition;
|
||||
std::string positionStr;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
int seconds = 0;
|
||||
auto parseResult = std::from_chars(
|
||||
arg.data(), arg.data() + arg.size(), 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;
|
||||
}
|
||||
|
||||
auto result = manager->seek(targetPosition);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Seek command failed: {}", result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Nothing is playing right now.");
|
||||
} else if (result.error().code == Api::ErrorCode::NotSupported) {
|
||||
ctx.reply("This track doesn't support seeking.");
|
||||
} else {
|
||||
ctx.reply("Couldn't seek. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::chrono::milliseconds targetPosition;
|
||||
std::string positionStr;
|
||||
|
||||
if (relative) {
|
||||
ctx.reply(std::format("Seeked {} from current position.", positionStr));
|
||||
} else {
|
||||
ctx.reply(std::format("Seeked to position {}.", positionStr));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Seek command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
if (relative) {
|
||||
// Get current position from playback state
|
||||
auto state = manager->getPlaybackState();
|
||||
if (!state) {
|
||||
ctx.reply(
|
||||
"Unable to get current playback position.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Seeks to a position in the current track. Use +seconds to skip forward, -seconds to skip backward.";
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<+/-seconds>";
|
||||
}
|
||||
auto result = manager->seek(targetPosition);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Seek command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Nothing is playing right now.");
|
||||
} else if (result.error().code ==
|
||||
Api::ErrorCode::NotSupported) {
|
||||
ctx.reply("This track doesn't support seeking.");
|
||||
} else {
|
||||
ctx.reply("Couldn't seek. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"jump"};
|
||||
}
|
||||
};
|
||||
if (relative) {
|
||||
ctx.reply(std::format(
|
||||
"Seeked {} from current position.", positionStr));
|
||||
} else {
|
||||
ctx.reply(
|
||||
std::format("Seeked to position {}.", positionStr));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Seek command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
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>";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"jump"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -2,76 +2,91 @@
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class SelectCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class SelectCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: select <number>\nSelect a track from your last search results.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse index
|
||||
uint32_t index = 0;
|
||||
auto result = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
index);
|
||||
if (result.ec != std::errc() || index == 0) {
|
||||
ctx.reply("Please provide a valid number (1, 2, 3, etc.).");
|
||||
return;
|
||||
}
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: select <number>\nSelect a track from "
|
||||
"your last search results.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string invokerName(ctx.invokerName);
|
||||
auto selectResult = manager->selectSearchResult(ctx.clientId, index, invokerName);
|
||||
|
||||
if (!selectResult) {
|
||||
ECHOION_LOG_ERROR(std::format("Select failed for client {} index {}: {}",
|
||||
ctx.clientId, index, selectResult.error().message));
|
||||
|
||||
if (selectResult.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply(std::format("No search results found. Use {}play "
|
||||
"<query> to search first.",
|
||||
ctx.prefix));
|
||||
} else {
|
||||
ctx.reply("Couldn't select that track. Please try again.");
|
||||
// Parse index
|
||||
uint32_t index = 0;
|
||||
auto result =
|
||||
std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
index);
|
||||
if (result.ec != std::errc() || index == 0) {
|
||||
ctx.reply(
|
||||
"Please provide a valid number (1, 2, 3, etc.).");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string invokerName(ctx.invokerName);
|
||||
auto selectResult = manager->selectSearchResult(
|
||||
ctx.clientId, index, invokerName);
|
||||
|
||||
if (!selectResult) {
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"Select failed for client {} index {}: {}",
|
||||
ctx.clientId, index, selectResult.error().message));
|
||||
|
||||
if (selectResult.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply(std::format(
|
||||
"No search results found. Use {}play "
|
||||
"<query> to search first.",
|
||||
ctx.prefix));
|
||||
} else {
|
||||
ctx.reply("Couldn't select that track. Please try "
|
||||
"again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*selectResult);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Select command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.reply(*selectResult);
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Selects a track from your search results.";
|
||||
}
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Select command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
std::string_view getUsage() const override { return "<number>"; }
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Selects a track from your search results.";
|
||||
}
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<number>";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"sel", "pick", "choose"};
|
||||
}
|
||||
};
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"sel", "pick", "choose"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,43 +4,48 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class ShuffleCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class ShuffleCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->toggleShuffle();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Shuffle command failed: {}", result.error().message));
|
||||
ctx.reply("Couldn't toggle shuffle. Please try again.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result ? "\xf0\x9f\x94\x80 Shuffle is now ON." : "Shuffle is now OFF.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Shuffle command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
// Actually shuffle the queue (not just toggle mode)
|
||||
manager->shuffleQueue();
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Toggles shuffle mode for the queue.";
|
||||
}
|
||||
ctx.reply("\xf0\x9f\x94\x80 Queue shuffled!");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Shuffle command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Toggles shuffle mode for the queue.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"random"};
|
||||
}
|
||||
};
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"random"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -2,70 +2,81 @@
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class SkipCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class SkipCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
uint32_t count = 1;
|
||||
if (!ctx.args.empty()) {
|
||||
auto result = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
count);
|
||||
if (result.ec != std::errc() || count == 0) {
|
||||
ctx.reply("Please provide a valid number (1 or more).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->skip(count);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Skip command failed: {}", result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply("No more tracks in the queue to skip to.");
|
||||
} else {
|
||||
ctx.reply("Couldn't skip. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
uint32_t count = 1;
|
||||
if (!ctx.args.empty()) {
|
||||
auto result =
|
||||
std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
count);
|
||||
if (result.ec != std::errc() || count == 0) {
|
||||
ctx.reply(
|
||||
"Please provide a valid number (1 or more).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1) {
|
||||
ctx.reply("Skipped to next track.");
|
||||
} else {
|
||||
ctx.reply(std::format("Skipped {} tracks.", count));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Skip command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->skip(count);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Skip command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Skips to the next track(s).";
|
||||
}
|
||||
if (result.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply(
|
||||
"No more tracks in the queue to skip to.");
|
||||
} else {
|
||||
ctx.reply("Couldn't skip. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "[count]";
|
||||
}
|
||||
if (count == 1) {
|
||||
ctx.reply("Skipped to next track.");
|
||||
} else {
|
||||
ctx.reply(std::format("Skipped {} tracks.", count));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Skip command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Skips to the next track(s).";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"next", "n"};
|
||||
}
|
||||
};
|
||||
std::string_view getUsage() const override { return "[count]"; }
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"next", "n"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,43 +4,53 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class StopCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class StopCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->stop();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Stop command failed: {}", result.error().message));
|
||||
ctx.reply("Couldn't stop playback. Please try again.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Playback stopped and queue cleared.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Stop command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->stop();
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Stop command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply("Couldn't stop playback. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Stops playback and clears the queue.";
|
||||
}
|
||||
ctx.reply("Playback stopped and queue cleared.");
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Stop command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Stops playback and clears the queue.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"s"};
|
||||
}
|
||||
};
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"s"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,43 +4,53 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class SubscribeCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class SubscribeCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->subscribe(ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Subscribe failed: {}", result.error().message));
|
||||
ctx.reply("Couldn't subscribe you. Please try again.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Subscribe command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->subscribe(ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Subscribe failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply("Couldn't subscribe you. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Subscribes to the music bot to receive audio.";
|
||||
}
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"Subscribe command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Subscribes to the music bot to receive audio.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"sub", "join"};
|
||||
}
|
||||
};
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"sub", "join"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,43 +4,54 @@
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class UnsubscribeCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class UnsubscribeCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
auto result = manager->unsubscribe(ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Unsubscribe failed: {}", result.error().message));
|
||||
ctx.reply("Couldn't unsubscribe you. Please try again.");
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Unsubscribe command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->unsubscribe(ctx.clientId);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Unsubscribe failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't unsubscribe you. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Unsubscribes from the music bot.";
|
||||
}
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"Unsubscribe command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Unsubscribes from the music bot.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"unsub", "leave"};
|
||||
}
|
||||
};
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"unsub", "leave"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -2,84 +2,100 @@
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class VolumeCommand : public Command {
|
||||
public:
|
||||
void execute(const CommandContext& ctx) override {
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
class VolumeCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
// Show current volume
|
||||
auto state = manager->getPlaybackState();
|
||||
if (state) {
|
||||
ctx.reply(std::format("Current volume: {}%", static_cast<int>(state->volume * 100)));
|
||||
} else {
|
||||
ctx.reply("Unable to get current volume.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse volume (0-100)
|
||||
int volumePercent = 0;
|
||||
auto result = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
volumePercent);
|
||||
if (result.ec != std::errc()) {
|
||||
ctx.reply("Please provide a valid number (0-100).");
|
||||
return;
|
||||
}
|
||||
if (ctx.args.empty()) {
|
||||
// Show current volume
|
||||
auto state = manager->getPlaybackState();
|
||||
if (state) {
|
||||
ctx.reply(std::format(
|
||||
"Current volume: {}%",
|
||||
static_cast<int>(state->volume * 100)));
|
||||
} else {
|
||||
ctx.reply("Unable to get current volume.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (volumePercent < 0 || volumePercent > 100) {
|
||||
ctx.reply("Volume must be between 0 and 100.");
|
||||
return;
|
||||
}
|
||||
// Parse volume (0-100)
|
||||
int volumePercent = 0;
|
||||
auto result =
|
||||
std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
volumePercent);
|
||||
if (result.ec != std::errc()) {
|
||||
ctx.reply("Please provide a valid number (0-100).");
|
||||
return;
|
||||
}
|
||||
|
||||
float volume = volumePercent / 100.0f;
|
||||
auto volResult = manager->setVolume(volume);
|
||||
if (!volResult) {
|
||||
ECHOION_LOG_ERROR(std::format("Volume command failed: {}", volResult.error().message));
|
||||
ctx.reply("Couldn't change volume. Please try again.");
|
||||
return;
|
||||
}
|
||||
if (volumePercent < 0 || volumePercent > 100) {
|
||||
ctx.reply("Volume must be between 0 and 100.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Visual volume indicator
|
||||
std::string indicator;
|
||||
int bars = volumePercent / 10;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
indicator += (i < bars) ? "\xe2\x96\x88" : "\xe2\x96\x91"; // Full block / Light shade
|
||||
}
|
||||
|
||||
ctx.reply(std::format("Volume: {}% {}", volumePercent, indicator));
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Volume command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
float volume = volumePercent / 100.0f;
|
||||
auto volResult = manager->setVolume(volume);
|
||||
if (!volResult) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Volume command failed: {}",
|
||||
volResult.error().message));
|
||||
ctx.reply("Couldn't change volume. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Sets or shows the playback volume.";
|
||||
}
|
||||
// Visual volume indicator
|
||||
std::string indicator;
|
||||
int bars = volumePercent / 10;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
indicator +=
|
||||
(i < bars)
|
||||
? "\xe2\x96\x88"
|
||||
: "\xe2\x96\x91"; // Full block / Light shade
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "[0-100]";
|
||||
}
|
||||
ctx.reply(std::format(
|
||||
"Volume: {}% {}", volumePercent, indicator));
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Volume command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Sets or shows the playback volume.";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"vol", "v"};
|
||||
}
|
||||
};
|
||||
std::string_view getUsage() const override { return "[0-100]"; }
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"vol", "v"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user