From 59b52bfab39d98a11052497ab387011a9835ef1b Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 19 May 2024 02:10:39 +0500 Subject: feat: handle ping messages --- bot/src/irc/client.cpp | 7 +++++++ bot/src/irc/message.cpp | 2 ++ bot/src/irc/message.hpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bot/src/irc/client.cpp b/bot/src/irc/client.cpp index 018736e..06b7a03 100644 --- a/bot/src/irc/client.cpp +++ b/bot/src/irc/client.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -77,6 +78,12 @@ void Client::run() { if (message.has_value()) { this->onPrivmsg(message.value()); } + } else if (m_type == MessageType::Ping) { + // as the docs say, the message should be the same as the one + // from the ping + std::string response_text = msg->str.substr(4, msg->str.size()); + + this->raw("PONG" + response_text); } } diff --git a/bot/src/irc/message.cpp b/bot/src/irc/message.cpp index 569e691..038df83 100644 --- a/bot/src/irc/message.cpp +++ b/bot/src/irc/message.cpp @@ -22,6 +22,8 @@ namespace bot { return MessageType::Notice; } else if (parts[i] == "PRIVMSG") { return MessageType::Privmsg; + } else if (parts[i] == "PING") { + return MessageType::Ping; } return std::nullopt; diff --git a/bot/src/irc/message.hpp b/bot/src/irc/message.hpp index 164d7ca..54b911b 100644 --- a/bot/src/irc/message.hpp +++ b/bot/src/irc/message.hpp @@ -11,7 +11,7 @@ namespace bot { namespace irc { - enum MessageType { Privmsg, Notice }; + enum MessageType { Privmsg, Ping, Notice }; std::optional define_message_type(const std::string &msg); struct MessageSender { -- cgit v1.2.3