How do I check if a user is authenticated with NickServ using POE::Component::IRC::State in Perl?

2.3k views Asked by At

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.

3

There are 3 answers

0
Hinrik On BEST ANSWER

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.

2
Fluff On

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.

0
Douglas Stevenson On

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