Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Net::IRC - how to check is user online?

by sago (Scribe)
on Jun 08, 2007 at 10:09 UTC ( [id://619996]=note: print w/replies, xml ) Need Help??


in reply to Net::IRC - how to check is user online?

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re: Net::IRC - how to check is user online?

Replies are listed 'Best First'.
Re^2: Net::IRC - how to check is user online?
by VoLAnD (Initiate) on Jun 08, 2007 at 12:15 UTC
    I'm already have IRC connection. When somebody send perl-bot message with nickname, I need to check - is this nickname online on the channel or not.
      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 ]

        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();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://619996]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2024-04-23 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found