From aff39640781cd7af28421fc2a97dcb4e93b467e2 Mon Sep 17 00:00:00 2001 From: Wim Date: Wed, 15 Nov 2017 23:32:49 +0100 Subject: Add support for ReplaceMessages using regexp to replace messages. #269 --- gateway/gateway.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gateway/gateway.go') 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 } -- cgit v1.2.3