diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 399785a..bc23154 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * Raw hooks now take hook names and support multiple hooks. This changes + rchook_add and rchook_del. * Vim modelines must be at the bottom of files. Modules updated. * Renamed Lib::Users to Core::IRC::Users. * Added Lib::Users, for network-wide user tracking. This brings many new diff --git a/lib/API/Std.pm b/lib/API/Std.pm index 1afa7b6..690a327 100644 --- a/lib/API/Std.pm +++ b/lib/API/Std.pm @@ -9,7 +9,7 @@ use Exporter; use base qw(Exporter); -our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS); +our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS, %RAWHOOKS); our @EXPORT_OK = qw(conf_get trans err awarn timer_add timer_del cmd_add cmd_del hook_add hook_del rchook_add rchook_del match_user has_priv mod_exists ratelimit_check fpfmt); @@ -263,12 +263,16 @@ sub timer_del # Hook onto a raw command. sub rchook_add { - my ($cmd, $sub) = @_; + my ($cmd, $name, $sub) = @_; $cmd = uc $cmd; - if (defined $Proto::IRC::RAWC{$cmd}) { return; } - - $Proto::IRC::RAWC{$cmd} = $sub; + # Make sure core doesn't already handle this. + if (defined $Proto::IRC::RAWC{$cmd}) { return } + # If the hook already exists, ignore it. + if (defined $RAWHOOKS{$cmd}{$name}) { return } + + # Create the hook. + $RAWHOOKS{$cmd}{$name} = $sub; return 1; } @@ -276,12 +280,14 @@ sub rchook_add # Delete a raw command hook. sub rchook_del { - my ($cmd) = @_; + my ($cmd, $name) = @_; $cmd = uc $cmd; - if (!defined $Proto::IRC::RAWC{$cmd}) { return; } + # Make sure the hook exists. + if (!defined $RAWHOOKS{$cmd}{$name}) { return } - delete $Proto::IRC::RAWC{$cmd}; + # Delete it. + delete $RAWHOOKS{$cmd}{$name}; return 1; } diff --git a/lib/Proto/IRC.pm b/lib/Proto/IRC.pm index be15b6a..7811f96 100644 --- a/lib/Proto/IRC.pm +++ b/lib/Proto/IRC.pm @@ -78,10 +78,16 @@ sub ircparse M::SASLAuth::handle_authenticate($svr, @ex); } } + # Check if it's handled by core. + elsif (defined $RAWC{$ex[1]}) { + &{ $RAWC{$ex[1]} }($svr, @ex); + } else { - # otherwise, check %RAWC for ex[1]. - if (defined $RAWC{$ex[1]}) { - &{ $RAWC{$ex[1]} }($svr, @ex); + # otherwise, check for a raw hook. + if (defined $API::Std::RAWHOOKS{$ex[1]}) { + foreach (keys %{$API::Std::RAWHOOKS{$ex[1]}}) { + &{ $API::Std::RAWHOOKS{$ex[1]}{$_} }($svr, @ex); + } } } } diff --git a/modules/SASLAuth.pm b/modules/SASLAuth.pm index 6861b7d..2a59167 100644 --- a/modules/SASLAuth.pm +++ b/modules/SASLAuth.pm @@ -23,11 +23,11 @@ sub _init # Hook for when CAP ACK sasl is received. hook_add('on_capack', 'sasl.cap', \&M::SASLAuth::handle_capack) or return; # Hook for parsing 903. - rchook_add('903', \&M::SASLAuth::handle_903) or return; + rchook_add('903', 'sasl.903', \&M::SASLAuth::handle_903) or return; # Hook for parsing 904. - rchook_add('904', \&M::SASLAuth::handle_904) or return; + rchook_add('904', 'sasl.904', \&M::SASLAuth::handle_904) or return; # Hook for parsing 906. - rchook_add('906', \&M::SASLAuth::handle_906) or return; + rchook_add('906', 'sasl.906', \&M::SASLAuth::handle_906) or return; return 1; } @@ -36,9 +36,9 @@ sub _void { # Delete the hooks. hook_del('on_capack') or return; - rchook_del('903') or return; - rchook_del('904') or return; - rchook_del('906') or return; + rchook_del('903', 'sasl.903') or return; + rchook_del('904', 'sasl.904') or return; + rchook_del('906', 'sasl.906') or return; return 1; }