80 lines
2.0 KiB
C++
80 lines
2.0 KiB
C++
#include "connection.hpp"
|
|
#include "settings.hpp"
|
|
|
|
#include <boost/asio.hpp>
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <memory>
|
|
|
|
#include "bot.hpp"
|
|
#include "client.hpp"
|
|
#include "registration.hpp"
|
|
|
|
using namespace std::literals;
|
|
|
|
auto start(boost::asio::io_context &io, const Settings &settings) -> void
|
|
{
|
|
const auto connection = std::make_shared<Connection>(io);
|
|
const auto client = Client::start(*connection);
|
|
Registration::start(settings, client);
|
|
|
|
const auto bot = Bot::start(client);
|
|
|
|
connection->sig_snote.connect([](auto &match) {
|
|
std::cout << "SNOTE " << static_cast<int>(match.get_tag()) << std::endl;
|
|
for (auto c : match.get_results())
|
|
{
|
|
std::cout << " " << std::string_view{c.first, c.second} << std::endl;
|
|
}
|
|
});
|
|
|
|
client->sig_registered.connect([connection]() {
|
|
connection->send_join("##glguy"sv);
|
|
});
|
|
|
|
connection->sig_disconnect.connect(
|
|
[&io, &settings, client, bot]() {
|
|
client->shutdown();
|
|
bot->shutdown();
|
|
|
|
auto timer = std::make_shared<boost::asio::steady_timer>(io);
|
|
timer->expires_after(5s);
|
|
timer->async_wait([&io, &settings, timer](auto) { start(io, settings); });
|
|
}
|
|
);
|
|
|
|
bot->sig_command.connect([connection](const Command &cmd) {
|
|
std::cout << "COMMAND " << cmd.command << " from " << cmd.account << std::endl;
|
|
});
|
|
|
|
connection->start({
|
|
.tls = settings.use_tls,
|
|
.host = settings.host,
|
|
.port = settings.service,
|
|
.verify = settings.tls_hostname,
|
|
});
|
|
}
|
|
|
|
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();
|
|
}
|