#!/usr/bin/perl # Purpose: To monitor kick wars on given IRC channel use strict; use warnings; use POE qw(Component::IRC); use POE::Component::IRC::Plugin::BotTraffic; my %config = ( nickname => 'KickBot', ircname => 'KickWars', ircserver => 'irc.myserver.net', port => '6667', channel => '#KickWars' ); my @channels=split(/,/, $config{channel}); #Create a new PoCo-IRC object/component my $irc = POE::Component::IRC->spawn( nick => $config{nickname}, server => $config{ircserver}, port => $config{port}, ircname => $config{ircname} ); $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() ); $irc->plugin_add( 'BotAddressed', POE::Component::IRC::Plugin::BotTraffic->new() ); POE::Session->create( package_states => [ 'main' => [ qw(_default _start irc_001 irc_public) ], ], heap => { irc => $irc }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; #Get session ID of component from object, register, #connect to specified server. my $irc_session = $heap->{irc}->session_id(); $kernel->post( $irc_session => register => 'all' ); $kernel->post( $irc_session => connect => { } ); undef; } sub irc_001 { my ($kernel,$sender) = @_[KERNEL,SENDER]; #Get component's object by accessing heap of SENDER my $poco_object = $sender->get_heap(); print "Connected to ",$poco_object->server_name(),"\n"; #In any irc_* events, the SENDER will be the PoCo IRC session $kernel->post( $sender => join => $_ ) for @channels; # my ($nick) = ( split /!/, )[0]; # my ($channel) = '#lobby'; # my ($what)="Hi" # &irc_bot_addressed($nick,$channel,$what); undef; } sub irc_public { my ($kernel,$sender,$who,$where,$what) = @_[KERNEL,SENDER,ARG0,ARG1,ARG2]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; my @dialogue=&irc_bot_addressed; my $command; my @args; ($command,@args) = split(/ /, @dialogue[2]); print @dialogue[2]; # if ($dialogue[0] eq 'Possum'){ # if ($command eq '!op'){ # $kernel->post( $sender => mode => $channel => '+o' => "$args[0]" ); # # } # if ( $command eq '!talk'){ # $kernel->post( $sender => privmsg => $channel => "@dialogue[0]: You said @dialogue[2]" ); if ( $command eq "!kick" ){ unless ($args[0] =~ /kickbot/i){ $kernel->post( $sender => kick => $channel => "@args[0]" => 'SuperKick!' ); } # } elsif ($command eq '!np'){ # print '!np\n'; # my $np=MPCout(); # $kernel->post( $sender => privmsg => $channel => "Currently playing: $np" ); # } elsif ( $command =~ /![a-zA-Z_0-9]/ ) { # print "Unkown Command $command!\n"; # $kernel->post( $sender => privmsg => $channel => "@dialogue[0]: Unkown Command\!") ; # } undef; # irc_bot_public('#lobby','Hi'); # sub irc_bot_public { # my ($kernel,$heap) = @_[KERNEL,HEAP]; # my ($channel) = $_[ARG0][0]; # my ($what) = $_[ARG1]; # # print "I said $what on $channel\n"; # } }} sub _default { my ( $event, $args ) = @_[ARG0 .. $#_]; my @output = ( "$event: " ); foreach my $arg ( @$args ) { if ( ref($arg) eq 'ARRAY' ) { push( @output, "[" . join(" ,", @$arg ) . "]" ); } else { push ( @output, "'$arg'" ); } } print STDOUT join ' ', @output, "\n"; return 0; } #sub irc_bot_public { # my ( $kernel,$heap ) = @_[KERNEL,HEAP]; # my ($channel) = $_[ARG0]->[0]; # my ($what) = $_[ARG1]; # # print "I said $what on $channel\n"; #} sub irc_bot_addressed { my ( $kernel,$heap ) = @_[KERNEL,HEAP]; my ($nick) = (split /!/, $_[ARG0] )[0]; my ($channel) = $_[ARG1][0]; my ($what) = $_[ARG2]; # $kernel->post( $sender => privmsg => $channel => "$nick: What do you want?" ); print "$nick addressed me in $channel with the message $what"; return ($nick,$channel,$what); }