Remove initial line break if present. Fixes #6.

This commit is contained in:
Stanislav Nikitin 2019-03-25 22:28:21 +05:00
parent 25ab43c8ba
commit 654aa94b0c
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE

View File

@ -20,6 +20,7 @@ package defaultparser
import (
// stdlib
"regexp"
"strings"
// local
"gitlab.com/pztrn/opensaps/slack/message"
@ -39,17 +40,17 @@ func (dp DefaultParser) ParseMessage(message slackmessage.SlackMessage) map[stri
msg += attachment.Text + "\n"
}
// Remove line break in very beginning, if present.
if strings.Contains(msg[0:3], "\n") {
c.Log.Debugln("Initial br found, removing")
msg = strings.Replace(msg, "\n", "", 1)
}
// Get all links from message.
r := regexp.MustCompile(`<{1}([\pL\pP\pN]+)\|{1}([\pL\pP\pN\pZs]+)>{1}`)
foundLinks := r.FindAllStringSubmatch(msg, -1)
c.Log.Debugln("Found links:", foundLinks)
// Replace them.
/*for _, link := range foundLinks {
c.Log.Debugln("Link:", link)
msg = strings.Replace(msg, "<"+link[0]+">", "<a href='"+link[2]+"'>"+link[3]+"</a>", 1)
}*/
data := make(map[string]interface{})
data["message"] = msg
data["links"] = foundLinks