From 85524f4408b5b1a449e634013f3949a7210ff1ff Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 23:04:04 +0100 Subject: [PATCH] ctcpflood: use CModCommand --- modules/ctcpflood.cpp | 58 +++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/modules/ctcpflood.cpp b/modules/ctcpflood.cpp index ac154e24..a8feecd3 100644 --- a/modules/ctcpflood.cpp +++ b/modules/ctcpflood.cpp @@ -22,6 +22,11 @@ public: MODCONSTRUCTOR(CCtcpFloodMod) { m_tLastCTCP = 0; m_iNumCTCP = 0; + + AddHelpCommand(); + AddCommand("Secs", static_cast(&CCtcpFloodMod::OnSecsCommand), "", "Set seconds limit"); + AddCommand("Lines", static_cast(&CCtcpFloodMod::OnLinesCommand), "", "Set lines limit"); + AddCommand("Show", static_cast(&CCtcpFloodMod::OnShowCommand), "", "Show the current limits"); } ~CCtcpFloodMod() { @@ -87,30 +92,41 @@ public: return Message(Nick, sMessage); } - void OnModCommand(const CString& sCommand) { - const CString& sCmd = sCommand.Token(0); + void OnSecsCommand(const CString& sCommand) { const CString& sArg = sCommand.Token(1, true); - if (sCmd.Equals("secs") && !sArg.empty()) { - m_iThresholdSecs = sArg.ToUInt(); - if (m_iThresholdSecs == 0) - m_iThresholdSecs = 1; - - PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]"); - Save(); - } else if (sCmd.Equals("lines") && !sArg.empty()) { - m_iThresholdMsgs = sArg.ToUInt(); - if (m_iThresholdMsgs == 0) - m_iThresholdMsgs = 2; - - PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]"); - Save(); - } else if (sCmd.Equals("show")) { - PutModule("Current limit is " + CString(m_iThresholdMsgs) + " CTCPs " - "in " + CString(m_iThresholdSecs) + " secs"); - } else { - PutModule("Commands: show, secs [limit], lines [limit]"); + if (sArg.empty()) { + PutModule("Usage: Secs "); + return; } + + m_iThresholdSecs = sArg.ToUInt(); + if (m_iThresholdSecs == 0) + m_iThresholdSecs = 1; + + PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]"); + Save(); + } + + void OnLinesCommand(const CString& sCommand) { + const CString& sArg = sCommand.Token(1, true); + + if (sArg.empty()) { + PutModule("Usage: Lines "); + return; + } + + m_iThresholdMsgs = sArg.ToUInt(); + if (m_iThresholdMsgs == 0) + m_iThresholdMsgs = 2; + + PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]"); + Save(); + } + + void OnShowCommand(const CString& sCommand) { + PutModule("Current limit is " + CString(m_iThresholdMsgs) + " CTCPs " + "in " + CString(m_iThresholdSecs) + " secs"); } private: