diff options
Diffstat (limited to 'include/commands.h')
-rw-r--r-- | include/commands.h | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/include/commands.h b/include/commands.h index dee85c56f..8cdb0d544 100644 --- a/include/commands.h +++ b/include/commands.h @@ -1,27 +1,36 @@ -/* Declarations for command data. +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2003-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ -#ifndef COMMAND_H -#define COMMAND_H +#pragma once #include "service.h" #include "anope.h" #include "channels.h" +#include "language.h" +#include "modules/nickserv.h"// XXX clang struct CommandGroup { Anope::string name, description; }; -/* Used in BotInfo::commands */ +/* Used in ServiceBot::commands */ struct CommandInfo { typedef Anope::map<CommandInfo> map; @@ -30,6 +39,8 @@ struct CommandInfo /* Service name of the command */ Anope::string name; + /* User visible name */ + Anope::string cname; /* Permission required to execute the command */ Anope::string permission; /* Group this command is in */ @@ -46,7 +57,7 @@ struct CommandInfo struct CoreExport CommandReply { virtual ~CommandReply() { } - virtual void SendMessage(BotInfo *source, const Anope::string &msg) = 0; + virtual void SendMessage(const MessageSource &, const Anope::string &msg) anope_abstract; }; /* The source for a command */ @@ -58,27 +69,33 @@ class CoreExport CommandSource Reference<User> u; public: /* The account executing the command */ - Reference<NickCore> nc; + Reference<NickServ::Account> nc; /* Where the reply should go */ CommandReply *reply; /* Channel the command was executed on (fantasy) */ Reference<Channel> c; /* The service this command is on */ - Reference<BotInfo> service; + Reference<ServiceBot> service; /* The actual name of the command being executed */ Anope::string command; /* The permission of the command being executed */ Anope::string permission; - CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply, BotInfo *bi); + CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *reply, ServiceBot *bi); const Anope::string &GetNick() const; User *GetUser(); - NickCore *GetAccount(); - AccessGroup AccessFor(ChannelInfo *ci); - bool IsFounder(ChannelInfo *ci); + NickServ::Account *GetAccount(); + ChanServ::AccessGroup AccessFor(ChanServ::Channel *ci); + bool IsFounder(ChanServ::Channel *ci); + + template<typename... Args> + void Reply(const char *message, Args&&... args) + { + const char *translated_message = Language::Translate(this->nc, message); + Reply(Anope::Format(translated_message, std::forward<Args>(args)...)); + } - void Reply(const char *message, ...); void Reply(const Anope::string &message); bool HasCommand(const Anope::string &cmd); @@ -107,6 +124,8 @@ class CoreExport Command : public Service /* Module which owns us */ Module *module; + static constexpr const char *NAME = "Command"; + protected: /** Create a new command. * @param owner The owner of the command @@ -125,12 +144,12 @@ class CoreExport Command : public Service void ClearSyntax(); void SetSyntax(const Anope::string &s); - void SendSyntax(CommandSource &); void AllowUnregistered(bool b); void RequireUser(bool b); public: + void SendSyntax(CommandSource &); bool AllowUnregistered() const; bool RequireUser() const; @@ -144,7 +163,7 @@ class CoreExport Command : public Service * @param source The source * @param params Command parameters */ - virtual void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) = 0; + virtual void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_abstract; /** Called when HELP is requsted for the client this command is on. * @param source The source @@ -179,7 +198,6 @@ class CoreExport Command : public Service * @param name If found, is set to the comand name, eg REGISTER * @return true if the given command service exists */ - static bool FindCommandFromService(const Anope::string &command_service, BotInfo* &bi, Anope::string &name); + static bool FindCommandFromService(const Anope::string &command_service, ServiceBot* &bi, Anope::string &name); }; -#endif // COMMANDS_H |