#include "connection.hpp" #include "event.hpp" #include "ircmsg.hpp" #include "linebuffer.hpp" #include "settings.hpp" #include "write_irc.hpp" #include "command_thread.hpp" #include "irc_parse_thread.hpp" #include "ping_thread.hpp" #include "registration_thread.hpp" #include "self_thread.hpp" #include "snote_thread.hpp" #include "watchdog_thread.hpp" #include "priv_thread.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std::chrono_literals; auto echo_thread( Connection& connection, std::shared_ptr priv_thread) -> void { connection.add_listener([&connection, priv_thread](CommandEvent& event) { if ("raw" == event.command && priv_thread->check_command(event, PrivThread::owner_priv)) { connection.write_line(std::string{event.arg}); event.handled_ = true; send_notice(connection, event.nick, "ack"); } }); } auto start(boost::asio::io_context & io, Settings const& settings) -> void { auto const connection = std::make_shared(io); WatchdogThread::start(*connection); IrcParseThread::start(*connection); PingThread::start(*connection); SelfThread::start(*connection); RegistrationThread::start(*connection, settings.password, settings.username, settings.realname, settings.nickname); SnoteThread::start(*connection); CommandThread::start(*connection); auto const priv_thread = PrivThread::start(*connection, "privs.toml"); echo_thread(*connection, priv_thread); /* connection->add_listener([](SnoteEvent& event) { std::cout << "SNOTE " << static_cast(event.get_tag()) << std::endl; for (auto c : event.get_results()) { std::cout << " " << std::string_view{c.first, c.second} << std::endl; } }); */ boost::asio::co_spawn( io, connection->connect(io, settings.host, settings.service), [&io, &settings](std::exception_ptr e) { auto timer = std::make_shared(io); timer->expires_from_now(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 { std::cerr << "Unable to open config.toml\n"; std::exit(1); } } auto main() -> int { auto const settings = get_settings(); auto io = boost::asio::io_context{}; start(io, settings); io.run(); }