aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorGravatar Sadie Powell2024-09-28 18:37:47 +0100
committerGravatar Sadie Powell2024-09-29 19:48:50 +0100
commit9506e09ff76118bf0127c745e449114bce2c7f3f (patch)
tree3010a8f4395f9a90fe66799028e1f92b89ca0b0d /src/modules
parentAdd %channel% to the messageflood and repeat module templates. (diff)
Allow customising the anticaps reason.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_anticaps.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/modules/m_anticaps.cpp b/src/modules/m_anticaps.cpp
index bb9fa0774..48f1d7b8b 100644
--- a/src/modules/m_anticaps.cpp
+++ b/src/modules/m_anticaps.cpp
@@ -168,6 +168,7 @@ private:
CharState uppercase;
CharState lowercase;
AntiCapsMode mode;
+ std::string message;
void CreateBan(Channel* channel, User* user, bool mute)
{
@@ -181,9 +182,9 @@ private:
ServerInstance->Modes.Process(ServerInstance->FakeClient, channel, nullptr, changelist);
}
- static void InformUser(Channel* channel, User* user, const std::string& message)
+ static void InformUser(Channel* channel, User* user, const std::string& msg)
{
- user->WriteNumeric(Numerics::CannotSendTo(channel, message + " and was blocked."));
+ user->WriteNumeric(Numerics::CannotSendTo(channel, msg));
}
public:
@@ -206,6 +207,8 @@ public:
lowercase.reset();
for (const auto chr : tag->getString("lowercase", "abcdefghijklmnopqrstuvwxyz", 1))
lowercase.set(static_cast<unsigned char>(chr));
+
+ message = tag->getString("message", "Your message exceeded the %percent%%% upper case character threshold for %channel%", 1);
}
ModResult OnUserPreMessage(User* user, MessageTarget& target, MessageDetails& details) override
@@ -255,11 +258,14 @@ public:
// Count the characters to see how many upper case and
// ignored (non upper or lower) characters there are.
size_t upper = 0;
+ size_t lower = 0;
for (const auto chr : msgbody)
{
if (uppercase.test(static_cast<unsigned char>(chr)))
upper += 1;
- else if (!lowercase.test(static_cast<unsigned char>(chr)))
+ else if (lowercase.test(static_cast<unsigned char>(chr)))
+ lower += 1;
+ else
length -= 1;
}
@@ -273,32 +279,38 @@ public:
if (percent < config->percent)
return MOD_RES_PASSTHRU;
- const std::string message = INSP_FORMAT("Your message exceeded the {}% upper case character threshold for {}",
- config->percent, channel->name);
+ const auto msg = Template::Replace(message, {
+ { "channel", channel->name },
+ { "lower", ConvToStr(lower) },
+ { "minlen", ConvToStr(config->minlen) },
+ { "percent", ConvToStr<uint16_t>(config->percent) },
+ { "punctuation", ConvToStr(msgbody.length() - upper - lower) },
+ { "upper", ConvToStr(upper) },
+ });
switch (config->method)
{
case AntiCapsMethod::BAN:
- InformUser(channel, user, message);
+ InformUser(channel, user, msg);
CreateBan(channel, user, false);
break;
case AntiCapsMethod::BLOCK:
- InformUser(channel, user, message);
+ InformUser(channel, user, msg);
break;
case AntiCapsMethod::MUTE:
- InformUser(channel, user, message);
+ InformUser(channel, user, msg);
CreateBan(channel, user, true);
break;
case AntiCapsMethod::KICK:
- channel->KickUser(ServerInstance->FakeClient, user, message);
+ channel->KickUser(ServerInstance->FakeClient, user, msg);
break;
case AntiCapsMethod::KICK_BAN:
CreateBan(channel, user, false);
- channel->KickUser(ServerInstance->FakeClient, user, message);
+ channel->KickUser(ServerInstance->FakeClient, user, msg);
break;
}
return MOD_RES_DENY;