- add basic 'help' command handler
authorAndreas Scherbaum <andreas@scherbaum.biz>
Fri, 25 May 2012 20:58:43 +0000 (22:58 +0200)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Fri, 25 May 2012 20:58:43 +0000 (22:58 +0200)
docbot.conf
docbot.pl

index 0315f46122cc49b73e31af95ca64adea19c657d2..68802e08d5136713cb181733cb2662a693aa27a4 100644 (file)
@@ -84,6 +84,9 @@ translations:
     more_results: 'weitere Ergebnisse'
     error_wallchan_command_parameter: 'Der "wallchan" Befehl erfordert einen Parameter'
     wallchan_command_message: 'Nachricht vom Operator'
+    help_general_line_1: 'Allgemeine Hilfe'
+    help_general_line_2: 'Starte eine Suche mit zwei Fragezeichen, danach der Suchbegriff'
+    help_general_line_3: 'Die folgenden Befehle stehen außerdem zur Verfügung'
   fr:
     learn: 'apprendre'
     forget: 'oublier'
index aaf207c794a96d11605d1cd29fb2a022a27d899d..cf04e0bd53f8c6d5de99d6e42531d1824ff70620 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -21,6 +21,7 @@
 # - add new statistic counter in init_statistics()
 # - output command statistic in handle_command_status()
 # - add the command to is_valid_command(), is_valid_operator_command() and/or is_valid_admin_command()
+# - add help for the command in handle_command_help()
 # - add any required translation to docbot.conf
 
 
@@ -1649,6 +1650,7 @@ sub handle_command {
         }
         case('help') {
             $main::statistics{'command_counter_help'}++;
+            return handle_command_help($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
         }
         case('info') {
             $main::statistics{'command_counter_info'}++;
@@ -1961,6 +1963,93 @@ sub handle_command_search {
 }
 
 
+# handle_command_help()
+#
+# command handler for the 'help' 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_help {
+    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;
+
+
+    my $session = find_irc_session($irc);
+
+
+    if (lc($channel) eq lc($irc->nick_name())) {
+        print_msg("Help issued: '$string', by $nick", DEBUG2);
+    } else {
+        print_msg("Help issued: '$string', by $nick in $channel", DEBUG2);
+    }
+
+
+    # remove spaces at beginning and end
+    $string =~ s/^[\s\t]+//gs;
+    $string =~ s/[\s\t]+$//gs;
+
+
+    # find out where to reply the answer
+    my $replyto = $channel;
+    if (lc($channel) eq lc($irc->nick_name())) {
+        $replyto = $nick;
+    } elsif ($string =~ /^(.+)\s+>\s+(\w+)/i) {
+        if (grep(/^$channel$/i, find_nick($heap, $2, $session))) {
+            $string = $1;
+            $replyto = $2;
+        } else {
+            return '';
+        }
+    }
+
+
+    if (length($string) == 0) {
+        my $answer = "General help";
+        # translate message
+        $answer = translate_text_for_channel($replyto, 'help_general_line_1', $answer);
+        $irc->yield( privmsg => $replyto, $answer . ':' );
+
+        $answer = "Start a search with two question marks, followed by the search term";
+        # translate message
+        $answer = translate_text_for_channel($replyto, 'help_general_line_2', $answer);
+        $irc->yield( privmsg => $replyto, $answer );
+
+        $answer = "The following commands are also available";
+        # translate message
+        $answer = translate_text_for_channel($replyto, 'help_general_line_3', $answer);
+        $answer .= ': ';
+        $answer .= 'search, help, info, learn, forget, config, status, wallchan';
+        $irc->yield( privmsg => $replyto, $answer );
+    }
+
+
+    return '';
+}
+
+
 ######################################################################
 # IRC functions
 ######################################################################