From 9953a68a5d1918ad6e77a7c614279d14ab1c6bc0 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 20 Apr 2024 23:22:45 +0500 Subject: feat: connecting to twitch irc servers --- src/irc/client.cpp | 29 +++++++++++++++++++++++++++++ src/irc/client.hpp | 2 ++ 2 files changed, 31 insertions(+) (limited to 'src/irc') 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 +#include + +#include #include 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; -- cgit v1.2.3