diff options
author | Adam <Adam@anope.org> | 2011-07-14 02:31:12 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-07-14 02:31:12 -0400 |
commit | f858164deed48f2dcacd5ffc06a55398a54da7e8 (patch) | |
tree | 89c3cf36bd8e94942370135218d67d6d17ee222e /modules/core/ns_resetpass.cpp | |
parent | 924f6849fee4598a1a3a7f1a98d96b79e5ffd3b4 (diff) |
Rewrote how commands are handled within Anope.
This allows naming commands and having spaces within command names.
Diffstat (limited to 'modules/core/ns_resetpass.cpp')
-rw-r--r-- | modules/core/ns_resetpass.cpp | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/modules/core/ns_resetpass.cpp b/modules/core/ns_resetpass.cpp index 55b4ae18b..b0d40226f 100644 --- a/modules/core/ns_resetpass.cpp +++ b/modules/core/ns_resetpass.cpp @@ -12,52 +12,48 @@ /*************************************************************************/ #include "module.h" -#include "nickserv.h" -static bool SendResetEmail(User *u, NickAlias *na); +static bool SendResetEmail(User *u, NickAlias *na, BotInfo *bi); class CommandNSResetPass : public Command { public: - CommandNSResetPass() : Command("RESETPASS", 1, 1) + CommandNSResetPass(Module *creator) : Command(creator, "nickserv/resetpass", 1, 1) { this->SetFlag(CFLAG_ALLOW_UNREGISTERED); this->SetDesc(_("Helps you reset lost passwords")); + this->SetSyntax(_("\037nickname\037")); } - CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { User *u = source.u; NickAlias *na; - if (Config->RestrictMail && (!u->Account() || !u->HasCommand("nickserv/resetpass"))) - source.Reply(_(ACCESS_DENIED)); + if (Config->RestrictMail && (!u->Account() || !u->HasCommand("nickserv/nickserv/resetpass"))) + source.Reply(ACCESS_DENIED); else if (!(na = findnick(params[0]))) - source.Reply(_(NICK_X_NOT_REGISTERED), params[0].c_str()); + source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str()); else { - if (SendResetEmail(u, na)) + if (SendResetEmail(u, na, source.owner)) { Log(LOG_COMMAND, u, this) << "for " << na->nick << " (group: " << na->nc->display << ")"; source.Reply(_("Password reset email for \002%s\002 has been sent."), na->nick.c_str()); } } - return MOD_CONT; + return; } bool OnHelp(CommandSource &source, const Anope::string &subcommand) { - source.Reply(_("Syntax: \002RESETPASS \037nickname\037\002\n" - "Sends a code key to the nickname with instructions on how to\n" + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Sends a code key to the nickname with instructions on how to\n" "reset their password.")); return true; } - - void OnSyntaxError(CommandSource &source, const Anope::string &subcommand) - { - SyntaxError(source, "RESETPASS", _("RESETPASS \037nickname\037\002")); - } }; class NSResetPass : public Module @@ -65,26 +61,24 @@ class NSResetPass : public Module CommandNSResetPass commandnsresetpass; public: - NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE) + NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandnsresetpass(this) { this->SetAuthor("Anope"); - if (!nickserv) - throw ModuleException("NickServ is not loaded!"); - if (!Config->UseMail) throw ModuleException("Not using mail."); - this->AddCommand(nickserv->Bot(), &commandnsresetpass); + ModuleManager::RegisterService(&commandnsresetpass); ModuleManager::Attach(I_OnPreCommand, this); } - EventReturn OnPreCommand(CommandSource &source, Command *command, const std::vector<Anope::string> ¶ms) + EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) { - User *u = source.u; - if (command->service->nick == Config->s_NickServ && command->name.equals_ci("CONFIRM") && params.size() > 1) + if (command->name == "nickserv/confirm" && params.size() > 1) { + User *u = source.u; NickAlias *na = findnick(params[0]); time_t t; @@ -108,7 +102,7 @@ class NSResetPass : public Module na->nc->UnsetFlag(NI_UNCONFIRMED); u->Identify(na); - source.Reply(_("You are now identified for your nick. Change your password using \"%s%s SET PASSWORD \002newpassword\002\" now."), Config->UseStrictPrivMsgString.c_str(), Config->s_NickServ.c_str()); + source.Reply(_("You are now identified for your nick. Change your passwor now.")); } else @@ -122,7 +116,7 @@ class NSResetPass : public Module } }; -static bool SendResetEmail(User *u, NickAlias *na) +static bool SendResetEmail(User *u, NickAlias *na, BotInfo *bi) { int min = 1, max = 62; int chars[] = { @@ -147,12 +141,12 @@ static bool SendResetEmail(User *u, NickAlias *na) " \n" "If you don't know why this mail was sent to you, please ignore it silently.\n" " \n" - "%s administrators.")), na->nick.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->s_NickServ.c_str(), na->nick.c_str(), passcode.c_str(), Config->NetworkName.c_str()); + "%s administrators.")), na->nick.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str(), na->nick.c_str(), passcode.c_str(), Config->NetworkName.c_str()); na->nc->Extend("ns_resetpass_code", new ExtensibleItemRegular<Anope::string>(passcode)); na->nc->Extend("ns_resetpass_time", new ExtensibleItemRegular<time_t>(Anope::CurTime)); - return Mail(u, na->nc, nickserv->Bot(), subject, message); + return Mail(u, na->nc, bi, subject, message); } MODULE_INIT(NSResetPass) |