mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-26 16:39:24 +00:00
Clip too long messages sent to discord (discord). Closes #440
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user