Table of Contents

Oracle plugin for sirc

sirc1) is a Perl based IRC client for text-mode terminals. It features a plugin interface which allows to easily extend its capabilities with Perl scripts.

Ask the Oracle of Delphi2) by Aapo Puskala graciously offers offered its expedient answers to the public.

The following plugin for sirc listens to an IRC channel and tries to answer questions to the Oracle. Any questions which is politely posed starting with "Dear Oracle" is sent to askoracle.net. Answers then get sent back to the IRC channel.

Screenshot

<andreas> Dear Oracle, do you think the oracle plugin for sirc is a valuable
           thing?
<oracle> Dear Andreas: Naturally! I just got a phone call where I learned this.
<andreas> Dear Oracle, what in fact is the meaning of life in IRC?
<oracle> Dear Andreas: Ah, this one again. The answer, my dear, is 42.

Invocation

Personally, I run a screen terminal where I start the Oracle's sirc with its own rc-file oraclerc (here located in ~/.sirc). The command for starting sirc should be something like

sirc -q -8 -L ~/.sirc/oraclerc -i "Oracle" oracle your_ircserver

where oraclerc reads

/LOAD /home/username/.sirc/oracle.pl
/JOIN #MYCHANNEL
/SET USERINFO I am the #MYCHANNEL oracle.

oracle.pl

Download: oracle.pl

# 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
1)
The only URL for sirc that I had (http://www.iagora.com/~espel/sirc.html) is gone as of 2012. Archive.org has some copies, and Debian still has had packages, though.
2)
askoracle.net is gone since 2011.