anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
bs_set.cpp (6253B)
1 /* BotServ core functions 2 * 3 * (C) 2003-2022 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> ¶ms) 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 bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"), 36 hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands"); 37 Anope::string this_name = source.command; 38 for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) 39 { 40 const Anope::string &c_name = it->first; 41 const CommandInfo &info = it->second; 42 if (c_name.find_ci(this_name + " ") == 0) 43 { 44 if (info.hide) 45 continue; 46 47 ServiceReference<Command> command("Command", info.name); 48 if (command) 49 { 50 // XXX dup 51 if (hide_registered_commands && !command->AllowUnregistered() && !source.GetAccount()) 52 continue; 53 54 if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission)) 55 continue; 56 57 source.command = it->first; 58 command->OnServHelp(source); 59 } 60 } 61 } 62 source.Reply(_("Type \002%s%s HELP %s \037option\037\002 for more information on a\n" 63 "particular option."), Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), this_name.c_str()); 64 65 return true; 66 } 67 }; 68 69 class CommandBSSetBanExpire : public Command 70 { 71 public: 72 class UnbanTimer : public Timer 73 { 74 Anope::string chname; 75 Anope::string mask; 76 77 public: 78 UnbanTimer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t) : Timer(creator, t), chname(ch), mask(bmask) { } 79 80 void Tick(time_t) anope_override 81 { 82 Channel *c = Channel::Find(chname); 83 if (c) 84 c->RemoveMode(NULL, "BAN", mask); 85 } 86 }; 87 88 CommandBSSetBanExpire(Module *creator, const Anope::string &sname = "botserv/set/banexpire") : Command(creator, sname, 2, 2) 89 { 90 this->SetDesc(_("Configures the time bot bans expire in")); 91 this->SetSyntax(_("\037channel\037 \037time\037")); 92 } 93 94 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override 95 { 96 const Anope::string &chan = params[0]; 97 const Anope::string &arg = params[1]; 98 99 ChannelInfo *ci = ChannelInfo::Find(chan); 100 if (ci == NULL) 101 { 102 source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); 103 return; 104 } 105 106 AccessGroup access = source.AccessFor(ci); 107 if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) 108 { 109 source.Reply(ACCESS_DENIED); 110 return; 111 } 112 113 if (Anope::ReadOnly) 114 { 115 source.Reply(_("Sorry, changing bot options is temporarily disabled.")); 116 return; 117 } 118 119 time_t t = Anope::DoTime(arg); 120 if (t < 0) 121 { 122 source.Reply(BAD_EXPIRY_TIME); 123 return; 124 } 125 126 /* cap at 1 day */ 127 if (t > 86400) 128 { 129 source.Reply(_("Ban expiry may not be longer than 1 day.")); 130 return; 131 } 132 133 ci->banexpire = t; 134 135 bool override = !access.HasPriv("SET"); 136 Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to change banexpire to " << ci->banexpire; 137 138 if (!ci->banexpire) 139 source.Reply(_("Bot bans will no longer automatically expire.")); 140 else 141 source.Reply(_("Bot bans will automatically expire after %s."), Anope::Duration(ci->banexpire, source.GetAccount()).c_str()); 142 } 143 144 bool OnHelp(CommandSource &source, const Anope::string &) anope_override 145 { 146 this->SendSyntax(source); 147 source.Reply(_(" \n" 148 "Sets the time bot bans expire in. If enabled, any bans placed by\n" 149 "bots, such as flood kicker, badwords kicker, etc. will automatically\n" 150 "be removed after the given time. Set to 0 to disable bans from\n" 151 "automatically expiring.")); 152 return true; 153 } 154 }; 155 156 class CommandBSSetPrivate : public Command 157 { 158 public: 159 CommandBSSetPrivate(Module *creator, const Anope::string &sname = "botserv/set/private") : Command(creator, sname, 2, 2) 160 { 161 this->SetDesc(_("Prevent a bot from being assigned by non IRC operators")); 162 this->SetSyntax(_("\037botname\037 {\037ON|OFF\037}")); 163 } 164 165 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override 166 { 167 BotInfo *bi = BotInfo::Find(params[0], true); 168 const Anope::string &value = params[1]; 169 170 if (Anope::ReadOnly) 171 { 172 source.Reply(READ_ONLY_MODE); 173 return; 174 } 175 176 if (bi == NULL) 177 { 178 source.Reply(BOT_DOES_NOT_EXIST, params[0].c_str()); 179 return; 180 } 181 182 if (value.equals_ci("ON")) 183 { 184 bi->oper_only = true; 185 source.Reply(_("Private mode of bot %s is now \002on\002."), bi->nick.c_str()); 186 } 187 else if (value.equals_ci("OFF")) 188 { 189 bi->oper_only = false; 190 source.Reply(_("Private mode of bot %s is now \002off\002."), bi->nick.c_str()); 191 } 192 else 193 this->OnSyntaxError(source, source.command); 194 } 195 196 bool OnHelp(CommandSource &source, const Anope::string &) anope_override 197 { 198 this->SendSyntax(source); 199 source.Reply(_(" \n" 200 "This option prevents a bot from being assigned to a\n" 201 "channel by users that aren't IRC Operators.")); 202 return true; 203 } 204 }; 205 206 class BSSet : public Module 207 { 208 CommandBSSet commandbsset; 209 CommandBSSetBanExpire commandbssetbanexpire; 210 CommandBSSetPrivate commandbssetprivate; 211 212 public: 213 BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), 214 commandbsset(this), commandbssetbanexpire(this), 215 commandbssetprivate(this) 216 { 217 } 218 219 void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) anope_override 220 { 221 if (!ci->banexpire) 222 return; 223 224 new CommandBSSetBanExpire::UnbanTimer(this, ci->name, mask, ci->banexpire); 225 } 226 }; 227 228 MODULE_INIT(BSSet)