diff --git a/bin/auto b/bin/auto index 80da4c4..696b8a0 100755 --- a/bin/auto +++ b/bin/auto @@ -28,7 +28,7 @@ BEGIN { RSTAGE => 'd' }; } -use API::Std qw(conf_get err cmd_add cmd_del); +use API::Std qw(conf_get err); use API::Log qw(println alog dbug); use DB::Flatfile; use Parser::Config; @@ -290,6 +290,8 @@ undef $it; # Create core hooks. API::Std::hook_add("on_uprivmsg", "ctcp_version_reply", \&Core::IRC::version_reply); +# Create core commands. +API::Std::cmd_add("MODLOAD", 1, \%Core::IRC::SHELP_MODLOAD, \%Core::IRC::FHELP_MODLOAD, \&Core::IRC::cmd_modload); # Infinite while loop. while (1) { diff --git a/doc/CHANGELOG b/doc/CHANGELOG index abe673f..7537d9b 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Added core command MODLOAD. * Added Weather module. * Added Calc module. * Fixed the NAME,VER,SVER,REV,RSTAGE constants. diff --git a/src/Core/IRC.pm b/src/Core/IRC.pm index 258b376..20881fc 100644 --- a/src/Core/IRC.pm +++ b/src/Core/IRC.pm @@ -7,6 +7,7 @@ package Core::IRC; use strict; use warnings; use English; +use API::Std qw(trans has_priv match_user); use API::IRC qw(notice usrc); sub version_reply @@ -22,4 +23,45 @@ sub version_reply } +# Help hashes for CMDLOAD. Spanish, French and German needed. +our %SHELP_CMDLOAD = ( + 'en' => 'Load a module.', +); +our %FHELP_CMDLOAD = ( + 'en' => 'Loads a module into the running Auto live.', +); +# CMDLOAD callback. +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")."."); + return 0; + } + + my $tn = Auto::mod_load($argv[0]); + + # Check if we were successful or not. + if ($tn) { + # We were! + notice($data{svr}, $data{nick}, "Module \002".$argv[0]."\002 successfully loaded."); + } + else { + # We weren't. + notice($data{svr}, $data{nick}, "Module \002".$argv[0]."\002 failed to load."); + return 0; + } + + return 1; +} + + 1;