From 654aa94b0ce856214fe7ec2bcba54d351808a8a9 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Mon, 25 Mar 2019 22:28:21 +0500 Subject: [PATCH] Remove initial line break if present. Fixes #6. --- parsers/default/defaultparser.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/parsers/default/defaultparser.go b/parsers/default/defaultparser.go index 4fd2cd5..ebef01d 100644 --- a/parsers/default/defaultparser.go +++ b/parsers/default/defaultparser.go @@ -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]+">", ""+link[3]+"", 1) - }*/ - data := make(map[string]interface{}) data["message"] = msg data["links"] = foundLinks