From a83831e68d47a83775ab54539ddf4fd776576fa7 Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 19 Apr 2018 12:53:49 +0200 Subject: Remove empty newlines from messages (telegram) #399 --- bridge/helper/helper.go | 10 ++++++++++ bridge/telegram/telegram.go | 10 ++-------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'bridge') diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index 81789741..7edffb80 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -88,3 +88,13 @@ func HandleDownloadData(flog *log.Entry, msg *config.Message, name, comment, url } msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: name, Data: data, URL: url, Comment: comment, Avatar: avatar}) } + +func RemoveEmptyNewLines(msg string) string { + lines := "" + for _, line := range strings.Split(msg, "\n") { + if line != "" { + lines += line + "\n" + } + } + return lines +} diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go index d2f229f8..ee7309ed 100644 --- a/bridge/telegram/telegram.go +++ b/bridge/telegram/telegram.go @@ -222,18 +222,12 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { usernameReply = "unknown" } if !b.GetBool("QuoteDisable") { - rmsg.Text = rmsg.Text + " (re @" + usernameReply + ":" - // remove empty lines - for _, m := range strings.Split(message.ReplyToMessage.Text, "\n") { - if m != "" { - rmsg.Text = rmsg.Text + m - } - } - rmsg.Text = rmsg.Text + ")" + rmsg.Text = rmsg.Text + " (re @" + usernameReply + ":" + message.ReplyToMessage.Text + ")" } } if rmsg.Text != "" || len(rmsg.Extra) > 0 { + rmsg.Text = helper.RemoveEmptyNewLines(rmsg.Text) rmsg.Avatar = helper.GetAvatar(b.avatarMap, strconv.Itoa(message.From.ID), b.General) b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account) -- cgit v1.2.3