Files
EchoionCore/include/echoion/core/commands/UnsubscribeIdCommand.hpp
T
2026-02-03 05:07:15 +03:00

72 lines
1.6 KiB
C++

#pragma once
#include "Command.hpp"
#include "echoion/core/Logger.hpp"
#include "echoion/core/MusicManager.hpp"
#include <format>
namespace Echoion::Core
{
class UnsubscribeIdCommand : 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("Please provide a user UID. Use !subscribers "
"to see UIDs.");
return;
}
std::string uid(ctx.args);
auto result = manager->unsubscribeByUid(uid);
if (!result) {
ECHOION_LOG_ERROR(
std::format("Unsubscribe by ID failed: {}",
result.error().message));
ctx.reply(
"Couldn't unsubscribe user. Please try again.");
return;
}
ctx.reply(*result);
} catch (const std::exception& e) {
ECHOION_LOG_ERROR(std::format(
"Unsubscribeid command exception: {}", e.what()));
ctx.reply("Something went wrong. Please try again.");
}
}
std::string_view getDescription() const override
{
return "Unsubscribes a user by their UID (admin only).";
}
std::string_view getUsage() const override { return "<uid>"; }
CommandCategory getCategory() const override
{
return CommandCategory::Admin;
}
std::vector<std::string_view> getAliases() const override
{
return {"unsubid", "removeuser"};
}
bool requiresAdmin() const override { return true; }
};
} // namespace Echoion::Core