#!/usr/ug/bin/perl5 # # sample use: # gsub -akf ~whuang/prog/gale/dict cmd/dict:@ugcs.caltech.edu/user/dict.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/dict.whuang/') { push(@cmdcats,$singlecat); } elsif ($singlecat =~ /^cmd\//) { push(@cmdcats,$singlecat); } else { push(@othercats,$singlecat); } } foreach $singlecat (@cmdcats) { if (join('',@MESSAGE) =~ /^\s*help\s*$/) { @MESSAGE = (); $MESSAGE[0] = <<'End of Help Message'; dict version 2.0 by Wei-Hwa Huang (whuang@ugcs.caltech.edu) Runs 'dict' on UGCS with the first three "words" in your puff and puffs the data back. Adds the /long tag if the resulting puff is more than 24 lines. Privately: Send a private puff to dict.whuang@ugcs.caltech.edu Publically: Send a puff to cmd.dict. The bot will respond in bot.dict, along with any crosspuffed categories. Known bugs: Can't handle punctuation. You can't find out the definition of the word 'help' unless you're clever. End of Help Message } else { # Add your code here. chomp @MESSAGE; my $long = join(' ',@MESSAGE); my @words = split(' ',$long); my $cmd = "dict ".join(' ',splice(@words,0,3))." |"; open(FHAND,$cmd); @MESSAGE = ; close(FHAND); if ($#MESSAGE > 24 and ($singlecat ne '@ugcs.caltech.edu/user/dict.whuang/') and (grep($_ eq '/long',@othercats)==())) { push(@othercats,'/long'); } } my $outstring; if ($singlecat eq '@ugcs.caltech.edu/user/dict.whuang/') { $outstring = (@othercats == ()) ? "| gsend $SIGN" : "| gsend $SIGN -c ".join(':',@othercats); } else { $outstring = (@othercats == ()) ? "| gsend -c bot/dict" : "| gsend -c bot/dict:".join(':',@othercats); } $ENV{'GALE_FROM'}= 'UGCS dict Gateway'; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND); }