commit afadffe598741688d39ccd364e664da1cb7407db
Author: Wim <wim@42.be>
Date: Sun Feb 17 21:49:28 2019 +0000
diff --git a/gateway/gateway.go b/gateway/gateway.go
index 72d0831..6ac0abe 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -23738 +2376 @@ func (gw *Gateway) ignoreTextEmpty(msg *config.Message) bool {
return true
}
-// ignoreTexts returns true if msg.Text matches any of the input regexes.
-func (gw *Gateway) ignoreTexts(msg *config.Message, input []string) bool {
- for _, entry := range input {
- if entry == "" {
- continue
- }
- // TODO do not compile regexps everytime
- re, err := regexp.Compile(entry)
- if err != nil {
- flog.Errorf("incorrect regexp %s for %s", entry, msg.Account)
- continue
- }
- if re.MatchString(msg.Text) {
- flog.Debugf("matching %s. ignoring %s from %s", entry, msg.Text, msg.Account)
- return true
- }
- }
- return false
-}
-
-// ignoreNicks returns true if msg.Username matches any of the input regexes.
-func (gw *Gateway) ignoreNicks(msg *config.Message, input []string) bool {
- // is the username in IgnoreNicks field
- for _, entry := range input {
- if msg.Username == entry {
- flog.Debugf("ignoring %s from %s", msg.Username, msg.Account)
- return true
- }
- }
- return false
-}
-
func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
// if we don't have the bridge, ignore it
if _, ok := gw.Bridges[msg.Account]; !ok {
@@ -2777 +2457 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
igNicks := strings.Fields(gw.Bridges[msg.Account].GetString("IgnoreNicks"))
igMessages := strings.Fields(gw.Bridges[msg.Account].GetString("IgnoreMessages"))
- if gw.ignoreTextEmpty(msg) || gw.ignoreNicks(msg, igNicks) || gw.ignoreTexts(msg, igMessages) {
+ if gw.ignoreTextEmpty(msg) || gw.ignoreText(msg.Username, igNicks) || gw.ignoreText(msg.Text, igMessages) {
return true
}
@@ -4353 +40323 @@ func getChannelID(msg config.Message) string {
func isAPI(account string) bool {
return strings.HasPrefix(account, "api.")
}
+
+// ignoreText returns true if text matches any of the input regexes.
+func (gw *Gateway) ignoreText(text string, input []string) bool {
+ for _, entry := range input {
+ if entry == "" {
+ continue
+ }
+ // TODO do not compile regexps everytime
+ re, err := regexp.Compile(entry)
+ if err != nil {
+ flog.Errorf("incorrect regexp %s", entry)
+ continue
+ }
+ if re.MatchString(text) {
+ flog.Debugf("matching %s. ignoring %s", entry, text)
+ return true
+ }
+ }
+ return false
+}
diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go
index cd78fe9..9621ab7 100644
--- a/gateway/gateway_test.go
+++ b/gateway/gateway_test.go
@@ -43468 +43468 @@ func TestIgnoreTextEmpty(t *testing.T) {
func TestIgnoreTexts(t *testing.T) {
msgTests := map[string]struct {
- input *config.Message
+ input string
re []string
output bool
}{
"no regex": {
- input: &config.Message{Text: "a text message"},
+ input: "a text message",
re: []string{},
output: false,
},
"simple regex": {
- input: &config.Message{Text: "a text message"},
+ input: "a text message",
re: []string{"text"},
output: true,
},
"multiple regex fail": {
- input: &config.Message{Text: "a text message"},
+ input: "a text message",
re: []string{"abc", "123$"},
output: false,
},
"multiple regex pass": {
- input: &config.Message{Text: "a text message"},
+ input: "a text message",
re: []string{"lala", "sage$"},
output: true,
},
}
gw := &Gateway{}
for testname, testcase := range msgTests {
- output := gw.ignoreTexts(testcase.input, testcase.re)
+ output := gw.ignoreText(testcase.input, testcase.re)
assert.Equalf(t, testcase.output, output, "case '%s' failed", testname)
}
}
func TestIgnoreNicks(t *testing.T) {
msgTests := map[string]struct {
- input *config.Message
+ input string
re []string
output bool
}{
"no entry": {
- input: &config.Message{Username: "user", Text: "a text message"},
+ input: "user",
re: []string{},
output: false,
},
"one entry": {
- input: &config.Message{Username: "user", Text: "a text message"},
+ input: "user",
re: []string{"user"},
output: true,
},
"multiple entries": {
- input: &config.Message{Username: "user", Text: "a text message"},
+ input: "user",
re: []string{"abc", "user"},
output: true,
},
"multiple entries fail": {
- input: &config.Message{Username: "user", Text: "a text message"},
+ input: "user",
re: []string{"abc", "def"},
output: false,
},
}
gw := &Gateway{}
for testname, testcase := range msgTests {
- output := gw.ignoreNicks(testcase.input, testcase.re)
+ output := gw.ignoreText(testcase.input, testcase.re)
assert.Equalf(t, testcase.output, output, "case '%s' failed", testname)
}
}
diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample
index 77f5b51..b3851a0 100644
--- a/matterbridge.toml.sample
+++ b/matterbridge.toml.sample
@@ -1026 +1027 @@ ColorNicks=false
RunCommands=["PRIVMSG user hello","PRIVMSG chanserv something"]
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
@@ -1966 +1977 @@ SkipTLSVerify=true
## Settings below can be reloaded by editing the file
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
@@ -2766 +2787 @@ Nick="yourlogin"
## Settings below can be reloaded by editing the file
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="spammer1 spammer2"
@@ -4166 +4197 @@ EditDisable=false
EditSuffix=" (edited)"
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
@@ -4916 +4957 @@ Token="Yourtokenhere"
## Settings below can be reloaded by editing the file
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
@@ -6096 +6147 @@ EditSuffix=" (edited)"
PrefixMessagesWithNick=false
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
@@ -7226 +7287 @@ EditDisable=false
EditSuffix=" (edited)"
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
@@ -8306 +8377 @@ EditDisable=false
EditSuffix=" (edited)"
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="spammer1 spammer2"
@@ -9456 +9537 @@ SkipTLSVerify=true
PrefixMessagesWithNick=false
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="ircspammer1 ircspammer2"
@@ -10316 +10407 @@ NoHomeServerSuffix=false
PrefixMessagesWithNick=false
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="spammer1 spammer2"
@@ -11116 +11217 @@ Authcode="ABCE12"
PrefixMessagesWithNick=false
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="spammer1 spammer2"
@@ -11916 +12027 @@ Topic="matterbridge"
## Settings below can be reloaded by editing the file
#Nicks you want to ignore.
+#Regular expressions supported
#Messages from those users will not be sent to other bridges.
#OPTIONAL
IgnoreNicks="spammer1 spammer2"