#!/usr/bin/perl #===[ MonkBot ]=============================================================== # # Jabber bot that serves as an IM gateway to the perlmonks.org chatterbox. # Homepage: http://hutta.com/perl/jabberbots/monkbot.html # # Note that this requires Net::Jabber, Net::Jabber::Bot and PerlMonks::Chat # http://download.jabber.org/perl/ # http://hutta.com/perl/jabberbots/ # http://www.cerias.purdue.edu/homes/zamboni/perlmonks.html # # My personal MonkBot is on jabber as MonkBot@jabber.icgcorp.net. # Add him to your roster and you can test this out. # #===[ TODO ]================================================================== # # - Let MonkBot take user/pass to allow people to send messages as themselves. # - More integration with PM... New nodes, etc, etc, etc. # #============================================================================= use Net::Jabber::Bot; use PerlMonks::Chat; #===[ Initialize ]============================================================ my $pm = new PerlMonks::Chat; $pm->add_cookies; my $bot = new Net::Jabber::Bot( client => 'MonkBot', verbos => '2', logfile => '/tmp/monkbot.log', version => '1.0', status => 'Meditating', ); $bot->connect( hostname => 'jabber.com', port => '5222' ) || die "Can't connect"; $bot->auth( username => 'MonkBot', password => 'passwordhere', resource => 'bot', digest => '1' ); $bot->send_presence(); #===[ Defining Callbacks ]==================================================== $bot->set_callback( "hello" => \&SayHello ); $bot->set_callback( "hi" => \&SayHello ); $bot->set_callback( "help" => \&SayHello ); $bot->set_callback( "all" => \&SendAll ); sub SayHello { my $user = shift; $user->write("Greetings."); $user->write("Add me to your roster/buddylist and I'll send you every" . "thing that happens on the chatterbox automatically. " . "Send the command 'all' to get all lines currently " . "available."); } sub SendAll { my $user = shift; my ($lines) = ($pm->getalllines(1,1)); foreach (@{$lines}) { $user->write("$_"); } } #===[ The main loop. ]======================================================== # # This is where the bot will spend most of its time. Looping and looping, # waiting for new chatterbox messages. When we get them, we'll send them # out to anyone subscribed to our presence. # #============================================================================= while (1) { $bot->Process(5); foreach ($pm->getnewlines(1,1)) { $bot->broadcast(body=>"$_", type=>'chat'); } $bot->Connected() || die "Lost my connection!"; } # Edited: Sun Oct 14 06:52:45 2001 (GMT), by [footpad] # Fixed formatting by adding line line breaks.