Last active
August 29, 2015 14:02
-
-
Save JayFoxRox/ae552a57f8094893f083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Module by infogulch and someone who "just stole it", just stolen again | |
#include "Chan.h" | |
#include "Modules.h" | |
#include "User.h" | |
class CQuitDetach : public CModule { | |
public: | |
MODCONSTRUCTOR(CQuitDetach) {} | |
virtual ~CQuitDetach() {} | |
virtual void OnIRCConnected() { | |
/* There might still be other clients */ | |
if (!m_pUser->IsUserAttached()) | |
safe_detach_all(); | |
} | |
virtual void OnClientDisconnect() { | |
/* There might still be other clients */ | |
if (!m_pUser->IsUserAttached()) | |
safe_detach_all(); | |
} | |
virtual void OnModCommand(const CString& sLine) { | |
if (sLine.Token(0).CaseCmp("help") == 0) { | |
PutModule("If a channel is saved in your config, and the last client quits it will be detached."); | |
} | |
} | |
private: | |
void safe_detach_all() { | |
const std::vector<CChan*>& Channels = m_pUser->GetChans(); | |
for (unsigned int c = 0; c < Channels.size(); c++) { | |
CChan* chan = Channels[c]; | |
if (chan && !chan->IsDetached() && chan->InConfig()) | |
chan->DetachUser(); | |
} | |
} | |
}; | |
MODULEDEFS(CQuitDetach, "Last client quit detaches, for saved chans") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For znc-0.206. Based on http://people.znc.in/~psychon/znc/modules/partdetach2.cpp