4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-26 07:29:24 +00:00

Add option IgnoreMessages to ignore messages based on regexp. (all). Closes #70

This commit is contained in:
Wim
2017-06-18 01:08:11 +02:00
parent 75fb2b8156
commit 25b1af1e11
3 changed files with 79 additions and 0 deletions

View File

@ -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
}