/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* privmsg.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Updated: 2025/06/24 14:40:03 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ #include "privmsg.hpp" #include "commands.hpp" #include "logs.hpp" #include "bonus.hpp" #include using namespace cmd; // exemple: // PRIVMSG #samy :salut e_code PrivMsg::checkArgs() { if (_args.size() < 3) { std::string msg461 = ":localhost 461 " + this->_sender->getNickname() + " " + this->_command + " :Not enough parameters\r\n"; this->_sender->appendToWriteBuffer(msg461); return ERR_NEEDMOREPARAMS; } std::string target = _args.at(1); if (target[0] == '#') { target.erase(0, 1); // Enlรจve le '#' _cTarget = searchList(_server->getChannelsList(), target); if (_cTarget == NULL) { WARNING_MSG("Channel not found for PRIVMSG command"); return ERR_NOSUCHCHANNEL; } } else { _uTarget = searchList(_users, target); if (_uTarget == NULL || !_uTarget->isRegistered()) { WARNING_MSG("User not found or not registered"); return ERR_NOSUCHNICK; } } return _PARSING_OK; } /** * @brief Execute the PrivMsg command * @note To send a private message to a user / a channel */ void PrivMsg::execute() { if (checkArgs() != _PARSING_OK) { ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)"); return; } std::string target = _args.at(1); std::string content = _args.at(2); std::string msg = ":" + _sender->getPrefix() + " PRIVMSG " + target + " :" + content + "\r\n"; //bonus msgBot std::string msgBot = ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ“œ Liste des commandes disponibles :\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- JOIN #channel โ†’ Rejoindre un canal\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- PART #channel โ†’ Quitter un canal\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- PRIVMSG msg โ†’ Envoyer un message\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- TOPIC #channel :txt โ†’ Voir / modifier le topic\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- MODE #channel +o nick โ†’ Ajouter un opรฉrateur\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- INVITE nick #channel โ†’ Inviter un utilisateur\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- KICK #channel nick โ†’ ร‰jecter un utilisateur\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- WHO / WHOIS โ†’ Infos sur les utilisateurs\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- DCC SEND nick /PATH โ†’ Transferer des fichiers ร  l'utilisateur\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- DCC GET /PATH โ†’ Accepter le transfert des fichiers reรงu\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- !emote โ†’ Affiche la liste d'emoji\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- !help โ†’ Affiche cette aide\r\n"; std::string msgEmote = ":bot!ircbot@localhost PRIVMSG " + target + " : ๐Ÿ“œ Emote list :\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜€๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†๐Ÿ˜‡๐Ÿ˜ˆ๐Ÿ˜‰๐Ÿ˜Š๐Ÿ˜‹๐Ÿ˜Œ๐Ÿ˜๐Ÿ˜Ž๐Ÿ˜\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜๐Ÿ˜‘๐Ÿ˜’๐Ÿ˜“๐Ÿ˜”๐Ÿ˜•๐Ÿ˜–๐Ÿ˜—๐Ÿ˜˜๐Ÿ˜™๐Ÿ˜š๐Ÿ˜›๐Ÿ˜œ๐Ÿ˜๐Ÿ˜ž๐Ÿ˜Ÿ\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜ ๐Ÿ˜ก๐Ÿ˜ข๐Ÿ˜ฃ๐Ÿ˜ค๐Ÿ˜ฅ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜จ๐Ÿ˜ฉ๐Ÿ˜ช๐Ÿ˜ซ๐Ÿ˜ฌ๐Ÿ˜ญ๐Ÿ˜ฎ๐Ÿ˜ฏ\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜ฐ๐Ÿ˜ฑ๐Ÿ˜ฒ๐Ÿ˜ณ๐Ÿ˜ด๐Ÿ˜ต๐Ÿ˜ถ๐Ÿ˜ท๐Ÿ˜ธ๐Ÿ˜น๐Ÿ˜บ๐Ÿ˜ป๐Ÿ˜ผ๐Ÿ˜ฝ๐Ÿ˜พ๐Ÿ˜ฟ\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ™€๐Ÿ™๐Ÿ™‚๐Ÿ™ƒ๐Ÿ™„๐Ÿ™…๐Ÿ™†๐Ÿ™‡๐Ÿ™ˆ๐Ÿ™‰๐Ÿ™Š๐Ÿ™‹๐Ÿ™Œ๐Ÿ™๐Ÿ™Ž๐Ÿ™\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿค๐Ÿค‘๐Ÿค’๐Ÿค“๐Ÿคค๐Ÿค”๐Ÿค•๐Ÿค–๐Ÿค—๐Ÿค˜๐Ÿค™๐Ÿคš๐Ÿค›๐Ÿคœ๐Ÿค๐ŸคŸ\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ’๐Ÿ’‘๐Ÿ’’๐Ÿ’“๐Ÿ’”๐Ÿ’•๐Ÿ’–๐Ÿ’—๐Ÿ’˜๐Ÿ’™๐Ÿ’š๐Ÿ’›๐Ÿ’œ๐Ÿ’๐Ÿ’ž๐Ÿ’Ÿ\r\n"; msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ’ ๐Ÿ’ก๐Ÿ’ข๐Ÿ’ฃ๐Ÿ’ค๐Ÿ’ฅ๐Ÿ’ฆ๐Ÿ’ง๐Ÿ’จ๐Ÿ’ฉ๐Ÿ’ช๐Ÿ’ซ๐Ÿ’ฌ๐Ÿ’ญ๐Ÿ’ฏ๐Ÿคจ\r\n"; // Envoi vers un channel if (target[0] == '#') { target.erase(0, 1); if (_cTarget) { if (BONUS && _cTarget->getBotChannel() && _args.at(2) == "!help") _sender->appendToWriteBuffer(msgBot); else if (BONUS && _cTarget->getBotChannel() && _args.at(2) == "!emote") _sender->appendToWriteBuffer(msgEmote); else _cTarget->sendAllClientInAChannel(msg, _sender); } } // Envoi vers un user const std::list& users = _server->getUsersList(); for (std::list::const_iterator it = users.begin(); it != users.end(); ++it) { if ((*it)->getName() == target) { (*it)->appendToWriteBuffer(msg); break; } } }