85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
#include "connection.hpp"
|
|
#include "ircmsg.hpp"
|
|
#include "settings.hpp"
|
|
#include "write_irc.hpp"
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "ping_thread.hpp"
|
|
#include "registration_thread.hpp"
|
|
#include "self_thread.hpp"
|
|
#include "snote_thread.hpp"
|
|
|
|
#include "irc_coroutine.hpp"
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
irc_coroutine example(Connection& connection) {
|
|
auto [cmd1, msg1] = co_await wait_command{IrcCommand::RPL_WELCOME};
|
|
std::cout << "WELCOME " << msg1.args[0] << "\n";
|
|
auto [cmd5, msg5] = co_await wait_command{IrcCommand::RPL_ISUPPORT};
|
|
std::cout << "ISUPPORT " << msg5.args[0] << "\n";
|
|
}
|
|
|
|
auto start(boost::asio::io_context & io, Settings const& settings) -> void
|
|
{
|
|
auto const connection = std::make_shared<Connection>(io);
|
|
|
|
RegistrationThread::start(*connection, settings.password, settings.username, settings.realname, settings.nickname);
|
|
PingThread::start(*connection);
|
|
SelfThread::start(*connection);
|
|
auto const snote_thread = SnoteThread::start(*connection);
|
|
|
|
/*
|
|
snote_thread->sig_snote.connect([](auto tag, auto &match) {
|
|
std::cout << "SNOTE " << static_cast<int>(tag) << std::endl;
|
|
for (auto c : match.get_results())
|
|
{
|
|
std::cout << " " << std::string_view{c.first, c.second} << std::endl;
|
|
}
|
|
});
|
|
*/
|
|
auto logic = example(*connection);
|
|
logic.start(*connection);
|
|
|
|
boost::asio::co_spawn(
|
|
io,
|
|
connection->connect(io, settings.host, settings.service),
|
|
[&io, &settings](std::exception_ptr e)
|
|
{
|
|
auto timer = std::make_shared<boost::asio::steady_timer>(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
|
|
{
|
|
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();
|
|
}
|