################################ # ChuckBot Module # ################################ package BotModules::ChuckBot; use vars qw(@ISA); @ISA = qw(BotModules); 1; sub Help { my $self = shift; my ($event) = @_; return { '' => 'ChuckBot 2.0 "It\'s like a roundhouse kick to the face!"', 'chuck' => 'The bot will listen for \'!chuck\' in any context and spit out a random phrase. Usage: \'ChuckBot: chuck\' or \'!chuck\'', 'norris' => 'The bot will listen for \'!norris\' in any context and spit out a random phrase. Usage: \'ChuckBot: norris\' or \'!norris\'', 'roundhouse' => 'The bot will listen for \'!roundhouse\' in any context and spit out a random phrase.Usage: \'ChuckBot: roundhouse\' or \'!roundhouse\'', 'cquote' => 'Usage: \'cquote\'. See http://www.screwedbydesign.com/mozilla/chuckbot/ for phrase numbers.', 'cstats' => 'Announces the number of phrases in the database.', }; } my $chuckHost = "chuckbot.screwedbydesign.com"; sub Told { my $self = shift; my ($event, $message) = @_; if (($message =~/^chuck$/i) or ($message =~/^roundhouse$/i) or ($message =~/^norris$/i) or($message =~/Chuck Norris/i)) { $self->getURI($event, "http://$chuckHost/?fetch", $1); } elsif ($message =~/^cstats$/i) { $self->getURI($event, "http://$chuckHost/?cstats", $1); } elsif ($message =~/^cquote$/i) { my $fetchQuote = 0; my $fetchQuote = substr $message, 6; $self->getURI($event, "http://$chuckHost/?cquote=$fetchQuote", $1); } else { return $self->SUPER::Told(@_); } return 0; } sub Heard { my $self = shift; my ($event, $message) = @_; if (($message =~/!chuck/i) or ($message =~/!roundhouse/i) or ($message =~/!norris/i) or($message =~/Chuck Norris/i)) { $self->getURI($event, "http://$chuckHost/?fetch", $1); } elsif ($message =~/!cstats/i) { $self->getURI($event, "http://$chuckHost/?cstats", $1); } elsif ($message =~/!cquote/i) { my $fetchQuote = 0; my $fetchQuote = substr $message, 7; $self->getURI($event, "http://$chuckHost/?cquote=$fetchQuote", $1); } else { return $self->SUPER::Told(@_); } return 0; } sub GotURI { my $self = shift; my ($event, $uri, $output) = @_; my $chuckPhrase = $output; my $message = ''; if ($event->{'channel'} ne '') { $message .= "$event->{'from'}: "; } $message = $chuckPhrase; $self->say($event, $message); }