Skip to content

Commit

Permalink
Sync the changes in the v3 version of antiknocker to v4.
Browse files Browse the repository at this point in the history
  • Loading branch information
SadieCat committed Aug 18, 2024
1 parent 01aec2f commit fcf25a6
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions 4/m_antiknocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

/// $ModAuthor: Sadie Powell <[email protected]>
/// $ModConfig: <antiknock nickregex="(st|sn|cr|pl|pr|fr|fl|qu|br|gr|sh|sk|tr|kl|wr|bl|[bcdfgklmnprstvwz])([aeiou][aeiou][bcdfgklmnprstvwz])(ed|est|er|le|ly|y|ies|iest|ian|ion|est|ing|led|inger|[abcdfgklmnprstvwz])" docmd="yes" donick="yes" donotice="yes" doshun="yes" shunduration="15" shunreason="User was caught in an antiknock trap">
/// $ModDesc: Attempts to block a common IRC spambot.
/// $ModDepends: core 4

Expand All @@ -31,22 +32,29 @@ class ModuleAntiKnocker final
: public Module
{
public:
bool docmd;
bool donick;
bool donotice;
bool doshun;
std::regex nickregex;
IntExtItem seenmsg;
unsigned long shunduration;
std::string shunreason;

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())
Expand Down Expand Up @@ -78,13 +86,17 @@ class ModuleAntiKnocker final
throw ModuleException(this, INSP_FORMAT("<antiknock:nickregex> 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"))
Expand Down Expand Up @@ -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: {}",
Expand All @@ -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)
Expand Down

0 comments on commit fcf25a6

Please sign in to comment.