feat(cmd/notice): adding the notice command
This commit is contained in:
parent
adabe2c2f0
commit
e9511e9fc3
3 changed files with 89 additions and 10 deletions
22
include/commands/notice.hpp
Normal file
22
include/commands/notice.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* notice.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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();
|
||||||
|
};
|
||||||
57
sources/commands/notice.cpp
Normal file
57
sources/commands/notice.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* notice.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 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,25 +18,25 @@ using namespace cmd;
|
||||||
|
|
||||||
bool PrivMsg::checkArgs() {
|
bool PrivMsg::checkArgs() {
|
||||||
if (_args.size() < 3) {
|
if (_args.size() < 3) {
|
||||||
WARNING_MSG("Not enough arguments for PrivMsg command");
|
WARNING_MSG("Not enough arguments for PRIVMSG command");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (_args.at(1).at(0) != '#') {
|
if (_args.at(1).at(0) != '#') {
|
||||||
_uTarget = searchList(this->_users, _args.at(1));
|
_uTarget = searchList(this->_users, _args.at(2));
|
||||||
if (this->_uTarget == NULL) {
|
if (this->_uTarget == NULL) {
|
||||||
WARNING_MSG("User not found");
|
WARNING_MSG("User not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this->_uTarget->isRegistered() == false) {
|
if (this->_uTarget->isRegistered() == false) {
|
||||||
WARNING_MSG("User is not registered for PrivMsg command");
|
WARNING_MSG("User is not registered for PRIVMSG command");
|
||||||
INFO_MSG("You can only PrivMsg registered users");
|
INFO_MSG("You can only privmsg registered users");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_cTarget = searchList(_channels, _args.at(1));
|
_cTarget = searchList(_channels, _args.at(1));
|
||||||
if (_cTarget == NULL) {
|
if (_cTarget == NULL) {
|
||||||
WARNING_MSG("Channel not found for PrivMsg command");
|
WARNING_MSG("Channel not found for PRIVMSG command");
|
||||||
INFO_MSG("You can only PrivMsg users to channels you are in");
|
INFO_MSG("You can only privmsg users to channels you are in");
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
_args.at(1).erase(0, 1);
|
_args.at(1).erase(0, 1);
|
||||||
|
|
@ -46,11 +46,11 @@ bool PrivMsg::checkArgs() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Execute the PrivMsg command
|
* @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() {
|
void PrivMsg::execute() {
|
||||||
if (checkArgs() == false) {
|
if (checkArgs() == false) {
|
||||||
ERROR_MSG("Invalid arguments for PrivMsg command (see warning message)");
|
ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check how the com
|
// check how the com
|
||||||
Loading…
Add table
Add a link
Reference in a new issue