From 49d159339049fbb06af10db1ab7e33e51be2595b Mon Sep 17 00:00:00 2001 From: Andreas Scherbaum Date: Sun, 22 Jan 2012 00:32:07 +0100 Subject: [PATCH] - add command handler --- docbot.pl | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/docbot.pl b/docbot.pl index 4f3a0c9..d7f68e9 100755 --- 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); } -- 2.39.5