本文介绍了如何使用Perl的POE :: Component :: IRC发出退出消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用POE :: Component :: IRC的简单IRC机器人.只是当我试图通过退出一条有用的消息使它优雅地处理SIGINT时,我发现无论是作为信号处理程序的一部分还是作为常规调用,我都无法使它完全退出任何消息.退出.

I have a simple IRC bot using POE::Component::IRC. It was only when I was attempting to make it gracefully handle SIGINT by quitting with a useful message that I found that I can't make it quit with any message at all, ever whether as part of a signal handler or just a normal call to quit.

比方说,我已经在会话中创建了以下内容:

Let's say I've got the session created something like this:


POE::Session->create(
        inline_states => {
                irc_disconnected => \&bot_reconnect,
                irc_error        => \&bot_reconnect,
                irc_socketerr    => \&bot_reconnect,
                connect          => \&bot_reconnect,
.
.
.
        },
);

bot_reconnect只是要连接回IRC出问题了:

And bot_reconnect is just going to connect back to IRC shouldanything go wrong:


sub bot_reconnect
{
        my ($kernel, $heap) = @_[KERNEL, HEAP];

        if (1 == $heap->{shutting_down}) {
                $heap->{irc}->yield(shutdown => 'blah');
        } else {
                some_log_func("Reconnecting in 60 secs");
                $kernel-delay(connect => 60);
        }
}

如果在代码中的其他任何地方,我都将shutting_down设置为1并告诉它要退出(例如$irc->yield(quit => "bye!")),则立即退出没有退出消息的IRC("Client Quit"(客户端退出),显示ircd)否则显示远程主机已关闭连接".

If, anywhere else in the code I set shutting_down to 1 and tell itto quit (e.g. $irc->yield(quit => "bye!")) it immediately quitsIRC with either no quit message ("Client Quit", the ircd displays)or else with "Remote host closed the connection".

然后接收到irc_disconnected事件,该事件将其发送到上面的bot_reconnect,其中shutdown似乎不起作用全部.实际上,如果在shutdown之后我没有明确地exit 0然后该过程只是处于混乱状态而没有与IRC的任何连接更多.

It then receives the irc_disconnected event which takes it tobot_reconnect above, where shutdown appears to do nothing atall. In fact if I don't explicitly exit 0 after that shutdownthen the process just stays in limbo with no connect to IRC anymore.

那应该发生什么吗?

我发现:

http://search.cpan.org/~bingos/POE-Component-IRC-6.79/lib/POE/Component/IRC/Cookbook/Disconnecting.pod

表示使用shutdown.如您所见,我尝试了似乎不起作用.

which says to use shutdown. As you can see, I tried that, and itdoesn't seem to work.

在另一个问题中,我还找到了一些示例代码:

I also found some sample code for this in another question:

如何正确关闭Bot :: BasicBot机器人(基于POE :: Component :: IRC)?

但是,这与我现在所拥有的非常相似,而且也没有似乎表现出任何不同.

However that is very similar to what I have now, and it also doesn'tseem to behave any differently.

libpoe-component-irc-perl的软件包版本为6.78 + dfsg-1,因此如上面的URL所示,该值应大于6.50.

The package version of libpoe-component-irc-perl is 6.78+dfsg-1 sothat should be greater than 6.50 as the above URL says.

有什么想法吗?

推荐答案

事实证明,这是ircd的故障".

It turns out that this is the "fault" of the ircd.

我也将其报告为POE :: Component :: IRC的请求跟踪程序的错误,Hinrik做出了回应,问我是否要在Freenode上执行此操作. Freenode的ircd具有一项功能,如果您未连接很长时间,它将忽略您的退出消息.

I also reported this as a bug to POE::Component::IRC's request tracker, and Hinrik responded, asking me if I was trying to do this on Freenode. Freenode's ircd has a feature where it ignores your quit message if you haven't been connected for very long.

我没有尝试在Freenode上执行此操作,但事实证明,我在上执行此操作的网络是.他们正在使用Charybdis:

I wasn't trying to do it on Freenode, but it turns out that the network I was doing it on does do this. They're using Charybdis:

https://github.com/atheme/charybdis/blob/master/modules/core/m_quit.c#L75

这篇关于如何使用Perl的POE :: Component :: IRC发出退出消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 19:15