// SPDX-FileCopyrightText: 2024 Yury Gubich // SPDX-License-Identifier: GPL-3.0-or-later #include "publish.h" #include Module::Publish::Publish(const std::shared_ptr& core, const Config::Module& conf): Module(core, conf, "Publish") {} Module::Publish::~Publish() noexcept {} Shared::Result Module::Publish::message(const std::shared_ptr<::Actor>& actor, const Shared::Strings& args) { if (args.front() == "to") { if (!hasPermission("publish", actor)) return Shared::forbidden; if (args.size() < 3) return Shared::error; return to(args[1], args[2]); } return Shared::unhandled; } Shared::Result Module::Publish::to(const std::string& address, const std::string& body) { Shared::Strings parts = Shared::split(address, "@"); if (parts.size() != 2) { warn("Malformed address in \"to\" method"); return Shared::error; } try { core->publish(parts[1], parts[0], "Completely testing stuff, early stages, ignore please", body); return Shared::success; } catch (const std::exception& e) { error("Exception in \"to\" method: " + std::string(e.what())); } catch (...) { error("Unhandled exception in \"to\" method"); } return Shared::error; }