diff --git a/include/commands/privmsg.cpp b/include/commands/privmsg.cpp new file mode 100644 index 0000000..b2f9fc5 --- /dev/null +++ b/include/commands/privmsg.cpp @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* privmsg.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 01:01:13 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "privmsg.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool PrivMsg::checkArgs() { + if (_args.size() < 3) { + WARNING_MSG("Not enough arguments for PrivMsg command"); + return false; + } + if (_args.at(1).at(0) != '#') { + _uTarget = searchList(this->_users, _args.at(1)); + if (this->_uTarget == NULL) { + WARNING_MSG("User not found"); + return false; + } + if (this->_uTarget->isRegistered() == false) { + WARNING_MSG("User is not registered for PrivMsg command"); + INFO_MSG("You can only PrivMsg registered users"); + return false; + } + } else { + _cTarget = searchList(_channels, _args.at(1)); + if (_cTarget == NULL) { + WARNING_MSG("Channel not found for PrivMsg command"); + INFO_MSG("You can only PrivMsg users to channels you are in"); + return false; + } else + _args.at(1).erase(0, 1); + } + return true; +} + +/** + * @brief Execute the PrivMsg command + * @note To send a private message to a user / channel + */ +void PrivMsg::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for PrivMsg command (see warning message)"); + return; + } + // check how the com +} diff --git a/include/commands/privmsg.hpp b/include/commands/privmsg.hpp new file mode 100644 index 0000000..6c012d2 --- /dev/null +++ b/include/commands/privmsg.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* privmsg.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:58:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::PrivMsg : public ACommand { + public: + PrivMsg(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual bool checkArgs(); +};