diff options
Diffstat (limited to 'modules/botserv')
| -rw-r--r-- | modules/botserv/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | modules/botserv/assign.cpp | 281 | ||||
| -rw-r--r-- | modules/botserv/autoassign.cpp | 37 | ||||
| -rw-r--r-- | modules/botserv/badwords.cpp | 465 | ||||
| -rw-r--r-- | modules/botserv/bot.cpp | 426 | ||||
| -rw-r--r-- | modules/botserv/botlist.cpp | 92 | ||||
| -rw-r--r-- | modules/botserv/control.cpp | 168 | ||||
| -rw-r--r-- | modules/botserv/info.cpp | 116 | ||||
| -rw-r--r-- | modules/botserv/kick.cpp | 1664 | ||||
| -rw-r--r-- | modules/botserv/main/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | modules/botserv/main/botserv.cpp | 228 | ||||
| -rw-r--r-- | modules/botserv/set.cpp | 221 |
12 files changed, 3700 insertions, 0 deletions
diff --git a/modules/botserv/CMakeLists.txt b/modules/botserv/CMakeLists.txt new file mode 100644 index 000000000..cd225a94d --- /dev/null +++ b/modules/botserv/CMakeLists.txt @@ -0,0 +1 @@ +build_modules(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/botserv/assign.cpp b/modules/botserv/assign.cpp new file mode 100644 index 000000000..840651dfc --- /dev/null +++ b/modules/botserv/assign.cpp @@ -0,0 +1,281 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" +#include "modules/bs_info.h" + +class CommandBSAssign : public Command +{ + public: + CommandBSAssign(Module *creator) : Command(creator, "botserv/assign", 2, 2) + { + this->SetDesc(_("Assigns a bot to a channel")); + this->SetSyntax(_("\037channel\037 \037nickname\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &chan = params[0]; + const Anope::string &nick = params[1]; + + if (Anope::ReadOnly) + { + source.Reply(_("Sorry, bot assignment is temporarily disabled.")); + return; + } + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + return; + } + + ServiceBot *bi = ServiceBot::Find(nick, true); + if (!bi) + { + source.Reply(_("Bot \002{0}\002 does not exist."), nick); + return; + } + + ChanServ::AccessGroup access = source.AccessFor(ci); + if (!access.HasPriv("ASSIGN") && !source.HasPriv("botserv/administration")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->GetName()); + return; + } + + if (ci->HasFieldS("BS_NOBOT")) + { + source.Reply(_("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), ci->GetName()); + return; + } + + if (bi->bi->GetOperOnly() && !source.HasPriv("botserv/administration")) + { + source.Reply(_("Access denied. Bot \002{0}\002 is for operators only."), bi->nick); + return; + } + + if (ci->GetBot() == bi) + { + source.Reply(_("Bot \002{0}\002 is already assigned to \002{1}\002."), ci->GetBot()->nick, ci->GetName()); + return; + } + + bool override = !access.HasPriv("ASSIGN"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << bi->nick; + + bi->Assign(source.GetUser(), ci); + source.Reply(_("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, ci->GetName()); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Assigns the bot \037nickname\037 to \037channel\037." + " You can then configure the bot for the channel so it fits your needs.\n" + "\n" + "Use of this command requires the \002{0}\002 privilege on \037channel\037." + "\n" + "Example:\n" + " {command} #anope Botox\n" + " Assigns the bot Botox to #anope.\n"), + "ASSIGN", "command"_kw = source.command); + return true; + } +}; + +class CommandBSUnassign : public Command +{ + public: + CommandBSUnassign(Module *creator) : Command(creator, "botserv/unassign", 1, 1) + { + this->SetDesc(_("Unassigns a bot from a channel")); + this->SetSyntax(_("\037channel\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &chan = params[0]; + + if (Anope::ReadOnly) + { + source.Reply(_("Sorry, bot assignment is temporarily disabled.")); + return; + } + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + return; + } + + ChanServ::AccessGroup access = source.AccessFor(ci); + if (!source.HasPriv("botserv/administration") && !access.HasPriv("ASSIGN")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->GetName()); + return; + } + + if (!ci->GetBot()) + { + source.Reply(_("There is no bot assigned to \002{0}\002."), ci->GetName()); + return; + } + + if (ci->HasFieldS("PERSIST") && !ModeManager::FindChannelModeByName("PERM")) + { + source.Reply(_("You cannot unassign bots while persist is set on the channel.")); + return; + } + + bool override = !access.HasPriv("ASSIGN"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << ci->GetBot()->nick; + + ServiceBot *bi = ci->GetBot(); + bi->UnAssign(source.GetUser(), ci); + source.Reply(_("Bot \002{0}\002 has been unassigned from \002{1}\002."), bi->nick, ci->GetName()); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Unassigns a bot from \037channel\037." + "Bot configuration is kept, so you will always be able to reassign a bot later without losing your settings.\n" + "\n" + "Use of this command requires the \002{0}\002 privilege on \037channel\037." + "\n" + "Example:\n" + " {command} #anope\n" + " Unassigns the current bot from #anope.\n"), + "ASSIGN", "command"_kw = source.command); + return true; + } +}; + +class CommandBSSetNoBot : public Command +{ + public: + CommandBSSetNoBot(Module *creator, const Anope::string &sname = "botserv/set/nobot") : Command(creator, sname, 2, 2) + { + this->SetDesc(_("Prevent a bot from being assigned to a channel")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037}")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &chan = params[0]; + const Anope::string &value = params[1]; + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + return; + } + + if (value.equals_ci("ON")) + { + Log(LOG_ADMIN, source, this, ci) << "to enable nobot"; + + ci->SetS<bool>("BS_NOBOT", true); + if (ci->GetBot()) + ci->GetBot()->UnAssign(source.GetUser(), ci); + source.Reply(_("No-bot mode is now \002on\002 for \002{0}\002."), ci->GetName()); + } + else if (value.equals_ci("OFF")) + { + Log(LOG_ADMIN, source, this, ci) << "to disable nobot"; + + ci->UnsetS<bool>("BS_NOBOT"); + source.Reply(_("No-bot mode is now \002off\002 for \002{0}\002."), ci->GetName()); + } + else + this->OnSyntaxError(source, source.command); + } + + bool OnHelp(CommandSource &source, const Anope::string &) override + { + source.Reply(_("If no-bot is set on a channel, then the channel will be unabled to have a bot assigned to it." + " If a bot is already assigned to the channel, it is unassigned automatically when no-bot is enabled." + "\n" + "Example:\n" + " {command} #anope on\n" + " Prevents a service bot from being assigned to #anope.\n"), + "command"_kw = source.command); + return true; + } +}; + +class BSAssign : public Module + , public EventHook<Event::Invite> + , public EventHook<Event::ServiceBotEvent> +{ + Serialize::Field<BotInfo, bool> nobot; + + CommandBSAssign commandbsassign; + CommandBSUnassign commandbsunassign; + CommandBSSetNoBot commandbssetnobot; + + public: + BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + + , nobot(this, botinfo, "BS_NOBOT") + + , commandbsassign(this) + , commandbsunassign(this) + , commandbssetnobot(this) + { + } + + void OnInvite(User *source, Channel *c, User *targ) override + { + ServiceBot *bi; + if (Anope::ReadOnly || !c->ci || targ->server != Me || !(bi = ServiceBot::Find(targ->nick, true))) + return; + + ChanServ::AccessGroup access = c->ci->AccessFor(source); + if (!access.HasPriv("ASSIGN") && !source->HasPriv("botserv/administration")) + { + targ->SendMessage(bi, _("Access denied. You do not have privilege \002ASSIGN\002 on \002{0}\002."), c->ci->GetName()); + return; + } + + if (nobot.HasExt(c->ci)) + { + targ->SendMessage(bi, _("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), c->ci->GetName()); + return; + } + + if (bi->bi->GetOperOnly() && !source->HasPriv("botserv/administration")) + { + targ->SendMessage(bi, _("Access denied. Bot \002{0}\002 is for operators only."), bi->nick); + return; + } + + if (c->ci->GetBot() == bi) + { + targ->SendMessage(bi, _("Bot \002{0}\002 is already assigned to \002{1}\002."), bi->nick, c->ci->GetName()); + return; + } + + bi->Assign(source, c->ci); + targ->SendMessage(bi, _("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, c->ci->GetName()); + } + + void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override + { + if (nobot.HasExt(ci)) + info.AddOption(_("No bot")); + } +}; + +MODULE_INIT(BSAssign) diff --git a/modules/botserv/autoassign.cpp b/modules/botserv/autoassign.cpp new file mode 100644 index 000000000..8978499ed --- /dev/null +++ b/modules/botserv/autoassign.cpp @@ -0,0 +1,37 @@ +/* + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#include "module.h" + +class BSAutoAssign : public Module + , public EventHook<Event::ChanRegistered> +{ + public: + BSAutoAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + { + } + + void OnChanRegistered(ChanServ::Channel *ci) override + { + const Anope::string &bot = Config->GetModule(this)->Get<Anope::string>("bot"); + if (bot.empty()) + return; + + ServiceBot *bi = ServiceBot::Find(bot, true); + if (bi == NULL) + { + Log(this) << "bs_autoassign is configured to assign bot " << bot << ", but it does not exist?"; + return; + } + + bi->Assign(NULL, ci); + } +}; + +MODULE_INIT(BSAutoAssign) diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp new file mode 100644 index 000000000..0f8e9e7d0 --- /dev/null +++ b/modules/botserv/badwords.cpp @@ -0,0 +1,465 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" +#include "modules/bs_badwords.h" + +static EventHandlers<Event::BadWordEvents> *bwevents; + +class BadWordImpl : public BadWord +{ + public: + BadWordImpl(Serialize::TypeBase *type) : BadWord(type) { } + BadWordImpl(Serialize::TypeBase *type, Serialize::ID id) : BadWord(type, id) { } + + ChanServ::Channel *GetChannel() override; + + void SetChannel(ChanServ::Channel *c) override; + + Anope::string GetWord() override; + + void SetWord(const Anope::string &w) override; + + BadWordType GetType() override; + + void SetType(const BadWordType &t) override; +}; + +class BadWordsType : public Serialize::Type<BadWordImpl> +{ + public: + Serialize::ObjectField<BadWordImpl, ChanServ::Channel *> channel; + Serialize::Field<BadWordImpl, Anope::string> word; + Serialize::Field<BadWordImpl, BadWordType> type; + + BadWordsType(Module *me) : Serialize::Type<BadWordImpl>(me, "BadWord") + , channel(this, "ci", true) + , word(this, "word") + , type(this, "type") + { + } +}; + +ChanServ::Channel *BadWordImpl::GetChannel() +{ + return Get(&BadWordsType::channel); +} + +void BadWordImpl::SetChannel(ChanServ::Channel *c) +{ + Set(&BadWordsType::channel, c); +} + +Anope::string BadWordImpl::GetWord() +{ + return Get(&BadWordsType::word); +} + +void BadWordImpl::SetWord(const Anope::string &w) +{ + Set(&BadWordsType::word, w); +} + +BadWordType BadWordImpl::GetType() +{ + return Get(&BadWordsType::type); +} + +void BadWordImpl::SetType(const BadWordType &t) +{ + Set(&BadWordsType::type, t); +} + +struct BadWordsImpl : BadWords +{ + BadWordsImpl(Module *me) : BadWords(me) { } + + BadWord* AddBadWord(ChanServ::Channel *ci, const Anope::string &word, BadWordType type) override + { + BadWord *bw = badword.Create(); + bw->SetChannel(ci); + bw->SetWord(word); + bw->SetType(type); + + (*bwevents)(&Event::BadWordEvents::OnBadWordAdd, ci, bw); + + return bw; + } + + std::vector<BadWord *> GetBadWords(ChanServ::Channel *ci) + { + return ci->GetRefs<BadWord *>(badword); + } + + BadWord* GetBadWord(ChanServ::Channel *ci, unsigned index) override + { + auto bw = GetBadWords(ci); + return index < bw.size() ? bw[index] : nullptr; + } + + unsigned GetBadWordCount(ChanServ::Channel *ci) override + { + return GetBadWords(ci).size(); + } + + void EraseBadWord(ChanServ::Channel *ci, unsigned index) override + { + auto bws = GetBadWords(ci); + if (index >= bws.size()) + return; + + BadWord *bw = bws[index]; + (*bwevents)(&Event::BadWordEvents::OnBadWordDel, ci, bw); + + delete bw; + } + + void ClearBadWords(ChanServ::Channel *ci) override + { + for (BadWord *bw : GetBadWords(ci)) + delete bw; + } +}; + +class CommandBSBadwords : public Command +{ + private: + void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) + { + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "LIST"; + ListFormatter list(source.GetAccount()); + + list.AddColumn(_("Number")).AddColumn(_("Word")).AddColumn(_("Type")); + + if (!badwords->GetBadWordCount(ci)) + { + source.Reply(_("The bad word list of \002{0}\002 is empty."), ci->GetName()); + return; + } + + if (!word.empty() && word.find_first_not_of("1234567890,-") == Anope::string::npos) + { + NumberList(word, false, + [&](unsigned int num) + { + if (!num || num > badwords->GetBadWordCount(ci)) + return; + + BadWord *b = badwords->GetBadWord(ci, num - 1); + ListFormatter::ListEntry entry; + entry["Number"] = stringify(num); + entry["Word"] = b->GetWord(); + entry["Type"] = b->GetType() == BW_SINGLE ? "(SINGLE)" : (b->GetType() == BW_START ? "(START)" : (b->GetType() == BW_END ? "(END)" : "")); + list.AddEntry(entry); + }, + [](){}); + } + else + { + for (unsigned i = 0, end = badwords->GetBadWordCount(ci); i < end; ++i) + { + BadWord *b = badwords->GetBadWord(ci, i); + + if (!word.empty() && !Anope::Match(b->GetWord(), word)) + continue; + + ListFormatter::ListEntry entry; + entry["Number"] = stringify(i + 1); + entry["Word"] = b->GetWord(); + entry["Type"] = b->GetType() == BW_SINGLE ? "(SINGLE)" : (b->GetType() == BW_START ? "(START)" : (b->GetType() == BW_END ? "(END)" : "")); + list.AddEntry(entry); + } + } + + if (list.IsEmpty()) + { + source.Reply(_("No matching entries on the bad word list of \002{0}\002."), ci->GetName()); + return; + } + + std::vector<Anope::string> replies; + list.Process(replies); + + source.Reply(_("Bad words list for \002{0}\002:"), ci->GetName()); + + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + + source.Reply(_("End of bad words list.")); + } + + void DoAdd(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) + { + size_t pos = word.rfind(' '); + BadWordType bwtype = BW_ANY; + Anope::string realword = word; + + if (pos != Anope::string::npos) + { + Anope::string opt = word.substr(pos + 1); + if (!opt.empty()) + { + if (opt.equals_ci("SINGLE")) + bwtype = BW_SINGLE; + else if (opt.equals_ci("START")) + bwtype = BW_START; + else if (opt.equals_ci("END")) + bwtype = BW_END; + } + realword = word.substr(0, pos); + } + + unsigned badwordsmax = Config->GetModule(this->module)->Get<unsigned>("badwordsmax"); + if (badwords->GetBadWordCount(ci) >= badwordsmax) + { + source.Reply(_("Sorry, you can only have \002{0}\002 bad words entries on a channel."), badwordsmax); + return; + } + + bool casesensitive = Config->GetModule(this->module)->Get<bool>("casesensitive"); + + for (BadWord *bw : badwords->GetBadWords(ci)) + if ((casesensitive && realword.equals_cs(bw->GetWord())) || (!casesensitive && realword.equals_ci(bw->GetWord()))) + { + source.Reply(_("\002{0}\002 already exists in \002{1}\002 bad words list."), bw->GetWord(), ci->GetName()); + return; + } + + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "ADD " << realword; + badwords->AddBadWord(ci, realword, bwtype); + + source.Reply(_("\002{0}\002 added to \002{1}\002 bad words list."), realword, ci->GetName()); + } + + void DoDelete(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) + { + if (!badwords->GetBadWordCount(ci)) + { + source.Reply(_("Bad word list for \002{0}\002 is empty."), ci->GetName()); + return; + } + + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + + /* Special case: is it a number/list? Only do search if it isn't. */ + if (!word.empty() && isdigit(word[0]) && word.find_first_not_of("1234567890,-") == Anope::string::npos) + { + unsigned int deleted = 0; + + NumberList(word, true, + [&](unsigned int num) + { + if (!num || num > badwords->GetBadWordCount(ci)) + return; + + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "DEL " << badwords->GetBadWord(ci, num - 1)->GetWord(); + ++deleted; + badwords->EraseBadWord(ci, num - 1); + }, + [&]() + { + if (!deleted) + source.Reply(_("No matching entries on the bad word list of \002{0}\002."), ci->GetName()); + else if (deleted == 1) + source.Reply(_("Deleted \0021\002 entry from bad word list of \002{0}\002."), ci->GetName()); + else + source.Reply(_("Deleted \002{0}\002 entries from the bad word list of \002{1}\002."), deleted, ci->GetName()); + }); + } + else + { + unsigned i, end; + BadWord *bw; + + for (i = 0, end = badwords->GetBadWordCount(ci); i < end; ++i) + { + bw = badwords->GetBadWord(ci, i); + + if (word.equals_ci(bw->GetWord())) + break; + } + + if (i == end) + { + source.Reply(_("\002{0}\002 was not found on the bad word list of \002{1}\002."), word, ci->GetName()); + return; + } + + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "DEL " << bw->GetWord(); + + source.Reply(_("\002{0}\002 deleted from \002{1}\002 bad words list."), bw->GetWord(), ci->GetName()); + + bw->Delete(); + } + } + + void DoClear(CommandSource &source, ChanServ::Channel *ci) + { + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "CLEAR"; + + badwords->ClearBadWords(ci); + source.Reply(_("Bad words list is now empty.")); + } + + public: + CommandBSBadwords(Module *creator) : Command(creator, "botserv/badwords", 2, 3) + { + this->SetDesc(_("Maintains the bad words list")); + this->SetSyntax(_("\037channel\037 ADD \037word\037 [\037SINGLE\037 | \037START\037 | \037END\037]")); + this->SetSyntax(_("\037channel\037 DEL {\037word\037 | \037entry-num\037 | \037list\037}")); + this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | \037list\037]")); + this->SetSyntax(_("\037channel\037 CLEAR")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &chan = params[0]; + const Anope::string &cmd = params[1]; + const Anope::string &word = params.size() > 2 ? params[2] : ""; + bool need_args = cmd.equals_ci("LIST") || cmd.equals_ci("CLEAR"); + + if (!need_args && word.empty()) + { + this->OnSyntaxError(source, cmd); + return; + } + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + return; + } + + if (!source.AccessFor(ci).HasPriv("BADWORDS") && (!need_args || !source.HasPriv("botserv/administration"))) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "BADWORDS", ci->GetName()); + return; + } + + if (Anope::ReadOnly) + { + source.Reply(_("Sorry, bad words list modification is temporarily disabled.")); + return; + } + + if (cmd.equals_ci("ADD")) + this->DoAdd(source, ci, word); + else if (cmd.equals_ci("DEL")) + this->DoDelete(source, ci, word); + else if (cmd.equals_ci("LIST")) + this->DoList(source, ci, word); + else if (cmd.equals_ci("CLEAR")) + this->DoClear(source, ci); + else + this->OnSyntaxError(source, ""); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + if (subcommand.equals_ci("ADD")) + { + source.Reply(_("Adds \037word\037 to the bad words list for \037channel\037. If \002SINGLE\002 is specified then the user must say the enire word for it to be considered a match." + " If \002START\002 is specified then the user only must say a word that starts with \037word\037." + " Likewise if \002END\002 is specified then the user must only say a word that ends with \037word\037." + " If no argument is specified, then any word which contains \037word\037 will be considered a match.\n" + "\n" + "Examples:\n" + " {command} #anope ADD raw SINGLE\n" + " Adds the bad word \"raw\" to the bad word list of #anope."), + "command"_kw = source.command); + } + else if (subcommand.equals_ci("DEL")) + { + source.Reply(_("Removes \037word\037 from the bad words list for \037channel\037. If a number or list of numbers is given, those entries are deleted.\n" + "\n" + "Examples:\n" + " {command} #anope DEL raw\n" + " Removes the bad word \"raw\" from the bad word list of #anope.\n" + "\n" + " {command} #anope DEL 2-5,7-9\n" + " Removes bad words entries numbered 2 through 5 and 7 through 9 on #anope."), + "command"_kw = source.command); + + } + else if (subcommand.equals_ci("LIST")) + { + source.Reply(_("Lists the badwords for \037channel\037." + " If a wildcard mask is given, only those entries matching the mask are displayed." + " If a list of entry numbers is given, only those entries are shown.\n" + "\n" + "Examples:\n" + " {command} #anope LIST\n" + " Lists the bad words for #anope.\n" + "\n" + " {command} #anope LIST 2-5,7-9\n" + " Lists bad words entries numbered 2 thorough 5 and 7 through 9 on #anope."), + "command"_kw = source.command); + } + else if (subcommand.equals_ci("CLEAR")) + { + source.Reply(_("Clears the bad words for \037channel\037." + "\n" + "\n" + "Example:\n" + " {command} #anope CLEAR\n" + " Clears the bad word list for #anope."), + "command"_kw = source.command); + } + else + { + source.Reply(_("Maintains the bad words list for a channel." + " When a word on the bad words list is said, action may be taken against the offending user.\n" + "\n" + "Use of this command requires the \002{0}\002 privilege on \037channel\037."), + "BADWORDS"); + + CommandInfo *help = source.service->FindCommand("generic/help"); + if (help) + source.Reply(_("\n" + "For help configuring the bad word kicker use \002{msg}{service} HELP KICK BADWORDS\002.\n"//XXX + "\n" + "The \002ADD\002 command adds \037word\037 to the badwords list.\n" + "\002{msg}{service} {help} {command} ADD\002 for more information.\n" + "\n" + "The \002DEL\002 command removes \037word\037 from the badwords list.\n" + "\002{msg}{service} {help} {command} DEL\002 for more information.\n" + "\n" + "The \002LIST\002 and \002CLEAR\002 commands show and clear the bad words list, respectively.\n" + "\002{msg}{service} {help} {command} LIST\002 and \002{msg}{service} {help} {command} CLEAR\002 for more information.\n"), + "msg"_kw = Config->StrictPrivmsg, "service"_kw = source.service->nick, "command"_kw = source.command, "help"_kw = help->cname); + } + return true; + } +}; + +class BSBadwords : public Module +{ + CommandBSBadwords commandbsbadwords; + BadWordsImpl badwords; + EventHandlers<Event::BadWordEvents> events; + BadWordsType bwtype; + + public: + BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsbadwords(this) + , badwords(this) + , events(this) + , bwtype(this) + { + bwevents = &events; + } +}; + +MODULE_INIT(BSBadwords) diff --git a/modules/botserv/bot.cpp b/modules/botserv/bot.cpp new file mode 100644 index 000000000..726c02ab2 --- /dev/null +++ b/modules/botserv/bot.cpp @@ -0,0 +1,426 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" +#include "modules/bs_bot.h" + +class CommandBSBot : public Command +{ + EventHandlers<Event::BotCreate> OnBotCreate; + EventHandlers<Event::BotChange> OnBotChange; + EventHandlers<Event::BotDelete> OnBotDelete; + + void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) + { + const Anope::string &nick = params[1]; + const Anope::string &user = params[2]; + const Anope::string &host = params[3]; + const Anope::string &real = params[4]; + + if (ServiceBot::Find(nick, true)) + { + source.Reply(_("Bot \002{0}\002 already exists."), nick); + return; + } + + Configuration::Block *networkinfo = Config->GetBlock("networkinfo"); + + if (nick.length() > networkinfo->Get<unsigned>("nicklen")) + { + source.Reply(_("Bot nicks may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("nicklen")); + return; + } + + if (user.length() > networkinfo->Get<unsigned>("userlen")) + { + source.Reply(_("Bot idents may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("userlen")); + return; + } + + if (host.length() > networkinfo->Get<unsigned>("hostlen")) + { + source.Reply(_("Bot hosts may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("hostlen")); + return; + } + + if (!IRCD->IsNickValid(nick)) + { + source.Reply(_("Bot nicks may only contain valid nick characters.")); + return; + } + + if (!IRCD->IsIdentValid(user)) + { + source.Reply(_("Bot idents may only contain valid ident characters.")); + return; + } + + if (!IRCD->IsHostValid(host)) + { + source.Reply(_("Bot hosts may only contain valid host characters.")); + return; + } + + /* We check whether the nick is registered, and inform the user + * if so. You need to drop the nick manually before you can use + * it as a bot nick from now on -GD + */ + NickServ::Nick *na = NickServ::FindNick(nick); + if (na) + { + source.Reply(_("\002{0}\002 is already registered!"), na->GetNick()); + return; + } + + User *targ = User::Find(nick, true); + if (targ) + { + source.Reply(_("\002{0}\002 is currently in use."), targ->nick); + return; + } + + ServiceBot *bi = new ServiceBot(nick, user, host, real); + + Log(LOG_ADMIN, source, this) << "ADD " << bi->GetMask() << " " << bi->realname; + + source.Reply(_("\002{0}!{1}@{2}\002 (\002{3}\002) added to the bot list."), bi->nick, bi->GetIdent(), bi->host, bi->realname); + + this->OnBotCreate(&Event::BotCreate::OnBotCreate, bi); + } + + void DoChange(CommandSource &source, const std::vector<Anope::string> ¶ms) + { + const Anope::string &oldnick = params[1]; + const Anope::string &nick = params.size() > 2 ? params[2] : ""; + const Anope::string &user = params.size() > 3 ? params[3] : ""; + const Anope::string &host = params.size() > 4 ? params[4] : ""; + const Anope::string &real = params.size() > 5 ? params[5] : ""; + + if (oldnick.empty() || nick.empty()) + { + this->OnSyntaxError(source, "CHANGE"); + return; + } + + ServiceBot *bi = ServiceBot::Find(oldnick, true); + if (!bi) + { + source.Reply(_("Bot \002{0}\002 does not exist."), oldnick); + return; + } + + if (bi->bi->conf) + { + source.Reply(_("Bot \002{0}\002 is not changeable because it is configured in services configuration."), bi->nick.c_str()); + return; + } + + Configuration::Block *networkinfo = Config->GetBlock("networkinfo"); + + if (nick.length() > networkinfo->Get<unsigned>("nicklen")) + { + source.Reply(_("Bot nicknames may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("nicklen")); + return; + } + + if (user.length() > networkinfo->Get<unsigned>("userlen")) + { + source.Reply(_("Bot usernames may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("userlen")); + return; + } + + if (host.length() > networkinfo->Get<unsigned>("hostlen")) + { + source.Reply(_("Bot hostnames may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("hostlen")); + return; + } + + /* Checks whether there *are* changes. + * Case sensitive because we may want to change just the case. + * And we must finally check that the nick is not already + * taken by another bot. + */ + if (nick.equals_cs(bi->nick) + && (user.empty() || user.equals_cs(bi->GetIdent())) + && (host.empty() || host.equals_cs(bi->host)) + && (real.empty() || real.equals_cs(bi->realname))) + { + source.Reply(_("There is no difference between the current settings and the new settings.")); + return; + } + + if (!IRCD->IsNickValid(nick)) + { + source.Reply(_("Bot nicknames may only contain valid nickname characters.")); + return; + } + + if (!user.empty() && !IRCD->IsIdentValid(user)) + { + source.Reply(_("Bot uesrnames may only contain valid username characters.")); + return; + } + + if (!host.empty() && !IRCD->IsHostValid(host)) + { + source.Reply(_("Bot hostnames may only contain valid hostname characters.")); + return; + } + + ServiceBot *newbi = ServiceBot::Find(nick, true); + if (newbi && bi != newbi) + { + source.Reply(_("Bot \002{0}\002 already exists."), newbi->nick); + return; + } + + User *target = User::Find(nick, true); + if (target) + { + source.Reply(_("\002{0}\002 is currently in use."), target->nick); + return; + } + + if (!nick.equals_ci(bi->nick)) + { + /* We check whether the nick is registered, and inform the user + * if so. You need to drop the nick manually before you can use + * it as a bot nick from now on -GD + */ + NickServ::Nick *na = NickServ::FindNick(nick); + if (na) + { + source.Reply(_("\002{0}\002 is already registered."), na->GetNick()); + return; + } + + /* The new nick is really different, so we remove the Q line for the old nick. */ + //XLine x_del(bi->nick); + //IRCD->SendSQLineDel(&x_del); + + /* Add a Q line for the new nick */ + //XLine x(nick, "Reserved for services"); + //IRCD->SendSQLine(NULL, &x); + } + + if (!user.empty()) + { + IRCD->SendQuit(bi, "Quit: Be right back"); + bi->introduced = false; + } + else + IRCD->SendNickChange(bi, nick); + + if (!nick.equals_cs(bi->nick)) + { + bi->SetNewNick(nick); + bi->bi->SetNick(nick); + } + + if (!user.equals_cs(bi->GetIdent())) + { + bi->SetIdent(user); + bi->bi->SetUser(user); + } + if (!host.equals_cs(bi->host)) + { + bi->host = host; + bi->bi->SetHost(host); + } + if (real.equals_cs(bi->realname)) + { + bi->realname = real; + bi->bi->SetRealName(real); + } + + if (!user.empty()) + bi->OnKill(); + + source.Reply(_("Bot \002{0}\002 has been changed to \002{1}!{2}@{3}\002 (\002{4}\002)."), oldnick, bi->nick, bi->GetIdent(), bi->host, bi->realname); + Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; + + this->OnBotChange(&Event::BotChange::OnBotChange, bi); + } + + void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) + { + const Anope::string &nick = params[1]; + + if (nick.empty()) + { + this->OnSyntaxError(source, "DEL"); + return; + } + + ServiceBot *bi = ServiceBot::Find(nick, true); + if (!bi) + { + source.Reply(_("Bot \002{0}\002 does not exist."), nick); + return; + } + + if (bi->bi->conf) + { + source.Reply(_("Bot \002{0}\002 is can not be deleted because it is configured in services configuration."), bi->nick); + return; + } + + this->OnBotDelete(&Event::BotDelete::OnBotDelete, bi); + + Log(LOG_ADMIN, source, this) << "DEL " << bi->nick; + + source.Reply(_("Bot \002{0}\002 has been deleted."), bi->nick); + delete bi; + } + + public: + CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6) + , OnBotCreate(creator) + , OnBotChange(creator) + , OnBotDelete(creator) + { + this->SetDesc(_("Maintains network bot list")); + this->SetSyntax(_("\002ADD \037nicknae\037 \037username\037 \037hostname\037 \037realname\037\002")); + this->SetSyntax(_("\002CHANGE \037oldnickname\037 \037newnickname\037 [\037username\037 [\037hostname\037 [\037realname\037]]]\002")); + this->SetSyntax(_("\002DEL \037nickname\037\002")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &cmd = params[0]; + + if (Anope::ReadOnly) + source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); + + if (cmd.equals_ci("ADD")) + { + if (!source.HasCommand("botserv/bot/add")) + { + source.Reply(_("Access denied. You do not have access to the operator command \002{0}\002."), "botserv/bot/add"); + return; + } + + // ADD nick user host real - 5 + if (params.size() < 5) + { + this->OnSyntaxError(source, "ADD"); + return; + } + + std::vector<Anope::string> tempparams = params; + // ADD takes less params than CHANGE, so we need to take 6 if given and append it with a space to 5. + if (tempparams.size() >= 6) + tempparams[4] = tempparams[4] + " " + tempparams[5]; + + this->DoAdd(source, tempparams); + } + else if (cmd.equals_ci("CHANGE")) + { + // CHANGE oldn newn user host real - 6 + // but only oldn and newn are required + if (!source.HasCommand("botserv/bot/change")) + { + source.Reply(_("Access denied. You do not have access to the operator command \002{0}\002."), "botserv/bot/change"); + return; + } + + if (params.size() < 3) + { + this->OnSyntaxError(source, "CHANGE"); + return; + } + + this->DoChange(source, params); + } + else if (cmd.equals_ci("DEL")) + { + // DEL nick + if (!source.HasCommand("botserv/bot/del")) + { + source.Reply(_("Access denied. You do not have access to the operator command \002{0}\002."), "botserv/bot/del"); + return; + } + + if (params.size() < 1) + { + this->OnSyntaxError(source, "DEL"); + return; + } + + this->DoDel(source, params); + } + else + this->OnSyntaxError(source, ""); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + if (subcommand.equals_ci("ADD")) + source.Reply(_("\002{command} ADD\002 adds a bot with the given \037nickname\037, \037username\037, \037hostname\037 and \037realname\037." + " You can not create a bot with a nickname that is currently registered. If an unregistered user is currently using the nick, they will be killed.\n" + " Once a bot is created, users will be able to assign the bot to their channels. This command requires the opererator privilege for command \002{0}\002." + "\n" + "Example:\n" + " {command} ADD Botox Botox services.anope.org Botox\n" + " Adds a service bot with nickname \"Botox\", username \"Botox\", hostname \"services.anope.org\", and realname \"Botox\" to the bot list."), + "botserv/bot/add", "command"_kw = source.command); + else if (subcommand.equals_ci("CHANGE")) + source.Reply(_("\002{command} CHANGE\002 allows changing the \037nickname\037, \037username\037, \037hostname\037 and \037realname\037 of bot \037oldnickname\037." + " If a new username, hostname, or realname is specified, then the bot \037nickname\037 will quit and rejoin all of its channels using the new mask." + " Otherwise, the bot simply change nick to \037newnickname\037. All settings on the bot, such as channels and no-bot, are retained." + " This command requires the operator privilege for command \002{0}\002." + "\n" + "Example:\n" + " {command} CHANGE Botox peer connection reset.by peer\n" + " Renames the bot \"Botox\" to \"peer\" with the given username, hostname, and realname."), + "botserv/bot/change", "command"_kw = source.command); + else if (subcommand.equals_ci("DEL")) + source.Reply(_("\002{command} DEL\002 removes the bot \037nickname\037 from the bot list. The bot will quit from any channels it is in, and will not be replaced." + " This command requires the operator privilege for command \002{0}\002.\n" + "\n" + "Example:\n" + " {command} DEL peer\n" + " Removes the bot \"peer\" from the bot list."), + "botserv/bot/del", "command"_kw = source.command); + else + { + source.Reply(_("Allows Services Operators to create, modify, and delete bots that users will be able to use on their channels.")); + + CommandInfo *help = source.service->FindCommand("generic/help"); + if (help) + source.Reply(_("\n" + "The \002ADD\002 command adds a bot with the given \037nickname\037, \037username\037, \037hostname\037 and \037realname\037 to the bot list.\n" + "\002{msg}{service} {help} {command} ADD\002 for more information.\n" + "\n" + "The \002CHANGE\002 command allows changing the \037nickname\037, \037username\037, \037hostname\037 and \037realname\037 of bot \037oldnickname\037.\n" + "\002{msg}{service} {help} {command} CHANGE\002 for more information.\n" + "\n" + "The \002{command} DEL\002 removes the bot \037nickname\037 from the bot list.\n" + "\002{msg}{service} {help} {command} DEL\002 for more information."), + "msg"_kw = Config->StrictPrivmsg, "help"_kw = help->cname, "command"_kw = source.command); + } + return true; + } +}; + +class BSBot : public Module +{ + CommandBSBot commandbsbot; + + public: + BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsbot(this) + { + + } +}; + +MODULE_INIT(BSBot) diff --git a/modules/botserv/botlist.cpp b/modules/botserv/botlist.cpp new file mode 100644 index 000000000..ce899719e --- /dev/null +++ b/modules/botserv/botlist.cpp @@ -0,0 +1,92 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" + +class CommandBSBotList : public Command +{ + public: + CommandBSBotList(Module *creator) : Command(creator, "botserv/botlist", 0, 0) + { + this->SetDesc(_("Lists available bots")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + unsigned count = 0; + ListFormatter list(source.GetAccount()); + + list.AddColumn(_("Nick")).AddColumn(_("Mask")); + + for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo)) + { + if (source.HasPriv("botserv/administration") || !bi->GetOperOnly()) + { + ++count; + ListFormatter::ListEntry entry; + entry["Nick"] = (bi->GetOperOnly() ? "* " : "") + bi->GetNick(); + entry["Mask"] = bi->GetUser() + "@" + bi->GetHost(); + list.AddEntry(entry); + } + } + + std::vector<Anope::string> replies; + list.Process(replies); + + if (!count) + { + source.Reply(_("There are no bots available")); + return; + } + + source.Reply(_("Bot list:")); + + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + + source.Reply(_("{0} bots available."), count); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + ServiceBot *bi; + Anope::string name; + Command::FindCommandFromService("botserv/assign", bi, name); + if (!bi) + return false; + + source.Reply(_("Lists all available bots. You may use the \002{msg}{service} {assign}\002 command to assign a bot to your channel." + "The bot names are vanity; they all proviate the same commands and features."), + "msg"_kw = Config->StrictPrivmsg, "service"_kw = bi->nick, "assign"_kw = name); + if (source.HasPriv("botserv/administration")) + source.Reply(_("Bots prefixed by a * are reserved for Services Operators with the privilege \002{0}\002."), + "botserv/administration"); + source.Reply(_("\n" + "Example:\n" + " {command} BOTLIST"), + "command"_kw = source.command); + return true; + } +}; + +class BSBotList : public Module +{ + CommandBSBotList commandbsbotlist; + + public: + BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsbotlist(this) + { + + } +}; + +MODULE_INIT(BSBotList) diff --git a/modules/botserv/control.cpp b/modules/botserv/control.cpp new file mode 100644 index 000000000..52c0933c5 --- /dev/null +++ b/modules/botserv/control.cpp @@ -0,0 +1,168 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" + +class CommandBSSay : public Command +{ + public: + CommandBSSay(Module *creator) : Command(creator, "botserv/say", 2, 2) + { + this->SetDesc(_("Makes the bot say the specified text on the specified channel")); + this->SetSyntax(_("\037channel\037 \037text\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &chan = params[0]; + const Anope::string &text = params[1]; + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + return; + } + + if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SAY", ci->GetName()); + return; + } + + if (!ci->GetBot()) + { + source.Reply(_("There is no bot assigned to \002{0}\002. One must be assigned to the channel before this command can be used."), ci->GetName()); + ServiceBot *bi; + Anope::string name; + Command::FindCommandFromService("botserv/assign", bi, name); + CommandInfo *help = source.service->FindCommand("generic/help"); + if (bi && help) + source.Reply(_("See \002{msg}{service} {help} {command}\002 for information on assigning bots."), + "msg"_kw = Config->StrictPrivmsg, "service"_kw = bi->nick, "help"_kw = help->cname, "command"_kw = name); + return; + } + + if (!ci->c || !ci->c->FindUser(ci->GetBot())) + { + source.Reply(_("Bot \002{0}\002 is not on channel \002{1}\002."), ci->GetBot()->nick, ci->GetName()); + return; + } + + if (text[0] == '\001') + { + this->OnSyntaxError(source, ""); + return; + } + + IRCD->SendPrivmsg(ci->GetBot(), ci->GetName(), "%s", text.c_str()); + ci->GetBot()->lastmsg = Anope::CurTime; + + bool override = !source.AccessFor(ci).HasPriv("SAY"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << text; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Makes the bot say the given \037text\037 on \037channel\037.\n" + "\n" + "Example:\n" + " {command} #anope mmm pie\n" + " Makes the assigned service bot say \"mmm pie\".")); + return true; + } +}; + +class CommandBSAct : public Command +{ + public: + CommandBSAct(Module *creator) : Command(creator, "botserv/act", 2, 2) + { + this->SetDesc(_("Makes the bot do the equivalent of a \"/me\" command")); + this->SetSyntax(_("\037channel\037 \037text\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &chan = params[0]; + Anope::string message = params[1]; + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + return; + } + + if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SAY", ci->GetName()); + return; + } + + if (!ci->GetBot()) + { + source.Reply(_("There is no bot assigned to \002{0}\002. One must be assigned to the channel before this command can be used."), ci->GetName()); + ServiceBot *bi; + Anope::string name; + Command::FindCommandFromService("botserv/assign", bi, name); + CommandInfo *help = source.service->FindCommand("generic/help"); + if (bi && help) + source.Reply(_("See \002{msg}{service} {help} {command}\002 for information on assigning bots."), + "msg"_kw = Config->StrictPrivmsg, "service"_kw = bi->nick, "help"_kw = help->cname, "command"_kw = name); + return; + } + + if (!ci->c || !ci->c->FindUser(ci->GetBot())) + { + source.Reply(_("Bot \002{0}\002 is not on channel \002{1}\002."), ci->GetBot()->nick, ci->GetName()); + return; + } + + message = message.replace_all_cs("\1", ""); + if (message.empty()) + return; + + IRCD->SendAction(ci->GetBot(), ci->GetName(), "%s", message.c_str()); + ci->GetBot()->lastmsg = Anope::CurTime; + + bool override = !source.AccessFor(ci).HasPriv("SAY"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << message; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Makes the assigned bot do the equivalent of a \"/me\" command on \037channel\037 using the given \037text\037.\n" + "\n" + "Example:\n" + " {command} #anope slaps Cronus\n" + " Shows the assigned service bot \"slapping\" Cronus."), + "command"_kw = source.command); + return true; + } +}; + +class BSControl : public Module +{ + CommandBSSay commandbssay; + CommandBSAct commandbsact; + + public: + BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbssay(this), commandbsact(this) + { + + } +}; + +MODULE_INIT(BSControl) diff --git a/modules/botserv/info.cpp b/modules/botserv/info.cpp new file mode 100644 index 000000000..6d74c308e --- /dev/null +++ b/modules/botserv/info.cpp @@ -0,0 +1,116 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#include "module.h" +#include "modules/bs_info.h" + +class CommandBSInfo : public Command +{ + EventHandlers<Event::ServiceBotEvent> &onbotinfo; + + public: + CommandBSInfo(Module *creator, EventHandlers<Event::ServiceBotEvent> &event) : Command(creator, "botserv/info", 1, 1), onbotinfo(event) + { + this->SetSyntax(_("{\037channel\037 | \037nickname\037}")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &query = params[0]; + + ServiceBot *bi = ServiceBot::Find(query, true); + ChanServ::Channel *ci = ChanServ::Find(query); + InfoFormatter info(source.nc); + + if (bi) + { + source.Reply(_("Information for bot \002%s\002:"), bi->nick.c_str()); + info[_("Mask")] = bi->GetIdent() + "@" + bi->host; + info[_("Real name")] = bi->realname; + info[_("Created")] = Anope::strftime(bi->bi->GetCreated(), source.GetAccount()); + info[_("Options")] = bi->bi->GetOperOnly() ? _("Private") : _("None"); + info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)"; + + this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); + + std::vector<Anope::string> replies; + info.Process(replies); + + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + + if (source.HasPriv("botserv/administration")) + { + Anope::string buf; + for (ChanServ::Channel *ci2 : bi->GetChannels()) + buf += " " + ci2->GetName(); + source.Reply(buf); + } + + } + else if (ci) + { + if (!source.AccessFor(ci).HasPriv("INFO") && !source.HasPriv("botserv/administration")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "INFO", ci->GetName()); + return; + } + + source.Reply(_("Information for channel \002{0}\002:"), ci->GetName()); + info[_("Bot nick")] = ci->GetBot() ? ci->GetBot()->nick : _("not assigned yet"); + + Anope::string enabled = Language::Translate(source.nc, _("Enabled")); + Anope::string disabled = Language::Translate(source.nc, _("Disabled")); + + this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); + + std::vector<Anope::string> replies; + info.Process(replies); + + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + } + else + source.Reply(_("\002{0}\002 is not a valid bot or registered channel."), query); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Allows you to see {0} information about a channel or a bot." + " If the parameter is a channel, then you'll get information such as enabled kickers." + " If the parameter is a bot nickname, you'll get information about a bot, such as creation time and number of channels it is on."), + source.service->nick); + return true; + } + + const Anope::string GetDesc(CommandSource &source) const override + { + return Anope::printf(Language::Translate(source.GetAccount(), _("Allows you to see %s information about a channel or a bot")), source.service->nick.c_str()); + } +}; + +class BSInfo : public Module +{ + CommandBSInfo commandbsinfo; + EventHandlers<Event::ServiceBotEvent> onbotinfo; + + public: + BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsinfo(this, onbotinfo) + , onbotinfo(this) + { + + } +}; + +MODULE_INIT(BSInfo) diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp new file mode 100644 index 000000000..70ed5b2ad --- /dev/null +++ b/modules/botserv/kick.cpp @@ -0,0 +1,1664 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#include "module.h" +#include "modules/bs_kick.h" +#include "modules/bs_badwords.h" +#include "modules/bs_info.h" + +static Module *me; + +enum TTBType +{ + TTB_BOLDS, + TTB_COLORS, + TTB_REVERSES, + TTB_UNDERLINES, + TTB_BADWORDS, + TTB_CAPS, + TTB_FLOOD, + TTB_REPEAT, + TTB_ITALICS, + TTB_AMSGS, + TTB_SIZE +}; + +class KickerDataImpl : public KickerData +{ + public: + KickerDataImpl(Serialize::TypeBase *type) : KickerData(type) { } + KickerDataImpl(Serialize::TypeBase *type, Serialize::ID id) : KickerData(type, id) { } + + ChanServ::Channel *GetChannel() override; + void SetChannel(ChanServ::Channel *) override; + + bool GetAmsgs() override; + void SetAmsgs(const bool &) override; + + bool GetBadwords() override; + void SetBadwords(const bool &) override; + + bool GetBolds() override; + void SetBolds(const bool &) override; + + bool GetCaps() override; + void SetCaps(const bool &) override; + + bool GetColors() override; + void SetColors(const bool &) override; + + bool GetFlood() override; + void SetFlood(const bool &) override; + + bool GetItalics() override; + void SetItalics(const bool &) override; + + bool GetRepeat() override; + void SetRepeat(const bool &) override; + + bool GetReverses() override; + void SetReverses(const bool &) override; + + bool GetUnderlines() override; + void SetUnderlines(const bool &) override; + + int16_t GetTTBBolds() override; + void SetTTBBolds(const int16_t &) override; + + int16_t GetTTBColors() override; + void SetTTBColors(const int16_t &) override; + + int16_t GetTTBReverses() override; + void SetTTBReverses(const int16_t &) override; + + int16_t GetTTBUnderlines() override; + void SetTTBUnderlines(const int16_t &) override; + + int16_t GetTTBBadwords() override; + void SetTTBBadwords(const int16_t &) override; + + int16_t GetTTBCaps() override; + void SetTTBCaps(const int16_t &) override; + + int16_t GetTTBFlood() override; + void SetTTBFlood(const int16_t &) override; + + int16_t GetTTBRepeat() override; + void SetTTBRepeat(const int16_t &) override; + + int16_t GetTTBItalics() override; + void SetTTBItalics(const int16_t &) override; + + int16_t GetTTBAmsgs() override; + void SetTTBAmsgs(const int16_t &) override; + + int16_t GetCapsMin() override; + void SetCapsMin(const int16_t &) override; + + int16_t GetCapsPercent() override; + void SetCapsPercent(const int16_t &) override; + + int16_t GetFloodLines() override; + void SetFloodLines(const int16_t &) override; + + int16_t GetFloodSecs() override; + void SetFloodSecs(const int16_t &) override; + + int16_t GetRepeatTimes() override; + void SetRepeatTimes(const int16_t &) override; + + bool GetDontKickOps() override; + void SetDontKickOps(const bool &) override; + + bool GetDontKickVoices() override; + void SetDontKickVoices(const bool &) override; +}; + +class KickerDataType : public Serialize::Type<KickerDataImpl> +{ + public: + Serialize::ObjectField<KickerDataImpl, ChanServ::Channel *> channel; + Serialize::Field<KickerDataImpl, bool> amsgs, badwords, bolds, caps, colors, flood, italics, repeat, reverses, underlines; + Serialize::Field<KickerDataImpl, int16_t> ttb_bolds, ttb_colors, ttb_reverses, ttb_underlines, ttb_badwords, ttb_caps, ttb_flood, ttb_repeat, ttb_italics, ttb_amsgs, + capsmin, capspercent, + floodlines, floodsecs, + repeattimes; + Serialize::Field<KickerDataImpl, bool> dontkickops, dontkickvoices; + + KickerDataType(Module *owner) : Serialize::Type<KickerDataImpl>(owner, "KickerData") + , channel(this, "channel", true) + , amsgs(this, "amsgs") + , badwords(this, "badwords") + , bolds(this, "bolds") + , caps(this, "caps") + , colors(this, "colors") + , flood(this, "flood") + , italics(this, "italics") + , repeat(this, "repeat") + , reverses(this, "reverses") + , underlines(this, "underlines") + , ttb_bolds(this, "ttb_bolds") + , ttb_colors(this, "ttb_colors") + , ttb_reverses(this, "ttb_reverses") + , ttb_underlines(this, "ttb_underlines") + , ttb_badwords(this, "ttb_badwords") + , ttb_caps(this, "ttb_caps") + , ttb_flood(this, "ttb_flood") + , ttb_repeat(this, "ttb_repeat") + , ttb_italics(this, "ttb_italics") + , ttb_amsgs(this, "ttb_amsgs") + , capsmin(this, "capsmin") + , capspercent(this, "capspercent") + , floodlines(this, "floodlines") + , floodsecs(this, "floodsecs") + , repeattimes(this, "repeattimes") + , dontkickops(this, "dontkickops") + , dontkickvoices(this, "dontkickvoices") + { + } +}; + +ChanServ::Channel *KickerDataImpl::GetChannel() +{ + return Get(&KickerDataType::channel); +} + +void KickerDataImpl::SetChannel(ChanServ::Channel *channel) +{ + Set(&KickerDataType::amsgs, channel); +} + +bool KickerDataImpl::GetAmsgs() +{ + return Get(&KickerDataType::amsgs); +} + +void KickerDataImpl::SetAmsgs(const bool &b) +{ + Set(&KickerDataType::amsgs, b); +} + +bool KickerDataImpl::GetBadwords() +{ + return Get(&KickerDataType::badwords); +} + +void KickerDataImpl::SetBadwords(const bool &b) +{ + Set(&KickerDataType::badwords, b); +} + +bool KickerDataImpl::GetBolds() +{ + return Get(&KickerDataType::bolds); +} + +void KickerDataImpl::SetBolds(const bool &b) +{ + Set(&KickerDataType::bolds, b); +} + +bool KickerDataImpl::GetCaps() +{ + return Get(&KickerDataType::caps); +} + +void KickerDataImpl::SetCaps(const bool &b) +{ + Set(&KickerDataType::caps, b); +} + +bool KickerDataImpl::GetColors() +{ + return Get(&KickerDataType::colors); +} + +void KickerDataImpl::SetColors(const bool &b) +{ + Set(&KickerDataType::colors, b); +} + +bool KickerDataImpl::GetFlood() +{ + return Get(&KickerDataType::flood); +} + +void KickerDataImpl::SetFlood(const bool &b) +{ + Set(&KickerDataType::flood, b); +} + +bool KickerDataImpl::GetItalics() +{ + return Get(&KickerDataType::italics); +} + +void KickerDataImpl::SetItalics(const bool &b) +{ + Set(&KickerDataType::italics, b); +} + +bool KickerDataImpl::GetRepeat() +{ + return Get(&KickerDataType::repeat); +} + +void KickerDataImpl::SetRepeat(const bool &b) +{ + Set(&KickerDataType::repeat, b); +} + +bool KickerDataImpl::GetReverses() +{ + return Get(&KickerDataType::reverses); +} + +void KickerDataImpl::SetReverses(const bool &b) +{ + Set(&KickerDataType::reverses, b); +} + +bool KickerDataImpl::GetUnderlines() +{ + return Get(&KickerDataType::underlines); +} + +void KickerDataImpl::SetUnderlines(const bool &b) +{ + Set(&KickerDataType::underlines, b); +} + +int16_t KickerDataImpl::GetTTBBolds() +{ + return Get(&KickerDataType::ttb_bolds); +} + +void KickerDataImpl::SetTTBBolds(const int16_t &i) +{ + Set(&KickerDataType::ttb_bolds, i); +} + +int16_t KickerDataImpl::GetTTBColors() +{ + return Get(&KickerDataType::ttb_colors); +} + +void KickerDataImpl::SetTTBColors(const int16_t &i) +{ + Set(&KickerDataType::ttb_colors, i); +} + +int16_t KickerDataImpl::GetTTBReverses() +{ + return Get(&KickerDataType::ttb_reverses); +} + +void KickerDataImpl::SetTTBReverses(const int16_t &i) +{ + Set(&KickerDataType::ttb_reverses, i); +} + +int16_t KickerDataImpl::GetTTBUnderlines() +{ + return Get(&KickerDataType::ttb_underlines); +} + +void KickerDataImpl::SetTTBUnderlines(const int16_t &i) +{ + Set(&KickerDataType::ttb_underlines, i); +} + +int16_t KickerDataImpl::GetTTBBadwords() +{ + return Get(&KickerDataType::ttb_badwords); +} + +void KickerDataImpl::SetTTBBadwords(const int16_t &i) +{ + Set(&KickerDataType::ttb_badwords, i); +} + +int16_t KickerDataImpl::GetTTBCaps() +{ + return Get(&KickerDataType::ttb_caps); +} + +void KickerDataImpl::SetTTBCaps(const int16_t &i) +{ + Set(&KickerDataType::ttb_caps, i); +} + +int16_t KickerDataImpl::GetTTBFlood() +{ + return Get(&KickerDataType::ttb_flood); +} + +void KickerDataImpl::SetTTBFlood(const int16_t &i) +{ + Set(&KickerDataType::ttb_flood, i); +} + +int16_t KickerDataImpl::GetTTBRepeat() +{ + return Get(&KickerDataType::ttb_repeat); +} + +void KickerDataImpl::SetTTBRepeat(const int16_t &i) +{ + Set(&KickerDataType::ttb_repeat, i); +} + +int16_t KickerDataImpl::GetTTBItalics() +{ + return Get(&KickerDataType::ttb_italics); +} + +void KickerDataImpl::SetTTBItalics(const int16_t &i) +{ + Set(&KickerDataType::ttb_italics, i); +} + +int16_t KickerDataImpl::GetTTBAmsgs() +{ + return Get(&KickerDataType::ttb_amsgs); +} + +void KickerDataImpl::SetTTBAmsgs(const int16_t &i) +{ + Set(&KickerDataType::ttb_amsgs, i); +} + +int16_t KickerDataImpl::GetCapsMin() +{ + return Get(&KickerDataType::capsmin); +} + +void KickerDataImpl::SetCapsMin(const int16_t &i) +{ + Set(&KickerDataType::capsmin, i); +} + +int16_t KickerDataImpl::GetCapsPercent() +{ + return Get(&KickerDataType::capspercent); +} + +void KickerDataImpl::SetCapsPercent(const int16_t &i) +{ + Set(&KickerDataType::capspercent, i); +} + +int16_t KickerDataImpl::GetFloodLines() +{ + return Get(&KickerDataType::floodlines); +} + +void KickerDataImpl::SetFloodLines(const int16_t &i) +{ + Set(&KickerDataType::floodlines, i); +} + +int16_t KickerDataImpl::GetFloodSecs() +{ + return Get(&KickerDataType::floodsecs); +} + +void KickerDataImpl::SetFloodSecs(const int16_t &i) +{ + Set(&KickerDataType::floodsecs, i); +} + +int16_t KickerDataImpl::GetRepeatTimes() +{ + return Get(&KickerDataType::repeattimes); +} + +void KickerDataImpl::SetRepeatTimes(const int16_t &i) +{ + Set(&KickerDataType::repeattimes, i); +} + +bool KickerDataImpl::GetDontKickOps() +{ + return Get(&KickerDataType::dontkickops); +} + +void KickerDataImpl::SetDontKickOps(const bool &b) +{ + Set(&KickerDataType::dontkickops, b); +} + +bool KickerDataImpl::GetDontKickVoices() +{ + return Get(&KickerDataType::dontkickvoices); +} + +void KickerDataImpl::SetDontKickVoices(const bool &b) +{ + Set(&KickerDataType::dontkickvoices, b); +} + +class CommandBSKick : public Command +{ + public: + CommandBSKick(Module *creator) : Command(creator, "botserv/kick", 0) + { + this->SetDesc(_("Configures kickers")); + this->SetSyntax(_("\037option\037 \037channel\037 {\037ON|OFF\037} [\037settings\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + this->OnSyntaxError(source, ""); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Configures bot kickers." + " Use of this command requires the \002SET\002 privilege on \037channel\037.\n" + "\n" + "Available kickers:")); + + Anope::string this_name = source.command; + for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + { + const Anope::string &c_name = it->first; + const CommandInfo &info = it->second; + + if (c_name.find_ci(this_name + " ") == 0) + { + ServiceReference<Command> command("Command", info.name); + if (command) + { + source.command = c_name; + command->OnServHelp(source); + } + } + } + + CommandInfo *help = source.service->FindCommand("generic/help"); + if (help) + source.Reply(_("See \002{0}{1} {2} {3} \037option\037\002 for more information on a specific option."), + Config->StrictPrivmsg, source.service->nick, help->cname, this_name); + + return true; + } +}; + +class CommandBSKickBase : public Command +{ + public: + CommandBSKickBase(Module *creator, const Anope::string &cname, int minarg, int maxarg) : Command(creator, cname, minarg, maxarg) + { + } + + virtual void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override anope_abstract; + + virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand) override anope_abstract; + + protected: + bool CheckArguments(CommandSource &source, const std::vector<Anope::string> ¶ms, ChanServ::Channel* &ci) + { + const Anope::string &chan = params[0]; + const Anope::string &option = params[1]; + + ci = ChanServ::Find(chan); + + if (Anope::ReadOnly) + source.Reply(_("Sorry, kicker configuration is temporarily disabled.")); + else if (ci == NULL) + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + else if (option.empty()) + this->OnSyntaxError(source, ""); + else if (!option.equals_ci("ON") && !option.equals_ci("OFF")) + this->OnSyntaxError(source, ""); + else if (!source.AccessFor(ci).HasPriv("SET") && !source.HasPriv("botserv/administration")) + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); + else if (!ci->GetBot()) + source.Reply(_("There is no bot assigned to \002{0}\002."), ci->GetName()); + else + return true; + + return false; + } + + bool CheckTTB(CommandSource &source, const Anope::string &ttb, int16_t &i) + { + i = 0; + if (ttb.empty()) + return true; + + try + { + i = convertTo<int16_t>(ttb); + if (i < 0) + throw ConvertException(); + } + catch (const ConvertException &) + { + i = 0; + source.Reply(_("\002{0}\002 can not be taken as times to ban. Times to ban must be a positive integer."), ttb); + return false; + } + + return true; + } + + void Process(CommandSource &source, ChanServ::Channel *ci, const Anope::string ¶m, const Anope::string &ttb, void (KickerData::*setter)(const bool &), void (KickerData::*ttbsetter)(const int16_t &), const Anope::string &optname) + { + KickerData *kd = ci->GetRef<KickerData *>(kickerdata); + + if (param.equals_ci("ON")) + { + int16_t i; + if (!CheckTTB(source, ttb, i)) + return; + + (kd->*setter)(true); + (kd->*ttbsetter)(i); + + if (i) + source.Reply(_("Bot will now kick for \002{0}\002, and will place a ban after \002{1}\002 kicks for the same user."), optname, i); + else + source.Reply(_("Bot will now kick for \002{0}\002."), optname); + + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable the " << optname << " kicker"; + } + else if (param.equals_ci("OFF")) + { + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable the " << optname << " kicker"; + + (kd->*setter)(false); + (kd->*ttbsetter)(0); + + source.Reply(_("Bot won't kick for \002{0}\002 anymore."), optname); + } + else + this->OnSyntaxError(source, ""); + } +}; + +class CommandBSKickAMSG : public CommandBSKickBase +{ + public: + CommandBSKickAMSG(Module *creator) : CommandBSKickBase(creator, "botserv/kick/amsg", 2, 3) + { + this->SetDesc(_("Configures AMSG kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (CheckArguments(source, params, ci)) + Process(source, ci, params[1], params.size() > 2 ? params[2] : "", &KickerData::SetAmsgs, &KickerData::SetTTBAmsgs, "amsgs"); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the AMSG kicker on or off on \037channel\037. When enabled, the bot will kick users who send the same message to multiple channels where {0} bots are.\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system."), + source.service->nick); + return true; + } +}; + +class CommandBSKickBadwords : public CommandBSKickBase +{ + public: + CommandBSKickBadwords(Module *creator) : CommandBSKickBase(creator, "botserv/kick/badwords", 2, 3) + { + this->SetDesc(_("Configures badwords kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (CheckArguments(source, params, ci)) + Process(source, ci, params[1], params.size() > 2 ? params[2] : "", &KickerData::SetBadwords, &KickerData::SetTTBBadwords, "badwords"); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + ServiceBot *bi; + Anope::string name; + CommandInfo *help; + source.Reply(_("Sets the bad words kicker on or off on \037channel\037. When enabled, the bot will kick users who say certain words on the channel.")); + if (Command::FindCommandFromService("botserv/badwords", bi, name) && (help = bi->FindCommand("generic/help"))) + source.Reply(_("You can define bad words for your channel using the \002{0}\002 command. See \002{1}{2} {3} {4}\002 for more information."), + name, Config->StrictPrivmsg, bi->nick, help->cname, name); + source.Reply(_("\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickBolds : public CommandBSKickBase +{ + public: + CommandBSKickBolds(Module *creator) : CommandBSKickBase(creator, "botserv/kick/bolds", 2, 3) + { + this->SetDesc(_("Configures bolds kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (CheckArguments(source, params, ci)) + Process(source, ci, params[1], params.size() > 2 ? params[2] : "", &KickerData::SetBolds, &KickerData::SetTTBBolds, "bolds"); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the bolds kicker on or off on \037channel\037. When enabled, the bot will kick users who use \002bolds\002.\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickCaps : public CommandBSKickBase +{ + public: + CommandBSKickCaps(Module *creator) : CommandBSKickBase(creator, "botserv/kick/caps", 2, 5) + { + this->SetDesc(_("Configures caps kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037 [\037min\037 [\037percent\037]]]\002")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (!CheckArguments(source, params, ci)) + return; + + KickerData *kd = GetKickerData(ci); + + if (params[1].equals_ci("ON")) + { + const Anope::string &ttb = params.size() > 2 ? params[2] : "", + &min = params.size() > 3 ? params[3] : "", + &percent = params.size() > 4 ? params[4] : ""; + + int16_t i; + if (!CheckTTB(source, ttb, i)) + return; + + kd->SetCaps(true); + kd->SetTTBCaps(i); + + kd->SetCapsMin(10); + try + { + kd->SetCapsMin(convertTo<int16_t>(min)); + } + catch (const ConvertException &) { } + if (kd->GetCapsMin() < 1) + kd->SetCapsMin(10); + + try + { + kd->SetCapsPercent(convertTo<int16_t>(percent)); + } + catch (const ConvertException &) { } + if (kd->GetCapsPercent() < 1 || kd->GetCapsPercent() > 100) + kd->SetCapsPercent(25); + + if (i) + source.Reply(_("Bot will now kick for \002caps\002 if they constitute at least {0} characters and {1}% of the entire message, and will place a ban after {2} kicks for the same user."), kd->GetCapsMin(), kd->GetCapsPercent(), i); + else + source.Reply(_("Bot will now kick for \002caps\002 if they constitute at least {0} characters and {1}% of the entire message."), kd->GetCapsMin(), kd->GetCapsPercent()); + } + else + { + kd->SetCaps(false); + kd->SetTTBCaps(0); + kd->SetCapsMin(0); + kd->SetCapsPercent(0); + source.Reply(_("Bot won't kick for \002caps\002 anymore.")); + } + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the caps kicker on or off on \037channel\037. When enabled, the bot will kick users who talk in CAPS." + " The bot kicks only if there are at least \002min\002 caps and they constitute at least \002percent\002% of the total text line." + " (if not given, it defaults to 10 characters and 25%).\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickColors : public CommandBSKickBase +{ + public: + CommandBSKickColors(Module *creator) : CommandBSKickBase(creator, "botserv/kick/colors", 2, 3) + { + this->SetDesc(_("Configures color kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (CheckArguments(source, params, ci)) + Process(source, ci, params[1], params.size() > 2 ? params[2] : "", &KickerData::SetColors, &KickerData::SetTTBColors, "colors"); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the colors kicker on or off on \037channel\037. When enabled, the bot will kick users who use \00304c\00307o\00308l\00303o\00306r\00312s\017.\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickFlood : public CommandBSKickBase +{ + public: + CommandBSKickFlood(Module *creator) : CommandBSKickBase(creator, "botserv/kick/flood", 2, 5) + { + this->SetDesc(_("Configures flood kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037 [\037lines\037 [\037seconds\037]]]\002")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (!CheckArguments(source, params, ci)) + return; + + KickerData *kd = GetKickerData(ci); + + if (params[1].equals_ci("ON")) + { + const Anope::string &ttb = params.size() > 2 ? params[2] : "", + &lines = params.size() > 3 ? params[3] : "", + &secs = params.size() > 4 ? params[4] : ""; + + int16_t i; + if (!CheckTTB(source, ttb, i)) + return; + + kd->SetFlood(true); + kd->SetTTBFlood(i); + + kd->SetFloodLines(6); + try + { + kd->SetFloodLines(convertTo<int16_t>(lines)); + } + catch (const ConvertException &) { } + if (kd->GetFloodLines() < 2) + kd->SetFloodLines(6); + + kd->SetFloodSecs(10); + try + { + kd->SetFloodSecs(convertTo<int16_t>(secs)); + } + catch (const ConvertException &) { } + if (kd->GetFloodSecs() < 1) + kd->SetFloodSecs(10); + if (kd->GetFloodSecs() > Config->GetModule(me)->Get<time_t>("keepdata")) + kd->SetFloodSecs(Config->GetModule(me)->Get<time_t>("keepdata")); + + if (i) + source.Reply(_("Bot will now kick for \002flood\002 ({0} lines in {1} seconds and will place a ban after {2} kicks for the same user."), kd->GetFloodLines(), kd->GetFloodSecs(), i); + else + source.Reply(_("Bot will now kick for \002flood\002 ({0} lines in {1} seconds)."), kd->GetFloodLines(), kd->GetFloodSecs()); + } + else if (params[1].equals_ci("OFF")) + { + kd->SetFlood(false); + kd->SetFloodLines(0); + kd->SetFloodSecs(0); + source.Reply(_("Bot won't kick for \002flood\002 anymore.")); + } + else + this->OnSyntaxError(source, params[1]); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the flood kicker on or off on \037channel\037. When enabled, the bot to kick users who are flooding the channel with at least \037lines\037 lines in \037seconds\037 seconds. If not given, it defaults to 6 lines in 10 seconds.\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickItalics : public CommandBSKickBase +{ + public: + CommandBSKickItalics(Module *creator) : CommandBSKickBase(creator, "botserv/kick/italics", 2, 3) + { + this->SetDesc(_("Configures italics kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (CheckArguments(source, params, ci)) + Process(source, ci, params[1], params.size() > 2 ? params[2] : "", &KickerData::SetItalics, &KickerData::SetTTBItalics, "itlaics"); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the italics kicker on or off on \037channel\037. When enabled, the bot will kick users who use \035italics\035." + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickRepeat : public CommandBSKickBase +{ + public: + CommandBSKickRepeat(Module *creator) : CommandBSKickBase(creator, "botserv/kick/repeat", 2, 4) + { + this->SetDesc(_("Configures repeat kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037 [\037num\037]]\002")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (!CheckArguments(source, params, ci)) + return; + + KickerData *kd = GetKickerData(ci); + + if (params[1].equals_ci("ON")) + { + const Anope::string &ttb = params.size() > 2 ? params[2] : "", + × = params.size() > 3 ? params[3] : ""; + + int16_t i; + if (!CheckTTB(source, ttb, i)) + return; + + kd->SetRepeat(true); + kd->SetTTBRepeat(i); + kd->SetRepeatTimes(3); + try + { + kd->SetRepeatTimes(convertTo<int16_t>(times)); + } + catch (const ConvertException &) { } + if (kd->GetRepeatTimes() < 2) + kd->SetRepeatTimes(3); + + if (i) + source.Reply(_("Bot will now kick for \002repeats\002 (users that say the same thing {0} times), and will place a ban after {1} kicks for the same user."), kd->GetRepeatTimes(), i); + else + source.Reply(_("Bot will now kick for \002repeats\002 (users that say the same thing {0} times)."), kd->GetRepeatTimes() + 1); + } + else if (params[1].equals_ci("OFF")) + { + kd->SetRepeat(false); + kd->SetTTBRepeat(0); + kd->SetRepeatTimes(0); + source.Reply(_("Bot won't kick for \002repeats\002 anymore.")); + } + else + this->OnSyntaxError(source, params[1]); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the repeat kicker on or off. When enabled, the bot will kick users who repeat themselves \037num\037 times. If \037num\037 is not given, it defaults to 3.\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickReverses : public CommandBSKickBase +{ + public: + CommandBSKickReverses(Module *creator) : CommandBSKickBase(creator, "botserv/kick/reverses", 2, 3) + { + this->SetDesc(_("Configures reverses kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (CheckArguments(source, params, ci)) + Process(source, ci, params[1], params.size() > 2 ? params[2] : "", &KickerData::SetReverses, &KickerData::SetTTBReverses, "reverses"); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the reverses kicker on or off. When enabled, the bot will kick users who use \026reverses\026.\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSKickUnderlines : public CommandBSKickBase +{ + public: + CommandBSKickUnderlines(Module *creator) : CommandBSKickBase(creator, "botserv/kick/underlines", 2, 3) + { + this->SetDesc(_("Configures underlines kicker")); + this->SetSyntax(_("\037channel\037 {\037ON|OFF\037} [\037ttb\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci; + if (CheckArguments(source, params, ci)) + Process(source, ci, params[1], params.size() > 2 ? params[2] : "", &KickerData::SetUnderlines, &KickerData::SetTTBUnderlines, "underlines"); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the underlines kicker on or off. When enabled, the bot will kick users who use \037underlines\037\n" + "\n" + "\037ttb\037 is the number of times a user can be kicked before they get banned. Don't give ttb to disable the ban system.")); + return true; + } +}; + +class CommandBSSetDontKickOps : public Command +{ + public: + CommandBSSetDontKickOps(Module *creator, const Anope::string &sname = "botserv/set/dontkickops") : Command(creator, sname, 2, 2) + { + this->SetDesc(_("To protect ops against bot kicks")); + this->SetSyntax(_("\037channel\037 {ON | OFF}")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci = ChanServ::Find(params[0]); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), params[0]); + return; + } + + ChanServ::AccessGroup access = source.AccessFor(ci); + if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); + return; + } + + if (Anope::ReadOnly) + { + source.Reply(_("Sorry, bot option setting is temporarily disabled.")); + return; + } + + KickerData *kd = GetKickerData(ci); + + if (params[1].equals_ci("ON")) + { + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickops"; + + kd->SetDontKickOps(true); + source.Reply(_("Bot \002won't kick ops\002 on channel \002{0}\002."), ci->GetName()); + } + else if (params[1].equals_ci("OFF")) + { + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickops"; + + kd->SetDontKickOps(false); + source.Reply(_("Bot \002will kick ops\002 on channel \002{0}\002."), ci->GetName()); + } + else + this->OnSyntaxError(source, source.command); + } + + bool OnHelp(CommandSource &source, const Anope::string &) override + { + source.Reply(_("Enables or disables \002op protection\002 mode on a channel." + " When it is enabled, ops won't be kicked by the bot, even if they don't have the \002{0}\002 privilege.\n" + "\n" + "Use of this command requires the \002{1}\002 privilege on \037channel\037."), + "NOKICK", "SET"); + return true; + } +}; + +class CommandBSSetDontKickVoices : public Command +{ + public: + CommandBSSetDontKickVoices(Module *creator, const Anope::string &sname = "botserv/set/dontkickvoices") : Command(creator, sname, 2, 2) + { + this->SetDesc(_("To protect voices against bot kicks")); + this->SetSyntax(_("\037channel\037 {ON | OFF}")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + ChanServ::Channel *ci = ChanServ::Find(params[0]); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), params[0]); + return; + } + + ChanServ::AccessGroup access = source.AccessFor(ci); + if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); + return; + } + + if (Anope::ReadOnly) + { + source.Reply(_("Sorry, bot option setting is temporarily disabled.")); + return; + } + + KickerData *kd = GetKickerData(ci); + + if (params[1].equals_ci("ON")) + { + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickvoices"; + + kd->SetDontKickVoices(true); + source.Reply(_("Bot \002won't kick voices\002 on channel %s."), ci->GetName().c_str()); + } + else if (params[1].equals_ci("OFF")) + { + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickvoices"; + + kd->SetDontKickVoices(false); + source.Reply(_("Bot \002will kick voices\002 on channel %s."), ci->GetName().c_str()); + } + else + this->OnSyntaxError(source, source.command); + } + + bool OnHelp(CommandSource &source, const Anope::string &) override + { + source.Reply(_("Enables or disables \002voice protection\002 mode on a channel." + " When it is enabled, ops won't be kicked by the bot, even if they don't have the \002{0}\002 privilege.\n" + "\n" + "Use of this command requires the \002{1}\002 privilege on \037channel\037."), + "NOKICK", "SET"); + return true; + } +}; + +struct BanData +{ + struct Data + { + Anope::string mask; + time_t last_use; + int16_t ttb[TTB_SIZE]; + + Data() + { + last_use = 0; + for (int i = 0; i < TTB_SIZE; ++i) + this->ttb[i] = 0; + } + }; + + private: + typedef Anope::map<Data> data_type; + data_type data_map; + + public: + Data &get(const Anope::string &key) + { + return this->data_map[key]; + } + + bool empty() const + { + return this->data_map.empty(); + } + + void purge() + { + time_t keepdata = Config->GetModule(me)->Get<time_t>("keepdata"); + for (data_type::iterator it = data_map.begin(), it_end = data_map.end(); it != it_end;) + { + const Anope::string &user = it->first; + Data &bd = it->second; + ++it; + + if (Anope::CurTime - bd.last_use > keepdata) + data_map.erase(user); + } + } +}; + +struct UserData +{ + UserData() + { + last_use = last_start = Anope::CurTime; + } + + /* Data validity */ + time_t last_use; + + /* for flood kicker */ + int16_t lines = 0; + time_t last_start; + + /* for repeat kicker */ + Anope::string lasttarget; + int16_t times = 0; + + Anope::string lastline; +}; + +class BanDataPurger : public Timer +{ + public: + BanDataPurger(Module *o) : Timer(o, 300, Anope::CurTime, true) { } + + void Tick(time_t) override + { + Log(LOG_DEBUG) << "bs_main: Running bandata purger"; + + for (channel_map::iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) + { + Channel *c = it->second; + + BanData *bd = c->GetExt<BanData>("bandata"); + if (bd != NULL) + { + bd->purge(); + if (bd->empty()) + c->ShrinkOK<BanData>("bandata"); + } + } + } +}; + +class BSKick : public Module + , public EventHook<Event::ServiceBotEvent> + , public EventHook<Event::Privmsg> +{ + ExtensibleItem<BanData> bandata; + ExtensibleItem<UserData> userdata; + + KickerDataType kdtype; + + CommandBSKick commandbskick; + CommandBSKickAMSG commandbskickamsg; + CommandBSKickBadwords commandbskickbadwords; + CommandBSKickBolds commandbskickbolds; + CommandBSKickCaps commandbskickcaps; + CommandBSKickColors commandbskickcolors; + CommandBSKickFlood commandbskickflood; + CommandBSKickItalics commandbskickitalics; + CommandBSKickRepeat commandbskickrepeat; + CommandBSKickReverses commandbskickreverse; + CommandBSKickUnderlines commandbskickunderlines; + + CommandBSSetDontKickOps commandbssetdontkickops; + CommandBSSetDontKickVoices commandbssetdontkickvoices; + + BanDataPurger purger; + + EventHandlers<Event::BotBan> onbotban; + + BanData::Data &GetBanData(User *u, Channel *c) + { + BanData *bd = bandata.Require(c); + return bd->get(u->GetMask()); + } + + UserData *GetUserData(User *u, Channel *c) + { + ChanUserContainer *uc = c->FindUser(u); + if (uc == nullptr) + return nullptr; + + return userdata.Require(uc); + } + + void TakeAction(ChanServ::Channel *ci, User *u, int ttb, TTBType ttbtype, const char *message, ...) + { + /* Don't ban ulines or protected users */ + if (u->IsProtected()) + return; + + BanData::Data &bd = this->GetBanData(u, ci->c); + + ++bd.ttb[ttbtype]; + if (ttb && bd.ttb[ttbtype] >= ttb) + { + bd.ttb[ttbtype] = 0; + + Anope::string mask = ci->GetIdealBan(u); + + ci->c->SetMode(NULL, "BAN", mask); + this->onbotban(&Event::BotBan::OnBotBan, u, ci, mask); + } + + if (!ci->c->FindUser(u)) + return; + + va_list args; + char buf[1024]; + + Anope::string fmt = Language::Translate(u, message); + va_start(args, message); + vsnprintf(buf, sizeof(buf), fmt.c_str(), args); + va_end(args); + + ci->c->Kick(ci->GetBot(), u, "%s", buf); + } + + public: + BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , bandata(this, "bandata") + , userdata(this, "userdata") + + , kdtype(this) + + , commandbskick(this) + , commandbskickamsg(this) + , commandbskickbadwords(this) + , commandbskickbolds(this) + , commandbskickcaps(this) + , commandbskickcolors(this) + , commandbskickflood(this) + , commandbskickitalics(this) + , commandbskickrepeat(this) + , commandbskickreverse(this) + , commandbskickunderlines(this) + + , commandbssetdontkickops(this) + , commandbssetdontkickvoices(this) + + , purger(this) + + , onbotban(this) + { + me = this; + } + + void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override + { + if (!ci) + return; + + Anope::string enabled = Language::Translate(source.nc, _("Enabled")); + Anope::string disabled = Language::Translate(source.nc, _("Disabled")); + KickerData *kd = ci->GetRef<KickerData *>(&kdtype); + + if (kd && kd->GetBadwords()) + { + if (kd->GetTTBBadwords()) + info[_("Bad words kicker")] = Anope::printf("%s (%d kick(s) to ban)", enabled.c_str(), kd->GetBadwords()); + else + info[_("Bad words kicker")] = enabled; + } + else + info[_("Bad words kicker")] = disabled; + + if (kd && kd->GetBolds()) + { + if (kd->GetTTBBolds()) + info[_("Bolds kicker")] = Anope::printf("%s (%d kick(s) to ban)", enabled.c_str(), kd->GetTTBBolds()); + else + info[_("Bolds kicker")] = enabled; + } + else + info[_("Bolds kicker")] = disabled; + + if (kd && kd->GetCaps()) + { + if (kd->GetTTBCaps()) + info[_("Caps kicker")] = Anope::printf(_("%s (%d kick(s) to ban; minimum %d/%d%%)"), enabled.c_str(), kd->GetTTBCaps(), kd->GetCapsMin(), kd->GetCapsPercent()); + else + info[_("Caps kicker")] = Anope::printf(_("%s (minimum %d/%d%%)"), enabled.c_str(), kd->GetCapsMin(), kd->GetCapsPercent()); + } + else + info[_("Caps kicker")] = disabled; + + if (kd && kd->GetColors()) + { + if (kd->GetTTBColors()) + info[_("Colors kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), kd->GetTTBColors()); + else + info[_("Colors kicker")] = enabled; + } + else + info[_("Colors kicker")] = disabled; + + if (kd && kd->GetFlood()) + { + if (kd->GetTTBFlood()) + info[_("Flood kicker")] = Anope::printf(_("%s (%d kick(s) to ban; %d lines in %ds)"), enabled.c_str(), kd->GetTTBFlood(), kd->GetFloodLines(), kd->GetFloodSecs()); + else + info[_("Flood kicker")] = Anope::printf(_("%s (%d lines in %ds)"), enabled.c_str(), kd->GetFloodLines(), kd->GetFloodSecs()); + } + else + info[_("Flood kicker")] = disabled; + + if (kd && kd->GetRepeat()) + { + if (kd->GetTTBRepeat()) + info[_("Repeat kicker")] = Anope::printf(_("%s (%d kick(s) to ban; %d times)"), enabled.c_str(), kd->GetTTBRepeat(), kd->GetRepeatTimes()); + else + info[_("Repeat kicker")] = Anope::printf(_("%s (%d times)"), enabled.c_str(), kd->GetRepeatTimes()); + } + else + info[_("Repeat kicker")] = disabled; + + if (kd && kd->GetReverses()) + { + if (kd->GetTTBReverses()) + info[_("Reverses kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), kd->GetTTBReverses()); + else + info[_("Reverses kicker")] = enabled; + } + else + info[_("Reverses kicker")] = disabled; + + if (kd && kd->GetUnderlines()) + { + if (kd->GetTTBUnderlines()) + info[_("Underlines kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), kd->GetTTBUnderlines()); + else + info[_("Underlines kicker")] = enabled; + } + else + info[_("Underlines kicker")] = disabled; + + if (kd && kd->GetItalics()) + { + if (kd->GetTTBItalics()) + info[_("Italics kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), kd->GetTTBItalics()); + else + info[_("Italics kicker")] = enabled; + } + else + info[_("Italics kicker")] = disabled; + + if (kd && kd->GetAmsgs()) + { + if (kd->GetTTBAmsgs()) + info[_("AMSG kicker")] = Anope::printf(_("%s (%d kick(s) to ban)"), enabled.c_str(), kd->GetTTBAmsgs()); + else + info[_("AMSG kicker")] = enabled; + } + else + info[_("AMSG kicker")] = disabled; + + if (kd && kd->GetDontKickOps()) + info.AddOption(_("Ops protection")); + if (kd && kd->GetDontKickVoices()) + info.AddOption(_("Voices protection")); + } + + void OnPrivmsg(User *u, Channel *c, Anope::string &msg) override + { + /* Now we can make kicker stuff. We try to order the checks + * from the fastest one to the slowest one, since there's + * no need to process other kickers if a user is kicked before + * the last kicker check. + * + * But FIRST we check whether the user is protected in any + * way. + */ + ChanServ::Channel *ci = c->ci; + if (ci == NULL) + return; + KickerData *kd = c->ci->GetRef<KickerData *>(&kdtype); + if (kd == NULL) + return; + + if (ci->AccessFor(u).HasPriv("NOKICK")) + return; + if (kd->GetDontKickOps() && (c->HasUserStatus(u, "HALFOP") || c->HasUserStatus(u, "OP") || c->HasUserStatus(u, "PROTECT") || c->HasUserStatus(u, "OWNER"))) + return; + if (kd->GetDontKickVoices() && c->HasUserStatus(u, "VOICE")) + return; + + Anope::string realbuf = msg; + + /* If it's a /me, cut the CTCP part because the ACTION will cause + * problems with the caps or badwords kicker + */ + if (realbuf.substr(0, 8).equals_ci("\1ACTION ") && realbuf[realbuf.length() - 1] == '\1') + { + realbuf.erase(0, 8); + realbuf.erase(realbuf.length() - 1); + } + + if (realbuf.empty()) + return; + + /* Bolds kicker */ + if (kd->GetBolds() && realbuf.find(2) != Anope::string::npos) + { + TakeAction(ci, u, kd->GetTTBBolds(), TTB_BOLDS, _("Don't use bolds on this channel!")); + return; + } + + /* Color kicker */ + if (kd->GetColors() && realbuf.find(3) != Anope::string::npos) + { + TakeAction(ci, u, kd->GetTTBColors(), TTB_COLORS, _("Don't use colors on this channel!")); + return; + } + + /* Reverses kicker */ + if (kd->GetReverses() && realbuf.find(22) != Anope::string::npos) + { + TakeAction(ci, u, kd->GetTTBReverses(), TTB_REVERSES, _("Don't use reverses on this channel!")); + return; + } + + /* Italics kicker */ + if (kd->GetItalics() && realbuf.find(29) != Anope::string::npos) + { + TakeAction(ci, u, kd->GetTTBItalics(), TTB_ITALICS, _("Don't use italics on this channel!")); + return; + } + + /* Underlines kicker */ + if (kd->GetUnderlines() && realbuf.find(31) != Anope::string::npos) + { + TakeAction(ci, u, kd->GetTTBUnderlines(), TTB_UNDERLINES, _("Don't use underlines on this channel!")); + return; + } + + /* Caps kicker */ + if (kd->GetCaps() && realbuf.length() >= static_cast<unsigned>(kd->GetCapsMin())) + { + int i = 0, l = 0; + + for (unsigned j = 0, end = realbuf.length(); j < end; ++j) + { + if (isupper(realbuf[j])) + ++i; + else if (islower(realbuf[j])) + ++l; + } + + /* i counts uppercase chars, l counts lowercase chars. Only + * alphabetic chars (so islower || isupper) qualify for the + * percentage of caps to kick for; the rest is ignored. -GD + */ + + if ((i || l) && i >= kd->GetCapsMin() && i * 100 / (i + l) >= kd->GetCapsPercent()) + { + TakeAction(ci, u, kd->GetTTBCaps(), TTB_CAPS, _("Turn caps lock OFF!")); + return; + } + } + + /* Bad words kicker */ + if (kd->GetBadwords()) + { + bool mustkick = false; + + /* Normalize the buffer */ + Anope::string nbuf = Anope::NormalizeBuffer(realbuf); + bool casesensitive = Config->GetModule("botserv")->Get<bool>("casesensitive"); + + /* Normalize can return an empty string if this only conains control codes etc */ + if (badwords && !nbuf.empty()) + for (unsigned i = 0; i < badwords->GetBadWordCount(ci); ++i) + { + BadWord *bw = badwords->GetBadWord(ci, i); + + if (bw->GetWord().empty()) + continue; // Shouldn't happen + + if (bw->GetWord().length() > nbuf.length()) + continue; // This can't ever match + + if (bw->GetType() == BW_ANY && ((casesensitive && nbuf.find(bw->GetWord()) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(bw->GetWord()) != Anope::string::npos))) + mustkick = true; + else if (bw->GetType() == BW_SINGLE) + { + size_t len = bw->GetWord().length(); + + if ((casesensitive && bw->GetWord().equals_cs(nbuf)) || (!casesensitive && bw->GetWord().equals_ci(nbuf))) + mustkick = true; + else if (nbuf.find(' ') == len && ((casesensitive && bw->GetWord().equals_cs(nbuf.substr(0, len))) || (!casesensitive && bw->GetWord().equals_ci(nbuf.substr(0, len))))) + mustkick = true; + else + { + if (len < nbuf.length() && nbuf.rfind(' ') == nbuf.length() - len - 1 && ((casesensitive && nbuf.find(bw->GetWord()) == nbuf.length() - len) || (!casesensitive && nbuf.find_ci(bw->GetWord()) == nbuf.length() - len))) + mustkick = true; + else + { + Anope::string wordbuf = " " + bw->GetWord() + " "; + + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + mustkick = true; + } + } + } + else if (bw->GetType() == BW_START) + { + size_t len = bw->GetWord().length(); + + if ((casesensitive && nbuf.substr(0, len).equals_cs(bw->GetWord())) || (!casesensitive && nbuf.substr(0, len).equals_ci(bw->GetWord()))) + mustkick = true; + else + { + Anope::string wordbuf = " " + bw->GetWord(); + + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + mustkick = true; + } + } + else if (bw->GetType() == BW_END) + { + size_t len = bw->GetWord().length(); + + if ((casesensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->GetWord())) || (!casesensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->GetWord()))) + mustkick = true; + else + { + Anope::string wordbuf = bw->GetWord() + " "; + + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + mustkick = true; + } + } + + if (mustkick) + { + if (Config->GetModule(me)->Get<bool>("gentlebadwordreason")) + TakeAction(ci, u, kd->GetTTBBadwords(), TTB_BADWORDS, _("Watch your language!")); + else + TakeAction(ci, u, kd->GetTTBBadwords(), TTB_BADWORDS, _("Don't use the word \"%s\" on this channel!"), bw->GetWord().c_str()); + + return; + } + } /* for */ + } /* if badwords */ + + UserData *ud = GetUserData(u, c); + + if (ud) + { + /* Flood kicker */ + if (kd->GetFlood()) + { + if (Anope::CurTime - ud->last_start > kd->GetFloodSecs()) + { + ud->last_start = Anope::CurTime; + ud->lines = 0; + } + + ++ud->lines; + if (ud->lines >= kd->GetFloodLines()) + { + TakeAction(ci, u, kd->GetTTBFlood(), TTB_FLOOD, _("Stop flooding!")); + return; + } + } + + /* Repeat kicker */ + if (kd->GetRepeat()) + { + if (!ud->lastline.equals_ci(realbuf)) + ud->times = 0; + else + ++ud->times; + + if (ud->times >= kd->GetRepeatTimes()) + { + TakeAction(ci, u, kd->GetTTBRepeat(), TTB_REPEAT, _("Stop repeating yourself!")); + return; + } + } + + if (ud->lastline.equals_ci(realbuf) && !ud->lasttarget.empty() && !ud->lasttarget.equals_ci(ci->GetName())) + { + for (User::ChanUserList::iterator it = u->chans.begin(); it != u->chans.end();) + { + Channel *chan = it->second->chan; + ++it; + + if (chan->ci && kd->GetAmsgs() && !chan->ci->AccessFor(u).HasPriv("NOKICK")) + { + TakeAction(ci, u, kd->GetTTBAmsgs(), TTB_AMSGS, _("Don't use AMSGs!")); + return; + } + } + } + + ud->lasttarget = ci->GetName(); + ud->lastline = realbuf; + } + } +}; + +MODULE_INIT(BSKick) diff --git a/modules/botserv/main/CMakeLists.txt b/modules/botserv/main/CMakeLists.txt new file mode 100644 index 000000000..781f0ef1f --- /dev/null +++ b/modules/botserv/main/CMakeLists.txt @@ -0,0 +1 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/botserv/main/botserv.cpp b/modules/botserv/main/botserv.cpp new file mode 100644 index 000000000..0b51691fc --- /dev/null +++ b/modules/botserv/main/botserv.cpp @@ -0,0 +1,228 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" +#include "modules/botserv.h" +#include "modules/help.h" + +class BotServCore : public Module, public BotServ::BotServService + , public EventHook<Event::SetCorrectModes> + , public EventHook<Event::BotAssign> + , public EventHook<Event::JoinChannel> + , public EventHook<Event::LeaveChannel> + , public EventHook<Event::Help> + , public EventHook<Event::ChannelModeSet> + , public EventHook<Event::CreateChan> + , public EventHook<Event::UserKicked> + , public EventHook<Event::CreateBot> +{ + Reference<ServiceBot> BotServ; + ExtensibleRef<bool> persist, inhabit;//XXX? + + public: + BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , BotServ::BotServService(this) + , persist("PERSIST") + , inhabit("inhabit") + { + } + + void OnReload(Configuration::Conf *conf) override + { + const Anope::string &bsnick = conf->GetModule(this)->Get<Anope::string>("client"); + BotServ = ServiceBot::Find(bsnick, true); + } + + void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override + { + /* Do not allow removing bot modes on our service bots */ + if (chan->ci && chan->ci->GetBot() == user) + { + const Anope::string &botmodes = Config->GetModule(this)->Get<Anope::string>("botmodes"); + for (unsigned i = 0; i < botmodes.length(); ++i) + chan->SetMode(chan->ci->GetBot(), ModeManager::FindChannelModeByChar(botmodes[i]), chan->ci->GetBot()->GetUID()); + } + } + + void OnBotAssign(User *sender, ChanServ::Channel *ci, ServiceBot *bi) override + { + if (ci->c && ci->c->users.size() >= Config->GetModule(this)->Get<unsigned>("minusers")) + { + ChannelStatus status(Config->GetModule(this)->Get<Anope::string>("botmodes")); + bi->Join(ci->c, &status); + } + } + + void OnJoinChannel(User *user, Channel *c) override + { + if (!Config || !IRCD) + return; + + ServiceBot *bi = user->server == Me ? dynamic_cast<ServiceBot *>(user) : NULL; + if (bi && Config->GetModule(this)->Get<bool>("smartjoin")) + { + std::vector<Anope::string> bans = c->GetModeList("BAN"); + + /* We check for bans */ + for (unsigned int i = 0; i < bans.size(); ++i) + { + Entry ban("BAN", bans[i]); + if (ban.Matches(user)) + c->RemoveMode(NULL, "BAN", ban.GetMask()); + } + + Anope::string Limit; + unsigned limit = 0; + try + { + if (c->GetParam("LIMIT", Limit)) + limit = convertTo<unsigned>(Limit); + } + catch (const ConvertException &) { } + + /* Should we be invited? */ + if (c->HasMode("INVITE") || (limit && c->users.size() >= limit)) + { + ChannelMode *cm = ModeManager::FindChannelModeByName("OP"); + char symbol = cm ? anope_dynamic_static_cast<ChannelModeStatus *>(cm)->symbol : 0; + IRCD->SendNotice(bi, (symbol ? Anope::string(symbol) : "") + c->name, "%s invited %s into the channel.", user->nick.c_str(), user->nick.c_str()); + } + + ModeManager::ProcessModes(); + } + + if (user->server != Me && c->ci && c->ci->GetBot()) + { + /** + * We let the bot join even if it was an ignored user, as if we don't, + * and the ignored user doesn't just leave, the bot will never + * make it into the channel, leaving the channel botless even for + * legit users - Rob + **/ + /* This is before the user has joined the channel, so check usercount + 1 */ + if (c->users.size() + 1 >= Config->GetModule(this)->Get<unsigned>("minusers") && !c->FindUser(c->ci->GetBot())) + { + ChannelStatus status(Config->GetModule(this)->Get<Anope::string>("botmodes")); + c->ci->GetBot()->Join(c, &status); + } + } + } + + void OnLeaveChannel(User *u, Channel *c) override + { + /* Channel is persistent, it shouldn't be deleted and the service bot should stay */ + if (c->ci && persist && persist->HasExt(c->ci)) + return; + + /* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediately + * We also don't part the bot here either, if necessary we will part it after the sync + */ + if (c->syncing) + return; + + /* Additionally, do not delete this channel if ChanServ/a BotServ bot is inhabiting it */ + if (inhabit && inhabit->HasExt(c)) + return; + + /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */ + if (c->ci && c->ci->GetBot() && u != c->ci->GetBot() && c->users.size() - 1 <= Config->GetModule(this)->Get<unsigned>("minusers") && c->FindUser(c->ci->GetBot())) + c->ci->GetBot()->Part(c->ci->c); + } + + EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (!params.empty()) + return EVENT_CONTINUE; + + if (source.c) + { + source.Reply(_("\002%s\002 allows you to execute \"fantasy\" commands in the channel.\n" + "Fantasy commands are commands that can be executed from messaging a\n" + "channel, and provide a more convenient way to execute commands. Commands that\n" + "require a channel as a parameter will automatically have that parameter\n" + "given.\n"), source.service->nick.c_str()); + const Anope::string &fantasycharacters = Config->GetModule("fantasy")->Get<Anope::string>("fantasycharacter", "!"); + if (!fantasycharacters.empty()) + source.Reply(_(" \n" + "Fantasy commands may be prefixed with one of the following characters: %s\n"), fantasycharacters.c_str()); + source.Reply(_(" \n" + "Available commands are:")); + } + else if (*source.service == BotServ) + { + source.Reply(_("\002%s\002 allows you to have a bot on your own channel.\n" + "It has been created for users that can't host or\n" + "configure a bot, or for use on networks that don't\n" + "allow user bots. Available commands are listed\n" + "below; to use them, type \002%s%s \037command\037\002. For\n" + "more information on a specific command, type\n" + "\002%s%s %s \037command\037\002.\n"), + BotServ->nick.c_str(), Config->StrictPrivmsg.c_str(), BotServ->nick.c_str(), + Config->StrictPrivmsg.c_str(), BotServ->nick.c_str(), source.command.c_str()); + } + + return EVENT_CONTINUE; + } + + void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (!params.empty() || source.c || source.service != *BotServ) + return; + + source.Reply(_(" \n" + "Bot will join a channel whenever there is at least\n" + "\002%d\002 user(s) on it."), Config->GetModule(this)->Get<unsigned>("minusers")); + const Anope::string &fantasycharacters = Config->GetModule("fantasy")->Get<Anope::string>("fantasycharacter", "!"); + if (!fantasycharacters.empty()) + source.Reply(_("Additionally, if fantasy is enabled fantasy commands\n" + "can be executed by prefixing the command name with\n" + "one of the following characters: %s"), fantasycharacters.c_str()); + } + + EventReturn OnChannelModeSet(Channel *c, const MessageSource &source, ChannelMode *mode, const Anope::string ¶m) override + { + if (source.GetUser() && !source.GetBot() && Config->GetModule(this)->Get<bool>("smartjoin") && mode->name == "BAN" && c->ci && c->ci->GetBot() && c->FindUser(c->ci->GetBot())) + { + ServiceBot *bi = c->ci->GetBot(); + + Entry ban("BAN", param); + if (ban.Matches(bi)) + c->RemoveMode(bi, "BAN", param); + } + + return EVENT_CONTINUE; + } + + void OnCreateChan(ChanServ::Channel *ci) override + { + /* Set default bot flags */ + spacesepstream sep(Config->GetModule(this)->Get<Anope::string>("defaults", "greet fantasy")); + for (Anope::string token; sep.GetToken(token);) + ci->SetS<bool>("BS_" + token.upper(), true); + } + + void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) override + { + ServiceBot *bi = ServiceBot::Find(target->GetUID()); + if (bi) + /* Bots get rejoined */ + bi->Join(channel, &status); + } + + void OnCreateBot(ServiceBot *bi) override + { + if (bi->botmodes.empty()) + bi->botmodes = Config->GetModule(this)->Get<Anope::string>("botumodes"); + } +}; + +MODULE_INIT(BotServCore) + diff --git a/modules/botserv/set.cpp b/modules/botserv/set.cpp new file mode 100644 index 000000000..6e2ae998f --- /dev/null +++ b/modules/botserv/set.cpp @@ -0,0 +1,221 @@ +/* BotServ core functions + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include "module.h" +#include "modules/bs_kick.h" + +class CommandBSSet : public Command +{ + public: + CommandBSSet(Module *creator) : Command(creator, "botserv/set", 3, 3) + { + this->SetDesc(_("Configures bot options")); + this->SetSyntax(_("\037option\037 \037(channel | bot)\037 \037settings\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + this->OnSyntaxError(source, ""); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Configures bot options.\n" + "\n" + "Available options:")); + bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"), + hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands"); + Anope::string this_name = source.command; + for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + { + const Anope::string &c_name = it->first; + const CommandInfo &info = it->second; + if (c_name.find_ci(this_name + " ") == 0) + { + ServiceReference<Command> command("Command", info.name); + if (command) + { + // XXX dup + if (hide_registered_commands && !command->AllowUnregistered() && !source.GetAccount()) + continue; + + if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission)) + continue; + + source.command = it->first; + command->OnServHelp(source); + } + } + } + + CommandInfo *help = source.service->FindCommand("generic/help"); + if (help) + source.Reply(_("Type \002{0}{1} {2} {3} \037option\037\002 for more information on a particular option."), + Config->StrictPrivmsg, source.service->nick, help->cname, this_name); + + return true; + } +}; + +class CommandBSSetBanExpire : public Command +{ + public: + class UnbanTimer : public Timer + { + Anope::string chname; + Anope::string mask; + + public: + UnbanTimer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t) : Timer(creator, t), chname(ch), mask(bmask) { } + + void Tick(time_t) override + { + Channel *c = Channel::Find(chname); + if (c) + c->RemoveMode(NULL, "BAN", mask); + } + }; + + CommandBSSetBanExpire(Module *creator, const Anope::string &sname = "botserv/set/banexpire") : Command(creator, sname, 2, 2) + { + this->SetDesc(_("Configures the time bot bans expire in")); + this->SetSyntax(_("\037channel\037 \037time\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &chan = params[0]; + const Anope::string &arg = params[1]; + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci == NULL) + { + source.Reply(_("Channel \002{0}\002 isn't registered."), chan); + return; + } + + ChanServ::AccessGroup access = source.AccessFor(ci); + if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) + { + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); + return; + } + + if (Anope::ReadOnly) + { + source.Reply(_("Sorry, changing bot options is temporarily disabled.")); + return; + } + + time_t t = Anope::DoTime(arg); + if (t == -1) + { + source.Reply(_("Invalid expiry time \002{0}\002."), arg); + return; + } + + /* cap at 1 day */ + if (t > 86400) + { + source.Reply(_("Ban expiry may not be longer than 1 day.")); + return; + } + + ci->SetBanExpire(t); + + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to change banexpire to " << arg; + + if (!t) + source.Reply(_("Bot bans will no longer automatically expire.")); + else + source.Reply(_("Bot bans will automatically expire after \002{0}\002."), Anope::Duration(t, source.GetAccount())); + } + + bool OnHelp(CommandSource &source, const Anope::string &) override + { + source.Reply(_("Sets the time bot bans expire in. If enabled, any bans placed by bots, such as by the flood kicker, badwords kicker, etc. will automatically be removed after the given time." + " Set to 0 to disable bans from automatically expiring.")); + return true; + } +}; + +class CommandBSSetPrivate : public Command +{ + public: + CommandBSSetPrivate(Module *creator, const Anope::string &sname = "botserv/set/private") : Command(creator, sname, 2, 2) + { + this->SetDesc(_("Prevent a bot from being assigned by non Services Operators")); + this->SetSyntax(_("\037botname\037 {\037ON|OFF\037}")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &nick = params[9]; + const Anope::string &value = params[1]; + + if (Anope::ReadOnly) + source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); + + ServiceBot *bi = ServiceBot::Find(nick, true); + if (bi == NULL) + { + source.Reply(_("Bot \002{0}\002 does not exist."), nick); + return; + } + + if (value.equals_ci("ON")) + { + bi->bi->SetOperOnly(true); + source.Reply(_("Private mode of bot \002{0}\002 is now \002on\002."), bi->nick); + } + else if (value.equals_ci("OFF")) + { + bi->bi->SetOperOnly(false); + source.Reply(_("Private mode of bot \002{0}\002 is now \002off\002."), bi->nick); + } + else + this->OnSyntaxError(source, source.command); + } + + bool OnHelp(CommandSource &source, const Anope::string &) override + { + source.Reply(_("This option prevents a bot from being assigned to channels by users who do not have the \002{0}\002 privilege."), + "botserv/administration"); + return true; + } +}; + +class BSSet : public Module + , public EventHook<Event::BotBan> +{ + CommandBSSet commandbsset; + CommandBSSetBanExpire commandbssetbanexpire; + CommandBSSetPrivate commandbssetprivate; + + public: + BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsset(this) + , commandbssetbanexpire(this) + , commandbssetprivate(this) + { + } + + void OnBotBan(User *u, ChanServ::Channel *ci, const Anope::string &mask) override + { + if (!ci->GetBanExpire()) + return; + + new CommandBSSetBanExpire::UnbanTimer(this, ci->GetName(), mask, ci->GetBanExpire()); + } +}; + +MODULE_INIT(BSSet) |
