diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 6be6a5b..ef02606 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Privilege to use a command is now handled by the priv arg of + cmd_add. * HELP now only displays help if the user has the appropriate privileges. * Updated Core::IRC and all modules to obey the updated API. diff --git a/src/Core/IRC.pm b/src/Core/IRC.pm index 22d9ffc..ad79b08 100644 --- a/src/Core/IRC.pm +++ b/src/Core/IRC.pm @@ -34,11 +34,6 @@ sub cmd_modload my (%data) = @_; my @argv = @{ $data{args} }; - # Check for the appropriate privilege. - if (!has_priv(match_user(%data), "cfunc.modules")) { - notice($data{svr}, $data{nick}, trans("Permission denied")."."); - return 0; - } # Check for the needed parameters. if (!defined $argv[0]) { notice($data{svr}, $data{nick}, trans("Not enough parameters")."."); @@ -78,11 +73,6 @@ sub cmd_modunload my (%data) = @_; my @argv = @{ $data{args} }; - # Check for the appropriate privilege. - if (!has_priv(match_user(%data), "cfunc.modules")) { - notice($data{svr}, $data{nick}, trans("Permission denied")."."); - return 0; - } # Check for the needed parameters. if (!defined $argv[0]) { notice($data{svr}, $data{nick}, trans("Not enough parameters")."."); @@ -122,11 +112,6 @@ sub cmd_modreload my (%data) = @_; my @argv = @{ $data{args} }; - # Check for the appropriate privilege. - if (!has_priv(match_user(%data), "cfunc.modules")) { - notice($data{svr}, $data{nick}, trans("Permission denied")."."); - return 0; - } # Check for the needed parameters. if (!defined $argv[0]) { notice($data{svr}, $data{nick}, trans("Not enough parameters")."."); @@ -167,12 +152,6 @@ sub cmd_shutdown { my (%data) = @_; - # Check for the appropriate privilege. - if (!has_priv(match_user(%data), "cmd.shutdown")) { - notice($data{svr}, $data{nick}, trans("Permission denied")."."); - return 0; - } - # Goodbye world! notice($data{svr}, $data{nick}, "Shutting down."); dbug "Got SHUTDOWN from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Shutting down. . ."; @@ -195,12 +174,6 @@ sub cmd_restart { my (%data) = @_; - # Check for the appropriate privilege. - if (!has_priv(match_user(%data), "cmd.restart")) { - notice($data{svr}, $data{nick}, trans("Permission denied")."."); - return 0; - } - # Goodbye world! notice($data{svr}, $data{nick}, "Restarting."); dbug "Got RESTART from ".$data{nick}."!".$data{user}."@".$data{host}."/".$data{svr}."! Restarting. . ."; diff --git a/src/Parser/IRC.pm b/src/Parser/IRC.pm index 551440e..68366c6 100644 --- a/src/Parser/IRC.pm +++ b/src/Parser/IRC.pm @@ -465,7 +465,17 @@ sub privmsg $cmd = uc(substr($ex[3], 1)); if (defined $API::Std::CMDS{$cmd}) { if ($API::Std::CMDS{$cmd}{lvl} == 1 or $API::Std::CMDS{$cmd}{lvl} == 2) { - &{ $API::Std::CMDS{$cmd}{sub} }(%data); + if ($API::Std::CMDS{$cmd}{priv}) { + if (API::Std::has_priv(API::Std::match_user(%data), $API::Std::CMDS{$cmd}{priv})) { + &{ $API::Std::CMDS{$cmd}{sub} }(%data); + } + else { + API::IRC::notice($data{svr}, $data{nick}, API::Std::trans("Permission denied")."."); + } + } + else { + &{ $API::Std::CMDS{$cmd}{sub} }(%data); + } } } @@ -480,7 +490,17 @@ sub privmsg $cmd = uc(substr($ex[3], 2)); if (defined $API::Std::CMDS{$cmd}) { if ($API::Std::CMDS{$cmd}{lvl} == 0 or $API::Std::CMDS{$cmd}{lvl} == 2) { - &{ $API::Std::CMDS{$cmd}{sub} }(%data) if $rprefix eq $cprefix; + if ($API::Std::CMDS{$cmd}{priv}) { + if (API::Std::has_priv(API::Std::match_user(%data), $API::Std::CMDS{$cmd}{priv})) { + &{ $API::Std::CMDS{$cmd}{sub} }(%data) if $rprefix eq $cprefix; + } + else { + API::IRC::notice($data{svr}, $data{nick}, API::Std::trans("Permission denied")."."); + } + } + else { + &{ $API::Std::CMDS{$cmd}{sub} }(%data) if $rprefix eq $cprefix; + } } }