diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index cd3c86e2..40e92829 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "regexp" "strings" "sync" @@ -189,8 +188,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { } // Strip IRC colors sent to Discord - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Make a action /me of the message if msg.Event == config.EventUserAction { diff --git a/bridge/gitter/gitter.go b/bridge/gitter/gitter.go index 7508df5a..6373182f 100644 --- a/bridge/gitter/gitter.go +++ b/bridge/gitter/gitter.go @@ -2,7 +2,6 @@ package bgitter import ( "fmt" - "regexp" "strings" "github.com/42wim/go-gitter" @@ -101,8 +100,7 @@ func (b *Bgitter) Send(msg config.Message) (string, error) { } // Strip IRC colors sent to Gitter - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Delete message if msg.Event == config.EventMsgDelete { diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index dceb4848..1e7ef82c 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -199,3 +199,6 @@ func ConvertWebPToPNG(data *[]byte) error { *data = w.Bytes() return nil } + +// Strip IRC colors +var StripIRCColors = regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go index 3aa0e174..92473755 100644 --- a/bridge/matrix/matrix.go +++ b/bridge/matrix/matrix.go @@ -75,8 +75,7 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) { b.Log.Debugf("Channel %s maps to channel id %s", msg.Channel, channel) // Strip IRC colors sent to Matrix - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Make a action /me of the message if msg.Event == config.EventUserAction { diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index cdc62810..55ed0842 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -3,7 +3,6 @@ package bmattermost import ( "errors" "fmt" - "regexp" "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" @@ -100,8 +99,7 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) { b.Log.Debugf("=> Receiving %#v", msg) // Strip IRC colors sent to Mattermost - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Make a action /me of the message if msg.Event == config.EventUserAction { diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go index 4bc4955f..3dcd0afe 100644 --- a/bridge/rocketchat/rocketchat.go +++ b/bridge/rocketchat/rocketchat.go @@ -2,7 +2,6 @@ package brocketchat import ( "errors" - "regexp" "strings" "sync" @@ -110,8 +109,7 @@ func (b *Brocketchat) Send(msg config.Message) (string, error) { channel := &models.Channel{ID: b.getChannelID(msg.Channel), Name: msg.Channel} // Strip IRC colors sent to Rocketchat - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Make a action /me of the message if msg.Event == config.EventUserAction { diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index b4ba3ea7..ed51e352 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "regexp" "strings" "sync" "time" @@ -183,8 +182,7 @@ func (b *Bslack) Send(msg config.Message) (string, error) { msg.Text = b.replaceCodeFence(msg.Text) // Strip IRC colors sent to Slack - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Make a action /me of the message if msg.Event == config.EventUserAction { diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go index 9d4cf2f0..a8ecd68b 100644 --- a/bridge/sshchat/sshchat.go +++ b/bridge/sshchat/sshchat.go @@ -3,7 +3,6 @@ package bsshchat import ( "bufio" "io" - "regexp" "strings" "github.com/42wim/matterbridge/bridge" @@ -83,8 +82,7 @@ func (b *Bsshchat) Send(msg config.Message) (string, error) { } // Strip IRC colors sent to SSHChat - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") _, err := b.w.Write([]byte(msg.Username + msg.Text + "\r\n")) return "", err diff --git a/bridge/steam/steam.go b/bridge/steam/steam.go index 9731f587..6ab143a7 100644 --- a/bridge/steam/steam.go +++ b/bridge/steam/steam.go @@ -2,7 +2,6 @@ package bsteam import ( "fmt" - "regexp" "sync" "time" @@ -69,8 +68,7 @@ func (b *Bsteam) Send(msg config.Message) (string, error) { } // Strip IRC colors sent to Steam - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Handle files if msg.Extra != nil { diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index eb5cc405..63edb1aa 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -2,7 +2,6 @@ package btelegram import ( "html" - "regexp" "strconv" "strings" @@ -93,8 +92,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) { } // Strip IRC colors sent to Telegram - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // edit the message if we have a msg ID if msg.ID != "" { diff --git a/bridge/whatsapp/whatsapp.go b/bridge/whatsapp/whatsapp.go index 842e1529..ed362faa 100644 --- a/bridge/whatsapp/whatsapp.go +++ b/bridge/whatsapp/whatsapp.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "os" - "regexp" "strings" "time" @@ -245,8 +244,7 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) { b.Log.Debugf("=> Receiving %#v", msg) // Strip IRC colors sent to Whatsapp - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Delete message if msg.Event == config.EventMsgDelete { diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 71596d19..93f5c411 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -2,7 +2,6 @@ package bxmpp import ( "crypto/tls" - "regexp" "strings" "time" @@ -84,8 +83,7 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) { b.Log.Debugf("=> Receiving %#v", msg) // Strip IRC colors sent to XMPP - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Upload a file (in xmpp case send the upload URL because xmpp has no native upload support) if msg.Extra != nil { diff --git a/bridge/zulip/zulip.go b/bridge/zulip/zulip.go index 088167bc..d73e96d7 100644 --- a/bridge/zulip/zulip.go +++ b/bridge/zulip/zulip.go @@ -3,7 +3,6 @@ package bzulip import ( "encoding/json" "io/ioutil" - "regexp" "strconv" "strings" "sync" @@ -65,8 +64,7 @@ func (b *Bzulip) Send(msg config.Message) (string, error) { } // Strip IRC colors sent to Zulip - re := regexp.MustCompile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) - msg.Text = re.ReplaceAllString(msg.Text, "") + msg.Text = helper.StripIRCColors.ReplaceAllString(msg.Text, "") // Upload a file if it exists if msg.Extra != nil {