Skip to content

Commit

Permalink
Merge pull request #146 from jdomingu98/121-privmsg-bug-canalusuario-…
Browse files Browse the repository at this point in the history
…no-existe-error-incorrecto

fix(privmsg): deleted CannotSendToChannel
  • Loading branch information
jdomingu98 authored Apr 28, 2024
2 parents d99baa2 + 69fcf40 commit ba07629
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
11 changes: 0 additions & 11 deletions includes/exceptions/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
# define ERR_BAD_CHAN_MASK(channel) (channel) + " :Bad Channel Mask"
# define ERR_NO_SUCH_CHANNEL(channelName) (channelName) + " :No such channel"
# define ERR_TOO_MANY_CHANNELS(channelName) (channelName) + " :You have joined too many channels"

# define ERR_NOT_ON_CHANNEL(channel) (channel) + " :You're not on that channel"

# define ERR_CHANOP_PRIVS_NEEDED(channel) (channel) + " :You're not channel operator"

# define ERR_NO_SUCH_NICK(nickname) (nickname) + " :No such nick/channel"
Expand All @@ -32,7 +30,6 @@

# define ERR_NO_RECIPIENT(command) ":No recipient given (" + (command) + ")"
# define ERR_NO_TEXT_TO_SEND ":No text to send"
# define ERR_CANNOT_SEND_TO_CHAN(channel) (channel) + " :Cannot send to channel"

# define ERR_KEYSET(channel) (channel) + " :Channel key already set"
# define ERR_UNKOWN_MODE(modeChar) (modeChar) + " :is unknown mode char to me"
Expand Down Expand Up @@ -212,14 +209,6 @@ class UnknownModeException : public IRCException {
UnknownModeException(const std::string &modeChar) : IRCException("472", ERR_UNKOWN_MODE(modeChar)) {}
};

/**
* This exception is thrown when the user tries to send a message to a channel that does not exist.
*/
class CannotSendToChanException : public IRCException {
public:
CannotSendToChanException(const std::string &channelName) : IRCException("404", ERR_CANNOT_SEND_TO_CHAN(channelName)) {}
};

/**
* This exception is thrown when the user tries to launch an unknown command.
*/
Expand Down
7 changes: 1 addition & 6 deletions src/commands/PrivateMessageCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ void PrivateMessageCommand::execute(int clientFd) {
if (this->_receivers[i][0] == '#' || this->_receivers[i][0] == '&') {
Logger::debug("Sending private message to channel " + this->_receivers[i]);

if (!server.channelExists(this->_receivers[i]))
throw CannotSendToChanException(this->_receivers[i]);

Channel &destinationChannel = server.getChannelByName(this->_receivers[i]);
if (!destinationChannel.isUserInChannel(sender.getNickname()))
throw CannotSendToChanException(this->_receivers[i]);
throw NoSuchNickException(this->_receivers[i]);

sender.sendPrivateMessageToChannel(destinationChannel, this->_message);
} else {
Expand All @@ -41,8 +38,6 @@ void PrivateMessageCommand::execute(int clientFd) {
Logger::debug("Channel " + this->_receivers[i] + " does not exist.");
} catch (const NoSuchNickException &e) {
server.sendExceptionMessage(clientFd, e);
} catch (const CannotSendToChanException &e) {
server.sendExceptionMessage(clientFd, e);
}
}
}

0 comments on commit ba07629

Please sign in to comment.