Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add string searching for autoattach

  • Loading branch information...
commit addd04746530e3cec9891de2b08bc261902a2444 1 parent 978e3b7
@gtmanfred gtmanfred authored gtmanfred committed
Showing with 48 additions and 25 deletions.
  1. +48 −25 modules/autoattach.cpp
View
73 modules/autoattach.cpp
@@ -8,28 +8,34 @@
#include <znc/Chan.h>
#include <znc/Modules.h>
+#include <znc/User.h>
using std::vector;
class CAttachMatch {
public:
- CAttachMatch(const CString& sChannels, const CString& sHostmasks, bool bNegated)
+ CAttachMatch(const CString& sChannels, const CString& sSearch, const CString& sHostmasks, bool bNegated)
{
m_sChannelWildcard = sChannels;
+ m_sSearchWildcard = sSearch;
m_sHostmaskWildcard = sHostmasks;
m_bNegated = bNegated;
if (m_sChannelWildcard.empty())
m_sChannelWildcard = "*";
+ if (m_sSearchWildcard.empty())
+ m_sSearchWildcard = "*";
if (m_sHostmaskWildcard.empty())
m_sHostmaskWildcard = "*!*@*";
}
- bool IsMatch(const CString& sChan, const CString& sHost) const {
+ bool IsMatch(const CString& sChan, const CString& sHost, const CString& sMessage) const {
if (!sHost.WildCmp(m_sHostmaskWildcard))
return false;
if (!sChan.WildCmp(m_sChannelWildcard))
return false;
+ if (!sMessage.WildCmp(m_pModule->GetUser()->ExpandString(m_sSearchWildcard)))
+ return false;
return true;
}
@@ -41,6 +47,10 @@ class CAttachMatch {
return m_sHostmaskWildcard;
}
+ const CString& GetSearch() const {
+ return m_sSearchWildcard;
+ }
+
const CString& GetChans() const {
return m_sChannelWildcard;
}
@@ -51,6 +61,8 @@ class CAttachMatch {
sRes += "!";
sRes += m_sChannelWildcard;
sRes += " ";
+ sRes += m_sSearchWildcard;
+ sRes += " ";
sRes += m_sHostmaskWildcard;
return sRes;
}
@@ -58,7 +70,9 @@ class CAttachMatch {
private:
bool m_bNegated;
CString m_sChannelWildcard;
+ CString m_sSearchWildcard;
CString m_sHostmaskWildcard;
+ CModules* m_pModule;
};
class CChanAttach : public CModule {
@@ -72,18 +86,19 @@ class CChanAttach : public CModule {
bool bHelp = false;
bool bNegated = sMsg.TrimPrefix("!");
CString sChan = sMsg.Token(0);
- CString sHost = sMsg.Token(1);
+ CString sSearch = sMsg.Token(1);
+ CString sHost = sMsg.Token(2);
if (sChan.empty()) {
bHelp = true;
- } else if (Add(bNegated, sChan, sHost)) {
+ } else if (Add(bNegated, sChan, sSearch, sHost)) {
PutModule("Added to list");
} else {
PutModule(sLine.Token(1, true) + " is already added");
bHelp = true;
}
if (bHelp) {
- PutModule("Usage: Add [!]<#chan> <host>");
+ PutModule("Usage: Add [!]<#chan> <search> <host>");
PutModule("Wildcards are allowed");
}
}
@@ -92,12 +107,13 @@ class CChanAttach : public CModule {
CString sMsg = sLine.Token(1, true);
bool bNegated = sMsg.TrimPrefix("!");
CString sChan = sMsg.Token(0);
- CString sHost = sMsg.Token(1);
+ CString sSearch = sMsg.Token(1);
+ CString sHost = sMsg.Token(2);
- if (Del(bNegated, sChan, sHost)) {
+ if (Del(bNegated, sChan, sSearch, sHost)) {
PutModule("Removed " + sChan + " from list");
} else {
- PutModule("Usage: Del [!]<#chan> <host>");
+ PutModule("Usage: Del [!]<#chan> <search> <host>");
}
}
@@ -105,6 +121,7 @@ class CChanAttach : public CModule {
CTable Table;
Table.AddColumn("Neg");
Table.AddColumn("Chan");
+ Table.AddColumn("Search");
Table.AddColumn("Host");
VAttachIter it = m_vMatches.begin();
@@ -112,6 +129,7 @@ class CChanAttach : public CModule {
Table.AddRow();
Table.SetCell("Neg", it->IsNegated() ? "!" : "");
Table.SetCell("Chan", it->GetChans());
+ Table.SetCell("Search", it->GetSearch());
Table.SetCell("Host", it->GetHostMask());
}
@@ -126,9 +144,9 @@ class CChanAttach : public CModule {
MODCONSTRUCTOR(CChanAttach) {
AddHelpCommand();
AddCommand("Add", static_cast<CModCommand::ModCmdFunc>(&CChanAttach::HandleAdd),
- "[!]<#chan> <host>", "Add an entry, use !#chan to negate and * for wildcards");
+ "[!]<#chan> <search> <host>", "Add an entry, use !#chan to negate and * for wildcards");
AddCommand("Del", static_cast<CModCommand::ModCmdFunc>(&CChanAttach::HandleDel),
- "[!]<#chan> <host>", "Remove an entry, needs to be an exact match");
+ "[!]<#chan> <search> <host>", "Remove an entry, needs to be an exact match");
AddCommand("List", static_cast<CModCommand::ModCmdFunc>(&CChanAttach::HandleList),
"", "List all entries");
}
@@ -144,9 +162,10 @@ class CChanAttach : public CModule {
CString sAdd = *it;
bool bNegated = sAdd.TrimPrefix("!");
CString sChan = sAdd.Token(0);
- CString sHost = sAdd.Token(1, true);
+ CString sSearch = sAdd.Token(1);
+ CString sHost = sAdd.Token(2, true);
- if (!Add(bNegated, sChan, sHost)) {
+ if (!Add(bNegated, sChan, sSearch, sHost)) {
PutModule("Unable to add [" + *it + "]");
}
}
@@ -157,17 +176,19 @@ class CChanAttach : public CModule {
CString sAdd = it->first;
bool bNegated = sAdd.TrimPrefix("!");
CString sChan = sAdd.Token(0);
- CString sHost = sAdd.Token(1, true);
+ CString sSearch = sAdd.Token(1);
+ CString sHost = sAdd.Token(2, true);
- Add(bNegated, sChan, sHost);
+ Add(bNegated, sChan, sSearch, sHost);
}
return true;
}
- void TryAttach(const CNick& Nick, CChan& Channel) {
+ void TryAttach(const CNick& Nick, CChan& Channel, CString& Message) {
const CString& sChan = Channel.GetName();
const CString& sHost = Nick.GetHostMask();
+ const CString& sMessage = Message;
VAttachIter it;
if (!Channel.IsDetached())
@@ -175,13 +196,13 @@ class CChanAttach : public CModule {
// Any negated match?
for (it = m_vMatches.begin(); it != m_vMatches.end(); ++it) {
- if (it->IsNegated() && it->IsMatch(sChan, sHost))
+ if (it->IsNegated() && it->IsMatch(sChan, sHost, sMessage))
return;
}
// Now check for a positive match
for (it = m_vMatches.begin(); it != m_vMatches.end(); ++it) {
- if (!it->IsNegated() && it->IsMatch(sChan, sHost)) {
+ if (!it->IsNegated() && it->IsMatch(sChan, sHost, sMessage)) {
Channel.JoinUser();
return;
}
@@ -189,25 +210,27 @@ class CChanAttach : public CModule {
}
virtual EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage) {
- TryAttach(Nick, Channel);
+ TryAttach(Nick, Channel, sMessage);
return CONTINUE;
}
virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) {
- TryAttach(Nick, Channel);
+ TryAttach(Nick, Channel, sMessage);
return CONTINUE;
}
virtual EModRet OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage) {
- TryAttach(Nick, Channel);
+ TryAttach(Nick, Channel, sMessage);
return CONTINUE;
}
- VAttachIter FindEntry(const CString& sChan, const CString& sHost) {
+ VAttachIter FindEntry(const CString& sChan, const CString& sSearch, const CString& sHost) {
VAttachIter it = m_vMatches.begin();
for (; it != m_vMatches.end(); ++it) {
if (sHost.empty() || it->GetHostMask() != sHost)
continue;
+ if (sSearch.empty() || it->GetSearch() != sSearch)
+ continue;
if (sChan.empty() || it->GetChans() != sChan)
continue;
return it;
@@ -215,8 +238,8 @@ class CChanAttach : public CModule {
return m_vMatches.end();
}
- bool Add(bool bNegated, const CString& sChan, const CString& sHost) {
- CAttachMatch attach(sChan, sHost, bNegated);
+ bool Add(bool bNegated, const CString& sChan, const CString& sSearch, const CString& sHost) {
+ CAttachMatch attach(sChan, sSearch, sHost, bNegated);
// Check for duplicates
VAttachIter it = m_vMatches.begin();
@@ -234,8 +257,8 @@ class CChanAttach : public CModule {
return true;
}
- bool Del(bool bNegated, const CString& sChan, const CString& sHost) {
- VAttachIter it = FindEntry(sChan, sHost);
+ bool Del(bool bNegated, const CString& sChan, const CString& sSearch, const CString& sHost) {
+ VAttachIter it = FindEntry(sChan, sSearch, sHost);
if (it == m_vMatches.end() || it->IsNegated() != bNegated)
return false;
Please sign in to comment.
Something went wrong with that request. Please try again.