diff options
author | Wim <wim@42.be> | 2017-11-24 23:27:13 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-11-24 23:29:00 +0100 |
commit | e0cbb69a4fa14f5f38417b19904a8b412deb2458 (patch) | |
tree | 7d1029dbf4704f9454f2c71f52ea8262f8b05392 | |
parent | 7ec95f786d55aab69541cb3065ea2c9b8eaf9c43 (diff) | |
download | matterbridge-msglm-e0cbb69a4fa14f5f38417b19904a8b412deb2458.tar.gz matterbridge-msglm-e0cbb69a4fa14f5f38417b19904a8b412deb2458.tar.bz2 matterbridge-msglm-e0cbb69a4fa14f5f38417b19904a8b412deb2458.zip |
Add MessageSplit option to split messages on MessageLength (irc). Closes #281
-rw-r--r-- | bridge/config/config.go | 5 | ||||
-rw-r--r-- | bridge/helper/helper.go | 12 | ||||
-rw-r--r-- | bridge/irc/irc.go | 5 | ||||
-rw-r--r-- | matterbridge.toml.sample | 5 |
4 files changed, 25 insertions, 2 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go index 8a13b488..47e2a1d6 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -62,10 +62,11 @@ type Protocol struct { Login string // mattermost, matrix MediaServerDownload string MediaServerUpload string - MessageQueue int // IRC, size of message queue for flood control MessageDelay int // IRC, time in millisecond to wait between messages - MessageLength int // IRC, max length of a message allowed 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 Name string // all protocols Nick string // all protocols diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index ecfc4df2..0b6be4f4 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -26,3 +26,15 @@ func DownloadFile(url string) (*[]byte, error) { resp.Body.Close() 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 +} diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 2d56bbc6..4fd5a8a2 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "fmt" "github.com/42wim/matterbridge/bridge/config" + "github.com/42wim/matterbridge/bridge/helper" log "github.com/Sirupsen/logrus" "github.com/lrstanley/girc" "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") { if len(text) > b.Config.MessageLength { text = text[:b.Config.MessageLength] + " <message clipped>" diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index b6a674e9..7552d395 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -80,6 +80,11 @@ MessageQueue=30 #OPTIONAL (default 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. #Messages from those users will not be sent to other bridges. #OPTIONAL |