From 2597c9bfacfbc04d1d77162465039eb9b45d0e4d Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 22 Jul 2018 00:27:49 +0200 Subject: Clip too long messages sent to discord (discord). Closes #440 --- bridge/helper/helper.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'bridge/helper/helper.go') diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index d0c1062c..a13e02af 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -8,6 +8,7 @@ import ( "regexp" "strings" "time" + "unicode/utf8" "github.com/42wim/matterbridge/bridge/config" log "github.com/sirupsen/logrus" @@ -115,3 +116,15 @@ func RemoveEmptyNewLines(msg string) string { lines = strings.TrimRight(lines, "\n") return lines } + +func ClipMessage(text string, length int) string { + // clip too long messages + if len(text) > length { + text = text[:length-len(" *message clipped*")] + if r, size := utf8.DecodeLastRuneInString(text); r == utf8.RuneError { + text = text[:len(text)-size] + } + text += " *message clipped*" + } + return text +} -- cgit v1.2.3