diff --git a/includes/bot.hpp b/includes/bot.hpp index 999cabb..d59aca2 100644 --- a/includes/bot.hpp +++ b/includes/bot.hpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/30 01:54:36 by vvaas #+# #+# */ -/* Updated: 2024/01/30 16:56:57 by vvaas ### ########.fr */ +/* Updated: 2024/01/30 17:24:08 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -27,6 +27,8 @@ class bot void handle_response(std::string buffer); ~bot(); private : + bool _channel_created; + bool _logged; struct sockaddr_in _serv_addr; int _fd; std::vector _connect_commands; diff --git a/srcs_bonus/bot.cpp b/srcs_bonus/bot.cpp index 5e5b20f..582a39b 100644 --- a/srcs_bonus/bot.cpp +++ b/srcs_bonus/bot.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/30 01:54:56 by vvaas #+# #+# */ -/* Updated: 2024/01/30 17:07:02 by vvaas ### ########.fr */ +/* Updated: 2024/01/30 17:26:11 by vvaas ### ########.fr */ /* */ /******************************************************************************/ @@ -18,7 +18,8 @@ #include #include -bot::bot() {} +bot::bot() : _channel_created(false), _logged(false) +{} bot::~bot() {} @@ -27,6 +28,7 @@ void bot::init() _connect_commands.push_back("PASS " PASSWORD "\r\n"); _connect_commands.push_back("NICK greg\r\n"); _connect_commands.push_back("USER greg_bot 0 * :botrealname\r\n"); + _connect_commands.push_back("JOIN #greg\r\n"); _fd = socket(AF_INET, SOCK_STREAM, 0); if (_fd == -1) irc::logs::report(irc::log_fatal_error, "FD error"); @@ -41,7 +43,20 @@ void bot::init() void bot::handle_response(std::string buffer) { - if (buffer == ":yipirc 001 greg :Welcome to yipirc :), greg\r\n") + std::cout << buffer << std::flush; + if (!_logged && buffer == ":yipirc 001 greg :Welcome to yipirc :), greg\r\n") + { + _logged = true; + irc::logs::report(irc::log_message, "Logged in succesfully"); + } + else if (!_logged) + return ; + if (!_channel_created && buffer == ":yipirc 353 greg @ #greg :@greg\r\n") + { + _channel_created = true; + irc::logs::report(irc::log_message, "Created the channel succesfully"); + } + else if (!_channel_created) return ; } @@ -52,6 +67,8 @@ void bot::connect_to_server() { if (send(_fd, (*it).c_str(), (*it).size(), 0) < 0) irc::logs::report(irc::log_fatal_error, "send error"); + if (recv(_fd, buffer, 1024, 0) > 0) + handle_response(buffer); } while (true) {