feat(cmd/part): adding part commands
This commit is contained in:
parent
67dd7f0ae8
commit
76448d5923
2 changed files with 77 additions and 0 deletions
22
include/commands/part.hpp
Normal file
22
include/commands/part.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* part.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */
|
||||
/* Updated: 2025/06/02 00:51:23 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
class cmd::Part : public ACommand {
|
||||
public:
|
||||
Part(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
||||
virtual void execute(void);
|
||||
virtual bool checkArgs();
|
||||
};
|
||||
55
sources/commands/part.cpp
Normal file
55
sources/commands/part.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* part.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/06/02 00:55:56 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "part.hpp"
|
||||
#include "commands.hpp"
|
||||
#include "logs.hpp"
|
||||
|
||||
using namespace cmd;
|
||||
|
||||
bool Part::checkArgs() {
|
||||
if (_args.size() < 2) {
|
||||
WARNING_MSG("Not enough arguments for PART command");
|
||||
return false;
|
||||
}
|
||||
if (_args.at(1).at(0) != '#') {
|
||||
WARNING_MSG("Invalid channel name for PART command");
|
||||
INFO_MSG("Channel names must start with a '#' character");
|
||||
return false;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
if (_cTarget == NULL) {
|
||||
WARNING_MSG("Channel not found for PART command");
|
||||
INFO_MSG("You can only Part users to channels you are in");
|
||||
return false;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) {
|
||||
WARNING_MSG("User is not in the channel he wants to leave");
|
||||
INFO_MSG("You cannot leave a channel where ur not a member");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Execute the Part command
|
||||
* @note To leave a channel givent in parameter
|
||||
*/
|
||||
void Part::execute() {
|
||||
if (checkArgs() == false) {
|
||||
ERROR_MSG("Invalid arguments for Part command (see warning message)");
|
||||
return;
|
||||
}
|
||||
// check how the com
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue