Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure MessageLength and MessageSplit work as documented. Fixes #1540 #1727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions bridge/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ func DownloadFileAuthRocket(url, token, userID string) (*[]byte, error) {
// word boundaries when splitting but this is hard to solve without potentially
// breaking formatting and other stylistic effects.
func GetSubLines(message string, maxLineLength int, clippingMessage string) []string {
if clippingMessage == "" {
clippingMessage = " <clipped message>"
}

var lines []string
for _, line := range strings.Split(strings.TrimSpace(message), "\n") {
if maxLineLength == 0 || len([]byte(line)) <= maxLineLength {
Expand All @@ -98,8 +94,8 @@ func GetSubLines(message string, maxLineLength int, clippingMessage string) []st
var splitStart int
var startOfPreviousRune int
for i := range line {
if i-splitStart > maxLineLength-len([]byte(clippingMessage)) {
lines = append(lines, line[splitStart:startOfPreviousRune]+clippingMessage)
if i-splitStart > maxLineLength {
lines = append(lines, line[splitStart:startOfPreviousRune])
splitStart = startOfPreviousRune
}
startOfPreviousRune = i
Expand Down
15 changes: 12 additions & 3 deletions bridge/irc/irc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

type Birc struct {
i *girc.Client
Nick string
Nick, MessageClipped string
names map[string][]string
connected chan error
Local chan config.Message // local queue for flood control
Expand Down Expand Up @@ -172,10 +172,11 @@ func (b *Birc) Send(msg config.Message) (string, error) {
}

if b.GetBool("MessageSplit") {
msgLines = helper.GetSubLines(msg.Text, b.MessageLength, b.GetString("MessageClipped"))
msgLines = helper.GetSubLines(msg.Text, b.MessageLength, "")
} 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 {
if len(b.Local) >= b.MessageQueue {
b.Log.Debugf("flooding, dropping message (queue at %d)", len(b.Local))
Expand Down Expand Up @@ -411,3 +412,11 @@ func (b *Birc) getTLSConfig() (*tls.Config, error) {

return tlsConfig, nil
}

func (b *Birc) getMessageClipped() string {
if b.GetString("MessageClipped") == "" {
return " <clipped message>"
}

return " " + b.GetString("MessageClipped")
}