Add support for IRCv3 message-tags Implement draft/multiline

This commit is contained in:
Benjamin Graillot
2025-11-28 20:30:12 +01:00
committed by mathieui
parent cf6dec8ce5
commit d13f66ab90
5 changed files with 262 additions and 9 deletions
+41 -1
View File
@@ -1,8 +1,27 @@
#include <irc/irc_message.hpp>
#include <iostream>
#include <string>
#include <utils/split.hpp>
#include <optional>
IrcMessage::IrcMessage(std::stringstream ss)
{
if (ss.peek() == '@')
{
std::string raw_tags;
ss.ignore();
ss >> raw_tags;
std::vector<std::string> tags = utils::split(raw_tags, ';', false);
for (auto &tag: tags)
{
auto pos = tag.find('=');
if (pos == std::string::npos)
this->tags[tag] = {};
else
this->tags[tag.substr(0, pos)] = tag.substr(pos+1);
}
ss.ignore();
}
if (ss.peek() == ':')
{
ss.ignore();
@@ -30,6 +49,7 @@ IrcMessage::IrcMessage(std::stringstream ss)
IrcMessage::IrcMessage(std::string&& prefix,
std::string&& command,
std::vector<std::string>&& args):
tags(),
prefix(std::move(prefix)),
command(std::move(command)),
arguments(std::move(args))
@@ -38,16 +58,36 @@ IrcMessage::IrcMessage(std::string&& prefix,
IrcMessage::IrcMessage(std::string&& command,
std::vector<std::string>&& args):
tags(),
prefix(),
command(std::move(command)),
arguments(std::move(args))
{
}
IrcMessage::IrcMessage(std::unordered_map<std::string, std::optional<std::string>>&& tags,
std::string&& prefix,
std::string&& command,
std::vector<std::string>&& args):
tags(std::move(tags)),
prefix(std::move(prefix)),
command(std::move(command)),
arguments(std::move(args))
{
}
std::ostream& operator<<(std::ostream& os, const IrcMessage& message)
{
os << "IrcMessage";
os << "[" << message.command << "]";
os << "{";
for (auto& tag: message.tags)
{
os << tag.first;
if (tag.second.has_value())
os << "=" << tag.second.value();
os << ";";
}
os << "}[" << message.command << "]";
for (const std::string& arg: message.arguments)
{
os << "{" << arg << "}";