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 | |
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
-rw-r--r-- | bridge/config/config.go | 1 | ||||
-rw-r--r-- | gateway/gateway.go | 18 | ||||
-rw-r--r-- | matterbridge.toml.sample | 60 |
3 files changed, 79 insertions, 0 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go index 4b3c4250..f79c40d0 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -44,6 +44,7 @@ type Protocol struct { EditDisable bool // mattermost, slack, discord, telegram, gitter IconURL string // mattermost, slack IgnoreNicks string // all protocols + IgnoreMessages string // all protocols Jid string // xmpp Login string // mattermost, matrix Muc string // xmpp 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 } diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index bcbab627..ecc921b1 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -63,6 +63,12 @@ MessageLength=400 #OPTIONAL IgnoreNicks="ircspammer1 ircspammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -115,6 +121,12 @@ SkipTLSVerify=true #OPTIONAL IgnoreNicks="ircspammer1 ircspammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -159,6 +171,12 @@ Nick="yourlogin" #OPTIONAL IgnoreNicks="spammer1 spammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -261,6 +279,12 @@ EditSuffix=" (edited)" #OPTIONAL IgnoreNicks="ircspammer1 ircspammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -294,6 +318,12 @@ Token="Yourtokenhere" #OPTIONAL IgnoreNicks="ircspammer1 ircspammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -383,6 +413,12 @@ PrefixMessagesWithNick=false #OPTIONAL IgnoreNicks="ircspammer1 ircspammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -427,6 +463,12 @@ EditSuffix=" (edited)" #OPTIONAL IgnoreNicks="ircspammer1 ircspammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -477,6 +519,12 @@ EditSuffix=" (edited)" #OPTIONAL IgnoreNicks="spammer1 spammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -535,6 +583,12 @@ PrefixMessagesWithNick=false #OPTIONAL IgnoreNicks="ircspammer1 ircspammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -584,6 +638,12 @@ PrefixMessagesWithNick=false #OPTIONAL IgnoreNicks="spammer1 spammer2" +#Messages you want to ignore. +#Messages matching these regexp will be ignored and not sent to other bridges +#See https://regex-golang.appspot.com/assets/html/index.html for more regex info +#OPTIONAL (example below ignores messages starting with ~~ or messages containing badword +IgnoreMessages="^~~ badword" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge |