Improved links parsing and replacing in Matrix and Telegram pushers.
Related to #3.
This commit is contained in:
parent
c93fa504ad
commit
27414ccf15
@ -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 {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user