Anope IRC Services  Version 2.0
commands.h
Go to the documentation of this file.
1 /* Declarations for command data.
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  */
11 
12 #ifndef COMMAND_H
13 #define COMMAND_H
14 
15 #include "service.h"
16 #include "anope.h"
17 #include "channels.h"
18 
20 {
22 };
23 
24 /* Used in BotInfo::commands */
26 {
28 
29  CommandInfo() : hide(false), prepend_channel(false) { }
30 
31  /* Service name of the command */
33  /* Permission required to execute the command */
35  /* Group this command is in */
37  /* whether or not to hide this command in help output */
38  bool hide;
39  /* Only used with fantasy */
41 };
42 
43 /* Where the replies from commands go to. User inheits from this and is the normal
44  * source of a CommandReply
45  */
47 {
48  virtual ~CommandReply() { }
49  virtual void SendMessage(BotInfo *source, const Anope::string &msg) = 0;
50 };
51 
52 /* The source for a command */
54 {
55  /* The nick executing the command */
57  /* User executing the command, may be NULL */
59  public:
60  /* The account executing the command */
62  /* Where the reply should go */
64  /* Channel the command was executed on (fantasy) */
66  /* The service this command is on */
68  /* The actual name of the command being executed */
70  /* The permission of the command being executed */
72 
73  CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply, BotInfo *bi);
74 
75  const Anope::string &GetNick() const;
76  User *GetUser();
77  NickCore *GetAccount();
78  AccessGroup AccessFor(ChannelInfo *ci);
79  bool IsFounder(ChannelInfo *ci);
80 
81  void Reply(const char *message, ...);
82  void Reply(const Anope::string &message);
83 
84  bool HasCommand(const Anope::string &cmd);
85  bool HasPriv(const Anope::string &cmd);
86  bool IsServicesOper();
87  bool IsOper();
88 };
89 
92 class CoreExport Command : public Service
93 {
95  std::vector<Anope::string> syntax;
96  /* Allow unregistered users to use this command */
98  /* Command requires that a user is executing it */
100 
101  public:
102  /* Maximum paramaters accepted by this command */
103  size_t max_params;
104  /* Minimum parameters required to use this command */
105  size_t min_params;
106 
107  /* Module which owns us */
109 
110  protected:
118  Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params = 0);
119 
120  public:
121  virtual ~Command();
122 
123  protected:
124  void SetDesc(const Anope::string &d);
125 
126  void ClearSyntax();
127  void SetSyntax(const Anope::string &s);
128  void SendSyntax(CommandSource &);
129 
130  void AllowUnregistered(bool b);
131  void RequireUser(bool b);
132 
133  public:
134  bool AllowUnregistered() const;
135  bool RequireUser() const;
136 
141  virtual const Anope::string GetDesc(CommandSource &source) const;
142 
147  virtual void Execute(CommandSource &source, const std::vector<Anope::string> &params) = 0;
148 
152  virtual void OnServHelp(CommandSource &source);
153 
159  virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand);
160 
165  virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand);
166 
171  static void Run(CommandSource &source, const Anope::string &message);
172 
180  static bool FindCommandFromService(const Anope::string &command_service, BotInfo* &bi, Anope::string &name);
181 };
182 
183 #endif // COMMANDS_H
Definition: bots.h:24
Anope::string permission
Definition: commands.h:34
Anope::string name
Definition: commands.h:32
bool allow_unregistered
Definition: commands.h:97
Definition: hashcomp.h:84
Module * module
Definition: commands.h:108
Anope::string group
Definition: commands.h:36
Reference< Channel > c
Definition: commands.h:65
Anope::string permission
Definition: commands.h:71
size_t max_params
Definition: commands.h:103
Definition: users.h:34
CoreExport bool IsFounder(const User *user, const ChannelInfo *ci)
Definition: regchannel.cpp:642
Anope::string name
Definition: commands.h:21
virtual ~CommandReply()
Definition: commands.h:48
size_t min_params
Definition: commands.h:105
CommandInfo()
Definition: commands.h:29
Anope::string description
Definition: commands.h:21
Anope::string command
Definition: commands.h:69
Anope::map< CommandInfo > map
Definition: commands.h:27
Reference< User > u
Definition: commands.h:58
Reference< BotInfo > service
Definition: commands.h:67
bool require_user
Definition: commands.h:99
#define CoreExport
Definition: services.h:62
std::vector< Anope::string > syntax
Definition: commands.h:95
Anope::string nick
Definition: commands.h:56
Anope::string desc
Definition: commands.h:94
bool hide
Definition: commands.h:38
static bool HasPriv(const AccessGroup &ag, const ChanAccess *access, const Anope::string &name)
Definition: access.cpp:358
Anope::string name
Definition: access.cpp:22
Reference< NickCore > nc
Definition: commands.h:61
bool prepend_channel
Definition: commands.h:40
CommandReply * reply
Definition: commands.h:63