From 9ca4638475624f033e1c8739ed7b343c14675732 Mon Sep 17 00:00:00 2001 From: zhaoYangguang <1163765691@qq.com> Date: Mon, 18 Jan 2021 15:08:10 +0800 Subject: [PATCH] muliti mention --- portal.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/portal.go b/portal.go index 7cfa128..a876ba2 100644 --- a/portal.go +++ b/portal.go @@ -1901,11 +1901,10 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event) //ctxInfo := &waProto.ContextInfo{} replyToID := content.GetReplyTo() var newContent string - + backStr := "" if len(replyToID) > 0 { rQuote := regexp.MustCompile(`(.*?)(.*)`) quoteMatches := rQuote.FindAllStringSubmatch(content.FormattedBody, -1) - backStr := "" if len(quoteMatches) > 0 { if len(quoteMatches[0]) > 2 { backStr = quoteMatches[0][2] @@ -1929,7 +1928,7 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event) puppet := sender.bridge.GetPuppetByJID(msg.Sender) - newContent = fmt.Sprintf(`[%s] %s: %s\n\n<<< %s`, + newContent = fmt.Sprintf(`[%s] %s: %s\n\n<<< `, author, puppet.Displayname, timestamp, @@ -1938,8 +1937,7 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event) cuid, timestamp, puppet.Displayname, - quoteMessage, - backStr) + quoteMessage) content.FormattedBody = newContent } } @@ -1975,9 +1973,12 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event) text = "/me " + text } if len(content.FormattedBody) > 0 { - //r := regexp.MustCompile(`]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@skype&([^"]+):(.*?)">(.*?)*`) - r := regexp.MustCompile(`]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@([^"]+):(.*?)">(.*?)*`) - matches := r.FindAllStringSubmatch(content.FormattedBody, -1) + matchStr := content.FormattedBody + if len(backStr) > 0 { + matchStr = backStr + } + r := regexp.MustCompile(`(?m)]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@([^"]+):(.*?)">(.*?)`) + matches := r.FindAllStringSubmatch(matchStr, -1) fmt.Println("matches: ", matches) if len(matches) > 0 { for _, match := range matches { @@ -1986,10 +1987,19 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event) skyId = strings.ReplaceAll(skyId, "skype&", "") skyId = strings.ReplaceAll(skyId, "-", ":") // Adapt to the message format sent by the matrix front end - content.FormattedBody = strings.ReplaceAll(content.FormattedBody, match[0] + ":", fmt.Sprintf(`%s`, skyId, match[4])) - content.FormattedBody = strings.ReplaceAll(content.FormattedBody, match[0], fmt.Sprintf(`%s`, skyId, match[4])) + matchStr = strings.ReplaceAll(matchStr, match[0] + ":", fmt.Sprintf(`%s`, skyId, match[4])) + matchStr = strings.ReplaceAll(matchStr, match[0], fmt.Sprintf(`%s`, skyId, match[4])) } } + if len(backStr) > 0 { + content.FormattedBody = content.FormattedBody + matchStr + } else { + content.FormattedBody = matchStr + } + } else { + if len(backStr) > 0 { + content.FormattedBody = content.FormattedBody + backStr + } } info.SendTextMessage = &skype.SendTextMessage{