#!/usr/ug/bin/perl5 # # sample use: # gsub -akf ~whuang/prog/gale/doublefish cmd/doublefish:@ugcs.caltech.edu/user/doublefish.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/doublefish.whuang/') { push(@cmdcats,$singlecat); } elsif ($singlecat =~ /^cmd\//) { push(@cmdcats,$singlecat); } else { push(@othercats,$singlecat); } } my @legalnames = ( "fr_fr","de_fr","it_fr","pt_fr","es_fr", "fr_de","de_de","it_de","pt_de","es_de", "fr_it","de_it","it_it","pt_it","es_it", "fr_pt","de_pt","it_pt","pt_pt","es_pt", "fr_es","de_es","it_es","pt_es","es_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/doublefish.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\/doublefish\/(.*)$/; $ext = $1; $outcat = 'bot/doublefish'; 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'; doublefish version 1.2 by Wei-Hwa Huang (whuang@ugcs.caltech.edu) Uses the babelfish WWW server at http://babelfish.altavista.com to translate your non-English puff into English and then into another non-English language, creating a piece of babble. Privately: Send a private puff to doublefish.whuang@ugcs.caltech.edu. The first line should contain _ and nothing else except whitespace. Publically: puff English to cmd/doublefish/_ . The bot will output to bot/doublefish/ , where is the language the output puff is in. and are each one of: fr : French de : German it : Italian pt : Portuguese es : Spanish is the source language, is the destination language. 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. (my $ext1, my $ext2) = split('_',$ext); open(FHAND, ">/home/whuang/prog/gale/data/temp3.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=' .$ext1.'_en&urltext=http://www.ugcs.caltech.edu/' .'~whuang/prog/gale/data/temp3.html\' ' .'>/home/whuang/prog/gale/data/out3.txt'); open(FHAND, "; close(FHAND); shift @MESSAGE; } open(FHAND, ">/home/whuang/prog/gale/data/temp4.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=en_' .$ext2.'&urltext=http://www.ugcs.caltech.edu/' .'~whuang/prog/gale/data/temp4.html\' ' .'>/home/whuang/prog/gale/data/out4.txt'); open(FHAND, "; close(FHAND); shift @MESSAGE; } } $ENV{'GALE_FROM'}= "$FROM (warped by Douglock)"; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND); } unlink("/home/whuang/prog/gale/data/temp3.html"); unlink("/home/whuang/prog/gale/data/out3.txt"); unlink("/home/whuang/prog/gale/data/temp4.html"); unlink("/home/whuang/prog/gale/data/out4.txt");