Initial commit
This commit is contained in:
commit
a583c17916
56 files changed
+11025
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Clears all tracks from the queue.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"clr", "empty"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include <echoion/api.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include "echoion/core/MusicManager.hpp"
|
||||
|
||||
namespace Echoion::Core {
|
||||
|
||||
class MusicManager;
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Context passed to every command execution.
|
||||
* Wraps all dependencies required to perform an action.
|
||||
*/
|
||||
struct CommandContext {
|
||||
uint64_t clientId = 0;
|
||||
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 Interface that all commands must implement.
|
||||
*/
|
||||
class Command {
|
||||
public:
|
||||
virtual ~Command() = default;
|
||||
|
||||
/**
|
||||
* @brief The logic of the command.
|
||||
*/
|
||||
virtual void execute(const CommandContext& ctx) = 0;
|
||||
|
||||
/**
|
||||
* @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
|
||||
@@ -0,0 +1,25 @@
|
||||
#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 "MoveCommand.hpp"
|
||||
#include "ShuffleCommand.hpp"
|
||||
#include "RepeatCommand.hpp"
|
||||
#include "PlaylistCommand.hpp"
|
||||
#include "NowPlayingCommand.hpp"
|
||||
#include "SearchCommand.hpp"
|
||||
#include "ReloadCommand.hpp"
|
||||
#include "ReloadConfigCommand.hpp"
|
||||
#include "SubscribeCommand.hpp"
|
||||
#include "UnsubscribeCommand.hpp"
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: move <from> <to>\nExample: move 5 1 (moves track 5 to position 1)");
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
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::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
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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("Nothing is currently playing. Add something with [prefix]play!");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& track = current->value();
|
||||
std::string msg = std::format("\xf0\x9f\x8e\xb5 **{}** by **{}**",
|
||||
track.track.title,
|
||||
track.track.artist);
|
||||
|
||||
if (track.track.duration > std::chrono::seconds(0)) {
|
||||
auto mins = std::chrono::minutes(track.track.duration->count()).count();
|
||||
auto secs = std::chrono::seconds(track.track.duration->count()).count() % 60;
|
||||
msg += std::format(" [{}:{:02}]", mins, secs);
|
||||
}
|
||||
|
||||
if (!track.addedBy.empty()) {
|
||||
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"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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::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
|
||||
@@ -0,0 +1,125 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ctx.reply(std::format("Added to queue: {}", track.title));
|
||||
return;
|
||||
}
|
||||
|
||||
// Multiple results - store and show list
|
||||
manager->storePendingSearch(ctx.clientId, searchResult->tracks);
|
||||
|
||||
std::string msg = "\xf0\x9f\x94\x8d Multiple results found. Use [prefix]select <number>:\n";
|
||||
for (size_t i = 0; i < searchResult->tracks.size() && i < 5; ++i) {
|
||||
const auto& track = searchResult->tracks[i];
|
||||
msg += std::format("{}. {}", i + 1, track.title);
|
||||
if (!track.artist.empty()) {
|
||||
msg += std::format(" by {}", track.artist);
|
||||
}
|
||||
if (track.duration.has_value()) {
|
||||
auto mins = std::chrono::duration_cast<std::chrono::minutes>(*track.duration).count();
|
||||
auto secs = std::chrono::duration_cast<std::chrono::seconds>(*track.duration).count() % 60;
|
||||
msg += std::format(" [{}:{:02}]", mins, secs);
|
||||
}
|
||||
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"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (playlists->empty()) {
|
||||
ctx.reply("No playlists available.");
|
||||
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(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;
|
||||
}
|
||||
|
||||
ctx.reply(std::format("Loaded {} tracks from playlist '{}'!", *result, 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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Lists or loads a playlist.";
|
||||
}
|
||||
|
||||
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
|
||||
@@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x9c **Queue**\n";
|
||||
|
||||
// Current track
|
||||
if (current && current->has_value()) {
|
||||
const auto& track = current->value();
|
||||
msg << std::format("\n**Now Playing:** {} by {}\n",
|
||||
track.track.title,
|
||||
track.track.artist);
|
||||
}
|
||||
|
||||
// Queue
|
||||
if (queue->empty()) {
|
||||
msg << "\nThe queue is empty. Add songs with [prefix]play!";
|
||||
} else {
|
||||
msg << std::format("\n**Up Next ({} tracks):**\n", queue->size());
|
||||
for (size_t i = 0; i < queue->size() && i < 10; ++i) {
|
||||
const auto& entry = (*queue)[i];
|
||||
msg << std::format("{}. {}", i + 1, entry.track.title);
|
||||
if (!entry.addedBy.empty()) {
|
||||
msg << std::format(" (by {})", entry.addedBy);
|
||||
}
|
||||
msg << "\n";
|
||||
}
|
||||
|
||||
if (queue->size() > 10) {
|
||||
msg << std::format("\n... and {} more", queue->size() - 10);
|
||||
}
|
||||
}
|
||||
|
||||
// State indicators
|
||||
if (state) {
|
||||
msg << "\n\n";
|
||||
if (state->isPaused) {
|
||||
msg << "\xe2\x8f\xb8 Paused | ";
|
||||
}
|
||||
if (state->shuffle) {
|
||||
msg << "\xf0\x9f\x94\x80 Shuffle | ";
|
||||
}
|
||||
if (state->repeat) {
|
||||
msg << "\xf0\x9f\x94\x81 Repeat | ";
|
||||
}
|
||||
msg << std::format("Volume: {}%", static_cast<int>(state->volume * 100));
|
||||
}
|
||||
|
||||
ctx.reply(msg.str());
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Queue command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Shows the current queue and playback status.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"q", "list"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Shows information about reloading the bot.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Admin;
|
||||
}
|
||||
|
||||
bool requiresAdmin() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"restart", "r"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include "echoion/core/Core.hpp" // For Core::reloadConfig
|
||||
#include <format>
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Reloads the bot configuration from file.";
|
||||
}
|
||||
|
||||
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
|
||||
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: remove <position>\nUse [prefix]queue to see track positions.");
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Removes a track from the queue by position.";
|
||||
}
|
||||
|
||||
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
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Toggles repeat mode for the current track.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"loop"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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::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,90 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
|
||||
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];
|
||||
msg << std::format("{}. {}", i + 1, track.title);
|
||||
if (!track.artist.empty()) {
|
||||
msg << std::format(" by {}", track.artist);
|
||||
}
|
||||
if (track.duration.has_value()) {
|
||||
auto mins = std::chrono::duration_cast<std::chrono::minutes>(*track.duration).count();
|
||||
auto secs = std::chrono::duration_cast<std::chrono::seconds>(*track.duration).count() % 60;
|
||||
msg << std::format(" [{}:{:02}]", mins, secs);
|
||||
}
|
||||
msg << "\n";
|
||||
}
|
||||
|
||||
msg << "\nUse [prefix]select <number> to play a result.";
|
||||
|
||||
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"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <chrono>
|
||||
#include <charconv>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: seek <seconds>\nExample: seek 60 (jumps to 1 minute)");
|
||||
return;
|
||||
}
|
||||
|
||||
int seconds = 0;
|
||||
auto parseResult = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
seconds);
|
||||
if (parseResult.ec != std::errc()) {
|
||||
ctx.reply("Please provide a valid number of seconds.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (seconds < 0) {
|
||||
ctx.reply("Time must be a positive number.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->seek(std::chrono::seconds(seconds));
|
||||
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;
|
||||
}
|
||||
|
||||
auto mins = seconds / 60;
|
||||
auto secs = seconds % 60;
|
||||
if (mins > 0) {
|
||||
ctx.reply(std::format("Seeked to {}:{:02}.", mins, secs));
|
||||
} else {
|
||||
ctx.reply(std::format("Seeked to {} seconds.", seconds));
|
||||
}
|
||||
} 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.";
|
||||
}
|
||||
|
||||
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
|
||||
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: select <number>\nSelect a track from your last search results.");
|
||||
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;
|
||||
}
|
||||
|
||||
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("No search results found. Use [prefix]play <query> to search first.");
|
||||
} 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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Selects a track from your search results.";
|
||||
}
|
||||
|
||||
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"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Toggles shuffle mode for the queue.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Queue;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"random"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Skips to the next track(s).";
|
||||
}
|
||||
|
||||
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
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Stops playback and clears the queue.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"s"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Subscribes to the music bot to receive audio.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"sub", "join"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Unsubscribes from the music bot.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"unsub", "leave"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// 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 (volumePercent < 0 || volumePercent > 100) {
|
||||
ctx.reply("Volume must be between 0 and 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;
|
||||
}
|
||||
|
||||
// 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.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Sets or shows the playback volume.";
|
||||
}
|
||||
|
||||
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