diff options
author | Wim <wim@42.be> | 2017-06-18 01:08:11 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-06-18 01:08:11 +0200 |
commit | 25b1af1e110afc72630027b8957f3bdaedfa943f (patch) | |
tree | 871bae657d215b29704539ea1661103efc44f0a1 /gateway/gateway.go | |
parent | 75fb2b8156e939385f5163215a9eee0e5fe17dee (diff) | |
download | matterbridge-msglm-25b1af1e110afc72630027b8957f3bdaedfa943f.tar.gz matterbridge-msglm-25b1af1e110afc72630027b8957f3bdaedfa943f.tar.bz2 matterbridge-msglm-25b1af1e110afc72630027b8957f3bdaedfa943f.zip |
Add option IgnoreMessages to ignore messages based on regexp. (all). Closes #70
Diffstat (limited to 'gateway/gateway.go')
-rw-r--r-- | gateway/gateway.go | 18 |
1 files changed, 18 insertions, 0 deletions
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 } |