mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 21:50:28 +00:00
Truncate messages sent to IRC based on byte count (#368)
* Truncate messages sent to IRC based on byte count * Avoid unnecessary string allocations
This commit is contained in:
parent
83c28cb857
commit
1d33e60e36
@ -19,6 +19,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Birc struct {
|
type Birc struct {
|
||||||
@ -200,9 +201,12 @@ func (b *Birc) Send(msg config.Message) (string, error) {
|
|||||||
msg.Text = helper.SplitStringLength(msg.Text, b.Config.MessageLength)
|
msg.Text = helper.SplitStringLength(msg.Text, b.Config.MessageLength)
|
||||||
}
|
}
|
||||||
for _, text := range strings.Split(msg.Text, "\n") {
|
for _, text := range strings.Split(msg.Text, "\n") {
|
||||||
input := []rune(text)
|
|
||||||
if len(text) > b.Config.MessageLength {
|
if len(text) > b.Config.MessageLength {
|
||||||
text = string(input[:b.Config.MessageLength]) + " <message clipped>"
|
text = text[:b.Config.MessageLength-len(" <message clipped>")]
|
||||||
|
if r, size := utf8.DecodeLastRuneInString(text); r == utf8.RuneError {
|
||||||
|
text = text[:len(text)-size]
|
||||||
|
}
|
||||||
|
text += " <message clipped>"
|
||||||
}
|
}
|
||||||
if len(b.Local) < b.Config.MessageQueue {
|
if len(b.Local) < b.Config.MessageQueue {
|
||||||
if len(b.Local) == b.Config.MessageQueue-1 {
|
if len(b.Local) == b.Config.MessageQueue-1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user