Anope IRC Services  Version 2.0
bs_control.cpp
Go to the documentation of this file.
1 /* BotServ core functions
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 #include "module.h"
13 
14 class CommandBSSay : public Command
15 {
16  public:
17  CommandBSSay(Module *creator) : Command(creator, "botserv/say", 2, 2)
18  {
19  this->SetDesc(_("Makes the bot say the given text on the given channel"));
20  this->SetSyntax(_("\037channel\037 \037text\037"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  const Anope::string &text = params[1];
26 
27  ChannelInfo *ci = ChannelInfo::Find(params[0]);
28  if (ci == NULL)
29  {
30  source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
31  return;
32  }
33 
34  if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration"))
35  {
36  source.Reply(ACCESS_DENIED);
37  return;
38  }
39 
40  if (!ci->bi)
41  {
42  source.Reply(BOT_NOT_ASSIGNED);
43  return;
44  }
45 
46  if (!ci->c || !ci->c->FindUser(ci->bi))
47  {
48  source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str());
49  return;
50  }
51 
52  if (text[0] == '\001')
53  {
54  this->OnSyntaxError(source, "");
55  return;
56  }
57 
58  IRCD->SendPrivmsg(*ci->bi, ci->name, "%s", text.c_str());
59  ci->bi->lastmsg = Anope::CurTime;
60 
61  bool override = !source.AccessFor(ci).HasPriv("SAY");
62  Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << text;
63  }
64 
65  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
66  {
67  this->SendSyntax(source);
68  source.Reply(" ");
69  source.Reply(_("Makes the bot say the given text on the given channel."));
70  return true;
71  }
72 };
73 
74 class CommandBSAct : public Command
75 {
76  public:
77  CommandBSAct(Module *creator) : Command(creator, "botserv/act", 2, 2)
78  {
79  this->SetDesc(_("Makes the bot do the equivalent of a \"/me\" command"));
80  this->SetSyntax(_("\037channel\037 \037text\037"));
81  }
82 
83  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
84  {
85  Anope::string message = params[1];
86 
87  ChannelInfo *ci = ChannelInfo::Find(params[0]);
88  if (ci == NULL)
89  {
90  source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
91  return;
92  }
93 
94  if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration"))
95  {
96  source.Reply(ACCESS_DENIED);
97  return;
98  }
99 
100  if (!ci->bi)
101  {
102  source.Reply(BOT_NOT_ASSIGNED);
103  return;
104  }
105 
106  if (!ci->c || !ci->c->FindUser(ci->bi))
107  {
108  source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str());
109  return;
110  }
111 
112  message = message.replace_all_cs("\1", "");
113  if (message.empty())
114  return;
115 
116  IRCD->SendAction(*ci->bi, ci->name, "%s", message.c_str());
117  ci->bi->lastmsg = Anope::CurTime;
118 
119  bool override = !source.AccessFor(ci).HasPriv("SAY");
120  Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << message;
121  }
122 
123  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
124  {
125  this->SendSyntax(source);
126  source.Reply(" ");
127  source.Reply(_("Makes the bot do the equivalent of a \"/me\" command\n"
128  "on the given channel using the given text."));
129  return true;
130  }
131 };
132 
133 class BSControl : public Module
134 {
137 
138  public:
139  BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
140  commandbssay(this), commandbsact(this)
141  {
142 
143  }
144 };
145 
virtual void SendAction(const MessageSource &source, const Anope::string &dest, const char *fmt,...)
Definition: protocol.cpp:231
CommandBSSay commandbssay
Definition: bs_control.cpp:135
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: bs_control.cpp:65
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: bs_control.cpp:83
Definition: hashcomp.h:84
Anope::string name
Definition: regchannel.h:63
virtual void SendPrivmsg(const MessageSource &source, const Anope::string &dest, const char *fmt,...)
Definition: protocol.cpp:242
#define ACCESS_DENIED
Definition: language.h:73
CommandBSAct(Module *creator)
Definition: bs_control.cpp:77
CommandBSAct commandbsact
Definition: bs_control.cpp:136
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
CoreExport time_t CurTime
Definition: main.cpp:41
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
#define BOT_NOT_ASSIGNED
Definition: language.h:121
Channel * c
Definition: regchannel.h:79
virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
Definition: command.cpp:191
string replace_all_cs(const string &_orig, const string &_repl) const
Definition: anope.h:229
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
ChanUserContainer * FindUser(User *u) const
Definition: channels.cpp:173
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
BSControl(const Anope::string &modname, const Anope::string &creator)
Definition: bs_control.cpp:139
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
Serialize::Reference< BotInfo > bi
Definition: regchannel.h:82
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: bs_control.cpp:23
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: bs_control.cpp:123
#define _(x)
Definition: services.h:50
#define BOT_NOT_ON_CHANNEL
Definition: language.h:122
CommandBSSay(Module *creator)
Definition: bs_control.cpp:17