]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/Modules/Dict.pl
- forgot to delete hash key even if current pid == parent pid.
[infobot.git] / blootbot / src / Modules / Dict.pl
index 1450107ec85ee30bea49af60098eb036d187e2c4..b055299c8e63d9453e0bb28e7fcbdbc0b4b14cfa 100644 (file)
@@ -18,7 +18,7 @@ my $proto     = getprotobyname('tcp');
 
 sub Dict {
     my ($query) = @_;
-###    return unless &main::loadPerlModule("IO::Socket");
+###    return unless &::loadPerlModule("IO::Socket");
     my $socket = new IO::Socket;
     my @results;
 
@@ -31,7 +31,7 @@ sub Dict {
     # connect.
     socket($socket, PF_INET, SOCK_STREAM, $proto) or return "error: socket: $!";
     eval {
-       alarm 15;
+       alarm 10;
        connect($socket, sockaddr_in($port, inet_aton($server))) or return "error: connect: $!";
        alarm 0;
     };
@@ -43,7 +43,7 @@ sub Dict {
        $socket->autoflush(1);  # required.
 
        my $num;
-       if ($query =~ /^(\d+)\s+/) {
+       if ($query =~ s/^(\d+)\s+//) {
            $num = $1;
        }
 
@@ -57,19 +57,23 @@ sub Dict {
 
        my $total = scalar @results;
 
-       if (defined $num and ($num > $total or $num < 0)) {
-           &msg($main::who, "error: choice in definition is out of range.");
+       if ($total == 0) {
+           $num = undef;
+       }
+
+       if (defined $num and ($num > $total or $num < 1)) {
+           &::msg($::who, "error: choice in definition is out of range.");
            return;
        }
 
        # parse the results.
        if ($total > 1) {
            if (defined $num) {
-               $retval = sprintf("[%d/%d] %s", $num, $total, $results[$num]);
+               $retval = sprintf("[%d/%d] %s", $num, $total, $results[$num-1]);
            } else {
                # suggested by larne and others.
                my $prefix = "Dictionary '$query' ";
-               $retval = &main::formListReply(1, $prefix, @results);
+               $retval = &::formListReply(1, $prefix, @results);
            }
        } elsif ($total == 1) {
            $retval = "Dictionary '$query' ".$results[0];
@@ -78,14 +82,14 @@ sub Dict {
        }
     }
 
-    &main::performStrictReply($retval);
+    &::performStrictReply($retval);
 }
 
 sub Dict_Wordnet {
     my ($socket, $query) = @_;
     my @results;
 
-    &main::status("Dict: asking Wordnet.");
+    &::status("Dict: asking Wordnet.");
     print $socket "DEFINE wn \"$query\"\n";
 
     my $def            = "";
@@ -104,14 +108,14 @@ sub Dict_Wordnet {
        } elsif (/^\s+(\S+ )?(\d+)?: (.*)/) {   # start of sub def.
            my $text = $3;
            $def =~ s/\s+$//;
-###        &main::DEBUG("def => '$def'.");
+###        &::DEBUG("def => '$def'.");
            push(@results, $def)                if ($def ne "");
            $def = $text;
 
            if (0) {    # old non-fLR format.
                $def = "$query $wordtype: $text" if (defined $text);
                $wordtype = substr($1,0,-1)     if (defined $1);
-###            &main::DEBUG("_ => '$_'.") if (!defined $text);
+###            &::DEBUG("_ => '$_'.") if (!defined $text);
            }
 
        } elsif (/^\s+(.*)/) {
@@ -121,7 +125,7 @@ sub Dict_Wordnet {
        }
     }
 
-    &main::status("Dict: wordnet: found ". scalar(@results) ." defs.");
+    &::status("Dict: wordnet: found ". scalar(@results) ." defs.");
 
     return if (!scalar @results);
 
@@ -132,7 +136,7 @@ sub Dict_Foldoc {
     my ($socket,$query) = @_;
     my @results;
 
-    &main::status("Dict: asking Foldoc.");
+    &::status("Dict: asking Foldoc.");
     print $socket "DEFINE foldoc \"$query\"\n";
 
     my $firsttime = 1;
@@ -165,7 +169,7 @@ sub Dict_Foldoc {
        $string .= $_." ";
     }
 
-    &main::status("Dict: foldoc: found ". scalar(@results) ." defs.");
+    &::status("Dict: foldoc: found ". scalar(@results) ." defs.");
 
     return if (!scalar @results);
     pop @results;      # last def is date of entry.