diff options
author | Adam <Adam@anope.org> | 2010-11-24 21:40:56 -0600 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-12-12 19:36:19 -0500 |
commit | cb6ef574e3df5cc846247450b74ca37d265f319e (patch) | |
tree | 8ce3374a537c312af63c78125bfea4622bb188f0 /modules/core/bs_bot.cpp | |
parent | 37e02a3594fdddc3d5a3df0501c528f42db6c4da (diff) |
Send replies from fantasy commands back to the channel, this will be expanded on later
Diffstat (limited to 'modules/core/bs_bot.cpp')
-rw-r--r-- | modules/core/bs_bot.cpp | 117 |
1 files changed, 59 insertions, 58 deletions
diff --git a/modules/core/bs_bot.cpp b/modules/core/bs_bot.cpp index 067633964..e16c4795a 100644 --- a/modules/core/bs_bot.cpp +++ b/modules/core/bs_bot.cpp @@ -16,70 +16,70 @@ class CommandBSBot : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[1]; - Anope::string user = params[2]; - Anope::string host = params[3]; - Anope::string real = params[4]; + const Anope::string &nick = params[1]; + const Anope::string &user = params[2]; + const Anope::string &host = params[3]; + const Anope::string &real = params[4]; BotInfo *bi; if (findbot(nick)) { - u->SendMessage(BotServ, BOT_BOT_ALREADY_EXISTS, nick.c_str()); + source.Reply(BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } if (nick.length() > Config->NickLen) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } if (user.length() > Config->UserLen) { - u->SendMessage(BotServ, BOT_LONG_IDENT, Config->UserLen); + source.Reply(BOT_LONG_IDENT, Config->UserLen); return MOD_CONT; } if (host.length() > Config->HostLen) { - u->SendMessage(BotServ, BOT_LONG_HOST, Config->HostLen); + source.Reply(BOT_LONG_HOST, Config->HostLen); return MOD_CONT; } /* Check the nick is valid re RFC 2812 */ if (isdigit(nick[0]) || nick[0] == '-') { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } for (unsigned i = 0, end = nick.length(); i < end && i < Config->NickLen; ++i) if (!isvalidnick(nick[i])) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } /* check for hardcored ircd forbidden nicks */ if (!ircdproto->IsNickValid(nick)) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } /* Check the host is valid re RFC 2812 */ if (!isValidHost(host, 3)) { - u->SendMessage(BotServ, BOT_BAD_HOST); + source.Reply(BOT_BAD_HOST); return MOD_CONT; } for (unsigned i = 0, end = user.length(); i < end && i < Config->UserLen; ++i) if (!isalnum(user[i])) { - u->SendMessage(BotServ, BOT_BAD_IDENT, Config->UserLen); + source.Reply(BOT_BAD_IDENT, Config->UserLen); return MOD_CONT; } @@ -89,73 +89,73 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - u->SendMessage(BotServ, NICK_ALREADY_REGISTERED, nick.c_str()); + source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } if (!(bi = new BotInfo(nick, user, host, real))) { // XXX this cant happen? - u->SendMessage(BotServ, BOT_BOT_CREATION_FAILED); + source.Reply(BOT_BOT_CREATION_FAILED); return MOD_CONT; } - Log(LOG_ADMIN, u, this) << "ADD " << bi->GetMask() << " " << bi->realname; + Log(LOG_ADMIN, source.u, this) << "ADD " << bi->GetMask() << " " << bi->realname; - u->SendMessage(BotServ, BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); + source.Reply(BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); FOREACH_MOD(I_OnBotCreate, OnBotCreate(bi)); return MOD_CONT; } - CommandReturn DoChange(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoChange(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string oldnick = params[1]; - Anope::string nick = params.size() > 2 ? params[2] : ""; - Anope::string user = params.size() > 3 ? params[3] : ""; - Anope::string host = params.size() > 4 ? params[4] : ""; - Anope::string real = params.size() > 5 ? params[5] : ""; + const Anope::string &oldnick = params[1]; + const Anope::string &nick = params.size() > 2 ? params[2] : ""; + const Anope::string &user = params.size() > 3 ? params[3] : ""; + const Anope::string &host = params.size() > 4 ? params[4] : ""; + const Anope::string &real = params.size() > 5 ? params[5] : ""; BotInfo *bi; if (oldnick.empty() || nick.empty()) { - this->OnSyntaxError(u, "CHANGE"); + this->OnSyntaxError(source.u, "CHANGE"); return MOD_CONT; } if (!(bi = findbot(oldnick))) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, oldnick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } if (!oldnick.equals_ci(nick) && nickIsServices(oldnick, false)) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, oldnick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } if (nick.length() > Config->NickLen) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } if (!user.empty() && user.length() > Config->UserLen) { - u->SendMessage(BotServ, BOT_LONG_IDENT, Config->UserLen); + source.Reply(BOT_LONG_IDENT, Config->UserLen); return MOD_CONT; } if (!host.empty() && host.length() > Config->HostLen) { - u->SendMessage(BotServ, BOT_LONG_HOST, Config->HostLen); + source.Reply(BOT_LONG_HOST, Config->HostLen); return MOD_CONT; } if (!oldnick.equals_ci(nick) && nickIsServices(nick, false)) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, oldnick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } @@ -166,34 +166,34 @@ class CommandBSBot : public Command */ if (nick.equals_cs(bi->nick) && (!user.empty() ? user.equals_cs(bi->GetIdent()) : 1) && (!host.empty() ? host.equals_cs(bi->host) : 1) && (!real.empty() ? real.equals_cs(bi->realname) : 1)) { - u->SendMessage(BotServ, BOT_BOT_ANY_CHANGES); + source.Reply(BOT_BOT_ANY_CHANGES); return MOD_CONT; } /* Check the nick is valid re RFC 2812 */ if (isdigit(nick[0]) || nick[0] == '-') { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } for (unsigned i = 0, end = nick.length(); i < end && i < Config->NickLen; ++i) if (!isvalidnick(nick[i])) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } /* check for hardcored ircd forbidden nicks */ if (!ircdproto->IsNickValid(nick)) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } if (!host.empty() && !isValidHost(host, 3)) { - u->SendMessage(BotServ, BOT_BAD_HOST); + source.Reply(BOT_BAD_HOST); return MOD_CONT; } @@ -201,13 +201,13 @@ class CommandBSBot : public Command for (unsigned i = 0, end = user.length(); i < end && i < Config->UserLen; ++i) if (!isalnum(user[i])) { - u->SendMessage(BotServ, BOT_BAD_IDENT, Config->UserLen); + source.Reply(BOT_BAD_IDENT, Config->UserLen); return MOD_CONT; } if (!nick.equals_ci(bi->nick) && findbot(nick)) { - u->SendMessage(BotServ, BOT_BOT_ALREADY_EXISTS, nick.c_str()); + source.Reply(BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } @@ -219,7 +219,7 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - u->SendMessage(BotServ, NICK_ALREADY_REGISTERED, nick.c_str()); + source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } @@ -262,46 +262,46 @@ class CommandBSBot : public Command bi->RejoinAll(); } - u->SendMessage(BotServ, BOT_BOT_CHANGED, oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); - Log(LOG_ADMIN, u, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; + source.Reply(BOT_BOT_CHANGED, oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); + Log(LOG_ADMIN, source.u, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; FOREACH_MOD(I_OnBotChange, OnBotChange(bi)); return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[1]; + const Anope::string &nick = params[1]; BotInfo *bi; if (nick.empty()) { - this->OnSyntaxError(u, "DEL"); + this->OnSyntaxError(source.u, "DEL"); return MOD_CONT; } if (!(bi = findbot(nick))) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, nick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } if (nickIsServices(nick, false)) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, nick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); - ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", u->nick.c_str()); + ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", source.u->nick.c_str()); XLine x(bi->nick); ircdproto->SendSQLineDel(&x); - Log(LOG_ADMIN, u, this) << "DEL " << bi->nick; + Log(LOG_ADMIN, source.u, this) << "DEL " << bi->nick; + source.Reply(BOT_BOT_DELETED, nick.c_str()); delete bi; - u->SendMessage(BotServ, BOT_BOT_DELETED, nick.c_str()); return MOD_CONT; } public: @@ -310,13 +310,14 @@ class CommandBSBot : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + const Anope::string &cmd = params[0]; + User *u = source.u; if (readonly) { - u->SendMessage(BotServ, BOT_BOT_READONLY); + source.Reply(BOT_BOT_READONLY); return MOD_CONT; } @@ -325,7 +326,7 @@ class CommandBSBot : public Command // ADD nick user host real - 5 if (!u->Account()->HasCommand("botserv/bot/add")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -340,7 +341,7 @@ class CommandBSBot : public Command if (tempparams.size() >= 6) tempparams[4] = tempparams[4] + " " + tempparams[5]; - return this->DoAdd(u, tempparams); + return this->DoAdd(source, tempparams); } else if (cmd.equals_ci("CHANGE")) { @@ -348,7 +349,7 @@ class CommandBSBot : public Command // but only oldn and newn are required if (!u->Account()->HasCommand("botserv/bot/change")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -358,14 +359,14 @@ class CommandBSBot : public Command return MOD_CONT; } - return this->DoChange(u, params); + return this->DoChange(source, params); } else if (cmd.equals_ci("DEL")) { // DEL nick if (!u->Account()->HasCommand("botserv/bot/del")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -375,7 +376,7 @@ class CommandBSBot : public Command return MOD_CONT; } - return this->DoDel(u, params); + return this->DoDel(source, params); } else this->OnSyntaxError(u, ""); |