From 9154f624199e06e382a4a0b5c40f445f35fbe92d Mon Sep 17 00:00:00 2001 From: timriker Date: Thu, 18 Nov 2004 09:03:52 +0000 Subject: [PATCH] more babelfish cleanup git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@1047 c11ca15a-4712-0410-83d8-924469b57eb5 --- files/sample/blootbot.chan | 7 ++--- files/sample/blootbot.config | 5 +--- src/CommandStubs.pl | 25 +++------------- src/Factoids/Core.pl | 1 - src/Modules/DumpVars.pl | 3 +- src/Modules/UserDCC.pl | 2 +- src/Modules/babelfish.pl | 55 +++++++++++++++++++++++------------- src/core.pl | 6 +++- src/modules.pl | 2 +- 9 files changed, 52 insertions(+), 54 deletions(-) diff --git a/files/sample/blootbot.chan b/files/sample/blootbot.chan index 0f45c3d..4581423 100644 --- a/files/sample/blootbot.chan +++ b/files/sample/blootbot.chan @@ -1,9 +1,6 @@ #v1: blootbot -- blootbot -- written Wed Oct 30 03:12:44 2002 #debian-bots - +allowTelling - +autojoin - +babelfish factoidDeleteDelay 7 ircTextCounters heh hah :) ? hi lol +joinfloodCheck @@ -13,13 +10,14 @@ newsDefaultExpire 7 +newsKeepRead +newsNotifyAll - +rootWarn rootWarnMode aggressive #botpark +autojoin _default + +allowTelling + +babelfish +allowConv +allowDNS +BZFlag @@ -51,6 +49,7 @@ _default +quote randomFactoidInterval 60 randomQuoteInterval 60 + +rootWarn +search +seen seenFlushInterval 60 diff --git a/files/sample/blootbot.config b/files/sample/blootbot.config index b042091..53ddc97 100644 --- a/files/sample/blootbot.config +++ b/files/sample/blootbot.config @@ -188,9 +188,6 @@ set backlog 24 # [str] anything which requires LWP + http proxy. ###set httpProxy http://HOSTNAME:PORT/ -# [0/1] babelfish translator. jdf++. -set babelfish true - # [0/1] offer free factoid cookies set cookie true @@ -300,7 +297,7 @@ set WIP 0 set useStrict 1 # debugging... -###set dumpvars 1 +###set DumpVars 1 ###set dumpvarsAtExit 1 # log to specific file or global log file. ###set dumpvarsLogFile dumpvars.log diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index ec45ff7..a4746fb 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -7,14 +7,13 @@ # use strict; use vars qw($who $msgType $conn $chan $message $ident $talkchannel - $bot_version $babel_lang_regex $bot_data_dir); + $bot_version $bot_data_dir); use vars qw(@vernick @vernicktodo); use vars qw(%channels %cache %mask %userstats %myModules %cmdstats %hooks_extra %lang %ver); # FIX THE FOLLOWING: use vars qw($total $x $type $i $good); -$babel_lang_regex = "de|ge|gr|el|sp|es|en|fr|it|ja|jp|ko|kr|nl|po|pt|ru|zh|zt"; $w3search_regex = "google"; ### COMMAND HOOK IMPLEMENTATION. @@ -266,6 +265,9 @@ sub parseCmdHook { &addCmdHook("extra", 'page', ('CODEREF' => 'pager::page', 'Identifier' => 'pager', 'Cmdstats' => 'pager', 'Forker' => 1, 'Help' => 'page') ); +&addCmdHook("extra", '?:babel(?:fish)?|x|xlate|translate', ('CODEREF' => 'babelfish::babelfish', + 'Identifier' => 'babelfish', 'Cmdstats' => 'babelfish', + 'Forker' => 1, 'Help' => 'babelfish') ); ### ### END OF ADDING HOOKS. ### @@ -277,25 +279,6 @@ sub Modules { return; } - # babelfish bot: Jonathan Feinberg++ - if ($message =~ m{ - ^\s* - (?:babel(?:fish)?|x|xlate|translate) - \s+ - ($babel_lang_regex)\w* # from language? - \s+ - ($babel_lang_regex)\w* # to language? - \s* - (.+) # The phrase to be translated - }xoi) { - return unless (&hasParam("babelfish")); - - &Forker("babelfish", sub { &babelfish::babelfish(lc $1, lc $2, $3); } ); - - $cmdstats{'BabelFish'}++; - return; - } - my $debiancmd = 'conflicts?|depends?|desc|file|(?:d)?info|provides?'; $debiancmd .= '|recommends?|suggests?|maint|maintainer'; diff --git a/src/Factoids/Core.pl b/src/Factoids/Core.pl index 4c896d6..6c64730 100644 --- a/src/Factoids/Core.pl +++ b/src/Factoids/Core.pl @@ -37,7 +37,6 @@ sub validFactoid { /^learn / and last; # teach. damn morons. /^tell (\S+) about / and last; # tell. /\=\~/ and last; # substituition. - /^\S+ to \S+ \S+/ and last; # babelfish. /^\=/ and last; # botnick = heh is. /wants you to know/ and last; diff --git a/src/Modules/DumpVars.pl b/src/Modules/DumpVars.pl index cbb3e34..2e9fa97 100644 --- a/src/Modules/DumpVars.pl +++ b/src/Modules/DumpVars.pl @@ -6,7 +6,8 @@ # NOTE: Ripped from ActivePerl "asp sample" example. # -use strict; +# FIXME +#use strict; #use vars qw(); diff --git a/src/Modules/UserDCC.pl b/src/Modules/UserDCC.pl index 0b98bf2..c4db845 100644 --- a/src/Modules/UserDCC.pl +++ b/src/Modules/UserDCC.pl @@ -115,7 +115,7 @@ sub userDCC { # dump variables. if ($message =~ /^dumpvars$/i) { return unless (&hasFlag("o")); - return unless (&IsParam("dumpvars")); + return unless (&IsParam("DumpVars")); &status("Dumping all variables..."); &dumpallvars(); diff --git a/src/Modules/babelfish.pl b/src/Modules/babelfish.pl index 6d3b092..3a2e9f0 100644 --- a/src/Modules/babelfish.pl +++ b/src/Modules/babelfish.pl @@ -53,7 +53,7 @@ BEGIN { $lang_regex = join '|', keys %lang_code; } -sub babelfish { +sub babelfishParam { return '' if $no_babelfish; my ($from, $to, $phrase) = @_; &main::DEBUG("babelfish($from, $to, $phrase)"); @@ -94,37 +94,52 @@ sub translate { my $translated; if ($res->is_success) { - my $html = $res->content; - # This method subject to change with the whims of Altavista's design - # staff. - ($translated) = $html; + my $html = $res->content; + # This method subject to change with the whims of Altavista's design + # staff. + ($translated) = $html; - $translated =~ s/<[^>]*>//sg; - $translated =~ s/ / /sg; - $translated =~ s/\s+/ /sg; - #&main::DEBUG("$translated\n===remove \n"); + $translated =~ s/<[^>]*>//sg; + $translated =~ s/ / /sg; + $translated =~ s/\s+/ /sg; + #&main::DEBUG("$translated\n===remove \n"); - $translated =~ s/\s*Translate again.*//i; - &main::DEBUG("$translated\n===remove after 'Translate again'\n"); + $translated =~ s/\s*Translate again.*//i; + &main::DEBUG("$translated\n===remove after 'Translate again'\n"); - $translated =~ s/[^:]*?:\s*(Help\s*)?//s; - &main::DEBUG("len=" . length($translated) . " $translated\n===remove to first ':', optional Help\n"); + $translated =~ s/[^:]*?:\s*(Help\s*)?//s; + &main::DEBUG("len=" . length($translated) . " $translated\n===remove to first ':', optional Help\n"); - $translated =~ s/\n/ /g; - # FIXME: should we do unicode->iso (no. use utf8!) + $translated =~ s/\n/ /g; + # FIXME: should we do unicode->iso (no. use utf8!) } else { - $translated = ":("; # failure + $translated = ":("; # failure } $translated = "babelfish.pl: result too long, probably an error" if (length($translated) > 700); - &main::pSReply($translated); + return $translated +} + +sub babelfish { + my ($message) = @_; + my $babel_lang_regex = "de|ge|gr|el|sp|es|en|fr|it|ja|jp|ko|kr|nl|po|pt|ru|zh|zt"; + if ($message =~ m{ + ($babel_lang_regex)\w* # from language? + \s+ + ($babel_lang_regex)\w* # to language? + \s* + (.+) # The phrase to be translated + }xoi) { + &::performStrictReply(&babelfishParam(lc $1, lc $2, lc $3)); + } + return; } if (0) { if (-t STDIN) { - #my $result = babelfish::babelfish('en','sp','hello world'); - #my $result = babelfish::babelfish('en','sp','The cheese is old and moldy, where is the bathroom?'); - my $result = babelfish::babelfish('en','gr','doesn\'t seem to translate things longer than 40 characters'); + #my $result = babelfish::babelfish('en sp hello world'); + #my $result = babelfish::babelfish('en sp The cheese is old and moldy, where is the bathroom?'); + my $result = babelfish::babelfish('en gr doesn\'t seem to translate things longer than 40 characters'); $result =~ s/; /\n/g; print "Babelfish says: \"$result\"\n"; } diff --git a/src/core.pl b/src/core.pl index 7a9f631..909ff37 100644 --- a/src/core.pl +++ b/src/core.pl @@ -130,7 +130,11 @@ sub doExit { &uptimeWriteFile() if (&IsChanConf("uptime")); &sqlCloseDB(); &closeSHM($shm); - &dumpallvars() if (&IsParam("dumpvarsAtExit")); + + if (&IsParam("dumpvarsAtExit")) { + &loadMyModule('DumpVars'); + &dumpallvars(); + } &symdumpAll() if (&IsParam("symdumpAtExit")); &closeLog(); &closeSQLDebug() if (&IsParam("SQLDebug")); diff --git a/src/modules.pl b/src/modules.pl index 6370369..854a9e5 100644 --- a/src/modules.pl +++ b/src/modules.pl @@ -29,7 +29,7 @@ if ($@) { "debian" => "Debian.pl", "debianExtra" => "DebianExtra.pl", "Dict" => "Dict.pl", - "dumpvars" => "DumpVars.pl", + "DumpVars" => "DumpVars.pl", "exchange" => "Exchange.pl", "factoids" => "Factoids.pl", "HTTPDtype" => "HTTPDtype.pl", -- 2.39.2