From fb2abcf03bb4baf158ed25a42e7bedaa3246effe Mon Sep 17 00:00:00 2001 From: imaginos Date: Sun, 15 May 2005 04:03:56 +0000 Subject: [PATCH] added new module stickychan git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@301 726aef4b-f618-498e-8847-2d620e286838 --- modules/stickychan.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 modules/stickychan.cpp diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp new file mode 100644 index 00000000..0d631500 --- /dev/null +++ b/modules/stickychan.cpp @@ -0,0 +1,82 @@ +#include "main.h" +#include "User.h" +#include "Nick.h" +#include "Modules.h" +#include "Chan.h" +#include "Utils.h" +#include "FileUtils.h" +#include +#include +#include + + +class CStickyChan : public CModule +{ +public: + MODCONSTRUCTOR(CStickyChan) {} + virtual ~CStickyChan() + { + } + + virtual bool OnLoad(const CString& sArgs); + + virtual CString GetDescription() + { + return ( "configless sticky chans, keeps you there very stickily even" ); + } + + virtual void OnModCommand( const CString& sCommand ) + { + CString sCmdName = sCommand.Token(0); + CString sChannel = sCommand.Token(1); + sChannel.MakeLower(); + if ( ( sCmdName == "stick" ) && ( !sChannel.empty() ) ) + { + SetNV( sChannel, sCommand.Token(2) ); + PutModule( "Stuck " + sChannel ); + } + else if ( ( sCmdName == "unstick" ) && ( !sChannel.empty() ) ) + { + MCString::iterator it = FindNV( sChannel ); + if ( it != EndNV() ) + DelNV( it ); + + PutModule( "UnStuck " + sChannel ); + } + else + { + PutModule( "USAGE: [un]stick #channel [key]" ); + } + } + + virtual void RunJob() + { + for( MCString::iterator it = BeginNV(); it != EndNV(); it++ ) + { + if ( !m_pUser->FindChan( it->first ) ) + { + CChan *pChan = new CChan( it->first, m_pUser ); + if ( !it->second.empty() ) + pChan->SetKey( it->second ); + m_pUser->AddChan( pChan ); + PutModule( "Joining [" + it->first + "]" ); + } + } + } +private: + +}; + + +static void RunTimer( CModule * pModule, CFPTimer *pTimer ) +{ + ((CStickyChan *)pModule)->RunJob(); +} + +bool CStickyChan::OnLoad(const CString& sArgs) +{ + AddTimer( RunTimer, "StickyChanTimer", 15 ); + return( true ); +} + +MODULEDEFS(CStickyChan)