summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-11-15 23:32:49 +0100
committerWim <wim@42.be>2017-11-15 23:33:00 +0100
commitaff39640781cd7af28421fc2a97dcb4e93b467e2 (patch)
treee511ff37c52251a218f2ac3aa185b2a49209c24f
parent2778580397b6105642c1a50d031d54dcb03fa4db (diff)
downloadmatterbridge-msglm-aff39640781cd7af28421fc2a97dcb4e93b467e2.tar.gz
matterbridge-msglm-aff39640781cd7af28421fc2a97dcb4e93b467e2.tar.bz2
matterbridge-msglm-aff39640781cd7af28421fc2a97dcb4e93b467e2.zip
Add support for ReplaceMessages using regexp to replace messages. #269
-rw-r--r--bridge/config/config.go93
-rw-r--r--gateway/gateway.go13
2 files changed, 60 insertions, 46 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index b4124347..f26e60bb 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -48,52 +48,53 @@ type ChannelInfo struct {
}
type Protocol struct {
- AuthCode string // steam
- BindAddress string // mattermost, slack // DEPRECATED
- Buffer int // api
- Charset string // irc
- EditSuffix string // mattermost, slack, discord, telegram, gitter
- 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
- Name string // all protocols
- Nick string // all protocols
- NickFormatter string // mattermost, slack
- NickServNick string // IRC
- NickServUsername string // IRC
- NickServPassword string // IRC
- NicksPerRow int // mattermost, slack
- NoHomeServerSuffix bool // matrix
- NoTLS bool // mattermost
- Password string // IRC,mattermost,XMPP,matrix
- PrefixMessagesWithNick bool // mattemost, slack
- Protocol string //all protocols
- MessageQueue int // IRC, size of message queue for flood control
- MessageDelay int // IRC, time in millisecond to wait between messages
- MessageLength int // IRC, max length of a message allowed
- MessageFormat string // telegram
- RemoteNickFormat string // all protocols
- Server string // IRC,mattermost,XMPP,discord
- ShowJoinPart bool // all protocols
- ShowEmbeds bool // discord
- SkipTLSVerify bool // IRC, mattermost
- StripNick bool // all protocols
- Team string // mattermost
- Token string // gitter, slack, discord, api
- URL string // mattermost, slack // DEPRECATED
- UseAPI bool // mattermost, slack
- UseSASL bool // IRC
- UseTLS bool // IRC
- UseFirstName bool // telegram
- UseUserName bool // discord
- UseInsecureURL bool // telegram
- WebhookBindAddress string // mattermost, slack
- WebhookURL string // mattermost, slack
- WebhookUse string // mattermost, slack, discord
+ AuthCode string // steam
+ BindAddress string // mattermost, slack // DEPRECATED
+ Buffer int // api
+ Charset string // irc
+ EditSuffix string // mattermost, slack, discord, telegram, gitter
+ 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
+ Name string // all protocols
+ Nick string // all protocols
+ NickFormatter string // mattermost, slack
+ NickServNick string // IRC
+ NickServUsername string // IRC
+ NickServPassword string // IRC
+ NicksPerRow int // mattermost, slack
+ NoHomeServerSuffix bool // matrix
+ NoTLS bool // mattermost
+ Password string // IRC,mattermost,XMPP,matrix
+ PrefixMessagesWithNick bool // mattemost, slack
+ Protocol string //all protocols
+ ReplaceMessages [][]string // all messages
+ MessageQueue int // IRC, size of message queue for flood control
+ MessageDelay int // IRC, time in millisecond to wait between messages
+ MessageLength int // IRC, max length of a message allowed
+ MessageFormat string // telegram
+ RemoteNickFormat string // all protocols
+ Server string // IRC,mattermost,XMPP,discord
+ ShowJoinPart bool // all protocols
+ ShowEmbeds bool // discord
+ SkipTLSVerify bool // IRC, mattermost
+ StripNick bool // all protocols
+ Team string // mattermost
+ Token string // gitter, slack, discord, api
+ URL string // mattermost, slack // DEPRECATED
+ UseAPI bool // mattermost, slack
+ UseSASL bool // IRC
+ UseTLS bool // IRC
+ UseFirstName bool // telegram
+ UseUserName bool // discord
+ UseInsecureURL bool // telegram
+ WebhookBindAddress string // mattermost, slack
+ WebhookURL string // mattermost, slack
+ WebhookUse string // mattermost, slack, discord
}
type ChannelOptions struct {
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
}