Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

XPBot -- check your XP on IRC

by LTjake (Prior)
on Aug 25, 2002 at 14:53 UTC ( #192672=sourcecode: print w/replies, xml ) Need Help??
Category: PerlMonks Related Scripts
Author/Contact Info /msg LTjake
Description: Now, I know that jcwren has an excellent bot that does this and much more. After making this reply, i decided to mess with Net::IRC. Why not make a quick XP checker? So, here is the result of my few hours of messing around. It's fun for about 5 minutes, then it starts to be annnoying. :)

You can kick it, but it will just rejoin - unless you use the trigger text. Of course, someone can just invite it back. So, if need be, just ban it. :)

It accepts the command "get_xp username" (leaving out the username will use your nick instead) via the channel and /msg.

use Net::IRC;
use LWP;
use HTTP::Request::Common;
use XML::Simple;
use strict;

my $server   = '';
my $port     = 6667;
my $nick     = 'XPBot';
my @channels = ('#perlmonks');
my $trigger  = 'ditty mao!';
# ------

my $irc = new Net::IRC;
my $conn = $irc->newconn(
    Nick    => $nick,
    Server  => $server,
    Port    => $port,
    Ircname => ' XP Bot'

$conn->add_handler('376'   , \&on_connect);
$conn->add_handler('public', \&on_message);
$conn->add_handler('kick'  , \&on_kick);
$conn->add_handler('invite', \&on_invite);
$conn->add_handler('msg'   , \&on_message);
$conn->add_handler('433'   , \&on_nick_taken);


sub on_connect {
    my $self = shift;
    foreach my $chan (@channels) {

sub on_message {
    my ($self, $event) = @_;
    my ($arg) = ($event->args);

    if ($arg =~ /^get_xp (.+)$/ || $arg =~ /^get_xp$/) {
        my $target = $event->format eq 'msg' ? $event->nick : $event->
        my $nick = $1 || $event->nick;
        my $xml = get_node_xml(
            node_id  => 16046,
            for_user => $nick
        if (uc($nick) eq uc($xml->{INFO}->{foruser})) {
            $self->privmsg($target, "$nick currently has " . $xml->{XP
+}->{xp} . " XP.");
        else {
            $self->privmsg($target, "$nick does not exist.");

sub on_kick {
    my ($self, $event) = @_;
    my (@args) = ($event->args);
    $self->join($args[0]) unless ($args[1] =~ /^$trigger$/i);

sub on_invite {
    my ($self, $event) = @_;
    my ($arg) = ($event->args);
    $self->join($arg) if grep{$_ eq $arg} @channels;

sub on_nick_taken {
    my ($self) = shift;

sub on_disconnect {
    my $self = shift;

sub get_node_xml {
    my $ua = LWP::UserAgent->new;
    $ua->agent('node_xml_grabber/1.0 (' . $ua->agent .')');
    my $request  = POST('', Content =
+> [@_]) or die "http request error!";
    my $response = $ua->request($request);
    my $content  = $response->content();
    my $xml      = XMLin($content) or die "xml error!";
    return $xml;
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://192672]
[james28909]: thanks
[james28909]: what i am trying to do is track state of a chat based application. i need to be able to store the channels and such for a user, and when they join a new server/channel i need to be able to update that feild.
[james28909]: do you think OO would best suite that?
[karlgoethebier]: james28909: The last two are not mainstream. You have been warned ;-)
[karlgoethebier]: james28909: I don't know. Try it.

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-05-25 16:33 GMT
Find Nodes?
    Voting Booth?