CClient: add ATTACH command

The main benefit is that (unlike JOIN) ATTACH allows wildcards.
It's also nicely symmetric with DETACH.
This commit is contained in:
J-P Nurmi
2015-09-08 00:17:02 +02:00
parent 832430659f
commit 7f03484899
3 changed files with 48 additions and 1 deletions
+1
View File
@@ -258,6 +258,7 @@ private:
void EchoMessage(const CMessage& Message);
std::set<CChan*> MatchChans(const CString& sPatterns) const;
unsigned int AttachChans(const std::set<CChan*>& sChans);
unsigned int DetachChans(const std::set<CChan*>& sChans);
protected:
+28 -1
View File
@@ -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<CChan*> 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<CChan*> CClient::MatchChans(const CString& sPatterns) const
return sChans;
}
unsigned int CClient::AttachChans(const std::set<CChan*>& 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<CChan*>& sChans)
{
unsigned int uDetached = 0;
+19
View File
@@ -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<CChan*> 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);