#!/usr/bin/perl #obot #James Stanley 2010 use strict; use warnings; use LWP; use POE qw(Component::IRC Component::IRC::Plugin::FollowTail Component::IRC::Plugin::Connector Component::IRC::Plugin::NickServID Component::IRC::Plugin::CTCP); my $nickname = 'obot'; my $ircname = 'obot'; my $server = 'irc.freenode.net'; my @channels = ('#maximilian'); # We create a new PoCo-IRC object my $irc = POE::Component::IRC->spawn( nick => $nickname, ircname => $ircname, server => $server, ) or die "Oh noooo! $!"; POE::Session->create( package_states => [ main => [ qw(irc_raw _start irc_001 irc_public irc_tail_input lag_o_meter) ], ], heap => { irc => $irc }, ); $poe_kernel->run(); sub _start { my ($kernel,$heap) = @_[KERNEL, HEAP]; # retrieve our component's object from the heap where we stashed it my $irc = $heap->{irc}; $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(); $irc->plugin_add('Connector' => $heap->{connector}); $irc->plugin_add('FollowTail' => POE::Component::IRC::Plugin::FollowTail->new( filename => "/var/games/nethack/logfile" )); $irc->plugin_add('FollowTail2' => POE::Component::IRC::Plugin::FollowTail->new( filename => "/var/spool/irc" )); $irc->plugin_add('NickServID' => POE::Component::IRC::Plugin::NickServID->new( Password => 'SECRET MOTHERFUCKER' )); $irc->plugin_add('CTCP' => POE::Component::IRC::Plugin::CTCP->new( version => "obot", userinfo => "obot" )); $irc->yield(register => 'all'); $irc->yield(connect => { Nick => "obot", Server => "irc.freenode.net" } ); $kernel->delay('lag_o_meter' => 60); return; } sub irc_001 { my $sender = $_[SENDER]; # Since this is an irc_* event, we can get the component's object by # accessing the heap of the sender. Then we register and connect to the # specified server. my $irc = $sender->get_heap(); print "Connected to ", $irc->server_name(), "\n"; # we join our channels $irc->yield( join => $_ ) for @channels; return; } sub irc_public { my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; print "$nick: $what\n"; #Match a URL, get the title if($what =~ /(https?:\/\/[^\s\)]+)/) { my $ua = LWP::UserAgent->new; $ua->max_size(1024); #Strip trailing dots my $url = $1; $url =~ s/[,.;"'!?]*$//; print "url: $url\n"; my $response = $ua->get($url); $irc->yield(privmsg => $channel => "Content-Type: " . $response->content_type) unless $response->content_type eq "text/html"; my ($title) = $response->content() =~ /