#!/usr/ug/bin/perl5 # # sample use: # gsub -akf ~whuang/prog/gale/babblefish cmd/babblefish:@ugcs.caltech.edu/user/babblefish.whuang # # by Wei-Hwa Huang (whuang@ugcs.caltech.edu) # sections of code stolen from jtr@ugcs.caltech.edu use strict; use POSIX qw(strftime); # gale info use vars qw($FROM $ENC $CAT $SIGN $TIME @MESSAGE $NEWCAT $FTIME); # misc use vars qw($GALE $HOME $LOGDIR $USER %LOGGEDTO); $FROM= $ENV{'HEADER_FROM'}; $TIME= $ENV{'HEADER_TIME'}; $CAT= $ENV{'GALE_CATEGORY'}; $CAT =~ s-zephyr/message-zephyr/MESSAGE-gi; print STDERR "incoming message from category: $CAT\n"; $ENC= $ENV{'GALE_ENCRYPTED'}; $SIGN= $ENV{'GALE_SIGNED'}; $HOME= $ENV{'HOME'}; $GALE= $HOME . "/.gale/"; $LOGDIR= $HOME . "/gale/"; $USER= $ENV{'USER'}; $FTIME= $ENV{'GALE_TIME_ID_TIME'}; @MESSAGE = <>; print STDERR "$CAT\n"; my @cats = split(":",$CAT); my (@cmdcats, @botcats, @othercats) = ((),(),()); my $singlecat; foreach $singlecat (@cats) { if ($singlecat =~ /^bot\//) { push(@botcats,$singlecat); } elsif ($singlecat eq '@ugcs.caltech.edu/user/babblefish.whuang/') { push(@cmdcats,$singlecat); } elsif ($singlecat =~ /^cmd\//) { push(@cmdcats,$singlecat); } else { push(@othercats,$singlecat); } } my @legalnames = ("fr","de","it","pt","es"); my $written = 0; # set to 1 when written, so we aren't redundant. foreach $singlecat (@cmdcats) { my $outstring; my $ext; my $outcat; if ($singlecat eq '@ugcs.caltech.edu/user/babblefish.whuang/') { $ext = shift(@MESSAGE); chomp $ext; $ext =~ s/^\s*//g; $ext =~ s/\s*$//g; $outstring = (@othercats == ()) ? "| gsend $SIGN" : "| gsend $SIGN -c ".join(':',@othercats); } else { $singlecat =~ /^cmd\/babblefish\/(.*)$/; $ext = $1; $outcat = 'bot/babblefish'; if (grep(($ext eq $_),@legalnames) == ()) { } elsif ($ext =~ /fr$/) { $outcat .= '/francais'; } elsif ($ext =~ /de$/) { $outcat .= '/deutsch'; } elsif ($ext =~ /fr$/) { $outcat .= '/francais'; } elsif ($ext =~ /it$/) { $outcat .= '/italiano'; } elsif ($ext =~ /pu$/) { $outcat .= '/portugues'; } elsif ($ext =~ /es$/) { $outcat .= '/espanol'; } $outstring = (@othercats == ()) ? "| gsend -c $outcat" : "| gsend -c $outcat:".join(':',@othercats); } if (join('',@MESSAGE) =~ /^\s*help\s*$/ or (grep(($ext eq $_),@legalnames) == ())) { @MESSAGE = (); $MESSAGE[0] = <<'End of Help Message'; babblefish version 2.2 by Wei-Hwa Huang (whuang@ugcs.caltech.edu) Uses the babelfish WWW server at http://babelfish.altavista.com to translate your English puff into another language and then back into English, creating a piece of English babble. Privately: Send a private puff to babblefish.whuang@ugcs.caltech.edu. The first line should contain and nothing else except whitespace. Publically: puff English to cmd/babblefish/ . The bot will output to bot/babblefish/ , where is the language the English went through. is one of: fr : English to French to English de : English to German to English it : English to Italian to English pt : English to Portuguese to English es : English to Spanish to English is one of: francais : French deutsch : German italiano : Italian portugues : Portugese espanol : Spanish Known bugs: Bad things will happen if the babelfish server is down. If the output string contains "Server Error", you will probabably never see a reply as the bot will try again. Funky things will happen if many instances of the bot run together. End of Help Message } else { # Add your code here. if ($written==0) { open(FHAND, ">/home/whuang/prog/gale/data/temp1.html"); print FHAND "
\n";
      print FHAND @MESSAGE;
      print FHAND "
\n"; close(FHAND); $written = 1; } @MESSAGE = (); $MESSAGE[0] = 'Server Error'; while (grep(/Server Error/,@MESSAGE) != ()) { system('lynx -dump \'http://babelfish.altavista.com/' .'cgi-bin/translate?doit=done&lp=en_' .$ext.'&urltext=http://www.ugcs.caltech.edu/' .'~whuang/prog/gale/data/temp1.html\' ' .'>/home/whuang/prog/gale/data/out1.txt'); open(FHAND, "; close(FHAND); shift @MESSAGE; } open(FHAND, ">/home/whuang/prog/gale/data/temp2.html"); print FHAND "
\n";
    print FHAND @MESSAGE;
    print FHAND "
\n"; close(FHAND); @MESSAGE = (); $MESSAGE[0] = 'Server Error'; while (grep(/Server Error/,@MESSAGE) != ()) { system('lynx -dump \'http://babelfish.altavista.com/' .'cgi-bin/translate?doit=done&lp=' .$ext.'_en&urltext=http://www.ugcs.caltech.edu/' .'~whuang/prog/gale/data/temp2.html\' ' .'>/home/whuang/prog/gale/data/out2.txt'); open(FHAND, "; close(FHAND); shift @MESSAGE; } } $ENV{'GALE_FROM'}= "$FROM (babbled by Warlock)"; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND); } unlink("/home/whuang/prog/gale/data/temp1.html"); unlink("/home/whuang/prog/gale/data/out1.txt"); unlink("/home/whuang/prog/gale/data/temp2.html"); unlink("/home/whuang/prog/gale/data/out2.txt");