jay/module/actor.cpp

36 lines
936 B
C++

// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "actor.h"
Module::Actor::Actor(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection):
Module(core, connection)
{}
Module::Actor::~Actor() noexcept {}
void Module::Actor::message(const std::shared_ptr<::Actor>& actor, const Module::Module::Tokens& args) {
std::string result;
if (args.front() == "list")
result = list();
if (!result.empty())
connection->send(actor->jid, result);
}
std::string Module::Actor::list() {
std::string result;
for (const std::pair<const std::string, std::string>& pair : core->router.getActors()) {
if (!result.empty())
result.append(1, '\n');
result += pair.first + ": " + pair.second;
}
if (result.empty())
result += "There are no actors currently";
return result;
}