diff --git a/include/znc/Modules.h b/include/znc/Modules.h index 9df08dde..73f9bfe0 100644 --- a/include/znc/Modules.h +++ b/include/znc/Modules.h @@ -994,6 +994,7 @@ public: bool MoveRegistry(const CString& sPath); bool SetNV(const CString & sName, const CString & sValue, bool bWriteToDisk = true); CString GetNV(const CString & sName) const; + bool HasNV(const CString & sName) const { return m_mssRegistry.find(sName) != m_mssRegistry.end(); } bool DelNV(const CString & sName, bool bWriteToDisk = true); MCString::iterator FindNV(const CString & sName) { return m_mssRegistry.find(sName); } MCString::iterator EndNV() { return m_mssRegistry.end(); } diff --git a/modules/log.cpp b/modules/log.cpp index 09d7729b..cb3526a9 100644 --- a/modules/log.cpp +++ b/modules/log.cpp @@ -51,6 +51,16 @@ private: }; class CLogMod: public CModule { + void Set(const CString& sLine) { + const CString sVar = sLine.Token(1).AsLower(); + bool b = sLine.Token(2).ToBool(); + + if (sVar == "joins" || sVar == "quits" || sVar == "nickchanges") { + SetNV(sVar, CString(b)); + PutModule("Set " + sVar + " to " + CString(b)); + } else + PutModule(sVar + " is invalid."); + } public: MODCONSTRUCTOR(CLogMod) { @@ -62,6 +72,8 @@ public: "", "Clear all logging rules"); AddCommand("ListRules", static_cast(&CLogMod::ListRulesCmd), "", "List all logging rules"); + AddCommand("Set", static_cast(&CLogMod::Set), + "boolean", "Set one of the following booleans, joins, quits, nickchanges"); } void SetRulesCmd(const CString& sLine); @@ -368,13 +380,16 @@ void CLogMod::OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Cha void CLogMod::OnQuit(const CNick& Nick, const CString& sMessage, const vector& vChans) { - for (CChan* pChan : vChans) - PutLog("*** Quits: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ") (" + sMessage + ")", *pChan); + if (!HasNV("quits") || GetNV("quits").ToBool()) { + for (CChan* pChan : vChans) + PutLog("*** Quits: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ") (" + sMessage + ")", *pChan); + } } void CLogMod::OnJoin(const CNick& Nick, CChan& Channel) { - PutLog("*** Joins: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ")", Channel); + if (!HasNV("joins") || GetNV("joins").ToBool()) + PutLog("*** Joins: " + Nick.GetNick() + " (" + Nick.GetIdent() + "@" + Nick.GetHost() + ")", Channel); } void CLogMod::OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage) @@ -384,8 +399,10 @@ void CLogMod::OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage) void CLogMod::OnNick(const CNick& OldNick, const CString& sNewNick, const vector& vChans) { - for (CChan* pChan : vChans) - PutLog("*** " + OldNick.GetNick() + " is now known as " + sNewNick, *pChan); + if (!HasNV("nickchanges") || GetNV("nickchanges").ToBool()) { + for (CChan* pChan : vChans) + PutLog("*** " + OldNick.GetNick() + " is now known as " + sNewNick, *pChan); + } } CModule::EModRet CLogMod::OnTopic(CNick& Nick, CChan& Channel, CString& sTopic)