From 3b0a91d3eebf7e54d184440a7fb2103b87ec8c09 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Sat, 20 Oct 2018 19:48:36 +0800 Subject: [PATCH] Fixed poor trimming of translation source text. --- bridge/slack/slack.go | 6 +++++- gateway/gateway.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index e1248660..3ea796f0 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -291,7 +291,11 @@ func (b *Bslack) createAttach(extra map[string][]interface{}) []slack.Attachment } func (b *Bslack) createTranslationAttach(msg config.Message) slack.Attachment { - untranslatedTextPreview := msg.TranslationSrcMsg.Text[:100]+"..." + untranslatedTextPreview := msg.TranslationSrcMsg.Text + previewCharCount := 100 + if len(msg.TranslationSrcMsg.Text) > previewCharCount { + untranslatedTextPreview = untranslatedTextPreview[:previewCharCount]+"..." + } ch, err := b.getChannelByName(msg.TranslationSrcMsg.Channel) time := strings.Split(msg.TranslationSrcMsg.ID, " ")[1] params := slack.PermalinkParameters{ diff --git a/gateway/gateway.go b/gateway/gateway.go index fe0bd714..3559097e 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -332,7 +332,9 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM msg.Avatar = gw.modifyAvatar(origmsg, dest) msg.Username = gw.modifyUsername(origmsg, dest) msg.ID = "" + // Don't keep artifacts in between processed translations msg.Text = origmsg.Text + msg.TranslationSrcMsg = nil // Translation if (gw.Router.GTClient != nil) && (channel.Options.Locale != "") && (msg.Text != "") {