diff options
author | Adam <Adam@anope.org> | 2017-01-27 08:40:26 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2017-01-27 08:40:26 -0500 |
commit | 9ad06f49bbb3824139b0c0ee0a74898a18c8f735 (patch) | |
tree | 618a4f0e173166e6f966a7cce78f06c3c1c3299f /src | |
parent | 16ca76c2e7ab287e480185fbb03a0bb438351eda (diff) |
Store CommandInfo in CommandSource instead of just command/permission
Diffstat (limited to 'src')
-rw-r--r-- | src/bots.cpp | 5 | ||||
-rw-r--r-- | src/command.cpp | 33 | ||||
-rw-r--r-- | src/config.cpp | 2 |
3 files changed, 29 insertions, 11 deletions
diff --git a/src/bots.cpp b/src/bots.cpp index 86d0a0136..7aaefccc1 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -198,12 +198,11 @@ void ServiceBot::OnMessage(User *u, const Anope::string &message) CommandInfo& ServiceBot::SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission) { - CommandInfo ci; + CommandInfo &ci = this->commands[cname]; ci.name = sname; ci.cname = cname; ci.permission = permission; - this->commands[cname] = ci; - return this->commands[cname]; + return ci; } CommandInfo *ServiceBot::GetCommand(const Anope::string &cname) diff --git a/src/command.cpp b/src/command.cpp index 9095c0526..e7fc61457 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -70,9 +70,29 @@ Anope::string CommandSource::GetSource() const Anope::string &CommandSource::GetCommand() const { + return this->command.cname; +} + +void CommandSource::SetCommand(const Anope::string &command) +{ + this->command.cname = command; +} + +const Anope::string &CommandSource::GetPermission() const +{ + return this->command.permission; +} + +const CommandInfo &CommandSource::GetCommandInfo() const +{ return this->command; } +void CommandSource::SetCommandInfo(const CommandInfo &ci) +{ + this->command = ci; +} + ChanServ::AccessGroup CommandSource::AccessFor(ChanServ::Channel *ci) { if (this->u) @@ -174,13 +194,13 @@ void Command::SendSyntax(CommandSource &source) Anope::string s = Language::Translate(source.GetAccount(), _("Syntax")); if (!this->syntax.empty()) { - source.Reply("{0}: \002{1} {2}\002", s, source.command, Language::Translate(source.GetAccount(), this->syntax[0].c_str())); + source.Reply("{0}: \002{1} {2}\002", s, source.GetCommand(), Language::Translate(source.GetAccount(), this->syntax[0].c_str())); Anope::string spaces(s.length(), ' '); for (unsigned i = 1, j = this->syntax.size(); i < j; ++i) - source.Reply("{0} \002{1} {2}\002", spaces, source.command, Language::Translate(source.GetAccount(), this->syntax[i].c_str())); + source.Reply("{0} \002{1} {2}\002", spaces, source.GetCommand(), Language::Translate(source.GetAccount(), this->syntax[i].c_str())); } else - source.Reply("{0}: \002{1}\002", s, source.command); + source.Reply("{0}: \002{1}\002", s, source.GetCommand()); } bool Command::AllowUnregistered() const @@ -210,7 +230,7 @@ const Anope::string Command::GetDesc(CommandSource &) const void Command::OnServHelp(CommandSource &source) { - source.Reply(Anope::printf(" %-14s %s", source.command.c_str(), Language::Translate(source.nc, this->GetDesc(source).c_str()))); + source.Reply(Anope::printf(" %-14s %s", source.GetCommand().c_str(), Language::Translate(source.nc, this->GetDesc(source).c_str()))); } bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; } @@ -220,7 +240,7 @@ void Command::OnSyntaxError(CommandSource &source, const Anope::string &subcomma this->SendSyntax(source); bool has_help = source.service->commands.find("HELP") != source.service->commands.end(); if (has_help) - source.Reply(_("\002{0}{1} HELP {2}\002 for more information."), Config->StrictPrivmsg, source.service->nick, source.command); + source.Reply(_("\002{0}{1} HELP {2}\002 for more information."), Config->StrictPrivmsg, source.service->nick, source.GetCommand()); } void Command::Run(CommandSource &source, const Anope::string &message) @@ -289,8 +309,7 @@ void Command::Run(CommandSource &source, const Anope::string &cmdname, const Com return; } - source.command = cmdname; - source.permission = info.permission; + source.SetCommandInfo(info); EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreCommand::OnPreCommand, source, this, params); if (MOD_RESULT == EVENT_STOP) diff --git a/src/config.cpp b/src/config.cpp index fbac466d9..d47b249f0 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -814,7 +814,7 @@ Block *Conf::GetCommand(CommandSource &source) { Block *b = &iters.first->second; - if (b->Get<Anope::string>("name") == source.command) + if (b->Get<Anope::string>("name") == source.GetCommand()) return b; } |