-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync the changes in the v3 version of antiknocker to v4.
- Loading branch information
Showing
1 changed file
with
28 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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()) | ||
|
@@ -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")) | ||
|
@@ -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) | ||
|