1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/* Declarations for command data.
*
* (C) 2003-2010 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for furhter details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
#ifndef COMMAND_H
#define COMMAND_H
#include "services.h"
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, const Anope::string &cmd);
extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message);
extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message);
enum CommandFlag
{
CFLAG_ALLOW_UNREGISTERED,
CFLAG_ALLOW_FORBIDDEN,
CFLAG_ALLOW_SUSPENDED,
CFLAG_ALLOW_UNREGISTEREDCHANNEL,
CFLAG_STRIP_CHANNEL,
CFLAG_DISABLE_FANTASY
};
/** Every services command is a class, inheriting from Command.
*/
class CoreExport Command : public Flags<CommandFlag>
{
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 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 = "");
virtual ~Command();
/** Execute this command.
* @param u The user executing the command.
*/
virtual CommandReturn Execute(User *u, const std::vector<Anope::string> &);
/** Called when HELP is requsted for the client this command is on.
* @param u The user requesting help
*/
virtual void OnServHelp(User *u);
/** Requested when the user is requesting help on this command. Help on this command should be sent to the user.
* @param u The user requesting help
* @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of "FOO BAR LOL")
* @return true if help was provided to the user, false otherwise.
*/
virtual bool OnHelp(User *u, const Anope::string &subcommand);
/** Requested when the user provides bad syntax to this command (not enough params, etc).
* @param u The user executing the command.
* @param subcommand The subcommand the user tried to use
*/
virtual void OnSyntaxError(User *u, const Anope::string &subcommand);
/** Set which command permission (e.g. chanserv/forbid) is required for this command.
* @param reststr The permission required to successfully execute this command
*/
void SetPermission(const Anope::string &reststr);
/** Add a subcommand to this command
* @param c The command
*/
virtual bool AddSubcommand(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 &name);
};
#endif // COMMANDS_H
|