From ae5c3f02eee234dd3fa01cd8f8f05865afe9af1a Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 15 Oct 2018 08:40:35 +0800 Subject: [PATCH] Added lots of debug output while working on PR. --- gateway/gateway.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gateway/gateway.go b/gateway/gateway.go index 3d25b275..8d6c7ef0 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -351,6 +351,8 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM url_re := regexp.MustCompile(`(((http(s)?(\:\/\/))+(www\.)?([\w\-\.\/])*(\.[a-zA-Z]{2,3}\/?))[^\s\n|]*[^.,;:\?\!\@\^\$ -])`) text = url_re.ReplaceAllString(text, "$0") + flog.Debugf("pre-parseMD:"+text) + // Get rid of these wierdo bullets that Slack uses, which confuse translation text = strings.Replace(text, "•", "-", -1) @@ -364,6 +366,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM blackfriday.EXTENSION_HARD_LINE_BREAK output := blackfriday.Markdown([]byte(text), renderer, extensions) text = string(output) + flog.Debugf("post-parseMD:"+string(output)) // @usernames results = regexp.MustCompile(`(@[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1) @@ -375,6 +378,8 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM text = regexp.MustCompile(fmt.Sprintf(`([^>])(%s)`, r[1])).ReplaceAllString(text, "$1$2") } + flog.Debugf("post cleanup:usernames:"+text) + // #channels results = regexp.MustCompile(`(#[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1) // Sort so that longest channel names are acted on first @@ -386,12 +391,15 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM text = regexp.MustCompile(fmt.Sprintf(`([^>])(%s)`, r[1])).ReplaceAllString(text, "$1$2") } + flog.Debugf("post cleanup:channels:"+text) + // :emoji: text = regexp.MustCompile(`:[a-z0-9-_]+?:`).ReplaceAllString(text, "$0") // :emoji: codepoints, ie. 💎 text = emoji.NewEmojiParser().ReplaceAllString(text, "$0") + flog.Debugf("post cleanup:emojis:"+text) channelLang, err := language.Parse(channel.Options.Locale) if err != nil { @@ -403,6 +411,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM }) text = resp[0].Text + flog.Debugf("post-translate:"+text) if resp[0].Source != channelLang { // If the source language is the same as this channel, @@ -429,6 +438,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM stripped, _ := htmltags.Strip(text, allowableTags, false) text = stripped.ToString() + flog.Debugf("post-strip:"+text) html2md.AddRule("del", &html2md.Rule{ Patterns: []string{"del"}, Replacement: func(innerHTML string, attrs []string) string { @@ -472,7 +482,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM // colons: revert temp token // See: previous comment on colons text = regexp.MustCompile(`(ː)([ $])`).ReplaceAllString(text, ":$2") + + flog.Debugf("post-MDconvert:"+text) text = html.UnescapeString(text) + flog.Debugf("post-unescaped:"+text) text = text + gw.Router.General.TranslationAttribution