Anope IRC Services  Version 2.0
bs_set.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 CommandBSSet : public Command
15 {
16  public:
17  CommandBSSet(Module *creator) : Command(creator, "botserv/set", 3, 3)
18  {
19  this->SetDesc(_("Configures bot options"));
20  this->SetSyntax(_("\037option\037 \037(channel | bot)\037 \037settings\037"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  this->OnSyntaxError(source, "");
26  }
27 
28  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
29  {
30  this->SendSyntax(source);
31  source.Reply(" ");
32  source.Reply(_("Configures bot options.\n"
33  " \n"
34  "Available options:"));
35  Anope::string this_name = source.command;
36  for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it)
37  {
38  const Anope::string &c_name = it->first;
39  const CommandInfo &info = it->second;
40  if (c_name.find_ci(this_name + " ") == 0)
41  {
42  ServiceReference<Command> command("Command", info.name);
43  if (command)
44  {
45  source.command = it->first;
46  command->OnServHelp(source);
47  }
48  }
49  }
50  source.Reply(_("Type \002%s%s HELP %s \037option\037\002 for more information on a\n"
51  "particular option."), Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), this_name.c_str());
52 
53  return true;
54  }
55 };
56 
58 {
59  public:
60  class UnbanTimer : public Timer
61  {
64 
65  public:
66  UnbanTimer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t) : Timer(creator, t), chname(ch), mask(bmask) { }
67 
68  void Tick(time_t) anope_override
69  {
70  Channel *c = Channel::Find(chname);
71  if (c)
72  c->RemoveMode(NULL, "BAN", mask);
73  }
74  };
75 
76  CommandBSSetBanExpire(Module *creator, const Anope::string &sname = "botserv/set/banexpire") : Command(creator, sname, 2, 2)
77  {
78  this->SetDesc(_("Configures the time bot bans expire in"));
79  this->SetSyntax(_("\037channel\037 \037time\037"));
80  }
81 
82  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
83  {
84  const Anope::string &chan = params[0];
85  const Anope::string &arg = params[1];
86 
88  if (ci == NULL)
89  {
90  source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
91  return;
92  }
93 
94  AccessGroup access = source.AccessFor(ci);
95  if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET"))
96  {
97  source.Reply(ACCESS_DENIED);
98  return;
99  }
100 
101  if (Anope::ReadOnly)
102  {
103  source.Reply(_("Sorry, bot option setting is temporarily disabled."));
104  return;
105  }
106 
107  time_t t = Anope::DoTime(arg);
108  if (t == -1)
109  {
110  source.Reply(BAD_EXPIRY_TIME);
111  return;
112  }
113 
114  /* cap at 1 day */
115  if (t > 86400)
116  {
117  source.Reply(_("Ban expiry may not be longer than 1 day."));
118  return;
119  }
120 
121  ci->banexpire = t;
122 
123  bool override = !access.HasPriv("SET");
124  Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to change banexpire to " << ci->banexpire;
125 
126  if (!ci->banexpire)
127  source.Reply(_("Bot bans will no longer automatically expire."));
128  else
129  source.Reply(_("Bot bans will automatically expire after %s."), Anope::Duration(ci->banexpire, source.GetAccount()).c_str());
130  }
131 
133  {
134  this->SendSyntax(source);
135  source.Reply(_(" \n"
136  "Sets the time bot bans expire in. If enabled, any bans placed by\n"
137  "bots, such as flood kicker, badwords kicker, etc. will automatically\n"
138  "be removed after the given time. Set to 0 to disable bans from\n"
139  "automatically expiring."));
140  return true;
141  }
142 };
143 
145 {
146  public:
147  CommandBSSetPrivate(Module *creator, const Anope::string &sname = "botserv/set/private") : Command(creator, sname, 2, 2)
148  {
149  this->SetDesc(_("Prevent a bot from being assigned by non IRC operators"));
150  this->SetSyntax(_("\037botname\037 {\037ON|OFF\037}"));
151  }
152 
153  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
154  {
155  BotInfo *bi = BotInfo::Find(params[0], true);
156  const Anope::string &value = params[1];
157 
158  if (Anope::ReadOnly)
159  {
160  source.Reply(READ_ONLY_MODE);
161  return;
162  }
163 
164  if (bi == NULL)
165  {
166  source.Reply(BOT_DOES_NOT_EXIST, params[0].c_str());
167  return;
168  }
169 
170  if (value.equals_ci("ON"))
171  {
172  bi->oper_only = true;
173  source.Reply(_("Private mode of bot %s is now \002on\002."), bi->nick.c_str());
174  }
175  else if (value.equals_ci("OFF"))
176  {
177  bi->oper_only = false;
178  source.Reply(_("Private mode of bot %s is now \002off\002."), bi->nick.c_str());
179  }
180  else
181  this->OnSyntaxError(source, source.command);
182  }
183 
185  {
186  this->SendSyntax(source);
187  source.Reply(_(" \n"
188  "This option prevents a bot from being assigned to a\n"
189  "channel by users that aren't IRC Operators."));
190  return true;
191  }
192 };
193 
194 class BSSet : public Module
195 {
199 
200  public:
201  BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
202  commandbsset(this), commandbssetbanexpire(this),
203  commandbssetprivate(this)
204  {
205  }
206 
208  {
209  if (!ci->banexpire)
210  return;
211 
212  new CommandBSSetBanExpire::UnbanTimer(this, ci->name, mask, ci->banexpire);
213  }
214 };
215 
Definition: bots.h:24
void Tick(time_t) anope_override
Definition: bs_set.cpp:68
CoreExport bool ReadOnly
Definition: main.cpp:28
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: bs_set.cpp:153
Anope::string name
Definition: commands.h:32
Definition: timers.h:18
time_t banexpire
Definition: regchannel.h:84
Definition: hashcomp.h:84
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: bs_set.cpp:28
void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) anope_override
Definition: bs_set.cpp:207
#define ACCESS_DENIED
Definition: language.h:73
bool OnHelp(CommandSource &source, const Anope::string &) anope_override
Definition: bs_set.cpp:184
CommandBSSetPrivate commandbssetprivate
Definition: bs_set.cpp:198
UnbanTimer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t)
Definition: bs_set.cpp:66
Definition: users.h:34
#define READ_ONLY_MODE
Definition: language.h:71
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool equals_ci(const char *_str) const
Definition: anope.h:78
CommandBSSetPrivate(Module *creator, const Anope::string &sname="botserv/set/private")
Definition: bs_set.cpp:147
bool HasPriv(const Anope::string &priv) const
Definition: access.cpp:384
bool OnHelp(CommandSource &source, const Anope::string &) anope_override
Definition: bs_set.cpp:132
size_type find_ci(const string &_str, size_type pos=0) const
Definition: anope.h:194
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
CommandBSSetBanExpire(Module *creator, const Anope::string &sname="botserv/set/banexpire")
Definition: bs_set.cpp:76
CommandBSSet commandbsset
Definition: bs_set.cpp:196
#define BOT_DOES_NOT_EXIST
Definition: language.h:120
Definition: Config.cs:26
virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
Definition: command.cpp:191
CoreExport time_t DoTime(const Anope::string &s)
Definition: misc.cpp:275
void Reply(const char *message,...)
Definition: command.cpp:96
CommandBSSetBanExpire commandbssetbanexpire
Definition: bs_set.cpp:197
#define anope_override
Definition: services.h:56
#define MODULE_INIT(x)
Definition: modules.h:45
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: bs_set.cpp:82
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
CommandBSSet(Module *creator)
Definition: bs_set.cpp:17
virtual void OnServHelp(CommandSource &source)
Definition: command.cpp:184
bool oper_only
Definition: bots.h:41
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
Anope::string nick
Definition: users.h:62
static Channel * Find(const Anope::string &name)
Definition: channels.cpp:920
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
CoreExport Anope::string Duration(time_t seconds, const NickCore *nc=NULL)
Definition: misc.cpp:315
#define BAD_EXPIRY_TIME
Definition: language.h:69
#define _(x)
Definition: services.h:50
static BotInfo * Find(const Anope::string &nick, bool nick_only=false)
Definition: bots.cpp:249
BSSet(const Anope::string &modname, const Anope::string &creator)
Definition: bs_set.cpp:201
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: bs_set.cpp:23
void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param="", bool enforce_mlock=true)
Definition: channels.cpp:459