60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "jay.h"
|
|
|
|
Jay::Jay(const std::string& configPath):
|
|
runMutex(),
|
|
config(std::make_shared<Config>(configPath)),
|
|
client(),
|
|
messageHandler(),
|
|
connectionHandler(),
|
|
loggers()
|
|
{}
|
|
|
|
Jay::~Jay() {}
|
|
|
|
bool Jay::isConfigValid() const {
|
|
return config->isValid();
|
|
}
|
|
|
|
|
|
void Jay::run() {
|
|
std::lock_guard lock(runMutex);
|
|
|
|
initialize();
|
|
client->connect(true);
|
|
}
|
|
|
|
void Jay::initialize() {
|
|
createClient();
|
|
|
|
if (!messageHandler)
|
|
messageHandler = std::make_unique<Message>(config, client);
|
|
|
|
if (!connectionHandler)
|
|
connectionHandler = std::make_unique<Connection>(config, client);
|
|
}
|
|
|
|
void Jay::createClient() {
|
|
if (client)
|
|
return;
|
|
|
|
client = std::make_shared<gloox::Client>(config->getFullJID(), config->getPassword());
|
|
addLogger(config->getLogLevel());
|
|
|
|
gloox::Disco* disco = client->disco();
|
|
|
|
disco->setVersion("Jay", "0.0.1");
|
|
disco->setIdentity("client", "bot");
|
|
|
|
client->setTls(config->getTLSPolicy());
|
|
client->setSASLMechanisms(gloox::SaslMechAll);
|
|
client->setStreamManagement(true, true);
|
|
}
|
|
|
|
|
|
void Jay::addLogger(gloox::LogLevel level) {
|
|
loggers.emplace_back(std::make_unique<Logger>(client->logInstance(), level));
|
|
}
|