User:ST47/BOT

use warnings; use POE qw(Component::IRC);
 * 1) use strict;

my $nickname = 'MiniTimeBot'; my $ircname = 'MiniTimeBot v1.0'; my $ircserver = 'irc.freenode.net'; my $port = 6667;

my @channels = ( '#TheLetterE' );

my $irc = POE::Component::IRC->spawn(      nick => $nickname,      server => $ircserver,      port => $port,      ircname => $ircname, ) or die "Oh noooo! $!";
 * 1) We create a new PoCo-IRC object and component.

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];

# We get the session ID of the component from the object # and register and connect to the 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 the component's object at any time by accessing the heap of   # the SENDER my $poco_object = $sender->get_heap; print "Connected to ", $poco_object->server_name, "\n";

# In any irc_* events SENDER will be the PoCo-IRC session $kernel->post( $sender => join => $_ ) for @channels; undef; }

sub irc_public { my ($kernel,$sender,$who,$where,$what) = @_[KERNEL,SENDER,ARG0,ARG1,ARG2]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); $month=$abbr[$mon]; my @days = qw( Sun Mon Tue Wed Thu Fri Sat ); $dow = $days[$wday]; $year+=1900; if ( $what=~/!time/i and $what!~/!timedate/i) { $kernel->post($sender=>privmsg=>$channel=>"The current time is: $hour:$min:$sec (UTC)."); } elsif ( $what=~/!date/i) { $kernel->post($sender=>privmsg=>$channel=>"The current date is: $dow, $mday $month, $year."); } elsif ( $what=~/!timedate/ ) { $kernel->post($sender=>privmsg=>$channel=>"The current time is: $hour:$min:$sec, $dow, $mday $month, $year."); }  undef; }

sub _default { my ($event, $args) = @_[ARG0 .. $#_];   my @output = ( "$event: " );
 * 1) We registered for all events, this will produce some debug info.

foreach my $arg ( @$args ) { if ( ref($arg) eq 'ARRAY' ) { push( @output, "[" . join(" ,", @$arg ) . "]" ); } else { push ( @output, "'$arg'" ); }   }    print STDOUT join ' ', @output, "\n"; return 0; }