Raw hooks now take hook names and support multiple hooks. This changes rchook_add and rchook_del.

This commit is contained in:
Elijah Perrault committed 2011-03-04 19:14:18 -07:00
1 parent f4448302e2
commit d4ff35a5f9
4 files changed
+31 -17

No files matched your search

+2
View File
@@ -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
+14 -8
View File
@@ -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;
}
+9 -3
View File
@@ -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);
}
}
}
}
+6 -6
View File
@@ -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;
}