From 25b1af1e110afc72630027b8957f3bdaedfa943f Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 18 Jun 2017 01:08:11 +0200 Subject: Add option IgnoreMessages to ignore messages based on regexp. (all). Closes #70 --- gateway/gateway.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gateway') diff --git a/gateway/gateway.go b/gateway/gateway.go index 2fa5a0bb..d2c6c220 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -5,6 +5,7 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" log "github.com/Sirupsen/logrus" + "regexp" "strings" "time" ) @@ -197,6 +198,9 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) { log.Debug("empty channel") return } + // hide message from bridge + //if msg.Text HideMessagesPrefix + originchannel := msg.Channel origmsg := msg for _, channel := range gw.DestChannelFunc(&msg, *dest) { @@ -230,6 +234,20 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool { return true } } + // TODO do not compile regexps everytime + for _, entry := range strings.Fields(gw.Bridges[msg.Account].Config.IgnoreMessages) { + if entry != "" { + re, err := regexp.Compile(entry) + if err != nil { + log.Errorf("incorrect regexp %s for %s", entry, msg.Account) + continue + } + if re.MatchString(msg.Text) { + log.Debugf("matching %s. ignoring %s from %s", entry, msg.Text, msg.Account) + return true + } + } + } return false } -- cgit v1.2.3