From e5e0bb356e1700b738d093d109e7252a2f65662b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 19 Aug 2014 19:48:48 +0200 Subject: [PATCH 1/3] Refactor flooddetach to use command callbacks This gives a proper help command "for free", and makes it more pleasant to add new commands (silent) later. --- modules/flooddetach.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/flooddetach.cpp b/modules/flooddetach.cpp index f4ed8921..831f7b11 100644 --- a/modules/flooddetach.cpp +++ b/modules/flooddetach.cpp @@ -24,6 +24,11 @@ public: MODCONSTRUCTOR(CFloodDetachMod) { m_iThresholdSecs = 0; m_iThresholdMsgs = 0; + + AddHelpCommand(); + AddCommand("Show", static_cast(&CFloodDetachMod::ShowCommand), ""); + AddCommand("Secs", static_cast(&CFloodDetachMod::SecsCommand), "[]"); + AddCommand("Lines", static_cast(&CFloodDetachMod::LinesCommand), "[]"); } ~CFloodDetachMod() { @@ -163,31 +168,37 @@ public: return CONTINUE; } - void OnModCommand(const CString& sCommand) { - const CString& sCmd = sCommand.Token(0); - const CString& sArg = sCommand.Token(1, true); + void ShowCommand(const CString& sLine) { + PutModule("Current limit is " + CString(m_iThresholdMsgs) + " lines " + "in " + CString(m_iThresholdSecs) + " secs."); + } - if (sCmd.Equals("secs") && !sArg.empty()) { + void SecsCommand(const CString& sLine) { + const CString sArg = sLine.Token(1, true); + + if (!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()) { + } + } + + void LinesCommand(const CString& sLine) { + const CString sArg = sLine.Token(1, true); + + if (!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) + " lines " - "in " + CString(m_iThresholdSecs) + " secs."); - } else { - PutModule("Commands: show, secs , lines "); } } + private: typedef map > Limits; Limits m_chans; From 44b10b5b975161d8ce83a09225487c4c85af7926 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 19 Aug 2014 19:50:15 +0200 Subject: [PATCH 2/3] flooddetach: make secs & lines commands rw Improves the usability of the module. --- modules/flooddetach.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/flooddetach.cpp b/modules/flooddetach.cpp index 831f7b11..72720264 100644 --- a/modules/flooddetach.cpp +++ b/modules/flooddetach.cpp @@ -176,7 +176,9 @@ public: void SecsCommand(const CString& sLine) { const CString sArg = sLine.Token(1, true); - if (!sArg.empty()) { + if (sArg.empty()) { + PutModule("Seconds limit is [" + CString(m_iThresholdSecs) + "]"); + } else { m_iThresholdSecs = sArg.ToUInt(); if (m_iThresholdSecs == 0) m_iThresholdSecs = 1; @@ -189,7 +191,9 @@ public: void LinesCommand(const CString& sLine) { const CString sArg = sLine.Token(1, true); - if (!sArg.empty()) { + if (sArg.empty()) { + PutModule("Lines limit is [" + CString(m_iThresholdMsgs) + "]"); + } else { m_iThresholdMsgs = sArg.ToUInt(); if (m_iThresholdMsgs == 0) m_iThresholdMsgs = 2; From 5279bb62a012bbf02ec377c310dc36ececed582f Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 19 Aug 2014 19:57:27 +0200 Subject: [PATCH 3/3] flooddetach: add command "silent [yes|no]" Inspired by the route_replis module. Resolves #591. --- modules/flooddetach.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/flooddetach.cpp b/modules/flooddetach.cpp index 72720264..2c17d519 100644 --- a/modules/flooddetach.cpp +++ b/modules/flooddetach.cpp @@ -29,6 +29,7 @@ public: AddCommand("Show", static_cast(&CFloodDetachMod::ShowCommand), ""); AddCommand("Secs", static_cast(&CFloodDetachMod::SecsCommand), "[]"); AddCommand("Lines", static_cast(&CFloodDetachMod::LinesCommand), "[]"); + AddCommand("Silent", static_cast(&CFloodDetachMod::SilentCommand), "[yes|no]"); } ~CFloodDetachMod() { @@ -85,8 +86,10 @@ public: // channels which we detached, this means that // we detached because of a flood. - PutModule("Flood in [" + pChan->GetName() + "] is over, " - "re-attaching..."); + if (!GetNV("silent").ToBool()) { + PutModule("Flood in [" + pChan->GetName() + "] is over, " + "re-attaching..."); + } // No buffer playback, makes sense, doesn't it? pChan->ClearBuffer(); pChan->JoinUser(); @@ -143,8 +146,10 @@ public: it->second.first = now; Channel.DetachUser(); - PutModule("Channel [" + Channel.GetName() + "] was " - "flooded, you've been detached"); + if (!GetNV("silent").ToBool()) { + PutModule("Channel [" + Channel.GetName() + "] was " + "flooded, you've been detached"); + } } EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) { @@ -203,6 +208,20 @@ public: } } + void SilentCommand(const CString& sLine) { + const CString sArg = sLine.Token(1, true); + + if (!sArg.empty()) { + SetNV("silent", CString(sArg.ToBool())); + } + + if (GetNV("silent").ToBool()) { + PutModule("Module messages are disabled"); + } else { + PutModule("Module messages are enabled"); + } + } + private: typedef map > Limits; Limits m_chans;