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:
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user