Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 917cb19d28193b031fe967fd7eb16e99b9c72111 Author: tsudoko <flan@flande.re> Date: Thu Feb 08 23:28:33 2018 +0000 Truncate messages sent to IRC based on byte count (#368) * Truncate messages sent to IRC based on byte count * Avoid unnecessary string allocations diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 0e90aaf..d95aef4 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -196 +197 @@ import (   "strconv"   "strings"   "time" + "unicode/utf8"  )    type Birc struct { @@ -2009 +20112 @@ func (b *Birc) Send(msg config.Message) (string, error) {   msg.Text = helper.SplitStringLength(msg.Text, b.Config.MessageLength)   }   for _, text := range strings.Split(msg.Text, "\n") { - input := []rune(text)   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-1 {