Ruby 中的 IRC-Bot:PRIVMSG 仅发送字符串的最后一个字

发布于 2024-10-10 09:15:28 字数 1607 浏览 6 评论 0原文

我正在学习 ruby​​,我从网上获取了一个已经完成的 IRC-Bot,它只连接到给定的服务器,仅此而已。 然后我添加了一些功能(在我的例子中,我尝试实现投票去哪里吃午餐)。

现在到目前为止这些工作正常,但我不知道 ruby​​ 脚本是否有问题或者 IRC 服务器有问题。

在我测试的机器人上,它运行良好,给出如下输出:

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.

机器人本身看到这样的结果:

--> 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.

但是在完成后应该运行的 irc 上,用户将看到如下所示的输出:

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
09:14 < EssNABot> seconds.

机器人的输出给出的内容与用户输出所在的服务器上的内容相同。

在我看来,问题出在 IRC 服务器上,也许有人可以指出我正确的方向?

你的, 马吕斯

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
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年已逝 2024-10-17 09:15:28

好像需要在昵称后面加冒号(':'),即 PRIVMSG #channel :Message

It seems that you need to add colon (':') after nickname, i.e. PRIVMSG #channel :Message

断念 2024-10-17 09:15:28

NIckolay O.的回答 是正确的,但只是为了澄清这里发生的情况:

每个 IRC 协议命令都包含多个字段,并用空格分隔。例外情况是字段的第一个字符是冒号 : - 在这种情况下,冒号后面的命令的其余部分是单个字段(这允许命令中的最后一个字段包含空格)。

因此,当您的机器人发送如下错误消息时:

PRIVMSG #test Voting time is 600 seconds.

...该消息包含 7 个字段(PRIVMSG#testVoting、<代码>时间、600秒。)。但是,PRIVMSG 命令应仅包含 PRIVMSG 后面的两个字段 - 通道和要发送的消息。在这种情况下,服务器显然选择了 last 字段作为消息(它选择通道后面的字段也不足为奇)。

正确的消息如下所示:

PRIVMSG #test :Voting time is 600 seconds.

...而是包含三个字段(PRIVMSG#test投票时间为 600 秒。)。现在这是一个格式正确的 PRIVMSG 命令。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文