xbot/irc_parse_thread.cpp

38 lines
1.0 KiB
C++
Raw Normal View History

2023-11-25 09:22:55 -08:00
#include "irc_parse_thread.hpp"
#include "connection.hpp"
2023-11-27 19:09:45 -08:00
#include "ircmsg.hpp"
2023-11-25 09:22:55 -08:00
2023-11-29 13:13:48 -08:00
#include <boost/log/trivial.hpp>
2023-11-26 15:08:55 -08:00
#include <cstring>
namespace {
#include "irc_commands.inc"
} // namespace
2023-11-27 19:09:45 -08:00
IrcMsgEvent::IrcMsgEvent(IrcCommand command, IrcMsg const& irc)
: command{command}, irc{irc} {}
2023-11-27 14:12:20 -08:00
auto IrcParseThread::start(Connection& connection) -> void
2023-11-25 09:22:55 -08:00
{
2023-11-26 15:40:40 -08:00
connection.add_listener<LineEvent>([&connection](LineEvent const& event)
2023-11-25 09:22:55 -08:00
{
2023-11-26 15:08:55 -08:00
auto const msg = parse_irc_message(event.line);
auto const recognized = IrcCommandHash::in_word_set(msg.command.data(), msg.command.size());
auto const command
= recognized
&& recognized->min_args <= msg.args.size()
&& recognized->max_args >= msg.args.size()
? recognized->command : IrcCommand::UNKNOWN;
2023-11-27 14:12:20 -08:00
if (IrcCommand::UNKNOWN == command)
{
2023-11-29 13:13:48 -08:00
BOOST_LOG_TRIVIAL(warning) << "Unrecognized command: " << msg.command << " " << msg.args.size();
2023-11-27 14:12:20 -08:00
}
2023-11-26 15:40:40 -08:00
connection.make_event<IrcMsgEvent>(command, msg);
2023-11-25 20:09:20 -08:00
});
2023-11-26 15:40:40 -08:00
}