summaryrefslogtreecommitdiff
path: root/include/commands.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/commands.h')
-rw-r--r--include/commands.h100
1 files changed, 63 insertions, 37 deletions
diff --git a/include/commands.h b/include/commands.h
index dee85c56f..1dddfa4fd 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -1,43 +1,52 @@
-/* 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;
- CommandInfo() : hide(false), prepend_channel(false) { }
-
/* 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 */
Anope::string group;
/* whether or not to hide this command in help output */
- bool hide;
+ bool hide = false;
/* Only used with fantasy */
- bool prepend_channel;
+ bool prepend_channel = false;
};
/* Where the replies from commands go to. User inheits from this and is the normal
@@ -46,7 +55,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 */
@@ -56,35 +65,55 @@ class CoreExport CommandSource
Anope::string nick;
/* User executing the command, may be NULL */
Reference<User> u;
+ /* Command info being executed */
+ CommandInfo command;
+ /* whether or not this is an override as determined by the command */
+ bool override = false;
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;
- /* The actual name of the command being executed */
- Anope::string command;
- /* The permission of the command being executed */
- Anope::string permission;
+ Reference<ServiceBot> service;
- 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();
+ Anope::string GetSource();
+
+ const Anope::string &GetCommand() const;
+ void SetCommand(const Anope::string &);
+
+ const Anope::string &GetPermission() const;
+
+ const CommandInfo &GetCommandInfo() const;
+ void SetCommandInfo(const CommandInfo &);
+
+ 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);
bool HasPriv(const Anope::string &cmd);
bool IsServicesOper();
bool IsOper();
+
+ bool HasOverridePriv(const Anope::string &priv);
+ bool HasOverrideCommand(const Anope::string &priv);
+ bool IsOverride() const;
};
/** Every services command is a class, inheriting from Command.
@@ -94,11 +123,13 @@ class CoreExport Command : public Service
Anope::string desc;
std::vector<Anope::string> syntax;
/* Allow unregistered users to use this command */
- bool allow_unregistered;
+ bool allow_unregistered = false;
/* Command requires that a user is executing it */
- bool require_user;
+ bool require_user = false;
public:
+ static constexpr const char *NAME = "Command";
+
/* Maximum paramaters accepted by this command */
size_t max_params;
/* Minimum parameters required to use this command */
@@ -107,7 +138,8 @@ class CoreExport Command : public Service
/* Module which owns us */
Module *module;
- protected:
+ Logger logger;
+
/** Create a new command.
* @param owner The owner of the command
* @param sname The command name
@@ -117,20 +149,15 @@ class CoreExport Command : public Service
*/
Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params = 0);
- public:
- virtual ~Command();
-
- protected:
void SetDesc(const Anope::string &d);
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 +171,7 @@ class CoreExport Command : public Service
* @param source The source
* @param params Command parameters
*/
- virtual void Execute(CommandSource &source, const std::vector<Anope::string> &params) = 0;
+ virtual void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_abstract;
/** Called when HELP is requsted for the client this command is on.
* @param source The source
@@ -179,7 +206,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