xbot/write_irc.hpp

24 lines
705 B
C++
Raw Normal View History

2023-11-25 09:22:55 -08:00
#pragma once
#include "connection.hpp"
auto write_irc(Connection& connection, std::string message) -> void;
auto write_irc(Connection& connection, std::string front, std::string_view last) -> void;
template <typename... Args>
auto write_irc(Connection& connection, std::string front, std::string_view next, Args ...rest) -> void
{
auto const is_invalid = [](char x) -> bool {
return x == '\0' || x == '\r' || x == '\n' || x == ' ';
};
if (next.empty() || next.end() != std::find_if(next.begin(), next.end(), is_invalid))
{
throw std::runtime_error{"bad irc argument"};
}
front += " ";
front += next;
write_irc(connection, std::move(front), rest...);
}