diff --git a/modules/simple_away.cpp b/modules/simple_away.cpp index ae662c03..0e4441b0 100644 --- a/modules/simple_away.cpp +++ b/modules/simple_away.cpp @@ -8,10 +8,13 @@ #include "User.h" +#define SIMPLE_AWAY_DEFAULT_REASON "Auto away at %s" +#define SIMPLE_AWAY_DEFAULT_TIME 60 + + class CSimpleAway; -class CSimpleAwayJob : public CTimer -{ +class CSimpleAwayJob : public CTimer { public: CSimpleAwayJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} @@ -22,167 +25,195 @@ protected: virtual void RunJob(); }; -class CSimpleAway : public CModule -{ +class CSimpleAway : public CModule { +private: + CString m_sReason; + unsigned int m_iAwayWait; + bool m_bClientSetAway; + bool m_bWeSetAway; + public: - MODCONSTRUCTOR(CSimpleAway) - { - m_sReason = "Auto away at %s"; - m_iAwayWait = 60; + MODCONSTRUCTOR(CSimpleAway) { + m_sReason = SIMPLE_AWAY_DEFAULT_REASON; + m_iAwayWait = SIMPLE_AWAY_DEFAULT_TIME; m_bClientSetAway = false; + m_bWeSetAway = false; } - virtual ~CSimpleAway() - { - } + virtual ~CSimpleAway() {} - virtual bool OnLoad(const CString& sArgs, CString& sMessage) - { - CString sMyArgs = sArgs; + virtual bool OnLoad(const CString& sArgs, CString& sMessage) { + CString sReasonArg; - if (sMyArgs.Token(0) == "-notimer") { - m_iAwayWait = 0; - sMyArgs = sMyArgs.Token(1, true); - } else if (sMyArgs.Token(0) == "-timer") { - m_iAwayWait = sMyArgs.Token(1).ToInt(); - sMyArgs = sMyArgs.Token(2, true); + // Load AwayWait + CString sFirstArg = sArgs.Token(0); + if (sFirstArg.Equals("-notimer")) { + SetAwayWait(0); + sReasonArg = sArgs.Token(1, true); + } else if (sFirstArg.Equals("-timer")) { + SetAwayWait(sArgs.Token(1).ToUInt()); + sReasonArg = sArgs.Token(2, true); + } else { + CString sAwayWait = GetNV("awaywait"); + if (!sAwayWait.empty()) + SetAwayWait(sAwayWait.ToUInt(), false); + sReasonArg = sArgs; } - if (!sMyArgs.empty()) { - m_sReason = sMyArgs; + + // Load Reason + if (!sReasonArg.empty()) { + SetReason(sReasonArg); + } else { + CString sSavedReason = GetNV("reason"); + if (!sSavedReason.empty()) + SetReason(sSavedReason, false); } return true; } - virtual void OnIRCConnected() - { + virtual void OnIRCConnected() { if (m_pUser->IsUserAttached()) - Back(); + SetBack(); else - Away(); + SetAway(false); } - virtual void OnUserAttached() - { - Back(); + virtual void OnUserAttached() { + SetBack(); } - virtual void OnUserDetached() - { + virtual void OnUserDetached() { /* There might still be other clients */ if (!m_pUser->IsUserAttached()) - StartTimer(); + SetAway(); } - virtual void OnModCommand(const CString& sCommand) - { - CString sCmdName = sCommand.Token(0); + virtual void OnModCommand(const CString& sLine) { + CString sCommand = sLine.Token(0); - if (sCmdName == "disabletimer") { - m_iAwayWait = 0; - PutModule("Timer disabled"); - } else if (sCmdName == "settimer") { - int iSetting = sCommand.Token(1).ToInt(); + if (sCommand.Equals("help")) { + CTable Table; + Table.AddColumn("Command"); + Table.AddColumn("Description"); + Table.AddRow(); + Table.SetCell("Command", "Reason []"); + Table.SetCell("Description", "Prints and optionally sets the away reason."); + Table.AddRow(); + Table.SetCell("Command", "Timer"); + Table.SetCell("Description", "Prints the current time to wait before setting you away."); + Table.AddRow(); + Table.SetCell("Command", "SetTimer