- add and implement handle_command_status()
authorAndreas Scherbaum <andreas@scherbaum.biz>
Sun, 22 Jan 2012 12:36:40 +0000 (13:36 +0100)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Sun, 22 Jan 2012 12:36:40 +0000 (13:36 +0100)
docbot.pl

index 5a4b95aeb2c4ed31a4f7e7de41de75102e245ec9..602c5158aa74362b4811ca87b3097b1c7d97e8d8 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -1371,16 +1371,86 @@ sub handle_command {
         }
         case('status') {
             $main::statistics{'command_counter_status'}++;
+            return handle_command_status($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
         }
     }
 
 
-
     return '';
 
 }
 
 
+# handle_command_status()
+#
+# command handler for the 'status' command
+#
+# parameter:
+#  - the command (lower case)
+#  - the parameter string (may be empty)
+#  - the command mode (admin/operator/user)
+#  - POE kernel
+#  - POE heap
+#  - the full who of the message sender, including the nick name
+#  - the nick name of the message sender
+#  - the full origin of the message
+#  - the message itself
+#  - POE sender
+#  - session irc handle
+#  - the channel name
+# return:
+#  - text to send back to the sender
+sub handle_command_status {
+    my $command = shift;
+    my $string = shift;
+    my $mode = shift;
+    my $kernel = shift;
+    my $heap = shift;
+    my $who = shift;
+    my $nick = shift;
+    my $where = shift;
+    my $msg = shift;
+    my $sender = shift;
+    my $irc = shift;
+    my $channel = shift;
+
+
+    # 'status' goes to the command channel only
+    if (lc($channel) eq lc($irc->nick_name())) {
+        return 'The "status" command is only allowed in the command channel';
+    }
+    if (lc($channel) ne lc(config_get_key2('bot', 'commandchannel'))) {
+        return 'The "status" command is only allowed in the command channel';
+    }
+
+
+    $irc->yield( privmsg => $channel, 'Bot uptime: ' . format_time_short_exact(time() - $main::statistics{'docbot_start'}) );
+    $irc->yield( privmsg => $channel, 'Number of parallel sessions: ' . scalar(keys(%main::sessions)) );
+    my @nicks = ();
+    my @channels = ();
+    foreach my $tmp_session (keys(%main::sessions)) {
+        push(@nicks, $main::sessions{$tmp_session}{'session'}->nick_name());
+        push(@channels, @{$main::sessions{$tmp_session}{'joined_channels'}});
+    }
+    $irc->yield( privmsg => $channel, 'Nick names: ' . join(", ", @nicks) );
+    $irc->yield( privmsg => $channel, 'Joined channels: ' . join(", ", @channels) );
+    $irc->yield( privmsg => $channel, 'Number of connects: ' . $main::statistics{'connects'} );
+    my @commands = ();
+    push(@commands, 'search: ' . $main::statistics{'command_counter_search'});
+    push(@commands, 'help: ' . $main::statistics{'command_counter_help'});
+    push(@commands, 'info: ' . $main::statistics{'command_counter_info'});
+    push(@commands, 'learn: ' . $main::statistics{'command_counter_learn'});
+    push(@commands, 'forget: ' . $main::statistics{'command_counter_forget'});
+    push(@commands, 'config: ' . $main::statistics{'command_counter_config'});
+    push(@commands, 'status: ' . $main::statistics{'command_counter_status'});
+    $irc->yield( privmsg => $channel, 'Number of executed commands: ' . join(", ", @commands) );
+    $irc->yield( privmsg => $channel, 'Number of denied requests: ' . $main::statistics{'command_access_denied'} );
+
+
+    return '';
+}
+
+