jay/module/module.cpp

40 lines
1.2 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 std::shared_ptr<Connection>& connection, const Permissions& permissions):
core(core),
connection(connection),
permissions(permissions)
{}
bool Module::Module::hasPermission(const std::string& permission, const std::shared_ptr<::Actor>& actor) const {
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::vector<std::string> Module::Module::split(const std::string& string, const std::string& delimiter) {
std::vector<std::string> result;
std::size_t last = 0;
std::size_t next = string.find(delimiter, last);
while (next != std::string::npos) {
result.emplace_back(string.substr(last, next - last));
last = next + 1;
next = string.find(delimiter, last);
}
result.emplace_back(string.substr(last));
return result;
}