# Infobot user extension stubs # Kevin A. Lenzo # put your routines in here. do 'src/nickometer.pl'; # Adam Spier's "lame nick-o-meter" code sub myRoutines { # called after it decides if it's been addressed. # you have access tothe global variables here, # which is bad, but anyway. # you can return 'NOREPLY' if you want to stop # processing past this point but don't want # an answer. if you don't return NOREPLY, it # will let all the rest of the default processing # go to it. think of it as 'catching' the event. # $addressed is whether the infobot has been # named or, if a private or standalone # context, addressed is always 'true' # $msgType can be 'public', 'private', maybe 'dcc_chat' # $who is the sender of the message # $message is the current state of the input, after # the addressing stuff stripped off the name # $origMessage is the text of the original message before # any normalization or processing # you have access to all the routines in urlIrc.pl too, # of course. # example: if ($addressed) { # only if the infobot is addressed if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) { if ($msgType eq 'public') { &say($howAreYa[rand($#howAreYa)].", $who"); } else { &msg($who, $howAreYa[rand($#howAreYa)].", $who"); } return 'NOREPLY'; } } else { # we haven't been addressed, but we are still listening } # from Chris Tessone: slashdot headlines # "slashdot" or "slashdot headlines" if (defined($param{'slash'}) and $message =~ /^\s*slashdot( headlines)?\W*\s*$/) { my $headlines = &getslashdotheads(); if ($msgType eq 'public') { &say("$who: $headlines"); } else { &msg($who, $headlines); } return "NOREPLY"; } # Jonathan Feinberg's babel-bot -- jdf++ if (defined $param{babel} && (1 or $addressed) && $message =~ m{ ^\s* (?:babel(?:fish)?|x|xlate|translate) \s+ (to|from) # direction of translation (through) \s+ ($babel::lang_regex)\w* # which language? \s* (.+) # The phrase to be translated }xoi) { my $whom = $who; # building a closure, need lexical my $callback = $msgType eq 'public' ? sub{say("$who: $_[0]")} : sub{msg($who, $_[0])}; &babel::forking_babelfish(lc $1, lc $2, $3, $callback); return 'NOREPLY'; } # insult server. patch thanks to michael@limit.org if ($param{'insult'} and ($message =~ /^\s*insult (.*)\s*$/)) { my $person = $1; my $language = "english"; if ($person =~ s/ in \s*($babel::lang_regex)\w*\s*$//xi) { $language = lc($1); } $person = $who if $person =~ /^\s*me\s*$/i; my $insult = &insult(); if ($person ne $who) { $insult =~ s/^\s*You are/$person is/i; } if ($insult =~ /\S/) { if ($param{'babel'} and ($language ne "english")) { my $whom = $who; # building a closure, need lexical my $callback = $msgType eq 'public' ? sub{say("$_[0]")} : sub{msg($whom, $_[0])}; &babel::forking_babelfish("to", $language, $insult, $callback); return 'NOREPLY'; } } else { $insult = "No luck, $who"; } if ($msgType eq 'public') { &say($insult); } else { &msg($who, $insult); } return "NOREPLY"; } if ($param{'weather'} and ($message =~ /^\s*weather\s+(?:for\s+)?(.*?)\s*\?*\s*$/)) { my $code = $1; my $weath ; if ($code =~ /^[a-zA-Z][a-zA-Z0-9]{3,4}$/) { $weath = &Weather::NOAA::get($code); } else { $weath = "Try a 4-letter station code (see http://weather.noaa.gov/weather/curcond.html for locations and codes)"; } # if ($msgType eq 'public') { # &say("$who: $weath"); # } else { &msg($who, $weath); # } return 'NOREPLY'; } if (defined $param{'metar'}) { my $metar = &metar::get($message); if ($metar) { # if ($msgType eq 'public') { # &say("$who: $metar"); # } else { &msg($who, $metar); # } return 'NOREPLY'; } } if (defined $param{'uaflight'}) { if ($message =~ /usair\s+flight\s+(\d+)/i) { my $res = &UAFlight::get_ua_flight_status($1); if ($res) { if ($msgType eq 'public') { &say("$who: $res"); } else { &msg($who, $res); } return 'NOREPLY'; } } } # from Simon: google searching # modified to fork and generally search by oznoid if(defined($param{'wwwsearch'}) and $message =~ /^\s*(?:search\s+)?($W3Search::regex)\s+for\s+['"]?(.*?)['"]?\s*\?*\s*$/i ) { my $callback = $msgType eq 'public' ? sub{say("$who: $_[0]")} : sub{msg($who, $_[0])}; &W3Search::forking_W3Search($1,$2,$param{'wwwsearch'}, $callback); return "NOREPLY"; } # Adam Spiers nickometer if ($message =~ /^\s*(?:lame|nick)-?o-?meter(?: for)? (\S+)/i) { my $term = $1; if (lc($term) eq 'me') { $term = $who; } $term =~ s/\?+\s*//; my $percentage = &nickometer($term); if ($percentage =~ /NaN/) { $percentage = "off the scale"; } else { $percentage = sprintf("%0.4f", $percentage); $percentage =~ s/\.?0+$//; $percentage .= '%'; } if ($msgType eq 'public') { &say("'$term' is $percentage lame, $who"); } else { &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who"); } return 'NOREPLY'; } if ($message =~ /^foldoc(?: for)?\s+(.*)/i) { my ($terms) = $1; $terms =~ s/\?\W*$//; my $key= $terms; $key =~ s/\s+$//; $key =~ s/^\s+//; $key =~ s/\W+/+/g; my $reply = "$terms may be sought in foldoc at http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=$key"; if ($msgType eq 'public') { &say($reply); } else { &msg($who, $reply); } return 'NOREPLY'; } if ($message =~ /^(?:quote|stock price)(?: of| for)? ([A-Z]{1,6})\?*$/) { my $reply = "stock quotes for $1 may be sought at http://quote.yahoo.com/q?s=$1\&d=v1"; if ($msgType eq 'public') { &say($reply); } else { &msg($who, $reply); } return 'NOREPLY'; } if ($message =~ /^rot13\s+(.*)/i) { # rot13 it my $reply = $1; $reply =~ y/A-Za-z/N-ZA-Mn-za-m/; if ($msgType eq 'public') { &say($reply); } else { &msg($who, $reply); } return 'NOREPLY'; } return ''; # do nothing and let the other routines have a go } @howAreYa = ("just great", "peachy", "mas o menos", "you know how it is", "eh, ok", "pretty good. how about you"); 1;