diff options
author | Fredrik de Vibe <fdv@ifi.uio.no> | 2016-03-18 18:03:15 -0400 |
---|---|---|
committer | Fredrik de Vibe <fdv@ifi.uio.no> | 2016-03-18 18:03:15 -0400 |
commit | f29822db029ab5838210e00e8b701525c34e8177 (patch) | |
tree | 7dceefa56a70dbb1e3d87afeb0ba57638f64be96 /matterbridge.go | |
parent | a63433e41bad06a9ef8132082b8ef40d91d07aec (diff) | |
download | matterbridge-msglm-f29822db029ab5838210e00e8b701525c34e8177.tar.gz matterbridge-msglm-f29822db029ab5838210e00e8b701525c34e8177.tar.bz2 matterbridge-msglm-f29822db029ab5838210e00e8b701525c34e8177.zip |
Add double newline if the message is markup and prefixed.
If the message is prefixed with the sender nick, it will break markup
formatting on the same line. This commit introduces a very rudimentary
markup checker, and if the message is deemed to be markup in those
cases, the space between sender nick and message is replaced by a
double newline.
Diffstat (limited to 'matterbridge.go')
-rw-r--r-- | matterbridge.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/matterbridge.go b/matterbridge.go index 6638c2c1..7c586b16 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -131,13 +131,32 @@ func (b *Bridge) Send(nick string, message string, channel string) error { return b.SendType(nick, message, channel, "") } +func IsMarkup(message string) bool { + switch (message[0]) { + case '|': fallthrough + case '#': fallthrough + case '_': fallthrough + case '*': fallthrough + case '~': fallthrough + case '-': fallthrough + case ':': fallthrough + case '>': fallthrough + case '=': return true + } + return false +} + func (b *Bridge) SendType(nick string, message string, channel string, mtype string) error { matterMessage := matterhook.OMessage{IconURL: b.Config.Mattermost.IconURL} matterMessage.Channel = channel matterMessage.UserName = nick matterMessage.Type = mtype - if (b.Config.Mattermost.PrefixMessagesWithNick) { - matterMessage.Text = nick + ": " + message + if b.Config.Mattermost.PrefixMessagesWithNick { + if IsMarkup(message) { + matterMessage.Text = nick + ":\n\n" + message + } else { + matterMessage.Text = nick + ": " + message + } } else { matterMessage.Text = message } |