jay/module/module.cpp

54 lines
1.6 KiB
C++

// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "module.h"
#include <algorithm>
#include "gloox/message.h"
Module::Module::Module(const std::shared_ptr<Core>& core, const Config::Module& conf, const std::string& name):
Shared::Loggable(core->logger, {"Module", name, conf.alias}),
name(name),
alias(conf.alias),
core(core),
permissions(conf.permissions)
{}
bool Module::Module::hasPermission(const std::string& permission, const std::shared_ptr<::Actor>& actor) const {
Shared::Permissions::const_iterator itr = permissions.find(permission);
if (itr == permissions.end())
return false;
return std::find(itr->second.begin(), itr->second.end(), actor->getGroup()) != itr->second.end();
}
Module::Module::~Module() noexcept {}
std::string Module::Module::lower(const std::string& text) {
return std::ranges::to<std::string>(text | std::views::transform(::tolower));
}
std::string_view Module::Module::pop(std::string_view& input, char delimiter) {
std::size_t pos = input.find(delimiter);
std::string_view token;
if (pos == std::string_view::npos) {
token = input;
input = {};
} else {
token = input.substr(0, pos);
pos = input.find_first_not_of(' ', pos + 1);
if (pos == std::string_view::npos)
input = {};
else
input.remove_prefix(pos);
}
return token;
}
void Module::Module::cancelDialog(const std::shared_ptr<::Actor>& actor) {
warn("Dialog with " + actor->jid + " was requested to be canceled, but this module doesn't handle canceling dialogs");
}