Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef COMMAND_H
00013 #define COMMAND_H
00014
00015 #include "service.h"
00016 #include "anope.h"
00017 #include "channels.h"
00018
00019 struct CommandGroup
00020 {
00021 Anope::string name, description;
00022 };
00023
00024
00025 struct CommandInfo
00026 {
00027 typedef Anope::map<CommandInfo> map;
00028
00029 CommandInfo() : hide(false), prepend_channel(false) { }
00030
00031
00032 Anope::string name;
00033
00034 Anope::string permission;
00035
00036 Anope::string group;
00037
00038 bool hide;
00039
00040 bool prepend_channel;
00041 };
00042
00043
00044
00045
00046 struct CoreExport CommandReply
00047 {
00048 virtual ~CommandReply() { }
00049 virtual void SendMessage(const BotInfo *source, const Anope::string &msg) = 0;
00050 };
00051
00052
00053 class CoreExport CommandSource
00054 {
00055
00056 Anope::string nick;
00057
00058 Reference<User> u;
00059 public:
00060
00061 Reference<NickCore> nc;
00062
00063 CommandReply *reply;
00064
00065 Reference<Channel> c;
00066
00067 Reference<BotInfo> service;
00068
00069 Anope::string command;
00070
00071 Anope::string permission;
00072
00073 CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply, BotInfo *bi);
00074
00075 const Anope::string &GetNick() const;
00076 User *GetUser();
00077 NickCore *GetAccount();
00078 AccessGroup AccessFor(ChannelInfo *ci);
00079 bool IsFounder(ChannelInfo *ci);
00080
00081 void Reply(const char *message, ...);
00082 void Reply(const Anope::string &message);
00083
00084 bool HasCommand(const Anope::string &cmd);
00085 bool HasPriv(const Anope::string &cmd);
00086 bool IsServicesOper();
00087 bool IsOper();
00088 };
00089
00092 class CoreExport Command : public Service
00093 {
00094 Anope::string desc;
00095 std::vector<Anope::string> syntax;
00096
00097 bool allow_unregistered;
00098
00099 bool require_user;
00100
00101 public:
00102
00103 size_t max_params;
00104
00105 size_t min_params;
00106
00107
00108 Module *module;
00109
00110 protected:
00118 Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params = 0);
00119
00120 public:
00121 virtual ~Command();
00122
00123 protected:
00124 void SetDesc(const Anope::string &d);
00125
00126 void ClearSyntax();
00127 void SetSyntax(const Anope::string &s);
00128 void SendSyntax(CommandSource &);
00129 void SendSyntax(CommandSource &, const Anope::string &syntax);
00130
00131 void AllowUnregistered(bool b);
00132 void RequireUser(bool b);
00133
00134 public:
00135 bool AllowUnregistered() const;
00136 bool RequireUser() const;
00137
00141 const Anope::string &GetDesc() const;
00142
00147 virtual void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) = 0;
00148
00152 virtual void OnServHelp(CommandSource &source);
00153
00159 virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand);
00160
00165 virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand);
00166 };
00167
00168 extern CoreExport void RunCommand(CommandSource &source, const Anope::string &message);
00169
00170 #endif // COMMANDS_H