# Oracle IRC bot for sirc using http://www.askoracle.net/
# Quickly and dirtily compiled by Andreas Schamanek * 2007-12-06
# http://www.fam.tuwien.ac.at/~schamane/_/sirc_plugin_askoracle
# License (see end of file)

my $o_version = 'v0.12';

use LWP 5.64;
use URI::Escape ('uri_escape');

$add_ons .= "+Oracle $o_version" if ($add_ons !~ /Oracle/);

my $url = 'http://www.askoracle.net/?skiphtml=TRUE&q=';

 $www_url=$& if (($_[1] || $_[0])  =~ /(http|ftp|telnet):\/\/[^ ]+/i); 

sub hook_oracle {
 # answer only to "Dear Oracle" (question will be $2)
 if ($_[1] =~ /^Dear Oracle *([!:;,.-]*) *([^	 !:;,.-].*)?$/i) {
  # check that we are in my channel
  if(&eq ($_[0], $talkchannel)) {
    &tell("--- Oracle quested by $who ---");
    &tell("<\cb$who\cb> $_[1]");
    &tell("--- Q: $2");
    # get answer from online oracle
    my $browser = LWP::UserAgent->new;
    my $response = $browser->get( $url . uri_escape($2) );
    if ($response->is_success) {
       my $answer = $response->content;
       my $whouc = ucfirst lc $who;
       &say("\cbDear $whouc\cb: $answer");
    } else {
       print "Can't get $url -- " . $response->status_line ."\n";
    }
  };
  $silent=1;
 }
}
&addhook("public", "oracle");

# Tagline
print("*\cb*\cb* \cvoracle.pl $o_version\cv for \c_sirc\c_ loaded\n");

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA


