Skip to content

Commit 8558c89

Browse files
committed
Handle multi-line messages
1 parent 9ecfa13 commit 8558c89

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

irc_server.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error {
187187
}
188188
// replace UIDs with user names
189189
text := ev.Msg.Text
190-
// handle multiline messages by replacing newlines
191-
text = strings.Replace(text, "\n", "\u2026 ", -1)
190+
// replace UIDs with nicknames
192191
text = rxSlackUser.ReplaceAllStringFunc(text, func(subs string) string {
193192
uid := subs[2 : len(subs)-1]
194193
user := ctx.GetUserInfo(uid)
@@ -209,12 +208,15 @@ func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error {
209208
// don't print my own messages
210209
continue
211210
}
212-
privmsg := fmt.Sprintf(":%v!%v@%v PRIVMSG %v :%v\r\n",
213-
name, ev.Msg.User, ctx.ServerName,
214-
channame, text,
215-
)
216-
log.Print(privmsg)
217-
ctx.Conn.Write([]byte(privmsg))
211+
// handle multi-line messages
212+
for _, line := range strings.Split(text, "\n") {
213+
privmsg := fmt.Sprintf(":%v!%v@%v PRIVMSG %v :%v\r\n",
214+
name, ev.Msg.User, ctx.ServerName,
215+
channame, line,
216+
)
217+
log.Print(privmsg)
218+
ctx.Conn.Write([]byte(privmsg))
219+
}
218220
msgEv := msg.Data.(*slack.MessageEvent)
219221
// Check if the topic has changed
220222
if msgEv.Topic != ctx.Channels[msgEv.Channel].Topic {

0 commit comments

Comments
 (0)