#!/usr/bin/perl # $Id$ use warnings; use strict; our $DEBUG = 1; $|=1; use Util::Backend; use Util::Common qw(try_uptime); use Chatbot::Eliza; use Regexp::Common 'RE_URI'; my $noisy = -1; srand( time ^ ($$ + ($$ << 15)) ); our $cb = new Chatbot::Eliza(); svc_run("127.0.0.1", 12345); exit 0; sub on_public { goto &read_irc; } sub on_msg { goto &read_irc; } sub uptime { my $msg = shift; # Support uptime request my $ut_response = try_uptime( $msg->message(), (defined $msg->{channel}) ? 'public' : 'private', $msg->nick(), $msg->addressed(), ); if (defined $ut_response) { $msg->say($ut_response); msg_send($msg); } } sub read_irc { my $msg = shift; # Respond only when requested, or when msg'ed return unless $msg->addressed() or !defined $msg->channel(); my $out = ($msg->channel() ne $msg->nick()) ? $msg->csnick().': ' : ''; # TODO: Per-channel setting for noisiness. # TODO: Better table-based command processing (see infobot?) if ($msg->message() =~ /help/i) { #$out .= "I am a simple minded URL muncher who posts to ". # "del.icio.us at $DEL_URL. Address me or message me with ". # "URLs. Add a comment after a url using '#'. Tell me to ". # "speak or shut up. I may have other talents."; #$msg->say($out); #msg_send($msg); } elsif ($msg->message() =~ /shut up/i) { if ($noisy) { #$out .= 'Shutting up now.'; #$msg->say($out); #msg_send($msg); } $noisy = undef; } elsif ($msg->message() =~ /speak/i) { if (!$noisy) { #$out .= 'Removing the gag.'; #$msg->say($out); #msg_send($msg); } $noisy = -1; } else { my $body = $msg->message(); my $url_re = RE_URI; unless ( $body =~ /$url_re/ ) { $out .= $cb->transform($body); if ($noisy) { $msg->say($out); msg_send($msg); } } } }