Initial commit
This commit is contained in:
commit
a583c17916
56 files changed
+11025
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user