mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 21:50:28 +00:00
Strip markdown URLs with blank text (slack) (#392)
This commit is contained in:
parent
d525230abd
commit
76360f89c1
@ -4,16 +4,17 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/42wim/matterbridge/bridge"
|
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
|
||||||
"github.com/42wim/matterbridge/bridge/helper"
|
|
||||||
"github.com/42wim/matterbridge/matterhook"
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
"html"
|
"html"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/42wim/matterbridge/bridge"
|
||||||
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
|
"github.com/42wim/matterbridge/matterhook"
|
||||||
|
"github.com/nlopes/slack"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bslack struct {
|
type Bslack struct {
|
||||||
@ -387,7 +388,11 @@ func (b *Bslack) replaceVariable(text string) string {
|
|||||||
func (b *Bslack) replaceURL(text string) string {
|
func (b *Bslack) replaceURL(text string) string {
|
||||||
results := regexp.MustCompile(`<(.*?)(\|.*?)?>`).FindAllStringSubmatch(text, -1)
|
results := regexp.MustCompile(`<(.*?)(\|.*?)?>`).FindAllStringSubmatch(text, -1)
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
text = strings.Replace(text, r[0], r[1], -1)
|
if len(strings.TrimSpace(r[2])) == 1 { // A display text separator was found, but the text was blank
|
||||||
|
text = strings.Replace(text, r[0], "", -1)
|
||||||
|
} else {
|
||||||
|
text = strings.Replace(text, r[0], r[1], -1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user