From b6006055ffc5222e0488fa578c94ec41d669b1f0 Mon Sep 17 00:00:00 2001 From: aroualid Date: Thu, 29 Jan 2026 22:55:31 +0100 Subject: [PATCH 1/5] miaouuuuuuuuuuuuuuuuuuuu --- incs/bot/MiaouBot.hpp | 28 +++++++++++++++++++ srcs/bot/MiaouBot.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 incs/bot/MiaouBot.hpp create mode 100644 srcs/bot/MiaouBot.cpp diff --git a/incs/bot/MiaouBot.hpp b/incs/bot/MiaouBot.hpp new file mode 100644 index 0000000..dab9ac8 --- /dev/null +++ b/incs/bot/MiaouBot.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "IChannel.hpp" +#include "IClient.hpp" +#include "IServer.hpp" +#include "bot/IBot.hpp" + +class BotClient; + +class MiaouBot : public IBot +{ +private: + IServer& m_server; + BotClient* m_client; + + void sendToChannel(IChannel* channel, const std::string& message); + +public: + MiaouBot(IServer& server, const std::string& nick = "Larry"); + ~MiaouBot(); + + void onPrivateMessage(IClient* sender, const std::string& message); + void onChannelMessage(IClient* sender, IChannel* channel, const std::string& message); + + IClient* getClient(); + + void joinChannel(const std::string& channelName); +}; diff --git a/srcs/bot/MiaouBot.cpp b/srcs/bot/MiaouBot.cpp new file mode 100644 index 0000000..9a968db --- /dev/null +++ b/srcs/bot/MiaouBot.cpp @@ -0,0 +1,65 @@ +#include "bot/MiaouBot.hpp" +#include "CommandType.hpp" +#include "protocol/Message.hpp" +#include "protocol/MessageParser.hpp" +#include +#include + + +MiaouBot::MiaouBot(IServer& server, const std::string& nick) : m_server(server) +{ + (void)nick; +} + +void MiaouBot::onChannelMessage(IClient *sender, IChannel *channel, const std::string &message) +{ + (void) sender; + (void) message; + std::time_t start = std::time(NULL); + while (true) + { + std::time_t now = std::time(NULL); + double difftime = std::difftime(start, now); + if (difftime >= 30.0) + { + int i = 1 + (rand()% 6); + switch (i) + { + case 1: + sendToChannel(channel, "MIAOUUUUUUUUU"); + break; + case 2: + sendToChannel(channel, "Quack i'm a DUCK NOW LET'S GOOO! 🦆🦆🦆🦆🦆"); + break; + case 3: + sendToChannel(channel, "Meow i'm a british cat 🇬🇧"); + break; + case 4: + sendToChannel(channel, "WAF im a weird cat"); + break; + case 5: + sendToChannel(channel, "ᵐᶦᵃᵒᵘ ᶦ ᵃᵐ ˢʰʸ ᵘʷᵘ ⁽,,>﹏<,,⁾👉👈"); + break; + case 6: + sendToChannel(channel, "check tes mails."); + break; + default: + break; + } + start = std::time(NULL); + } + } +} + +void MiaouBot::sendToChannel(IChannel *channel, const std::string &message) +{ + Message msg; + msg.m_prefix = m_client->getPrefix(); + msg.m_command = "PRIVMSG"; + msg.m_command_type = irc::PRIVMSG; + msg.m_params.push_back(channel->getName()); + msg.m_params.push_back(message); + + std::string serialized = MessageParser::serialize(msg); + channel->broadcast(serialized, m_client); +} From 424567b85744314c3b91a0d00c59f756099472eb Mon Sep 17 00:00:00 2001 From: aroualid Date: Thu, 29 Jan 2026 23:04:25 +0100 Subject: [PATCH 2/5] miaouuuuuuuuuuuuuuu: --- incs/bot/MiaouBot.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/incs/bot/MiaouBot.hpp b/incs/bot/MiaouBot.hpp index dab9ac8..4439f4c 100644 --- a/incs/bot/MiaouBot.hpp +++ b/incs/bot/MiaouBot.hpp @@ -4,8 +4,7 @@ #include "IClient.hpp" #include "IServer.hpp" #include "bot/IBot.hpp" - -class BotClient; +#include "bot/BotClient.hpp" class MiaouBot : public IBot { From 7fd4b6219f315605b0cafac8ef00f2d6fb5c5540 Mon Sep 17 00:00:00 2001 From: aroualid Date: Fri, 30 Jan 2026 18:01:55 +0100 Subject: [PATCH 3/5] fix on bot --- incs/bot/BotClient.hpp | 2 +- srcs/bot/MiaouBot.cpp | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/incs/bot/BotClient.hpp b/incs/bot/BotClient.hpp index b63b8e1..3fe4a8d 100644 --- a/incs/bot/BotClient.hpp +++ b/incs/bot/BotClient.hpp @@ -4,8 +4,8 @@ #include "IServer.hpp" #include "IChannel.hpp" #include "BotMessageBuffer.hpp" +#include "IBot.hpp" -class IBot; class BotClient : public IClient { private: diff --git a/srcs/bot/MiaouBot.cpp b/srcs/bot/MiaouBot.cpp index 9a968db..decbfbd 100644 --- a/srcs/bot/MiaouBot.cpp +++ b/srcs/bot/MiaouBot.cpp @@ -8,9 +8,16 @@ MiaouBot::MiaouBot(IServer& server, const std::string& nick) : m_server(server) { - (void)nick; + m_client = new BotClient(nick, server); + } +MiaouBot::~MiaouBot() +{ + delete m_client; +} + + void MiaouBot::onChannelMessage(IClient *sender, IChannel *channel, const std::string &message) { (void) sender; @@ -18,6 +25,7 @@ void MiaouBot::onChannelMessage(IClient *sender, IChannel *channel, const std::s std::time_t start = std::time(NULL); while (true) { + std::cout << "salut" << std::endl; std::time_t now = std::time(NULL); double difftime = std::difftime(start, now); if (difftime >= 30.0) @@ -63,3 +71,28 @@ void MiaouBot::sendToChannel(IChannel *channel, const std::string &message) std::string serialized = MessageParser::serialize(msg); channel->broadcast(serialized, m_client); } + +void MiaouBot::joinChannel(const std::string& channelName) +{ + IChannel* channel = m_server.getChannel(channelName); + if (!channel) + channel = m_server.createChannel(channelName, m_client); + if (!channel->hasMember(m_client)) + { + channel->addMember(m_client); + m_client->joinChannel(channel); + } +} + + +void MiaouBot::onPrivateMessage(IClient* sender, const std::string& message) +{ + if (sender == m_client) + return; + (void)message; +} + +IClient* MiaouBot::getClient() +{ + return (m_client); +} From d0bb356af914cedccf3500c51d98e107c2127f26 Mon Sep 17 00:00:00 2001 From: aroualid Date: Fri, 30 Jan 2026 18:02:13 +0100 Subject: [PATCH 4/5] add things for bot to work --- Makefile | 4 +++- srcs/commands/InviteCommand.cpp | 9 ++++++++- srcs/main.cpp | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 579d955..13937c8 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,9 @@ SRCS = $(SRCS_DIR)/main.cpp \ $(SRCS_DIR)/modes/UserLimitMode.cpp \ $(SRCS_DIR)/protocol/IrcUtils.cpp \ $(SRCS_DIR)/bot/BotMessageBuffer.cpp \ - $(SRCS_DIR)/bot/BotClient.cpp + $(SRCS_DIR)/bot/BotClient.cpp \ + $(SRCS_DIR)/bot/MiaouBot.cpp + OBJ = $(SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/%.o) diff --git a/srcs/commands/InviteCommand.cpp b/srcs/commands/InviteCommand.cpp index c547488..5584915 100644 --- a/srcs/commands/InviteCommand.cpp +++ b/srcs/commands/InviteCommand.cpp @@ -4,6 +4,7 @@ #include "core/IMessageBuffer.hpp" #include "protocol/MessageParser.hpp" #include +#include REGISTER_COMMAND(InviteCommand, irc::INVITE, "INVITE"); @@ -28,6 +29,12 @@ void InviteCommand::doExecute(IClient* client, const Message& message) } IChannel* channel = m_server.getChannel(channelName); + if (target && target->getFd() < 0) // It's a bot! + { + channel->addMember(target); + target->joinChannel(channel); + return; + } if (!channel) { sendReply(client, NumericReply::noSuchChannel(client->getNickname(), channelName)); @@ -51,7 +58,7 @@ void InviteCommand::doExecute(IClient* client, const Message& message) sendReply(client, NumericReply::userOnChannel(client->getNickname(), targetNick, channelName)); return; - } + } channel->addInvite(target); diff --git a/srcs/main.cpp b/srcs/main.cpp index 213e602..d8e73f3 100644 --- a/srcs/main.cpp +++ b/srcs/main.cpp @@ -2,6 +2,7 @@ #include "core/Server.hpp" #include #include +#include "bot/MiaouBot.hpp" volatile sig_atomic_t g_shutdown = 0; @@ -21,7 +22,9 @@ int main(int argc, char** argv) try { Config cfg = Config::checkArgs(argc, argv); - Server srv(cfg); + Server srv(cfg); + MiaouBot* bot = new MiaouBot(srv, "larry"); + srv.registerBot(bot); srv.run(); return (0); } From 67f08b3e0f00e476994c43d5a0209eaf661ad0c4 Mon Sep 17 00:00:00 2001 From: aroualid Date: Sat, 31 Jan 2026 18:58:58 +0100 Subject: [PATCH 5/5] MIAOUUUUUUUUUU bot finish --- Makefile | 4 +-- incs/bot/BotMessageBuffer.hpp | 1 - incs/bot/MiaouBot.hpp | 3 +- srcs/bot/MiaouBot.cpp | 64 +++++++++++++++------------------ srcs/commands/InviteCommand.cpp | 6 ---- srcs/main.cpp | 3 +- 6 files changed, 34 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 7369a5d..fe84e6f 100644 --- a/Makefile +++ b/Makefile @@ -66,9 +66,9 @@ OBJ = $(SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/%.o) BONUS_SRCS := $(SRCS_DIR)/bot/BotMessageBuffer.cpp \ $(SRCS_DIR)/bot/BotClient.cpp \ - $(SRCS_DIR)/bot/Miaou.cpp \ + $(SRCS_DIR)/bot/MiaouBot.cpp \ $(SRCS_DIR)/bot/SixSevenBot.cpp - + OBJS := $(SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/%.o) OBJS_BONUS := $(SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/bonus/%.o) \ $(BONUS_SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/bonus/%.o) diff --git a/incs/bot/BotMessageBuffer.hpp b/incs/bot/BotMessageBuffer.hpp index dc86085..0af8417 100644 --- a/incs/bot/BotMessageBuffer.hpp +++ b/incs/bot/BotMessageBuffer.hpp @@ -8,7 +8,6 @@ #include "bot/IBot.hpp" #include "protocol/Message.hpp" - class BotMessageBuffer : public IMessageBuffer { private: diff --git a/incs/bot/MiaouBot.hpp b/incs/bot/MiaouBot.hpp index 4439f4c..2e5c970 100644 --- a/incs/bot/MiaouBot.hpp +++ b/incs/bot/MiaouBot.hpp @@ -11,7 +11,8 @@ class MiaouBot : public IBot private: IServer& m_server; BotClient* m_client; - + int _count_message; + int _index; void sendToChannel(IChannel* channel, const std::string& message); public: diff --git a/srcs/bot/MiaouBot.cpp b/srcs/bot/MiaouBot.cpp index 466edf3..b9baf32 100644 --- a/srcs/bot/MiaouBot.cpp +++ b/srcs/bot/MiaouBot.cpp @@ -6,10 +6,14 @@ #include -MiaouBot::MiaouBot(IServer& server, const std::string& nick) : m_server(server) + +MiaouBot::MiaouBot(IServer& server, const std::string& nick) : m_server(server), _count_message(0), _index(0) { m_client = new BotClient(nick, server); - + m_client->setBot(this); + BotMessageBuffer *bmb = dynamic_cast(&m_client->getBuffer()); + bmb->setBot(this); + std::srand(std::time(0)); } MiaouBot::~MiaouBot() @@ -20,42 +24,30 @@ MiaouBot::~MiaouBot() void MiaouBot::onChannelMessage(IClient *sender, IChannel *channel, const std::string &message) { - (void) sender; - (void) message; - std::time_t start = std::time(NULL); - while (true) + + if (sender == m_client) + return; + if (message.empty()) + return; + _count_message++; + + if (_count_message >= 5) { - std::time_t now = std::time(NULL); - double difftime = std::difftime(start, now); - if (difftime >= 30.0) - { - int i = 1 + (rand()% 6); - switch (i) - { - case 1: - sendToChannel(channel, "MIAOUUUUUUUUU"); - break; - case 2: - sendToChannel(channel, "Quack i'm a DUCK NOW LET'S GOOO! 🦆🦆🦆🦆🦆"); - break; - case 3: - sendToChannel(channel, "Meow i'm a british cat 🇬🇧"); - break; - case 4: - sendToChannel(channel, "WAF im a weird cat"); - break; - case 5: - sendToChannel(channel, "ᵐᶦᵃᵒᵘ ᶦ ᵃᵐ ˢʰʸ ᵘʷᵘ ⁽,,>﹏<,,⁾👉👈"); - break; - case 6: - sendToChannel(channel, "check tes mails."); - break; - default: - break; - } - start = std::time(NULL); - } + _count_message = 0; + _index++; + + const char* responses[] = { + "MIAOUUUUUUUUU", + "Quack i'm a DUCK NOW LET'S GOOO! 🦆🦆🦆🦆", + "Meow i'm a british cat 🇬🇧 ", + "WAF im a weird cat", + "miaou I am shy uwu (,,>﹏<,,)👉👈", + "check tes mails." + }; + + sendToChannel(channel, responses[_index%6]); } + } void MiaouBot::sendToChannel(IChannel *channel, const std::string &message) diff --git a/srcs/commands/InviteCommand.cpp b/srcs/commands/InviteCommand.cpp index 5584915..830ac6b 100644 --- a/srcs/commands/InviteCommand.cpp +++ b/srcs/commands/InviteCommand.cpp @@ -29,12 +29,6 @@ void InviteCommand::doExecute(IClient* client, const Message& message) } IChannel* channel = m_server.getChannel(channelName); - if (target && target->getFd() < 0) // It's a bot! - { - channel->addMember(target); - target->joinChannel(channel); - return; - } if (!channel) { sendReply(client, NumericReply::noSuchChannel(client->getNickname(), channelName)); diff --git a/srcs/main.cpp b/srcs/main.cpp index 4aef51f..ec0130c 100644 --- a/srcs/main.cpp +++ b/srcs/main.cpp @@ -33,8 +33,9 @@ int main(int argc, char** argv) SixSevenBot *sixSevenBot = new SixSevenBot(srv); srv.registerBot(sixSevenBot); sixSevenBot->joinChannel("#eighty-nine"); - MiaouBot* miaouBot = new MiaouBot(srv, "larry"); + MiaouBot *miaouBot = new MiaouBot(srv); srv.registerBot(miaouBot); + miaouBot->joinChannel("#cat"); #endif srv.run(); return (0);