IRC-Bot in Ruby: PRIVMSG sends only last word of string
I'm on learning ruby and I took a already done IRC-Bot from the web which just connects to a given serven and not much more. Then I added some features (in my case I try to implement a voting where to eat lunch).
Now these work fine so far but I don't know if the ruby script does something wrong or there is something wrong with the IRC-server.
On the one I tested the Bot it worked well, giving an output like this:
09:14 < Wayne> !EssNA
09:14 < EssNABot> [-=EssNA-Vote=-]
09:14 < EssNABot> Options are:
09:14 < EssNABot> McDonalds. 0
09:14 < EssNABot> Currywurst 0
09:14 < EssNABot> Hendl..... 0
09:14 < EssNABot> Salatbar.. 0
09:14 < EssNABot> Griechr... 0
09:14 < EssNABot> Metzger... 0
09:14 < EssNABot> Merowinger 0
09:14 < EssNABot> Lidl...... 0
09:14 < EssNABot> Voting time is 600 seconds.
The bot itself sees that like this:
--> PRIVMSG #test [-=EssNA-Vote=-]
--> PRIVMSG #test Options are:
--> PRIVMSG #test McDonalds. 0
--> PRIVMSG #test Currywurst 0
--> PRIVMSG #test Hendl..... 0
--> PRIVMSG #test Salatbar.. 0
--> PRIVMSG #test Griechr... 0
--> PRIVMSG #test Metzger... 0
--> PRIVMSG #test Merowinger 0
--> PRIVMSG #test Lidl...... 0
--> PRIVMSG #test Voting time is 600 seconds.
But on the irc which it should run on if its done the output users will see looks like this:
09:14 < Wayne> !EssNA
09:14 < EssNABot> [-=EssNA-Vote=-]
09:14 < EssNABot> are:
09:14 < EssNABot> 0
09:14 < EssNABot> 0
09:14 < EssNABot> 0
09:14 < EssNABot> 0
09:14 < EssNABot> 0
09:14 < EssNABot> 0
09:14 < EssNABot> 0
09:14 < EssNABot> 0开发者_StackOverflow
09:14 < EssNABot> seconds.
The output the bot gives is the same as on the server on which the output for users works.
Seems to me that the problem is the IRC-server, maybe someone can point me in the right direction?
Yours, Marius
It seems that you need to add colon (':') after nickname, i.e. PRIVMSG #channel :Message
NIckolay O.'s answer is correct, but just to clarify what's going on here:
Each IRC protocol command consists of several fields, separated by whitespace. The exception to this is when the first character of a field is a colon :
- in this case, the remainder of the command following the colon is a single field (this allows the last field in the command to contain whitespace).
So, when your bot was sending incorrect messages like this:
PRIVMSG #test Voting time is 600 seconds.
...the message contained 7 fields (PRIVMSG
, #test
, Voting
, time
, is
, 600
and seconds.
). However, a PRIVMSG
command should only contain two fields following the PRIVMSG
- the channel and the message to send. In this case, the server was apparently picking the last field as the message (it would also have been unsurprising for it to pick the field following the channel instead).
The correct message, like this:
PRIVMSG #test :Voting time is 600 seconds.
...instead contains three fields (PRIVMSG
, #test
, and Voting time is 600 seconds.
). This is now a correctly formatted PRIVMSG
command.
精彩评论