如何在 Perl 中使用 POE::Component::IRC::State 检查用户是否通过 NickServ 进行身份验证?
我正在尝试测试用户是否在 FreeNode 上注册。 nick_info() 似乎没有返回有关此的信息,所以我想使用 $irc->yield(whois => $nick);然后获取 irc_whois 事件的回复。问题是我想等到这个事件被触发,所以我创建了一个全局变量 $whois_result 并编写了一个像这样的子:
sub whois {
my $nick = $_[0];
$whois_result = 0;
$irc->yield(whois => $nick);
while($whois_result == 0) { }
return $whois_result;
}
irc_whois 处理程序看起来像:
sub on_whois {
$whois_result = $_[ARG0];
print "DEBUG: irc_whois fired.\n";
}
不幸的是,该事件在循环运行时无法触发,所以这挂起。我确信有更好的方法可以做到这一点,但我对这种编程还不够熟悉。任何帮助将不胜感激。
I'm trying to test whether a user is registered on FreeNode. nick_info() doesn't seem to return information about this, so I want to use $irc->yield(whois => $nick); and then grab the irc_whois event's reply. The problem is that I want to wait until this event is fired, so I created a global variable $whois_result and wrote a sub like this:
sub whois {
my $nick = $_[0];
$whois_result = 0;
$irc->yield(whois => $nick);
while($whois_result == 0) { }
return $whois_result;
}
with the irc_whois handler looking like:
sub on_whois {
$whois_result = $_[ARG0];
print "DEBUG: irc_whois fired.\n";
}
Unfortunately, the event can't fire while the loop is running so this hangs. I'm sure there's a better way to do this, but I'm not familiar enough with this kind of programming to know. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 POE 中的状态的子目录上...您必须在另一个状态中屈服或调用它。
另外,当您从 IRC 命令获得数据时,请让步到另一个状态来处理它。
_开始
- 启动计时器等。
定时器
- 收益 on_whois
on_whois
- 跑谁是谁
- 设置数据
- 屈服于下一个计时器
_stop
- 杀死计时器
- 刷新数据
On the sub for states in POE... You have to yield or call it in another state.
Also, when you have data from the IRC command, yield to another state to process it.
_start
- Start up a timer, etc.
timer
- yield on_whois
on_whois
- run who is
- Set data
- yield to the next timer
_stop
- Kill the timer
- flush the data
我在 Freenode 上运行了一个机器人,并通过向 Nickserv 询问命令解决了该问题:
ACC [nick] *
Nickserv 随后将回复以下格式的通知:
[昵称] -> [registerd nickservname] ACC [level]
其中级别 3 表示用户被识别为 nickserv。
I run a bot on Freenode and resolved the issue by asking Nickserv the command:
ACC [nick] *
Nickserv will then reply with a notice in the format:
[nickname] -> [registerd nickservname] ACC [level]
Where level 3 means that the user is identified to nickserv.
以下内容至少适用于 FreeNode(或任何支持识别消息功能的服务器)。
如果您对来自用户的消息(
irc_msg
、irc_public
或irc_ctcp_action
)做出反应,您可以通过以下方式判断他是否已向 NickServ 识别:查看提供给事件处理程序的第三个参数 ($_[ARG3]
)。如果用户已识别,则为 true,否则为 false。The following applies to FreeNode at least (or any server supporting the identify-msg feature).
If you are reacting to a message (
irc_msg
,irc_public
, orirc_ctcp_action
) from a user, you can tell whether he has identified to NickServ by looking at the third argument ($_[ARG3]
) provided to the event handler. It will be true if the user has identified, false otherwise.