113 lines
2.9 KiB
C++
113 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "Command.hpp"
|
|
#include "echoion/core/MusicManager.hpp"
|
|
#include <Void/Log/Log.hpp>
|
|
#include <algorithm>
|
|
#include <format>
|
|
#include <sstream>
|
|
|
|
namespace Echoion::Core
|
|
{
|
|
|
|
class SubscribersCommand : public Command
|
|
{
|
|
public:
|
|
|
|
void execute(const CommandContext& ctx) override
|
|
{
|
|
try {
|
|
auto manager = ctx.musicManager.lock();
|
|
if (!manager) {
|
|
ctx.reply(ctx.tr(
|
|
"The music service is currently unavailable."));
|
|
return;
|
|
}
|
|
|
|
auto subscribers = manager->getSubscribers();
|
|
auto onlineUids = manager->getOnlineSubscriberUids();
|
|
|
|
if (subscribers.empty()) {
|
|
ctx.reply(ctx.tr("No subscribers. Use !subscribe to "
|
|
"receive audio."));
|
|
return;
|
|
}
|
|
|
|
// Separate online and offline
|
|
std::vector<SubscriptionManager::Subscriber> online;
|
|
std::vector<SubscriptionManager::Subscriber> offline;
|
|
|
|
for (const auto& sub : subscribers) {
|
|
if (onlineUids.contains(sub.uid)) {
|
|
online.push_back(sub);
|
|
} else {
|
|
offline.push_back(sub);
|
|
}
|
|
}
|
|
|
|
std::stringstream msg;
|
|
msg << ctx.tr("\xf0\x9f\x93\x8b **Subscribed Users** (")
|
|
<< subscribers.size() << ctx.tr(" total)\n");
|
|
msg << ctx.tr("\xf0\x9f\x9f\xa2 Online: ") << online.size()
|
|
<< ctx.tr(" | \xe2\x9a\xaa Offline: ") << offline.size()
|
|
<< ctx.tr("\n\n");
|
|
|
|
// Online subscribers
|
|
if (!online.empty()) {
|
|
msg << ctx.tr("**\xf0\x9f\x9f\xa2 Online:**\n");
|
|
for (size_t i = 0; i < online.size(); ++i) {
|
|
const auto& sub = online[i];
|
|
msg << ctx.trf("{}. **{}**\n", i + 1, sub.nickname);
|
|
msg << ctx.trf(" UID: `{}`\n", sub.uid);
|
|
}
|
|
msg << ctx.tr("\n");
|
|
}
|
|
|
|
// Offline subscribers
|
|
if (!offline.empty()) {
|
|
msg << ctx.tr("**\xe2\x9a\xaa Offline:**\n");
|
|
for (size_t i = 0; i < offline.size(); ++i) {
|
|
const auto& sub = offline[i];
|
|
msg << ctx.trf("{}. **{}**\n", i + 1, sub.nickname);
|
|
msg << ctx.trf(" UID: `{}`\n", sub.uid);
|
|
}
|
|
msg << ctx.tr("\n");
|
|
}
|
|
|
|
msg << ctx.tr(
|
|
"Use `!unsubscribeid <uid>` to remove a specific "
|
|
"subscriber.\n");
|
|
msg << ctx.tr(
|
|
"Use `!unsubscribeall` to remove all subscribers.");
|
|
|
|
ctx.reply(msg.str());
|
|
} catch (const std::exception& e) {
|
|
Void::Log::error(
|
|
"SubscribersCommand", "{}",
|
|
std::format("Subscribers command exception: {}",
|
|
e.what()));
|
|
ctx.reply(
|
|
ctx.tr("Something went wrong. Please try again."));
|
|
}
|
|
}
|
|
|
|
std::string_view getDescription() const override
|
|
{
|
|
return "Lists all subscribed users (online/offline).";
|
|
}
|
|
|
|
std::string_view getUsage() const override { return ""; }
|
|
|
|
CommandCategory getCategory() const override
|
|
{
|
|
return CommandCategory::Admin;
|
|
}
|
|
|
|
std::vector<std::string_view> getAliases() const override
|
|
{
|
|
return {"subs", "listsubs"};
|
|
}
|
|
};
|
|
|
|
} // namespace Echoion::Core
|