- add command handler
authorAndreas Scherbaum <[email protected]>
Sat, 21 Jan 2012 23:32:07 +0000 (00:32 +0100)
committerAndreas Scherbaum <[email protected]>
Sat, 21 Jan 2012 23:32:07 +0000 (00:32 +0100)
docbot.pl

index 4f3a0c92e21444c6d9653d85896b92bbe7ffa4e3..d7f68e9d04fac32e2435aaa294d44c6298935057 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -1228,7 +1228,7 @@ sub translate_text_for_channel {
 sub is_nick_allowed_admin_command {
     my $nick = shift;
 
-    if ($nick eq 'ads2') {
+    if ($nick eq 'ads') {
         return 1;
     }
 
@@ -1248,6 +1248,72 @@ sub is_nick_allowed_operator_command {
 }
 
 
+# handle_command()
+#
+# wrapper to handle all commands
+#
+# 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 channel or nick name of the message origin
+#  - POE sender
+#  - session irc handle
+#  - the channel name
+# return:
+#  - text to send back to the sender
+sub handle_command {
+    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 $sender = shift;
+    my $irc = shift;
+    my $channel = shift;
+
+
+    switch ($command) {
+        case('search') {
+        
+        }
+        case('help') {
+        
+        }
+        case('info') {
+        
+        }
+        case('learn') {
+        
+        }
+        case('forget') {
+        
+        }
+        case('config') {
+        
+        }
+        case('status') {
+        
+        }
+    }
+
+
+
+    return '';
+
+}
+
+
+
+
 
 
 
@@ -1348,7 +1414,6 @@ sub on_message {
     my $channel = $where->[0];
     my $replyto = $channel;
     my $full_msg = $msg;
-    my $like = 0;
     print_msg("on_message($msg)", DEBUG);
 
     my $irc = $sender->get_heap();
@@ -1390,6 +1455,7 @@ sub on_message {
                     #$answer = $admin_commands->{$command}($kernel, $nick, $channel, $string);
                     $answer = "Execute command: $command";
                     print_msg("Execute command: $command", INFO);
+                    $answer = handle_command($command, $string, 'admin', $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
                 } else {
                     # user is not allowed to execute admin commands
                     $answer = "Access denied";
@@ -1403,6 +1469,7 @@ sub on_message {
                     #$answer = $admin_commands->{$command}($kernel, $nick, $channel, $string);
                     $answer = "Execute command: $command";
                     print_msg("Execute command: $command", INFO);
+                    $answer = handle_command($command, $string, 'operator', $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
                 } else {
                     # user is not allowed to execute admin commands
                     $answer = "Access denied";
@@ -1419,6 +1486,7 @@ sub on_message {
             #$answer = $admin_commands->{$command}($kernel, $nick, $channel, $string);
             $answer = "Execute command: $command";
             print_msg("Execute command: $command", INFO);
+            $answer = handle_command($command, $string, 'user', $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
 
         }