whyrusleeping / hellabot

A hella awesome irc bot framework written in go, Simply plug in your triggers and run!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Message sending fails on '\n'

m-242 opened this issue · comments

If a message is sent with using the Reply function, and the text argument contains a line feed character, only the part of text before that return is sent.

Example:
If the following code is used, bot.Reply(message, "AA\nBB\nCC")

Only AA will be sent back.

While this usefully limits the output of a trigger, it can be annoying, especially when trying to format information.

If PRs are welcome, could I write a new ReplyWithReturn type function, different from the Reply function to avoid breaking backward compatibility ?

Thanks in advance.

IRC doesn't allow newlines in messages, each line must be sent separately. (*Bot).Msg should probably do that automatically.

ok, I will try to send a PR soon.

@flexd where?

hellabot/hellabot.go

Lines 272 to 278 in cb7358f

func (bot *Bot) Msg(who, text string) {
for len(text) > 400 {
bot.Send("PRIVMSG " + who + " :" + text[:400])
text = text[400:]
}
bot.Send("PRIVMSG " + who + " :" + text)
}

That was a reply to you @icholy, about Msg splitting messages when they are too long. I tried answering via email on my phone but it didn't work properly it looks like. The for loop on line 273 does exactly that. Any message over 400 characters long is split up into multiple messages to avoid getting cut off.

I think that if you want to send separate messages, do so yourself. We should not parse \n inside a IRC message to split up the message in the bot. That would be very unexpected behaviour for anyone else.

@flexd I don't think it's much different than splitting long messages. When I paste multi-line text into irssi, it sends each line as a separate message. Alternatively, we can just escape/remove the newlines from the text.

I wrote and opened #42 before seeing @flexd's answer, sorry about that, I will update my PR following the way this issue goes.

I agree that this would create an unexpected behavior, but on the other hand, I've seen several people try to get multiple line messages by using a line feed.

I don't think removing the line feed characters would be a good idea, as there are often used as a way to format the output of a trigger, at least in my experience.