summaryrefslogtreecommitdiff
path: root/include/commands.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-07-14 02:31:12 -0400
committerAdam <Adam@anope.org>2011-07-14 02:31:12 -0400
commitf858164deed48f2dcacd5ffc06a55398a54da7e8 (patch)
tree89c3cf36bd8e94942370135218d67d6d17ee222e /include/commands.h
parent924f6849fee4598a1a3a7f1a98d96b79e5ffd3b4 (diff)
Rewrote how commands are handled within Anope.
This allows naming commands and having spaces within command names.
Diffstat (limited to 'include/commands.h')
-rw-r--r--include/commands.h64
1 files changed, 14 insertions, 50 deletions
diff --git a/include/commands.h b/include/commands.h
index 89fd1436c..0ee9af226 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -18,36 +18,15 @@ class Module;
class BotInfo;
class Command;
-typedef std::map<Anope::string, Command *, std::less<ci::string> > CommandMap;
-
-/** The return value from commands.
- */
-enum CommandReturn
-{
- MOD_CONT,
- MOD_STOP
-};
-
-extern CoreExport Command *FindCommand(BotInfo *bi, const Anope::string &cmd);
-extern CoreExport void mod_help_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &cmd);
-extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &message);
-extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, Command *c, const Anope::string &command, const Anope::string &message);
-
enum CommandFlag
{
CFLAG_ALLOW_UNREGISTERED,
- CFLAG_ALLOW_SUSPENDED,
- CFLAG_ALLOW_UNREGISTEREDCHANNEL,
- CFLAG_STRIP_CHANNEL,
- CFLAG_DISABLE_FANTASY
+ CFLAG_STRIP_CHANNEL
};
const Anope::string CommandFlagStrings[] = {
"CFLAG_ALLOW_UNREGISTERED",
- "CFLAG_ALLOW_SUSPENDED",
- "CFLAG_ALLOW_UNREGISTEREDCHANNEL",
"CFLAG_STRIP_CHANNEL",
- "CFLAG_DISABLE_FANTASY",
""
};
@@ -56,14 +35,14 @@ struct CoreExport CommandSource
{
/* User executing the command */
User *u;
- /* Channel (if applicable) */
- ChannelInfo *ci;
+ /* Channel the command was executed on (fantasy) */
+ Channel *c;
/* The service this command is on */
BotInfo *owner;
/* The service the reply should come from, *not* necessarily the service the command is on */
BotInfo *service;
- /* Whether or not this was a fantasy command */
- bool fantasy;
+ /* The actual name of the command being executed */
+ Anope::string command;
std::list<Anope::string> reply;
@@ -75,38 +54,40 @@ struct CoreExport CommandSource
/** Every services command is a class, inheriting from Command.
*/
-class CoreExport Command : public Flags<CommandFlag>, public Base
+class CoreExport Command : public Service, public Flags<CommandFlag>
{
Anope::string desc;
+ std::vector<Anope::string> syntax;
public:
/* Maximum paramaters accepted by this command */
size_t MaxParams;
/* Minimum parameters required to use this command */
size_t MinParams;
- /* Command name */
- Anope::string name;
/* Permission needed to use this comand */
Anope::string permission;
/* Module which owns us */
Module *module;
- /* Service this command is on */
- BotInfo *service;
/** Create a new command.
+ * @param owner The owner of the command
* @param sname The command name
* @param min_params The minimum number of parameters the parser will require to execute this command
* @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument.
* NOTE: If max_params is not set (default), there is no limit to the max number of params.
*/
- Command(const Anope::string &sname, size_t min_params, size_t max_params = 0, const Anope::string &spermission = "");
+ Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params = 0, const Anope::string &spermission = "");
virtual ~Command();
protected:
void SetDesc(const Anope::string &d);
+ void ClearSyntax();
+ void SetSyntax(const Anope::string &s);
+ void SendSyntax(CommandSource &);
+ void SendSyntax(CommandSource &, const Anope::string &syntax);
public:
/** Get the command description
* @return The commands description
@@ -117,7 +98,7 @@ class CoreExport Command : public Flags<CommandFlag>, public Base
* @param source The source
* @param params Command parameters
*/
- virtual CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> &params) = 0;
+ virtual void Execute(CommandSource &source, const std::vector<Anope::string> &params) = 0;
/** Called when HELP is requsted for the client this command is on.
* @param source The source
@@ -141,23 +122,6 @@ class CoreExport Command : public Flags<CommandFlag>, public Base
* @param reststr The permission required to successfully execute this command
*/
void SetPermission(const Anope::string &reststr);
-
- /** Add a subcommand to this command
- * @param creator The creator of the subcommand
- * @param c The command
- */
- virtual bool AddSubcommand(Module *creator, Command *c);
-
- /** Delete a subcommand from this command
- * @param c The command
- */
- virtual bool DelSubcommand(Command *c);
-
- /** Find a subcommand
- * @param name The subcommand name
- * @return The subcommand
- */
- virtual Command *FindSubcommand(const Anope::string &subcommand);
};
#endif // COMMANDS_H