my ($command, $string);
- if ($msg =~ /^\s*\?([a-z]+)\s+(.+)/) {
+ if ($msg =~ /^\s*\?([a-z]+)\s*(.*)/) {
$command = lc($1);
- $string = $2;
+ $string = defined($2) ? $2 : '';
# looks like a command, at least started with a question mark
# find out if it really is one
}
}
+ if ($msg =~ /^\s*\?\?(.+)/) {
+ # a valid search
+ return ('search', $1);
+ }
+
return undef;
}
# is_valid_command()
#
-# find out if this is a valid command (includes valid admin commands)
+# find out if this is a valid command (includes valid admin and operator commands)
#
# parameter:
# - command
sub is_valid_command {
my $command = shift;
- my $status = is_valid_admin_command($command);
+ my $status;
+
+ $status = is_valid_operator_command($command);
+ if ($status == 1) {
+ return 1;
+ }
+ $status = is_valid_admin_command($command);
if ($status == 1) {
return 1;
}
return 1;
} elsif ($command eq 'info') {
return 1;
+ } elsif ($command eq 'search') {
+ return 1;
}
return 0;
}
-# is_valid_admin_command()
+# is_valid_operator_command()
#
-# find out if this is a valid admin command
+# find out if this is a valid operator command
#
# parameter:
# - command
# return:
# - 0/1
-sub is_valid_admin_command {
+sub is_valid_operator_command {
my $command = shift;
if ($command eq 'learn') {
return 1;
} elsif ($command eq 'forget') {
return 1;
- } elsif ($command eq 'config') {
+ }
+
+ return 0;
+}
+
+
+# is_valid_admin_command()
+#
+# find out if this is a valid admin command
+#
+# parameter:
+# - command
+# return:
+# - 0/1
+sub is_valid_admin_command {
+ my $command = shift;
+
+ if ($command eq 'config') {
+ return 1;
+ } elsif ($command eq 'status') {
return 1;
}
}
+# FIXME: implement this function
+sub is_nick_allowed_admin_command {
+ my $nick = shift;
+
+ if ($nick eq 'ads2') {
+ return 1;
+ }
+
+ return 0;
+}
+
+
+# FIXME: implement this function
+sub is_nick_allowed_operator_command {
+ my $nick = shift;
+
+ if ($nick eq 'ads') {
+ return 1;
+ }
+
+ return 0;
+}
+
if (defined($command)) {
- my $answer;
+ my $answer = '';
- # handle all admin commands
- if (is_valid_admin_command($command)) {
+ # handle authentication commands
+ if (is_valid_admin_command($command) or is_valid_operator_command($command)) {
# no authentication information available, create callback
if (!defined($heap->{whois_callback}->{$nick}->{authed})) {
# translate error message
$answer = translate_text_for_channel($channel, 'you_are_not_authorized', $answer);
}
- else {
- # execute desired command
- #$answer = $admin_commands->{$command}($kernel, $nick, $channel, $string);
- $answer = "Execute command: $command";
- print_msg("Execute command: $command", INFO);
- }
- # drop the callback for this nick
- undef ($heap->{whois_callback}->{$nick});
-
- if (length($answer)) {
- # if command was called in channel print answer to channel, if it was PM print it as PM
- if (lc($channel) eq lc($irc->nick_name())) {
- $irc->yield( privmsg => $nick, $answer);
+ elsif (is_valid_admin_command($command)) {
+ if (is_nick_allowed_admin_command($nick)) {
+ # execute desired command
+ #$answer = $admin_commands->{$command}($kernel, $nick, $channel, $string);
+ $answer = "Execute command: $command";
+ print_msg("Execute command: $command", INFO);
+ } else {
+ # user is not allowed to execute admin commands
+ $answer = "Access denied";
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'access_denied', $answer);
}
- else {
- $irc->yield( privmsg => $channel, $answer);
+ }
+ elsif (is_valid_operator_command($command)) {
+ if (is_nick_allowed_operator_command($nick)) {
+ # execute desired command
+ #$answer = $admin_commands->{$command}($kernel, $nick, $channel, $string);
+ $answer = "Execute command: $command";
+ print_msg("Execute command: $command", INFO);
+ } else {
+ # user is not allowed to execute admin commands
+ $answer = "Access denied";
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'access_denied', $answer);
}
- return;
}
+ # drop the callback for this nick
+ undef ($heap->{whois_callback}->{$nick});
+ } else {
+ # execute desired command
+ #$answer = $admin_commands->{$command}($kernel, $nick, $channel, $string);
+ $answer = "Execute command: $command";
+ print_msg("Execute command: $command", INFO);
+ }
+ if (length($answer)) {
+ # if command was called in channel print answer to channel, if it was PM print it as PM
+ if (lc($channel) eq lc($irc->nick_name())) {
+ $irc->yield( privmsg => $nick, $answer);
+ }
+ else {
+ $irc->yield( privmsg => $channel, $answer);
+ }
+ return;
}
+
}