]> jfr.im git - irc/rizon/znc.git/commitdiff
autocycle: Only cycle once in 15 seconds
authorUli Schlachter <redacted>
Sun, 4 Sep 2011 19:00:06 +0000 (21:00 +0200)
committerUli Schlachter <redacted>
Tue, 13 Sep 2011 07:36:59 +0000 (09:36 +0200)
This should stop all fights against ChanServ. Please note that nothing will
happen if we are the only one in the channel after 15 secs since this module
only checks if it needs to do something when someone leaves a channel.

Signed-off-by: Uli Schlachter <redacted>
modules/autocycle.cpp

index 969cf81a85d3d126fa5d494c47c31e066e300a3b..7a0ba1c0e8167d5e4510fd699bb34fb5d8a31ccf 100644 (file)
 
 class CAutoCycleMod : public CModule {
 public:
-       MODCONSTRUCTOR(CAutoCycleMod) {}
+       MODCONSTRUCTOR(CAutoCycleMod) {
+               m_recentlyCycled.SetTTL(15 * 1000);
+       }
+
        virtual ~CAutoCycleMod() {}
 
        virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
@@ -119,14 +122,20 @@ protected:
                if (!IsAutoCycle(Channel.GetName()))
                        return;
 
+               // Did we recently annoy opers via cycling of an empty channel?
+               if (m_recentlyCycled.HasItem(Channel.GetName()))
+                       return;
+
                // Is there only one person left in the channel?
                if (Channel.GetNickCount() != 1)
                        return;
 
                // Is that person us and we don't have op?
                const CNick& pNick = Channel.GetNicks().begin()->second;
-               if (!pNick.HasPerm(CChan::Op) && pNick.GetNick().Equals(m_pUser->GetCurNick()))
+               if (!pNick.HasPerm(CChan::Op) && pNick.GetNick().Equals(m_pUser->GetCurNick())) {
                        Channel.Cycle();
+                       m_recentlyCycled.AddItem(Channel.GetName());
+               }
        }
 
        bool AlreadyAdded(const CString& sInput) {
@@ -222,6 +231,7 @@ protected:
 private:
        vector<CString> m_vsChans;
        vector<CString> m_vsNegChans;
+       TCacheMap<CString> m_recentlyCycled;
 };
 
 template<> void TModInfo<CAutoCycleMod>(CModInfo& Info) {