gg
This commit is contained in:
@@ -6,28 +6,33 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/30 01:54:56 by vvaas #+# #+# */
|
||||
/* Updated: 2024/01/30 17:26:11 by vvaas ### ########.fr */
|
||||
/* Updated: 2024/01/30 18:34:07 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
#include <bot.hpp>
|
||||
#include <Bot.hpp>
|
||||
#include <logs.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
bot::bot() : _channel_created(false), _logged(false)
|
||||
Bot::Bot() : _channel_created(false), _logged(false)
|
||||
{}
|
||||
|
||||
bot::~bot() {}
|
||||
Bot::~Bot()
|
||||
{
|
||||
if (_fd >= 0)
|
||||
close(_fd);
|
||||
}
|
||||
|
||||
void bot::init()
|
||||
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("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)
|
||||
@@ -41,9 +46,16 @@ void bot::init()
|
||||
irc::logs::report(irc::log_fatal_error, "fcntl() error");
|
||||
}
|
||||
|
||||
void bot::handle_response(std::string buffer)
|
||||
void Bot::send_message(const std::string &content)
|
||||
{
|
||||
if (send(_fd, content.c_str(), content.length(), 0) < 0)
|
||||
irc::logs::report(irc::log_fatal_error, "send error");
|
||||
}
|
||||
|
||||
void Bot::handle_response(std::string buffer)
|
||||
{
|
||||
std::cout << buffer << std::flush;
|
||||
|
||||
if (!_logged && buffer == ":yipirc 001 greg :Welcome to yipirc :), greg\r\n")
|
||||
{
|
||||
_logged = true;
|
||||
@@ -51,16 +63,23 @@ void bot::handle_response(std::string buffer)
|
||||
}
|
||||
else if (!_logged)
|
||||
return ;
|
||||
if (!_channel_created && buffer == ":yipirc 353 greg @ #greg :@greg\r\n")
|
||||
if (!_channel_created && buffer == ":greg JOIN :#greg\r\n")
|
||||
{
|
||||
_channel_created = true;
|
||||
irc::logs::report(irc::log_message, "Created the channel succesfully");
|
||||
}
|
||||
else if (!_channel_created)
|
||||
return ;
|
||||
if (buffer.find("KICK #greg greg :") != std::string::npos || buffer.find("explose") != std::string::npos)
|
||||
{
|
||||
send_message("QUIT: Explose\r\n");
|
||||
std::exit(0);
|
||||
}
|
||||
if (buffer.find("quoi") != std::string::npos)
|
||||
send_message("PRIVMSG #greg :feur\r\n");
|
||||
}
|
||||
|
||||
void bot::connect_to_server()
|
||||
void Bot::connect_to_server()
|
||||
{
|
||||
char buffer[1024];
|
||||
for (std::vector<std::string>::iterator it = _connect_commands.begin(); it != _connect_commands.end(); ++it)
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:36:23 by vvaas #+# #+# */
|
||||
/* Updated: 2024/01/30 02:40:04 by vvaas ### ########.fr */
|
||||
/* Updated: 2024/01/30 17:58:07 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
#include <bot.hpp>
|
||||
#include <Bot.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
bot greg;
|
||||
Bot greg;
|
||||
|
||||
greg.init();
|
||||
greg.connect_to_server();
|
||||
|
||||
Reference in New Issue
Block a user