#include "command_thread.hpp" #include "connection.hpp" #include "irc_parse_thread.hpp" #include auto CommandThread::start(Connection& connection) -> void { connection.add_listener([&connection](IrcMsgEvent& event) { if (IrcCommand::PRIVMSG != event.command) return; auto const message = event.irc.args[1]; if (message.empty()) return; if ('!' != message.front()) return; CommandEvent command_event; { auto const cmdend = message.find(' '); if (std::string_view::npos == cmdend) { command_event.command = message.substr(1); } else { command_event.command = message.substr(1, cmdend - 1); command_event.arg = message.substr(cmdend + 1); } } { auto const nickend = event.irc.source.find('!'); if (std::string_view::npos != nickend) { command_event.nick = event.irc.source.substr(0, nickend); } } for (auto const& [k,v] : event.irc.tags) { if ("solanum.chat/oper" == k) { command_event.oper = v; } else if ("account" == k) { command_event.account = v; } } connection.dispatch(command_event); }); }