From c86137449e733fc643337f33eaa33daf9e16d73c Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 27 May 2021 21:45:23 +0200 Subject: Add a MessageClipped option to set your own clipped message. Closes #1359 (#1487) --- bridge/helper/helper.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'bridge/helper/helper.go') diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index 0ad31457..1bdd8a40 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -82,8 +82,10 @@ func DownloadFileAuthRocket(url, token, userID string) (*[]byte, error) { // TODO: The current implementation has the inconvenient that it disregards // word boundaries when splitting but this is hard to solve without potentially // breaking formatting and other stylistic effects. -func GetSubLines(message string, maxLineLength int) []string { - const clippingMessage = " " +func GetSubLines(message string, maxLineLength int, clippingMessage string) []string { + if clippingMessage == "" { + clippingMessage = " " + } var lines []string for _, line := range strings.Split(strings.TrimSpace(message), "\n") { @@ -193,8 +195,11 @@ func RemoveEmptyNewLines(msg string) string { // ClipMessage trims a message to the specified length if it exceeds it and adds a warning // to the message in case it does so. -func ClipMessage(text string, length int) string { - const clippingMessage = " " +func ClipMessage(text string, length int, clippingMessage string) string { + if clippingMessage == "" { + clippingMessage = " " + } + if len(text) > length { text = text[:length-len(clippingMessage)] if r, size := utf8.DecodeLastRuneInString(text); r == utf8.RuneError { -- cgit v1.2.3