diff options
| -rw-r--r-- | src/irc/client.cpp | 29 | ||||
| -rw-r--r-- | src/irc/client.hpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 2 |
3 files changed, 33 insertions, 0 deletions
diff --git a/src/irc/client.cpp b/src/irc/client.cpp index a4a2e5c..470bad9 100644 --- a/src/irc/client.cpp +++ b/src/irc/client.cpp @@ -1,5 +1,9 @@ #include "client.hpp" +#include <ixwebsocket/IXWebSocketMessage.h> +#include <ixwebsocket/IXWebSocketMessageType.h> + +#include <iostream> #include <string> using namespace RedpilledBot::IRC; @@ -13,3 +17,28 @@ Client::Client(std::string username, std::string password) { this->websocket.setUrl(this->host + ":" + this->port); } + +void Client::run() { + this->websocket.setOnMessageCallback( + [this](const ix::WebSocketMessagePtr &msg) { + switch (msg->type) { + case ix::WebSocketMessageType::Message: { + std::cout << "Got a message: " << msg->str << std::endl; + break; + } + case ix::WebSocketMessageType::Open: { + std::cout << "Connected to Twitch IRC!\n"; + break; + } + case ix::WebSocketMessageType::Close: { + std::cout << "Twitch IRC Connection closed!\n"; + break; + } + default: { + break; + } + } + }); + + this->websocket.run(); +} diff --git a/src/irc/client.hpp b/src/irc/client.hpp index 18e9854..52c8cbf 100644 --- a/src/irc/client.hpp +++ b/src/irc/client.hpp @@ -11,6 +11,8 @@ namespace RedpilledBot { Client(std::string username, std::string password); ~Client() = default; + void run(); + private: std::string username; std::string password; diff --git a/src/main.cpp b/src/main.cpp index 34839eb..3e13f5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,5 +7,7 @@ int main(int argc, char *argv[]) { RedpilledBot::IRC::Client client("", ""); + client.run(); + return 0; } |
