diff options
author | Wim <wim@42.be> | 2017-11-15 23:32:49 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-11-15 23:33:00 +0100 |
commit | aff39640781cd7af28421fc2a97dcb4e93b467e2 (patch) | |
tree | e511ff37c52251a218f2ac3aa185b2a49209c24f /gateway/gateway.go | |
parent | 2778580397b6105642c1a50d031d54dcb03fa4db (diff) | |
download | matterbridge-msglm-aff39640781cd7af28421fc2a97dcb4e93b467e2.tar.gz matterbridge-msglm-aff39640781cd7af28421fc2a97dcb4e93b467e2.tar.bz2 matterbridge-msglm-aff39640781cd7af28421fc2a97dcb4e93b467e2.zip |
Add support for ReplaceMessages using regexp to replace messages. #269
Diffstat (limited to 'gateway/gateway.go')
-rw-r--r-- | gateway/gateway.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go index e1a6c9cb..8a0a666f 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -287,6 +287,19 @@ func (gw *Gateway) modifyAvatar(msg config.Message, dest *bridge.Bridge) string func (gw *Gateway) modifyMessage(msg *config.Message) { // replace :emoji: to unicode msg.Text = emojilib.Replace(msg.Text) + br := gw.Bridges[msg.Account] + // loop to replace messages + for _, outer := range br.Config.ReplaceMessages { + search := outer[0] + replace := outer[1] + // TODO move compile to bridge init somewhere + re, err := regexp.Compile(search) + if err != nil { + log.Errorf("regexp in %s failed: %s", msg.Account, err) + break + } + msg.Text = re.ReplaceAllString(msg.Text, replace) + } msg.Gateway = gw.Name } |