]> git.donarmstrong.com Git - infobot.git/blobdiff - src/UserExtra.pl
- added mkcrypt, fixed up "crypt" cmd.
[infobot.git] / src / UserExtra.pl
index 87a87c11eed9c1164c02d5e1888095628420508f..e0c234a4cadc3580cb1e05503e77bc18af88b8ef 100644 (file)
@@ -44,9 +44,10 @@ sub chaninfo {
     my $mode;
 
     if ($chan eq "") {         # all channels.
-       my $count       = 0;
        my $i           = keys %channels;
        my $reply       = "i am on \002$i\002 ".&fixPlural("channel",$i);
+       my $tucount     = 0;    # total user count.
+       my $uucount     = 0;    # unique user count.
        my @array;
 
        ### line 1.
@@ -60,19 +61,27 @@ sub chaninfo {
        }
        &pSReply($reply.": ".join(' ', @array));
 
-       ### line 2.
+       ### total user count.
        foreach $chan (keys %channels) {
-           # crappy debugging...
-           # TODO: use $mask{chan} instead?
-           if ($chan =~ / /) {
-               &ERROR("bad channel: chan => '$chan'.");
+           $tucount += scalar(keys %{$channels{$chan}{''}});
+       }
+
+       ### unique user count.
+       my @nicks;
+       foreach $chan (keys %channels) {
+           foreach (keys %{ $channels{$chan}{''} }) {
+               next if (grep /^\Q$_\E$/, @nicks);
+               $uucount++;
+               push(@nicks, $_);
            }
-           $count += scalar(keys %{$channels{$chan}{''}});
        }
+
+       my $chans = scalar(keys %channels);
        &pSReply(
-               "i've cached \002$count\002 ".&fixPlural("user",$count).
-               " distributed over \002".scalar(keys %channels)."\002 ".
-               &fixPlural("channel",scalar(keys %channels))."."
+           "i've cached \002$tucount\002 ". &fixPlural("user",$tucount).
+           ", \002$uucount\002 unique ". &fixPlural("user",$uucount).
+           ", distributed over \002$chans\002 ".
+           &fixPlural("channel", $chans)."."
        );
 
        return;
@@ -310,14 +319,15 @@ sub tell {
        return;
     }
 
-    # ...
+    my $oldwho         = $who;
+    my $oldmtype       = $msgType;
+    $who               = $target;
     my $result = &doQuestion($tell_obj);
-    # ^ returns '0' if nothing was found.
+       # ^ returns '0' if nothing was found.
+    $who               = $oldwho;
 
     # no such factoid.
     if ($result =~ /^0?$/) {
-       my $oldwho      = $who;
-       my $oldmtype    = $msgType;
        $who            = $target;
        $msgType        = "private";
 
@@ -397,24 +407,20 @@ sub DNS {
 sub userCommands {
     # conversion: ascii.
     if ($message =~ /^(asci*|chr) (\d+)$/) {
-       return '' unless (&IsParam("allowConv"));
+       return unless (&IsParam("allowConv"));
 
-       $arg = $2;
-       if ($arg < 32) {
-           $arg += 64;
-           $result = "^".chr($arg);
-       } else {
-           $result = chr($2);
-       }
-       $result = "NULL"        if ($arg == 0);
+       $arg    = $2;
+       $result = chr($arg);
+       $result = "NULL"        if ($arg == 0);
 
        &performReply( sprintf("ascii %s is '%s'", $arg, $result) );
+
        return;
     }
 
     # conversion: ord.
     if ($message =~ /^ord (.)$/) {
-       return '' unless (&IsParam("allowConv"));
+       return unless (&IsParam("allowConv"));
 
        $arg = $1;
        if (ord($arg) < 32) {
@@ -432,6 +438,7 @@ sub userCommands {
 
     # hex.
     if ($message =~ /^hex(\s+(.*))?$/i) {
+       return unless (&IsParam("allowConv"));
        my $arg = $2;
 
        if (!defined $arg) {
@@ -455,13 +462,27 @@ sub userCommands {
     }
 
     # crypt.
-    if ($message =~ /^crypt\s+(\S+)\s*(?:,| )\s*(\S+)/) {
-       # word salt.
-       &pSReply(crypt($1, $2));
-       return;
-    }
+    if ($message =~ /^crypt(\s+(.*))?$/i) {
+       my @args        = split /\s+/, $2;
 
+       if (!scalar @args or scalar @args > 2) {
+           &help("crypt");
+           return;
+       }
 
+       if (scalar @args == 2) {
+           if (length $args[0] != 2) {
+               &msg($who, "invalid format...");
+               return;
+           }
+
+           &pSReply( crypt($args[1], $args[0]) );
+       } else {
+           &pSReply( &mkcrypt($args[0]) );
+       }
+
+       return;
+    }
 
     # cycle.
     if ($message =~ /^(cycle)(\s+(\S+))?$/i) {
@@ -523,13 +544,19 @@ sub userCommands {
        my @redir;
        &status("Redirect '$factoid' (". ($#list) .")...");
        for (@list) {
+           my $x = $_;
            next if (/^\Q$factoid\E$/i);
 
            &status("  Redirecting '$_'.");
            my $was = &getFactoid($_);
+           if ($was =~ /<REPLY> see/i) {
+               &status("warn: not redirecting a redirection.");
+               next;
+           }
+
            &DEBUG("  was '$was'.");
-           push(@redir,$_);
-           &setFactInfo($_, "factoid_value", "<REPLY> see $factoid");
+           push(@redir,$x);
+           &setFactInfo($x, "factoid_value", "<REPLY> see $factoid");
        }
        &status("Done.");
 
@@ -592,8 +619,12 @@ sub userCommands {
     if ($message =~ /^ircstats$/i) {
        my $count       = $ircstats{'ConnectCount'};
        my $format_time = &Time2String(time() - $ircstats{'ConnectTime'});
+       my $total_time  = time() - $ircstats{'ConnectTime'} + $ircstats{'TotalTime'};
        my $reply;
 
+       &DEBUG("ircstats: total_time => $total_time.");
+       &DEBUG("ircstats: offtime => $ircstats{'OffTime'}");
+
        foreach (keys %ircstats) {
            &DEBUG("ircstats: $_ => '$ircstats{$_}'.");
        }
@@ -650,11 +681,16 @@ sub userCommands {
            &msg($who, "I hope you're right. I'll try anyway.");
        }
 
-       my $str = "attempting to change nick to $param{'ircNick'}";
-       &status($str);
-       &msg($who, $str);
+       if (! &IsNickInAnyChan( $param{ircNick} ) ) {
+           my $str = "attempting to change nick to $param{'ircNick'}";
+           &status($str);
+           &msg($who, $str);
+           &nick($param{'ircNick'});
+       } else {
+           &msg($who, "hrm... can't do it");
+           &DEBUG("wN: nick is somewhere... should try later.");
+       }
 
-       &nick($param{'ircNick'});
        return;
     }