From e9511e9fc3f387a19c5b9ae87d9a008fca776a6e Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:19:56 +0200 Subject: [PATCH] feat(cmd/notice): adding the notice command --- include/commands/notice.hpp | 22 +++++++++ sources/commands/notice.cpp | 57 +++++++++++++++++++++++ {include => sources}/commands/privmsg.cpp | 20 ++++---- 3 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 include/commands/notice.hpp create mode 100644 sources/commands/notice.cpp rename {include => sources}/commands/privmsg.cpp (73%) diff --git a/include/commands/notice.hpp b/include/commands/notice.hpp new file mode 100644 index 0000000..256eb28 --- /dev/null +++ b/include/commands/notice.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* notice.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/02 01:18:19 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::Notice : public ACommand { + public: + Notice(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual bool checkArgs(); +}; diff --git a/sources/commands/notice.cpp b/sources/commands/notice.cpp new file mode 100644 index 0000000..9985b3c --- /dev/null +++ b/sources/commands/notice.cpp @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* notice.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 01:18:05 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "notice.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool Notice::checkArgs() { + if (_args.size() < 3) { + WARNING_MSG("Not enough arguments for NOTICE command"); + return false; + } + if (_args.at(1).at(0) != '#') { + _uTarget = searchList(this->_users, _args.at(2)); + if (this->_uTarget == NULL) { + WARNING_MSG("User not found"); + return false; + } + if (this->_uTarget->isRegistered() == false) { + WARNING_MSG("User is not registered for NOTICE command"); + INFO_MSG("You can only NOTICE registered users"); + return false; + } + } else { + _cTarget = searchList(_channels, _args.at(1)); + if (_cTarget == NULL) { + WARNING_MSG("Channel not found for NOTICE command"); + INFO_MSG("You can only NOTICE 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 / a channel + */ +void Notice::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.cpp b/sources/commands/privmsg.cpp similarity index 73% rename from include/commands/privmsg.cpp rename to sources/commands/privmsg.cpp index b2f9fc5..c1c3cd4 100644 --- a/include/commands/privmsg.cpp +++ b/sources/commands/privmsg.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/06/02 01:01:13 by rparodi ### ########.fr */ +/* Updated: 2025/06/02 01:15:00 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,27 +18,27 @@ using namespace cmd; bool PrivMsg::checkArgs() { if (_args.size() < 3) { - WARNING_MSG("Not enough arguments for PrivMsg command"); + WARNING_MSG("Not enough arguments for PRIVMSG command"); return false; } if (_args.at(1).at(0) != '#') { - _uTarget = searchList(this->_users, _args.at(1)); + _uTarget = searchList(this->_users, _args.at(2)); 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"); + 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"); + WARNING_MSG("Channel not found for PRIVMSG command"); + INFO_MSG("You can only privmsg users to channels you are in"); return false; - } else + } else _args.at(1).erase(0, 1); } return true; @@ -46,11 +46,11 @@ bool PrivMsg::checkArgs() { /** * @brief Execute the PrivMsg command - * @note To send a private message to a user / channel + * @note To send a private message to a user / a channel */ void PrivMsg::execute() { if (checkArgs() == false) { - ERROR_MSG("Invalid arguments for PrivMsg command (see warning message)"); + ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)"); return; } // check how the com