#!/USr/bin/perl # Idles... use strict; use warnings; use POE qw(Component::IRC); use POE::Component::IRC::Plugin::BotTraffic; my %config = ( nickname => 'IdleBot', ircname => 'Idle Bot of Possum', ircserver => 'possum.kicks-ass.org', port => '6667', channel => '#lobby' ); my @channels=('#lobby'); #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; $kernel->post( $sender => privmsg => @channels => 'I\'m made to idle!' ); # 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] ); if ( $command eq "$nick:" ){ $kernel->post( $sender => privmsg => $channel => "@dialogue[0]: I'm IDLING!" ); }# elsif ( @dialogue[2] eq '!kick IdleBot'){ # $kernel->post( $sender => kick => $channel => 'IdleBot' => 'Stop Idling!' ); # } 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); }