- identify commands in private messages
authorAndreas Scherbaum <[email protected]>
Fri, 25 May 2012 21:41:52 +0000 (23:41 +0200)
committerAndreas Scherbaum <[email protected]>
Fri, 25 May 2012 21:41:52 +0000 (23:41 +0200)
docbot.pl

index a555c36047807e3a8a1db2a31cf3786674e48b9e..ac1b3b09f391b876a151642c1d34612e4c7b9a80 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -1145,7 +1145,6 @@ sub find_command {
 
         # looks like a command, at least started with a question mark
         # find out if it really is one
-
         if (is_valid_command($command)) {
             return ($command, $string);
         }
@@ -1153,7 +1152,7 @@ sub find_command {
         # try to translate the command
         # find the channel language
         my $channel_language = config_get_key3('channels', $channel, 'language');
-        # not defined channel language leads to a full search across all languages
+        # not defined channel language triggers a full search across all languages
         # this is just fine
 
         my $translation = find_translation($channel_language, $command);
@@ -1162,6 +1161,26 @@ sub find_command {
         }
     }
 
+    if (!is_a_channel($channel)) {
+        # go the extra mile and identify commands in private messages to the bot
+        if ($msg =~ /^\s*([a-z]+)\s*(.*)/) {
+            $command = lc($1);
+            $string = defined($2) ? $2 : '';
+
+            # find out if it a command
+            if (is_valid_command($command)) {
+                return ($command, $string);
+            }
+
+            # not defined channel language triggers a full search across all languages
+            # this is just fine
+            my $translation = find_translation(undef, $command);
+            if (defined($translation) and is_valid_command($translation)) {
+                return ($translation, $string);
+            }
+        }
+    }
+
     if ($msg =~ /^\s*\?\?(.+)/) {
         # a valid search
         return ('search', $1);