yail/main.cpp

46 lines
1.9 KiB
C++
Raw Normal View History

2024-10-22 18:23:46 +00:00
#include <unordered_set>
#include <utempl/tuple.hpp>
#include <yail/yail.hpp>
auto Test() -> boost::asio::awaitable<void> {
try {
2024-10-22 18:28:09 +00:00
auto executor = co_await boost::asio::this_coro::executor;
2024-10-22 18:23:46 +00:00
// NOLINTNEXTLINE
auto sock = co_await yail::Socks5ProxyConnect("127.0.0.1", 4447, "irc.ilita.i2p", 6667);
auto client =
yail::IrcClient<std::tuple<>, utempl::Tuple{}, std::tuple<>>{// clangd bug :(
.socket = std::move(sock),
.nick = "sha512sum_bot",
.server = "irc.ilita.i2p"}
.AddState<std::unordered_set<yail::User, yail::User::Hash>, "ruUsers">()
// NOLINTNEXTLINE
.With([](auto& self, yail::event::Ping ping) -> boost::asio::awaitable<void> {
co_await self.Pong(ping.data);
})
// NOLINTNEXTLINE
.With([](auto& self, yail::event::Welcome message) -> boost::asio::awaitable<void> {
std::println("Welcome: {}", message.message);
co_await self.Join("#ru");
co_await self.SendMessage("#ru", "Hello from yet another irc library");
})
// NOLINTNEXTLINE
.With([](auto& self, yail::event::ChannelUsers event) -> boost::asio::awaitable<void> {
std::unordered_set<yail::User, yail::User::Hash>& ruUsers = self.template GetState<"ruUsers">();
for(yail::UserView view : event.users) {
ruUsers.emplace(view);
}
co_return;
});
co_await client.Connect("sha512sum_bot");
co_await client.Loop();
} catch(const std::exception& err) {
std::println("Err: {}", err.what());
}
};
auto main() -> int {
boost::asio::io_context context;
boost::asio::co_spawn(context, Test(), boost::asio::detached);
context.run();
};