From 8558c89087cbafe1ca8a311c5a186cc90a7d0198 Mon Sep 17 00:00:00 2001 From: Andrea Barberio Date: Wed, 4 Apr 2018 10:27:10 +0100 Subject: [PATCH] Handle multi-line messages --- irc_server.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/irc_server.go b/irc_server.go index f1b547b..6714f54 100644 --- a/irc_server.go +++ b/irc_server.go @@ -187,8 +187,7 @@ func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error { } // replace UIDs with user names text := ev.Msg.Text - // handle multiline messages by replacing newlines - text = strings.Replace(text, "\n", "\u2026 ", -1) + // replace UIDs with nicknames text = rxSlackUser.ReplaceAllStringFunc(text, func(subs string) string { uid := subs[2 : len(subs)-1] user := ctx.GetUserInfo(uid) @@ -209,12 +208,15 @@ func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error { // don't print my own messages continue } - privmsg := fmt.Sprintf(":%v!%v@%v PRIVMSG %v :%v\r\n", - name, ev.Msg.User, ctx.ServerName, - channame, text, - ) - log.Print(privmsg) - ctx.Conn.Write([]byte(privmsg)) + // handle multi-line messages + for _, line := range strings.Split(text, "\n") { + privmsg := fmt.Sprintf(":%v!%v@%v PRIVMSG %v :%v\r\n", + name, ev.Msg.User, ctx.ServerName, + channame, line, + ) + log.Print(privmsg) + ctx.Conn.Write([]byte(privmsg)) + } msgEv := msg.Data.(*slack.MessageEvent) // Check if the topic has changed if msgEv.Topic != ctx.Channels[msgEv.Channel].Topic {