in reply to Re^2: Net::IRC - how to check is user online?
in thread Net::IRC - how to check is user online?

The IRC command 'WHOIS' will respond if they're connected or not, but it won't tell you if they're in your channel or not.

If you want to find out if they're in a channel, you *might* get that from their WHOIS information, but the server might hide channel membership for various reasons. You can *usually* see if they're in the same channel *you* are in, but if that's not the case, you might not see it. Channels can be secret or private-moded, which means they're hidden from various requests.

--
[ e d @ h a l l e y . c c ]

  • Comment on Re^3: Net::IRC - how to check is user online?

Replies are listed 'Best First'.
Re^4: Net::IRC - how to check is user online?
by VoLAnD (Initiate) on Jun 09, 2007 at 05:40 UTC
    Yes, you're right.
    I've found event 'ison'.
    In console output all is OK, but on IRC-channel I have delay in one request. Example
    >isonline John
    >OFFLINE
    >isonline John
    >ONLINE

    In console:
    Find:
    ONLINE
    Find:
    ONLINE


    This is script:
    #!/usr/bin/perl -w

    use Net::IRC;
    use strict;

    my $irc = new Net::IRC;

    my $global_name = 'Test'; my $global_search = 0;

    my $channel = '#TEST';
    my $globalconn = $irc->newconn(
    Server => 'servername',
    Port => '6667',
    Nick => 'IBot',
    Ircname => 'Bot',
    Username => 'IRC-Bot'
    );

    $globalconn->{channel} = shift || $channel;

    sub on_connect {

    my $conn = shift;
    $conn->join($conn->{channel});
    $conn->{connected} = 1;
    print "connected\n";
    }

    sub on_ison_reply {
    my $self = shift;
    my $event = shift;
    print "ISON $global_name: ";
    if ($event->{args}->\1\ eq $global_name) {
    $global_search = 1;
    print "ONLINE: $global_search\n";
    }
    else {
    $global_search = 0;
    print "OFFLINE: $global_search\n";
    }
    }

    sub on_public {

    my ($conn, $event) = @_;

    my $text = $event->{args}\0\;

    if ($text =~ /isonline (.+)/) {
    my $test_text = test($1, $event->{nick});
    $conn->privmsg($event->{to}\0\, $test_text);
    }


    }

    sub test {

    my $input = shift;
    my $nick = shift;

    print "Found: $input\n";
    $global_name = $input;
    $globalconn->ison($input);

    if ($global_search == 1) {
    return "ONLINE";}
    else {return "OFFLINE";}

    return "wrong request";
    }

    $globalconn->add_handler('422', \&on_connect);
    $globalconn->add_handler('public', \&on_public);
    $globalconn->add_handler('ison', \&on_ison_reply);

    $irc->start();