From 40f6dad8bfd5a8a707a69cb31ba62cc6d26139c1 Mon Sep 17 00:00:00 2001 From: djmcgrath Date: Thu, 17 Apr 2008 23:11:59 +0000 Subject: [PATCH] * Merged r1666:1760 from src-cleanup branch git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@1761 c11ca15a-4712-0410-83d8-924469b57eb5 --- ChangeLog | 6 + infobot | 87 +- patches/Google.pm | 335 ---- patches/Net_IRC_Connection_pm.patch | 32 - patches/WWW_Search.patch | 444 ----- patches/WWW_Search.patch.old | 31 - scripts/backup_table-slave.pl | 95 +- scripts/dbm2mysql.pl | 32 +- scripts/dbm2txt.pl | 12 +- scripts/findparam.pl | 78 +- scripts/fixbadchars.pl | 60 +- scripts/insertDB.pl | 14 +- scripts/irclog2html.pl | 477 ++--- scripts/makepasswd | 4 +- scripts/mysql2txt.pl | 14 +- scripts/oreilly_dumpvar.pl | 36 +- scripts/oreilly_prettyp.pl | 104 +- scripts/parse_warn.pl | 116 +- scripts/showvars.pl | 134 +- scripts/symname.pl | 168 +- scripts/txt2mysql.pl | 57 +- scripts/vartree.pl | 80 +- scripts/webbackup.pl | 91 +- setup/setup.pl | 82 +- src/CLI/Support.pl | 82 +- src/CommandStubs.pl | 1043 +++++------ src/DynaConfig.pl | 1110 ++++++------ src/Factoids/Core.pl | 1023 ++++++----- src/Factoids/DBCommon.pl | 104 +- src/Factoids/Norm.pl | 151 +- src/Factoids/Question.pl | 447 ++--- src/Factoids/Reply.pl | 494 +++--- src/Factoids/Statement.pl | 152 +- src/Factoids/Update.pl | 416 +++-- src/Files.pl | 79 +- src/IRC/Irc.pl | 1118 ++++++------ src/IRC/IrcHelpers.pl | 480 ++--- src/IRC/IrcHooks.pl | 1504 ++++++++-------- src/IRC/Schedulers.pl | 1446 ++++++++------- src/Misc.pl | 722 ++++---- src/Modules/BZFlag.pl | 698 ++++---- src/Modules/Debian.pl | 1552 ++++++++-------- src/Modules/DebianBugs.pm | 205 ++- src/Modules/DebianExtra.pl | 217 ++- src/Modules/Dict.pl | 283 +-- src/Modules/DumpVars.pl | 165 +- src/Modules/DumpVars2.pl | 49 +- src/Modules/Exchange.pl | 683 ++++---- src/Modules/Factoids.pl | 1446 +++++++-------- src/Modules/HTTPDtype.pl | 24 +- src/Modules/Kernel.pl | 93 +- src/Modules/Math.pl | 187 +- src/Modules/News.pl | 1468 ++++++++-------- src/Modules/OnJoin.pl | 227 +-- src/Modules/Plug.pl | 63 +- src/Modules/Quote.pl | 38 +- src/Modules/RSSFeeds.pl | 219 +-- src/Modules/RootWarn.pl | 146 +- src/Modules/Rss.pl | 14 +- src/Modules/Search.pl | 31 +- src/Modules/Topic.pl | 583 +++--- src/Modules/Units.pl | 33 +- src/Modules/Uptime.pl | 116 +- src/Modules/UserDCC.pl | 2534 ++++++++++++++------------- src/Modules/UserInfo.pl | 221 +-- src/Modules/W3Search.pl | 59 +- src/Modules/Weather.pl | 196 ++- src/Modules/Wingate.pl | 102 +- src/Modules/Zippy.pl | 14 +- src/Modules/babelfish.pl | 188 +- src/Modules/botmail.pl | 138 +- src/Modules/case.pl | 9 +- src/Modules/countdown.pl | 158 +- src/Modules/dice.pl | 53 +- src/Modules/dns.pl | 51 +- src/Modules/hex2ip.pl | 11 +- src/Modules/insult.pl | 26 +- src/Modules/md5.pl | 4 +- src/Modules/nickometer.pl | 408 ++--- src/Modules/pager.pl | 153 +- src/Modules/piglatin.pl | 65 +- src/Modules/reverse.pl | 4 +- src/Modules/scramble.pl | 83 +- src/Modules/slashdot.pl | 64 +- src/Modules/spell.pl | 118 +- src/Modules/wikipedia.pl | 386 ++-- src/Modules/wtf.pl | 57 +- src/Modules/zfi.pl | 99 +- src/Modules/zsi.pl | 99 +- src/Net.pl | 246 +-- src/Process.pl | 559 +++--- src/Shm.pl | 371 ++-- src/UserExtra.pl | 1109 ++++++------ src/core.pl | 678 +++---- src/dbi.pl | 825 +++++---- src/logger.pl | 544 +++--- src/modules.pl | 366 ++-- 97 files changed, 16191 insertions(+), 15307 deletions(-) delete mode 100644 patches/Google.pm delete mode 100644 patches/Net_IRC_Connection_pm.patch delete mode 100644 patches/WWW_Search.patch delete mode 100644 patches/WWW_Search.patch.old diff --git a/ChangeLog b/ChangeLog index 0791052..1033aad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * Correction to factoid updates to treat appending as a modification +* Code formatting cleanups + +* Removed unmaintained patches directory + 1.5.1 ===== @@ -10,3 +14,5 @@ created_by properly * New +M flag to allow modifying factoids created by same nick + +# vim:ts=4:sw=4:expandtab:tw=80 diff --git a/infobot b/infobot index f20af53..7fc8989 100755 --- a/infobot +++ b/infobot @@ -7,27 +7,28 @@ use strict; use vars qw($bot_base_dir $bot_src_dir $bot_misc_dir $bot_state_dir - $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir - $bot_pid $memusage %param + $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir + $bot_pid $memusage %param ); BEGIN { - if (@ARGV and -f $ARGV[0]) { - # source passed config to allow $bot_*_dir to be set. - do $ARGV[0]; + if ( @ARGV and -f $ARGV[0] ) { + + # source passed config to allow $bot_*_dir to be set. + do $ARGV[0]; } # set any $bot_*_dir var's that aren't already set - $bot_base_dir ||= '.'; - $bot_config_dir ||= 'files/'; - $bot_data_dir ||= 'files/'; - $bot_state_dir ||= 'files/'; - $bot_run_dir ||= '.'; - $bot_src_dir ||= "$bot_base_dir/src"; - $bot_log_dir ||= "$bot_base_dir/log"; - $bot_misc_dir ||= "$bot_base_dir/files"; + $bot_base_dir ||= '.'; + $bot_config_dir ||= 'files/'; + $bot_data_dir ||= 'files/'; + $bot_state_dir ||= 'files/'; + $bot_run_dir ||= '.'; + $bot_src_dir ||= "$bot_base_dir/src"; + $bot_log_dir ||= "$bot_base_dir/log"; + $bot_misc_dir ||= "$bot_base_dir/files"; - $bot_pid = $$; + $bot_pid = $$; require "$bot_src_dir/logger.pl"; require "$bot_src_dir/core.pl"; @@ -36,7 +37,7 @@ BEGIN { # load the configuration (params) file. &setupConfig(); - &showProc(); # to get the first value. + &showProc(); # to get the first value. &status("Initial memory usage: $memusage kB"); &loadCoreModules(); &loadDBModules(); @@ -50,17 +51,19 @@ BEGIN { &duperuncheck(); # initialize everything -&startup(); # first time initialization. +&startup(); # first time initialization. &setup(); -if (!&IsParam("Interface") or $param{'Interface'} =~ /IRC/) { +if ( !&IsParam("Interface") or $param{'Interface'} =~ /IRC/ ) { + # launch the irc event loop &ircloop(); -} else { +} +else { &cliloop(); } -exit 0; # just so you don't look farther down in this file :) +exit 0; # just so you don't look farther down in this file :) # --- support routines @@ -68,30 +71,32 @@ exit 0; # just so you don't look farther down in this file :) # added by the xk sub duperuncheck { - my $pid = $$; - my $file = $file{PID}; - - if ( -f $file) { - open(PIDFILE,$file) or die "error: cannot open $file."; - my $thispid = || "NULL\n"; - close PIDFILE; - chop $thispid; - - if ($thispid =~ /^\D$/) { - &staus("warning: pidfile is invalid; wiping out."); - } else { - if ( -d "/proc/$thispid/") { - &ERROR("bot is already running from this directory."); - &ERROR("if this is incorrect, erase '*.pid'."); - &ERROR("verify with 'ps -axu | grep $thispid'."); - exit 1; - } else { - &status("warning: stale $file found; wiping."); - } - } + my $pid = $$; + my $file = $file{PID}; + + if ( -f $file ) { + open( PIDFILE, $file ) or die "error: cannot open $file."; + my $thispid = || "NULL\n"; + close PIDFILE; + chop $thispid; + + if ( $thispid =~ /^\D$/ ) { + &staus("warning: pidfile is invalid; wiping out."); + } + else { + if ( -d "/proc/$thispid/" ) { + &ERROR("bot is already running from this directory."); + &ERROR("if this is incorrect, erase '*.pid'."); + &ERROR("verify with 'ps -axu | grep $thispid'."); + exit 1; + } + else { + &status("warning: stale $file found; wiping."); + } + } } - open(PIDFILE,">$file") or die "error: cannot write to $file."; + open( PIDFILE, ">$file" ) or die "error: cannot write to $file."; print PIDFILE "$pid\n"; close PIDFILE; diff --git a/patches/Google.pm b/patches/Google.pm deleted file mode 100644 index 04f586e..0000000 --- a/patches/Google.pm +++ /dev/null @@ -1,335 +0,0 @@ -########################################################## -# Google.pm -# by Jim Smyser -# Copyright (C) 1996-1999 by Jim Smyser & USC/ISI -# $Id: Google.pm,v 2.20 2000/07/09 14:29:22 jims Exp $ -########################################################## - - -package WWW::Search::Google; - - -=head1 NAME - -WWW::Search::Google - class for searching Google - - -=head1 SYNOPSIS - -use WWW::Search; -my $Search = new WWW::Search('Google'); # cAsE matters -my $Query = WWW::Search::escape_query("Where is Jimbo"); -$Search->native_query($Query); -while (my $Result = $Search->next_result()) { -print $Result->url, "\n"; -} - -=head1 DESCRIPTION - -This class is a Google specialization of WWW::Search. -It handles making and interpreting Google searches. -F. - -This class exports no public interface; all interaction should -be done through L objects. - -=head1 LINUX SEARCH - -For LINUX lovers like me, you can put Googles in a LINUX only search -mode by changing search URL from: - - 'search_url' => 'http://www.google.com/search', - -to: - - 'search_url' => 'http://www.google.com/linux', - -=head1 SEE ALSO - -To make new back-ends, see L. - -=head1 HOW DOES IT WORK? - -C is called (from C) -before we do anything. It initializes our private variables (which -all begin with underscore) and sets up a URL to the first results -page in C<{_next_url}>. - -C is called (from C) -whenever more hits are needed. It calls C -to fetch the page specified by C<{_next_url}>. -It then parses this page, appending any search hits it finds to -C<{cache}>. If it finds a ``next'' button in the text, -it sets C<{_next_url}> to point to the page for the next -set of results, otherwise it sets it to undef to indicate we''re done. - - -=head1 TESTING - -This module adheres to the C test suite mechanism. - -=head1 AUTHOR - -This backend is written and maintained/supported by Jim Smyser. - - -=head1 BUGS - -Google is not an easy search engine to parse in that it is capable -of altering it's output ever so slightly on different search terms. -There may be new slight results output the author has not yet seen that -will pop at any given time for certain searches. So, if you think you see -a bug keep the above in mind and send me the search words you used so I -may code for any new variations. - -=head1 CHANGES - -2.21.1 -Parsing update from Tim Riker - -2.21 -Minor code correction for empty returned titles - -2.20 -Forgot to add new next url regex in 2.19! - -2.19 -Regex work on some search results url's that has changed. Number found -return should be right now. - -2.17 -Insert url as a title when no title is found. - -2.13 -New regexp to parse newly found results format with certain search terms. - -2.10 -removed warning on absence of description; new test case - -2.09 -Google NOW returning url and title on one line. - -2.07 -Added a new parsing routine for yet another found result line. -Added a substitute for whacky url links some queries can produce. -Added Kingpin's new hash_to_cgi_string() 10/12/99 - -2.06 -Fixed missing links / regexp crap. - -2.05 -Matching overhaul to get the code parsing right due to multiple -tags being used by google on the hit lines. 9/25/99 - -2.02 -Last Minute description changes 7/13/99 - -2.01 -New test mechanism 7/13/99 - -1.00 -First release 7/11/99 - -=head1 LEGALESE - -THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - - -=cut -#' - - -##################################################################### - -require Exporter; -@EXPORT = qw(); -@EXPORT_OK = qw(); -@ISA = qw(WWW::Search Exporter); -$VERSION = '2.21.1'; - -$MAINTAINER = 'Jim Smyser '; -$TEST_CASES = <<"ENDTESTCASES"; -# Google looks for partial words it can find results for so it will end up finding "Bogus" pages. -&test('Google', '$MAINTAINER', 'zero', '4036e7757s5', \$TEST_EXACTLY); -&test('Google', '$MAINTAINER', 'one_page', '+LS'.'AM +rep'.'lication', \$TEST_RANGE, 2,99); -&test('Google', '$MAINTAINER', 'multi', 'dir'.'ty ha'.'rr'.'y bimbo', \$TEST_GREATER_THAN, 101); -ENDTESTCASES - -use Carp (); -use WWW::Search(qw(generic_option strip_tags)); -require WWW::SearchResult; - - -sub undef_to_emptystring { -return defined($_[0]) ? $_[0] : ""; -} -# private -sub native_setup_search - { - my($self, $native_query, $native_options_ref) = @_; - $self->user_agent('user'); - $self->{_next_to_retrieve} = 0; - $self->{'_num_hits'} = 100; - if (!defined($self->{_options})) { - $self->{_options} = { - 'search_url' => 'http://www.google.com/search', - 'num' => $self->{'_num_hits'}, - }; - }; - my($options_ref) = $self->{_options}; - if (defined($native_options_ref)) { - # Copy in new options. - foreach (keys %$native_options_ref) { - $options_ref->{$_} = $native_options_ref->{$_}; - }; - }; - # Process the options. - my($options) = ''; - foreach (keys %$options_ref) { - # printf STDERR "option: $_ is " . $options_ref->{$_} . "\n"; - next if (generic_option($_)); - $options .= $_ . '=' . $options_ref->{$_} . '&'; - }; - $self->{_debug} = $options_ref->{'search_debug'}; - $self->{_debug} = 2 if ($options_ref->{'search_parse_debug'}); - $self->{_debug} = 0 if (!defined($self->{_debug})); - - # Finally figure out the url. - $self->{_base_url} = - $self->{_next_url} = - $self->{_options}{'search_url'} . - "?" . $options . - "q=" . $native_query; - } - -# private -sub begin_new_hit { - my($self) = shift; - my($old_hit) = shift; - my($old_raw) = shift; - if (defined($old_hit)) { - $old_hit->raw($old_raw) if (defined($old_raw)); - push(@{$self->{cache}}, $old_hit); - }; - return (new WWW::SearchResult, ''); - } -sub native_retrieve_some { - my ($self) = @_; - # fast exit if already done - return undef if (!defined($self->{_next_url})); - # get some - print STDERR "Fetching " . $self->{_next_url} . "\n" if ($self->{_debug}); - my($response) = $self->http_request('GET', $self->{_next_url}); - $self->{response} = $response; - if (!$response->is_success) { - return undef; - }; - - # parse the output - my($HEADER, $HITS, $TRAILER, $POST_NEXT) = (1..10); - my($hits_found) = 0; - my($state) = ($HEADER); - my($hit) = undef; - my($raw) = ''; - foreach ($self->split_lines($response->content())) { - next if m@^$@; # short circuit for blank lines - - if ($state == $HEADER && m/about ([\d,]+)<\/b>/) - { - my($n) = $1; - $self->approximate_result_count($n); - print STDERR "Found Total: $n\n" ; - $state = $HITS; - } - if ($state == $HITS && - m|

]*)\>(.*?)|i) { - my ($url, $title) = ($1,$2); - ($hit, $raw) = $self->begin_new_hit($hit, $raw); - print STDERR "**Found HIT0 Line** $url - $title\n" if ($self->{_debug}); - $raw .= $_; - $url =~ s/(>.*)//g; - $hit->add_url(strip_tags($url)); - $hits_found++; - $title = "No Title" if ($title =~ /^\s+/); - $hit->title(strip_tags($title)); - $state = $HITS; - } - elsif ($state == $HITS && - m|(.*?)
<.*?>|i) { - my ($url, $title) = ($1,$2); - ($hit, $raw) = $self->begin_new_hit($hit, $raw); - print STDERR "**Found HIT1 Line**\n" if ($self->{_debug}); - $raw .= $_; - $url =~ s/(>.*)//g; - $hit->add_url(strip_tags($url)); - $hits_found++; - $title = "No Title" if ($title =~ /^\s+/); - $hit->title(strip_tags($title)); - $state = $HITS; - } - elsif ($state == $HITS && - m@^

(.*)
(.*)@i || - m@^

(.*).*?
(.*)@i) - { - ($hit, $raw) = $self->begin_new_hit($hit, $raw); - print STDERR "**Found HIT2 Line**\n" if ($self->{_debug}); - my ($url, $title) = ($1,$2); - $mDesc = $3; - $url =~ s/\/url\?sa=\w&start=\d+&q=//g; - $url =~ s/&(.*)//g; - $url =~ s/(>.*)//g; - $raw .= $_; - $hit->add_url(strip_tags($url)); - $hits_found++; - $title = "No Title" if ($title =~ /^\s+/); - $hit->title(strip_tags($title)); - $mDesc =~ s/<.*?>//g; - $mDesc = $mDesc . '
' if not $mDesc =~ m@
@; - $hit->description($mDesc) if (defined($hit)); - $state = $HITS; - } - elsif ($state == $HITS && m@^(\.\.(.+))@i) - { - print STDERR "**Parsing Description Line**\n" if ($self->{_debug}); - $raw .= $_; - $sDesc = $1; - $sDesc ||= ''; - $sDesc =~ s/<.*?>//g; - $sDesc = $mDesc . $sDesc; - $hit->description($sDesc) if $sDesc =~ m@^\.@; - $sDesc = ''; - $state = $HITS; - } - elsif ($state == $HITS && m@