From 759e40563edfdf7acc19d2c2436cf4b5249b8f22 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 14 Aug 2023 14:34:05 +0100 Subject: Refactor how the anticaps module parses the mode value. --- src/modules/m_anticaps.cpp | 48 ++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/modules/m_anticaps.cpp b/src/modules/m_anticaps.cpp index 7bf6699bc..ade189840 100644 --- a/src/modules/m_anticaps.cpp +++ b/src/modules/m_anticaps.cpp @@ -37,24 +37,8 @@ enum class AntiCapsMethod class AntiCapsSettings final { -public: - const AntiCapsMethod method; - const uint16_t minlen; - const uint8_t percent; - - AntiCapsSettings(const AntiCapsMethod& Method, const uint16_t& MinLen, const uint8_t& Percent) - : method(Method) - , minlen(MinLen) - , percent(Percent) - { - } -}; - -class AntiCapsMode final - : public ParamMode> -{ private: - static bool ParseMethod(irc::sepstream& stream, AntiCapsMethod& method) + bool ParseMethod(irc::sepstream& stream) { std::string methodstr; if (!stream.GetToken(methodstr)) @@ -76,7 +60,7 @@ private: return true; } - static bool ParseMinimumLength(irc::sepstream& stream, uint16_t& minlen) + bool ParseMinimumLength(irc::sepstream& stream) { std::string minlenstr; if (!stream.GetToken(minlenstr)) @@ -90,7 +74,7 @@ private: return true; } - static bool ParsePercent(irc::sepstream& stream, uint8_t& percent) + bool ParsePercent(irc::sepstream& stream) { std::string percentstr; if (!stream.GetToken(percentstr)) @@ -104,6 +88,21 @@ private: return true; } +public: + AntiCapsMethod method = AntiCapsMethod::BLOCK; + uint16_t minlen = 0; + uint8_t percent = 0; + + bool Parse(const std::string& str) + { + irc::sepstream stream(str, ':'); + return ParseMethod(stream) && ParseMinimumLength(stream) && ParsePercent(stream); + } +}; + +class AntiCapsMode final + : public ParamMode> +{ public: AntiCapsMode(Module* Creator) : ParamMode>(Creator, "anticaps", 'B') @@ -113,19 +112,14 @@ public: bool OnSet(User* source, Channel* channel, std::string& parameter) override { - irc::sepstream stream(parameter, ':'); - AntiCapsMethod method; - uint16_t minlen; - uint8_t percent; - - // Attempt to parse the method. - if (!ParseMethod(stream, method) || !ParseMinimumLength(stream, minlen) || !ParsePercent(stream, percent)) + AntiCapsSettings settings; + if (!settings.Parse(parameter)) { source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); return false; } - ext.SetFwd(channel, method, minlen, percent); + ext.Set(channel, settings); return true; } -- cgit v1.3.1-10-gc9f91