Improved links parsing and replacing in Matrix and Telegram pushers.

Related to #3.
This commit is contained in:
Stanislav Nikitin 2019-03-06 05:08:00 +05:00
parent c93fa504ad
commit 27414ccf15
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
3 changed files with 5 additions and 4 deletions

View File

@ -40,8 +40,9 @@ func (dp DefaultParser) ParseMessage(message slackmessage.SlackMessage) map[stri
} }
// Get all links from message. // Get all links from message.
r := regexp.MustCompile("((https??://[a-zA-Z0-9.#!*/ _-]+)\\|([a-zA-Z0-9.#!*/ _+-]+))") r := regexp.MustCompile(`<{1}([\pL\pP\pN]+)\|{1}([\pL\pP\pN\pZs]+)>{1}`)
foundLinks := r.FindAllStringSubmatch(msg, -1) foundLinks := r.FindAllStringSubmatch(msg, -1)
c.Log.Debugln("Found links:", foundLinks)
// Replace them. // Replace them.
/*for _, link := range foundLinks { /*for _, link := range foundLinks {

View File

@ -185,7 +185,7 @@ func (mxc *MatrixConnection) Initialize(conn_name string, api_root string, user
// If we're here - everything is okay and we already in room. Send // If we're here - everything is okay and we already in room. Send
// greeting message. // greeting message.
mxc.SendMessage("OpenSAPS is back in business for connection '" + mxc.conn_name + "'!") //mxc.SendMessage("OpenSAPS is back in business for connection '" + mxc.conn_name + "'!")
} }
// This function launches when new data was received thru Slack API. // This function launches when new data was received thru Slack API.
@ -200,7 +200,7 @@ func (mxc *MatrixConnection) ProcessMessage(message slackmessage.SlackMessage) {
if linksFound { if linksFound {
links := linksRaw.([][]string) links := linksRaw.([][]string)
for _, link := range links { for _, link := range links {
messageToSend = strings.Replace(messageToSend, "<"+link[0]+">", `<a href="`+link[2]+`">`+link[3]+`</a>`, -1) messageToSend = strings.Replace(messageToSend, link[0], `<a href="`+link[1]+`">`+link[2]+`</a>`, -1)
} }
} }

View File

@ -47,7 +47,7 @@ func (tc *TelegramConnection) ProcessMessage(message slackmessage.SlackMessage)
if linksFound { if linksFound {
links := linksRaw.([][]string) links := linksRaw.([][]string)
for _, link := range links { for _, link := range links {
messageToSend = strings.Replace(messageToSend, "<"+link[0]+">", `<a href="`+link[2]+`">`+link[3]+`</a>`, -1) messageToSend = strings.Replace(messageToSend, link[0], `<a href="`+link[1]+`">`+link[2]+`</a>`, -1)
} }
} }