#include "connection.hpp" #include "settings.hpp" #include #include #include #include #include #include #include "bot.hpp" #include "registration_thread.hpp" #include "self_thread.hpp" using namespace std::chrono_literals; auto start(boost::asio::io_context &io, const Settings &settings) -> void { const auto connection = std::make_shared(io); const auto selfThread = SelfThread::start(*connection); RegistrationThread::start(*connection, settings, selfThread); Bot::start(selfThread); connection->sig_snote.connect([](auto &match) { std::cout << "SNOTE " << static_cast(match.get_tag()) << std::endl; for (auto c : match.get_results()) { std::cout << " " << std::string_view{c.first, c.second} << std::endl; } }); boost::asio::co_spawn( io, connection->connect(io, ConnectSettings{ .tls = settings.use_tls, .host = settings.host, .port = settings.service, .verify = settings.tls_hostname, }), [&io, &settings, connection](std::exception_ptr e) { try { if (e) std::rethrow_exception(e); } catch (const std::exception &e) { BOOST_LOG_TRIVIAL(debug) << "TERMINATED: " << e.what(); } auto timer = std::make_shared(io); timer->expires_after(5s); timer->async_wait( [&io, &settings, timer](auto) { start(io, settings); }); }); } auto get_settings() -> Settings { if (auto config_stream = std::ifstream{"config.toml"}) { return Settings::from_stream(config_stream); } else { BOOST_LOG_TRIVIAL(error) << "Unable to open config.toml"; std::exit(1); } } auto main() -> int { const auto settings = get_settings(); auto io = boost::asio::io_context{}; start(io, settings); io.run(); }