5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-26 02:01:36 +00:00

Add MessageSplit option to split messages on MessageLength (irc). Closes #281

This commit is contained in:
Wim 2017-11-24 23:27:13 +01:00
parent 7ec95f786d
commit e0cbb69a4f
4 changed files with 25 additions and 2 deletions

View File

@ -62,10 +62,11 @@ type Protocol struct {
Login string // mattermost, matrix Login string // mattermost, matrix
MediaServerDownload string MediaServerDownload string
MediaServerUpload string MediaServerUpload string
MessageQueue int // IRC, size of message queue for flood control
MessageDelay int // IRC, time in millisecond to wait between messages MessageDelay int // IRC, time in millisecond to wait between messages
MessageLength int // IRC, max length of a message allowed
MessageFormat string // telegram MessageFormat string // telegram
MessageLength int // IRC, max length of a message allowed
MessageQueue int // IRC, size of message queue for flood control
MessageSplit bool // IRC, split long messages with newlines on MessageLength instead of clipping
Muc string // xmpp Muc string // xmpp
Name string // all protocols Name string // all protocols
Nick string // all protocols Nick string // all protocols

View File

@ -26,3 +26,15 @@ func DownloadFile(url string) (*[]byte, error) {
resp.Body.Close() resp.Body.Close()
return &data, nil return &data, nil
} }
func SplitStringLength(input string, length int) string {
a := []rune(input)
str := ""
for i, r := range a {
str = str + string(r)
if i > 0 && (i+1)%length == 0 {
str += "\n"
}
}
return str
}

View File

@ -5,6 +5,7 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/lrstanley/girc" "github.com/lrstanley/girc"
"github.com/paulrosania/go-charset/charset" "github.com/paulrosania/go-charset/charset"
@ -191,6 +192,10 @@ func (b *Birc) Send(msg config.Message) (string, error) {
} }
} }
// split long messages on messageLength, to avoid clipped messages #281
if b.Config.MessageSplit {
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") {
if len(text) > b.Config.MessageLength { if len(text) > b.Config.MessageLength {
text = text[:b.Config.MessageLength] + " <message clipped>" text = text[:b.Config.MessageLength] + " <message clipped>"

View File

@ -80,6 +80,11 @@ MessageQueue=30
#OPTIONAL (default 400) #OPTIONAL (default 400)
MessageLength=400 MessageLength=400
#Split messages on MessageLength instead of showing the <message clipped>
#WARNING: this could lead to flooding
#OPTIONAL (default false)
MessageSplit=false
#Nicks you want to ignore. #Nicks you want to ignore.
#Messages from those users will not be sent to other bridges. #Messages from those users will not be sent to other bridges.
#OPTIONAL #OPTIONAL