Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!c:\perl\bin\perl.exe use Net::IRC; use LWP; use HTTP::Request::Common; use XML::Simple; use strict; # CONFIG my $server = 'irc.slashnet.org'; 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 => 'Perlmonks.org 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); $irc->start; sub on_connect { my $self = shift; foreach my $chan (@channels) { $self->join($chan); } } 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-> +to; 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; $self->nick($nick.int(rand(999))); } sub on_disconnect { my $self = shift; $self->connect(); } sub get_node_xml { my $ua = LWP::UserAgent->new; $ua->agent('node_xml_grabber/1.0 (' . $ua->agent .')'); my $request = POST('http://www.perlmonks.org/index.pl', 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; }

In reply to XPBot -- check your XP on IRC by LTjake

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (9)
    As of 2014-09-21 07:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (167 votes), past polls