tags:

views:

204

answers:

2

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.

A: 

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.

Fluff
Thanks, but my main problem isn't on the IRC end, it's on the POE end. I want to ask if the user is registered and not do anything else until I get an answer. The problem I'm running into is that this stuff is all event driven, and the request and response are separate events. That means that I have to send the request, then let the bot do its thing for a while, and then whenever a response happens to come up I get to process it.My solution above was to have the response handler set a global variable and poll that variable, but it failed.
Troy
Okay, I figured out a solution. What I've done is that I've created a global queue. Each time I do a whois call, I unshift an anonymous function onto the queue that will handle the resulting info. My whois response handler just looks like this: sub on_whois { my $function = pop(@whois_queue); $function->($_[ARG0]); }
Troy
A: 

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, or irc_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.

Hinrik