-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from ArthanIRC/bot-registration
feat: implement bot registration server side
- Loading branch information
Showing
17 changed files
with
157 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "Command.hpp" | ||
|
||
class BotCommand : public Command { | ||
private: | ||
std::string _key; | ||
|
||
public: | ||
BotCommand(std::string source, std::vector<std::string> params, | ||
Client* client); | ||
~BotCommand(); | ||
|
||
void run(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "BotCommand.hpp" | ||
#include "Client.hpp" | ||
#include "Exception.hpp" | ||
#include "JoinCommand.hpp" | ||
#include <vector> | ||
|
||
using std::map; | ||
using std::string; | ||
using std::vector; | ||
|
||
BotCommand::BotCommand(string source, vector<string> params, Client* client) { | ||
if (!client->isRegistered()) { | ||
client->sendMessage(Replies::ERR_NOTREGISTERED()); | ||
throw ClientException(); | ||
} | ||
|
||
if (params.empty()) { | ||
client->sendMessage(Replies::ERR_NEEDMOREPARAMS(client, "BOT")); | ||
throw ClientException(); | ||
} | ||
|
||
this->_source = source; | ||
this->_params = params; | ||
this->_client = client; | ||
this->_key = params[0]; | ||
} | ||
|
||
BotCommand::~BotCommand() {} | ||
|
||
void BotCommand::run() { | ||
if (Server::getInstance().getBotKey() != _key) { | ||
_client->sendMessage(Replies::ERR_INVALIDBOTKEY(_client)); | ||
return; | ||
} | ||
|
||
_client->setState(OPERATOR); | ||
_client->setBot(true); | ||
_client->sendMessage(Replies::RPL_YOUREOPER(_client)); | ||
string reply = ":" + Server::getInstance().getSource() + " MODE " + | ||
_client->getNickname() + " +Bo"; | ||
_client->sendMessage(Message::create(reply)); | ||
_client->sendMessage(Replies::RPL_YOUREPRIVBOT(_client)); | ||
|
||
map<string, Channel*> channels = Server::getInstance().getChannels(); | ||
string chansToJoin; | ||
for (map<string, Channel*>::iterator it = channels.begin(); | ||
it != channels.end(); it++) { | ||
if (!chansToJoin.empty()) | ||
chansToJoin += ","; | ||
chansToJoin += it->first; | ||
} | ||
|
||
vector<string> tmp; | ||
tmp.push_back(chansToJoin); | ||
JoinCommand j("", tmp, _client); | ||
j.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.