mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-14 16:09:26 +01:00
Make sure MessageLength and MessageSplit work as documented. Fixes #1540
This commit is contained in:
parent
7288f71201
commit
52d4705a91
@ -80,10 +80,6 @@ func DownloadFileAuthRocket(url, token, userID string) (*[]byte, error) {
|
|||||||
// word boundaries when splitting but this is hard to solve without potentially
|
// word boundaries when splitting but this is hard to solve without potentially
|
||||||
// breaking formatting and other stylistic effects.
|
// breaking formatting and other stylistic effects.
|
||||||
func GetSubLines(message string, maxLineLength int, clippingMessage string) []string {
|
func GetSubLines(message string, maxLineLength int, clippingMessage string) []string {
|
||||||
if clippingMessage == "" {
|
|
||||||
clippingMessage = " <clipped message>"
|
|
||||||
}
|
|
||||||
|
|
||||||
var lines []string
|
var lines []string
|
||||||
for _, line := range strings.Split(strings.TrimSpace(message), "\n") {
|
for _, line := range strings.Split(strings.TrimSpace(message), "\n") {
|
||||||
if maxLineLength == 0 || len([]byte(line)) <= maxLineLength {
|
if maxLineLength == 0 || len([]byte(line)) <= maxLineLength {
|
||||||
@ -98,8 +94,8 @@ func GetSubLines(message string, maxLineLength int, clippingMessage string) []st
|
|||||||
var splitStart int
|
var splitStart int
|
||||||
var startOfPreviousRune int
|
var startOfPreviousRune int
|
||||||
for i := range line {
|
for i := range line {
|
||||||
if i-splitStart > maxLineLength-len([]byte(clippingMessage)) {
|
if i-splitStart > maxLineLength {
|
||||||
lines = append(lines, line[splitStart:startOfPreviousRune]+clippingMessage)
|
lines = append(lines, line[splitStart:startOfPreviousRune])
|
||||||
splitStart = startOfPreviousRune
|
splitStart = startOfPreviousRune
|
||||||
}
|
}
|
||||||
startOfPreviousRune = i
|
startOfPreviousRune = i
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
type Birc struct {
|
type Birc struct {
|
||||||
i *girc.Client
|
i *girc.Client
|
||||||
Nick string
|
Nick, MessageClipped string
|
||||||
names map[string][]string
|
names map[string][]string
|
||||||
connected chan error
|
connected chan error
|
||||||
Local chan config.Message // local queue for flood control
|
Local chan config.Message // local queue for flood control
|
||||||
@ -172,10 +172,11 @@ func (b *Birc) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if b.GetBool("MessageSplit") {
|
if b.GetBool("MessageSplit") {
|
||||||
msgLines = helper.GetSubLines(msg.Text, b.MessageLength, b.GetString("MessageClipped"))
|
msgLines = helper.GetSubLines(msg.Text, b.MessageLength, "")
|
||||||
} else {
|
} else {
|
||||||
msgLines = helper.GetSubLines(msg.Text, 0, b.GetString("MessageClipped"))
|
msgLines = []string{helper.GetSubLines(msg.Text, b.MessageLength, "")[0] + b.getMessageClipped()}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range msgLines {
|
for i := range msgLines {
|
||||||
if len(b.Local) >= b.MessageQueue {
|
if len(b.Local) >= b.MessageQueue {
|
||||||
b.Log.Debugf("flooding, dropping message (queue at %d)", len(b.Local))
|
b.Log.Debugf("flooding, dropping message (queue at %d)", len(b.Local))
|
||||||
@ -411,3 +412,11 @@ func (b *Birc) getTLSConfig() (*tls.Config, error) {
|
|||||||
|
|
||||||
return tlsConfig, nil
|
return tlsConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Birc) getMessageClipped() string {
|
||||||
|
if b.GetString("MessageClipped") == "" {
|
||||||
|
return " <clipped message>"
|
||||||
|
}
|
||||||
|
|
||||||
|
return " " + b.GetString("MessageClipped")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user