diff --git a/include/znc/Client.h b/include/znc/Client.h index 597ebc52..07f3cc9b 100644 --- a/include/znc/Client.h +++ b/include/znc/Client.h @@ -258,6 +258,7 @@ private: void EchoMessage(const CMessage& Message); std::set MatchChans(const CString& sPatterns) const; + unsigned int AttachChans(const std::set& sChans); unsigned int DetachChans(const std::set& sChans); protected: diff --git a/src/Client.cpp b/src/Client.cpp index ae8e0a68..8fbaf707 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -349,7 +349,22 @@ void CClient::ReadLine(const CString& sData) { return; } - if (sCommand.Equals("DETACH")) { + if (sCommand.Equals("ATTACH")) { + CString sPatterns = sLine.Token(1, true); + + if (sPatterns.empty()) { + PutStatusNotice("Usage: /attach <#chans|queries>"); + return; + } + + set sChans = MatchChans(sPatterns); + unsigned int uAttachedChans = AttachChans(sChans); + + PutStatusNotice("There were [" + CString(sChans.size()) + "] channels matching [" + sPatterns + "]"); + PutStatusNotice("Attached [" + CString(uAttachedChans) + "] channels"); + + return; + } else if (sCommand.Equals("DETACH")) { if (!m_pNetwork) { return; } @@ -1061,6 +1076,18 @@ set CClient::MatchChans(const CString& sPatterns) const return sChans; } +unsigned int CClient::AttachChans(const std::set& sChans) +{ + unsigned int uAttached = 0; + for (CChan* pChan : sChans) { + if (!pChan->IsDetached()) + continue; + uAttached++; + pChan->AttachUser(); + } + return uAttached; +} + unsigned int CClient::DetachChans(const std::set& sChans) { unsigned int uDetached = 0; diff --git a/src/ClientCommand.cpp b/src/ClientCommand.cpp index 1ce7a1b0..77a43527 100644 --- a/src/ClientCommand.cpp +++ b/src/ClientCommand.cpp @@ -107,6 +107,24 @@ void CClient::UserCommand(CString& sLine) { } PutStatus(Table); + } else if (sCommand.Equals("ATTACH")) { + if (!m_pNetwork) { + PutStatus("You must be connected with a network to use this command"); + return; + } + + CString sPatterns = sLine.Token(1, true); + + if (sPatterns.empty()) { + PutStatus("Usage: Attach <#chans|queries>"); + return; + } + + set sChans = MatchChans(sPatterns); + unsigned int uAttachedChans = AttachChans(sChans); + + PutStatus("There were [" + CString(sChans.size()) + "] channels matching [" + sPatterns + "]"); + PutStatus("Attached [" + CString(uAttachedChans) + "] channels"); } else if (sCommand.Equals("DETACH")) { if (!m_pNetwork) { PutStatus("You must be connected with a network to use this command"); @@ -1565,6 +1583,7 @@ void CClient::HelpUser(const CString& sFilter) { AddCommandHelp(Table, "ShowChan", "<#chan>", "Show channel details", sFilter); AddCommandHelp(Table, "EnableChan", "<#chans>", "Enable channels", sFilter); AddCommandHelp(Table, "DisableChan", "<#chans>", "Disable channels", sFilter); + AddCommandHelp(Table, "Attach", "<#chans>", "Attach to channels", sFilter); AddCommandHelp(Table, "Detach", "<#chans>", "Detach from channels", sFilter); AddCommandHelp(Table, "Topics", "", "Show topics in all your channels", sFilter);