feat(cmd/topic): topic command is now working
This commit is contained in:
parent
1c0e771dd5
commit
49a9f4b40a
2 changed files with 78 additions and 0 deletions
22
include/commands/topic.hpp
Normal file
22
include/commands/topic.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* topic.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/02 22:48:36 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/06/17 22:10:31 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
|
|
||||||
|
class cmd::Topic : public ACommand {
|
||||||
|
public:
|
||||||
|
Topic(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
|
virtual void execute(void);
|
||||||
|
virtual e_code checkArgs();
|
||||||
|
};
|
||||||
56
sources/commands/topic.cpp
Normal file
56
sources/commands/topic.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* topic.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/06/18 12:51:40 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
|
#include "core.hpp"
|
||||||
|
#include "logs.hpp"
|
||||||
|
#include "topic.hpp"
|
||||||
|
|
||||||
|
using namespace cmd;
|
||||||
|
|
||||||
|
e_code Topic::checkArgs() {
|
||||||
|
if (_args.size() < 2) {
|
||||||
|
std::string msg461 = ":localhost 461 " + this->_sender->getNickname() + " " + this->_command + " :Not enough parameters\r\n";
|
||||||
|
this->_sender->appendToWriteBuffer(msg461);
|
||||||
|
return ERR_NEEDMOREPARAMS;
|
||||||
|
}
|
||||||
|
this->_cTarget = searchList(this->_channels, this->_args[1]);
|
||||||
|
if (this->_cTarget == NULL)
|
||||||
|
return ERR_NOSUCHCHANNEL;
|
||||||
|
if (this->_cTarget->getProtectTopic()) {
|
||||||
|
if (searchList(this->_cTarget->getOperators(), this->_sender->getName()) == NULL)
|
||||||
|
return ERR_CHANOPRIVSNEEDED;
|
||||||
|
} else {
|
||||||
|
if (searchList(this->_cTarget->getUsers(), this->_sender->getName()) == NULL)
|
||||||
|
return ERR_NOTONCHANNEL;
|
||||||
|
}
|
||||||
|
return _PARSING_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Execute the Topic
|
||||||
|
* @note To change the topic of the channel
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Topic::execute() {
|
||||||
|
if (checkArgs() != _PARSING_OK) {
|
||||||
|
ERROR_MSG("Invalid arguments for TOPIC command (see warning message)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this->_cTarget->getTopic().empty()) {
|
||||||
|
std::string msg331 = ":localhost 331 " + this->_sender->getNickname() + " " + this->_cTarget->getName() + " :No topic is set" + "\r\n";
|
||||||
|
this->_sender->appendToWriteBuffer(msg331);
|
||||||
|
} else {
|
||||||
|
std::string msg332 = ":localhost 332 " + this->_sender->getNickname() + " " + this->_cTarget->getName() + " :" + _cTarget->getTopic() + "\r\n";
|
||||||
|
this->_sender->appendToWriteBuffer(msg332);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue