Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use POE qw(Component::IRC);
- use POE::Component::IRC::Common;
- use POE::Component::IRC::Plugin;
- use POE::Component::IRC::Plugin::AutoJoin;
- use POE::Component::IRC::Plugin::BotTraffic;
- use POE::Component::IRC::Plugin::Connector;
- use POE::Component::IRC::Plugin::Logger;
- use POE::Component::IRC::Plugin::NickReclaim;
- use Acme::24;
- use Acme::ICHC::Lolcats;
- use Acme::LOLCAT;
- my $irc = POE::Component::IRC->spawn(
- nick => 'POEBot',
- ircname => 'POEBot',
- server => 'irc.rizon.net'
- ) || exit;
- POE::Session->create(
- package_states => [
- main => [qw(_default _start irc_001 irc_public)],
- ],
- heap => {
- irc => $irc
- },
- );
- $poe_kernel->run();
- sub _start {
- my ($kernel, $heap) = @_[KERNEL, HEAP];
- my $irc = $heap->{irc};
- $irc->yield(register => 'all');
- $heap->{connector} = POE::Component::IRC::Plugin::Connector->new('reconnect' => 10);
- $irc->plugin_add('AutoJoin', POE::Component::IRC::Plugin::AutoJoin->new(Channels => \qw(#/g/perl), RejoinOnKick => 1, Rejoin_delay => 1));
- $irc->plugin_add('BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new());
- $irc->plugin_add('Connector' => $heap->{connector});
- $irc->plugin_add('NickReclaim' => POE::Component::IRC::Plugin::NickReclaim->new(poll => 30));
- $irc->yield(connect => (Nick => 'POEBot', Server => 'irc.rizon.net'));
- $kernel->delay('lag_o_meter' => 60);
- return;
- }
- sub irc_001 {
- my $sender = $_[SENDER];
- my $irc = $sender->get_heap();
- print $irc->server_name(), "\n";
- $irc->yield(join => '#/g/perl');
- return;
- }
- sub irc_public {
- my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2];
- my $nick = (split /!/, $who)[0];
- my $channel = $where->[0];
- if ($what =~ /!dice/i) {
- $irc->yield(privmsg => $channel => "$nick rolled a " . ((int rand 6) + 1) . '!');
- } elsif ($what =~ /!cat/i) {
- $irc->yield(privmsg => $channel => 'Borked.');#Acme::ICHC::Lolcats->new->getImageUrl);
- } elsif ((int rand 10) == 0) {
- my $resp = translate(Acme::24->random_jackbauer_fact());
- $resp =~ s/\"\;/\"/ig;
- $irc->yield(privmsg => $channel => $resp);
- }
- return;
- }
- sub _default {
- my ($event, $args) = @_[ARG0 .. $#_];
- my @output = ("$event: ");
- for my $arg (@$args) {
- if (ref $arg eq 'ARRAY') {
- push(@output, '[' . join(', ', @$arg) . ']');
- } else {
- push(@output, "'$arg'");
- }
- }
- print join ' ', @output, "\n";
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment