]> git.donarmstrong.com Git - infobot.git/blobdiff - src/UserExtra.pl
Many changes, basically added and integrated News, and bug fixes.
[infobot.git] / src / UserExtra.pl
index d854effc3189208f641e29c1869922da611a2407..56c3ccfcc4902c6407195934dd8efd0de36c44b9 100644 (file)
@@ -31,7 +31,7 @@ use vars qw(%channels %chanstats %cmdstats);
        Forker => "NULL", ) );
 &addCmdHook("main", 'tell|explain', ('CODEREF' => 'tell', 
        Help => 'tell', Identifier => 'allowTelling', ) );
-
+&addCmdHook("main", 'news', ('CODEREF' => 'News::Parse', ) );
 
 &status("CMD: loaded ".scalar(keys %hooks_main)." MAIN command hooks.");
 
@@ -75,6 +75,10 @@ sub chaninfo {
                push(@nicks, $_);
            }
        }
+       &DEBUG("nicks => '".scalar(@nicks)."'...");
+       if (scalar @nicks != $uucount) {
+           &DEBUG("nicks != uucount...");
+       }
 
        my $chans = scalar(keys %channels);
        &pSReply(
@@ -407,7 +411,7 @@ sub DNS {
 sub userCommands {
     # conversion: ascii.
     if ($message =~ /^(asci*|chr) (\d+)$/) {
-       return '' unless (&IsParam("allowConv"));
+       return unless (&IsParam("allowConv"));
 
        $arg    = $2;
        $result = chr($arg);
@@ -420,7 +424,7 @@ sub userCommands {
 
     # conversion: ord.
     if ($message =~ /^ord (.)$/) {
-       return '' unless (&IsParam("allowConv"));
+       return unless (&IsParam("allowConv"));
 
        $arg = $1;
        if (ord($arg) < 32) {
@@ -438,7 +442,7 @@ sub userCommands {
 
     # hex.
     if ($message =~ /^hex(\s+(.*))?$/i) {
-       return '' unless (&IsParam("allowConv"));
+       return unless (&IsParam("allowConv"));
        my $arg = $2;
 
        if (!defined $arg) {
@@ -462,13 +466,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) {
@@ -602,13 +620,31 @@ sub userCommands {
     }
 
     # ircstats.
-    if ($message =~ /^ircstats$/i) {
+    if ($message =~ /^ircstats?$/i) {
+       $ircstats{'TotalTime'}  ||= 0;
+       $ircstats{'OffTime'}    ||= 0;
+
        my $count       = $ircstats{'ConnectCount'};
        my $format_time = &Time2String(time() - $ircstats{'ConnectTime'});
+       my $total_time  = time() - $ircstats{'ConnectTime'} +
+                               $ircstats{'TotalTime'};
        my $reply;
 
-       foreach (keys %ircstats) {
-           &DEBUG("ircstats: $_ => '$ircstats{$_}'.");
+       my $connectivity = 100 * ($total_time - $ircstats{'OffTime'}) /
+                               $total_time;
+       my $p = sprintf("%.02f", $connectivity);
+       $p =~ s/(\.\d*)0+$/$1/;
+       if ($p =~ s/\.0$//) {
+           &DEBUG("p sar not working properly :(");
+       } else {
+           $p =~ s/\.$//
+       }
+
+       &DEBUG("connectivity => $p %");
+
+       if ($total_time != (time() - $ircstats{'ConnectTime'}) ) {
+           my $tt_format = &Time2String($total_time);
+           &DEBUG("tt_format => $tt_format");
        }
 
        ### RECONNECT COUNT.