Skip to content

Instantly share code, notes, and snippets.

@JayFoxRox
Last active August 29, 2015 14:02
Show Gist options
  • Save JayFoxRox/ae552a57f8094893f083 to your computer and use it in GitHub Desktop.
Save JayFoxRox/ae552a57f8094893f083 to your computer and use it in GitHub Desktop.
// 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")
@JayFoxRox
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment