From ede2219ba4aaa6efc875a9babe2387134b3c1418 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:02:25 +0200 Subject: [PATCH] feat(cmd/nick): adding nick commands --- include/commands/nick.hpp | 22 ++++++++++++++++++ sources/commands/nick.cpp | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 include/commands/nick.hpp create mode 100644 sources/commands/nick.cpp diff --git a/include/commands/nick.hpp b/include/commands/nick.hpp new file mode 100644 index 0000000..fdc88ac --- /dev/null +++ b/include/commands/nick.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* nick.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:40:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::Nick : public ACommand { + public: + Nick(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/nick.cpp b/sources/commands/nick.cpp new file mode 100644 index 0000000..1eec360 --- /dev/null +++ b/sources/commands/nick.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* nick.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:55:45 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "nick.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool Nick::checkArgs() { + if (this->_uTarget->isRegistered() == false) { + WARNING_MSG("User is not registered for Nick command"); + INFO_MSG("You can only Nick registered users"); + return false; + } + if (_args.size() < 2) { + WARNING_MSG("Not enough arguments for Nick command"); + return false; + } + _uTarget = searchList(this->_users, _args.at(1)); + if (this->_uTarget != NULL) { + WARNING_MSG(_uTarget->getName() << " is already taken") + return false; + } + return true; +} + +/** + * @brief Execute the Nick command + * @note To change the nickname of the user + */ +void Nick::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for Nick command (see warning message)"); + return; + } + // check how the com +}