Compile regexp in external package

This commit is contained in:
chotaire
2019-04-18 15:38:24 +02:00
parent cda1628538
commit a17024c125
13 changed files with 15 additions and 35 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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:]]`)

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 != "" {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {