diff --git a/4/m_antiknocker.cpp b/4/m_antiknocker.cpp index 971213e1..e2b49cad 100644 --- a/4/m_antiknocker.cpp +++ b/4/m_antiknocker.cpp @@ -17,6 +17,7 @@ */ /// $ModAuthor: Sadie Powell +/// $ModConfig: /// $ModDesc: Attempts to block a common IRC spambot. /// $ModDepends: core 4 @@ -31,6 +32,10 @@ class ModuleAntiKnocker final : public Module { public: + bool docmd; + bool donick; + bool donotice; + bool doshun; std::regex nickregex; IntExtItem seenmsg; unsigned long shunduration; @@ -38,15 +43,18 @@ class ModuleAntiKnocker final void PunishUser(LocalUser* user) { - auto* sh = new Shun(ServerInstance->Time(), shunduration, MODNAME "@" + ServerInstance->Config->ServerName, shunreason, user->GetAddress()); - if (ServerInstance->XLines->AddLine(sh, nullptr)) + if (doshun) { - ServerInstance->XLines->ApplyLines(); - return; - } + auto* sh = new Shun(ServerInstance->Time(), shunduration, MODNAME "@" + ServerInstance->Config->ServerName, shunreason, user->GetAddress()); + if (ServerInstance->XLines->AddLine(sh, nullptr)) + { + ServerInstance->XLines->ApplyLines(); + return; + } - // No shunning? Annoying. Just quit em. - delete sh; + // No shunning? Annoying. Just quit em. + delete sh; + } std::string message; if (!user->IsFullyConnected()) @@ -78,13 +86,17 @@ class ModuleAntiKnocker final throw ModuleException(this, INSP_FORMAT(" is invalid: {}", err.what())); } - shunduration = tag->getDuration("shunduration", 60*60, 60); + docmd = tag->getBool("docmd", true); + donick = tag->getBool("donick", true); + donotice = tag->getBool("donotice", true); + doshun = tag->getBool("doshun", true); + shunduration = tag->getDuration("shunduration", 60*15, 60); shunreason = tag->getString("shunreason", "User was caught in an antiknock trap", 1); } ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) override { - if (!validated || !user->IsFullyConnected()) + if (!docmd || !validated || !user->IsFullyConnected()) return MOD_RES_PASSTHRU; if (command == "PRIVMSG" && irc::equals(parameters[0], "NickServ")) @@ -113,7 +125,7 @@ class ModuleAntiKnocker final ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) override { - if (!std::regex_match(newnick, nickregex)) + if (!donick || !std::regex_match(newnick, nickregex)) return MOD_RES_PASSTHRU; ServerInstance->SNO.WriteToSnoMask('a', "User {} ({}) was prevented from using a knocker nick: {}", @@ -122,6 +134,12 @@ class ModuleAntiKnocker final PunishUser(user); return MOD_RES_DENY; } + + void OnUserConnect(LocalUser* user) override + { + if (donotice) + user->WriteNotice("*** You are not welcome on this network if you are a malicious bot. If you are not a malicious bot bot please ignore this message."); + } }; MODULE_INIT(ModuleAntiKnocker)