diff options
| author | ilotterytea <iltsu@alright.party> | 2024-05-19 02:10:39 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-05-19 02:10:39 +0500 |
| commit | 59b52bfab39d98a11052497ab387011a9835ef1b (patch) | |
| tree | 9f911b85fa2a621386bbff418c48582c51637172 | |
| parent | a808ec07cbbb4fc6118d97b8e7985debe1274a5f (diff) | |
feat: handle ping messages
| -rw-r--r-- | bot/src/irc/client.cpp | 7 | ||||
| -rw-r--r-- | bot/src/irc/message.cpp | 2 | ||||
| -rw-r--r-- | bot/src/irc/message.hpp | 2 |
3 files changed, 10 insertions, 1 deletions
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 <ixwebsocket/IXWebSocketMessageType.h> #include <algorithm> +#include <iostream> #include <optional> #include <string> #include <vector> @@ -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<MessageType> define_message_type(const std::string &msg); struct MessageSender { |
