TeamBlast

POEbot - a smelly dumb boat scum

Nov 26th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.40 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. use POE qw(Component::IRC);
  5. use POE::Component::IRC::Common;
  6. use POE::Component::IRC::Plugin;
  7. use POE::Component::IRC::Plugin::AutoJoin;
  8. use POE::Component::IRC::Plugin::BotTraffic;
  9. use POE::Component::IRC::Plugin::Connector;
  10. use POE::Component::IRC::Plugin::Logger;
  11. use POE::Component::IRC::Plugin::NickReclaim;
  12.  
  13.  
  14. use Acme::24;
  15. use Acme::ICHC::Lolcats;
  16. use Acme::LOLCAT;
  17.  
  18. my $irc = POE::Component::IRC->spawn(
  19.     nick => 'POEBot',
  20.     ircname => 'POEBot',
  21.     server => 'irc.rizon.net'
  22. ) || exit;
  23.  
  24. POE::Session->create(
  25.     package_states => [
  26.         main => [qw(_default _start irc_001 irc_public)],
  27.     ],
  28.     heap => {
  29.         irc => $irc
  30.     },
  31. );
  32.  
  33. $poe_kernel->run();
  34.  
  35. sub _start {
  36.     my ($kernel, $heap) = @_[KERNEL, HEAP];
  37.     my $irc = $heap->{irc};
  38.    
  39.     $irc->yield(register => 'all');
  40.     $heap->{connector} = POE::Component::IRC::Plugin::Connector->new('reconnect' => 10);
  41.     $irc->plugin_add('AutoJoin', POE::Component::IRC::Plugin::AutoJoin->new(Channels => \qw(#/g/perl), RejoinOnKick => 1, Rejoin_delay => 1));
  42.     $irc->plugin_add('BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new());
  43.     $irc->plugin_add('Connector' => $heap->{connector});
  44.     $irc->plugin_add('NickReclaim' => POE::Component::IRC::Plugin::NickReclaim->new(poll => 30));
  45.     $irc->yield(connect => (Nick => 'POEBot', Server => 'irc.rizon.net'));
  46.     $kernel->delay('lag_o_meter' => 60);
  47.    
  48.     return;
  49. }
  50.  
  51. sub irc_001 {
  52.     my $sender = $_[SENDER];
  53.     my $irc = $sender->get_heap();
  54.    
  55.     print $irc->server_name(), "\n";
  56.    
  57.     $irc->yield(join => '#/g/perl');
  58.    
  59.     return;
  60. }
  61.  
  62. sub irc_public {
  63.     my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2];
  64.     my $nick = (split /!/, $who)[0];
  65.     my $channel = $where->[0];
  66.    
  67.     if ($what =~ /!dice/i) {
  68.         $irc->yield(privmsg => $channel => "$nick rolled a " . ((int rand 6) + 1) . '!');
  69.     } elsif ($what =~ /!cat/i) {
  70.         $irc->yield(privmsg => $channel => 'Borked.');#Acme::ICHC::Lolcats->new->getImageUrl);
  71.     } elsif ((int rand 10) == 0) {
  72.         my $resp = translate(Acme::24->random_jackbauer_fact());
  73.         $resp =~ s/\&quot\;/\"/ig;
  74.         $irc->yield(privmsg => $channel => $resp);
  75.     }
  76.    
  77.     return;
  78. }
  79.  
  80. sub _default {
  81.     my ($event, $args) = @_[ARG0 .. $#_];
  82.     my @output = ("$event: ");
  83.    
  84.     for my $arg (@$args) {
  85.         if (ref $arg eq 'ARRAY') {
  86.             push(@output, '[' . join(', ', @$arg) . ']');
  87.         } else {
  88.             push(@output,  "'$arg'");
  89.         }
  90.     }
  91.    
  92.     print join ' ', @output, "\n";
  93.    
  94.     return;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment