Refactored in a way modules have access to bot infrastructure

This commit is contained in:
Blue 2025-03-09 21:01:41 +02:00
parent c605b3ba93
commit 89c04254b8
Signed by: blue
GPG key ID: 9B203B252A63EE38
25 changed files with 245 additions and 216 deletions

47
connection/connection.h Normal file
View file

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <memory>
#include <gloox/client.h>
#include <gloox/message.h>
#include <gloox/disco.h>
#include <gloox/connectionlistener.h>
#include <gloox/messagehandler.h>
#include "component/core.h"
class Connection:
public gloox::ConnectionListener,
public gloox::MessageHandler
{
public:
enum State {
initial,
disconnected,
connected
};
public:
Connection(const std::shared_ptr<Core>& core);
~Connection() noexcept;
void initiialize();
void deinitialize();
void connect();
void send(const std::string& jid, const std::string& body);
public:
void onConnect() override;
void onDisconnect(gloox::ConnectionError e) override;
bool onTLSConnect(const gloox::CertInfo&) override;
void handleMessage(const gloox::Message& message, gloox::MessageSession* session = 0) override;
private:
State state;
std::shared_ptr<Core> core;
std::unique_ptr<gloox::Client> gloox;
};