1
0
mirror of https://github.com/anope/anope.git synced 2026-06-26 12:16:38 +02:00

Rewrote how commands are handled within Anope.

This allows naming commands and having spaces within command names.
This commit is contained in:
Adam
2011-07-14 02:31:12 -04:00
parent 924f6849fe
commit f858164dee
227 changed files with 8808 additions and 12352 deletions
+22 -28
View File
@@ -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> &params)
void Execute(CommandSource &source, const std::vector<Anope::string> &params)
{
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> &params)
EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params)
{
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)