From dda0b7785b9a882c8e82c207a68ae7fb9691b866 Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Fri, 21 Jan 2011 18:16:28 -0700 Subject: [PATCH] Added events on_ucjoin, on_rcjoin and on_nick. --- doc/CHANGELOG | 1 + src/Parser/IRC.pm | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/CHANGELOG b/doc/CHANGELOG index d57afb4..6b273b5 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Added events on_ucjoin, on_rcjoin and on_nick. * Parse numerics 465, 471-475 and 477. * Added an optional @args onto event_run() for sending @args to the subs that have hooked onto the event. diff --git a/src/Parser/IRC.pm b/src/Parser/IRC.pm index 454787e..1371367 100644 --- a/src/Parser/IRC.pm +++ b/src/Parser/IRC.pm @@ -28,6 +28,11 @@ our %RAWC = ( # Variables for various functions. our (%got_001, %botnick, %botchans); +# Events. +API::Std::event_add("on_rcjoin"); +API::Std::event_add("on_ucjoin"); +API::Std::event_add("on_nick"); + # Parse raw data. sub _parse { @@ -191,26 +196,37 @@ sub cjoin # Check if this is coming from ourselves. if ($src{nick} eq $botnick{$svr}) { + # It is. Add channel to array and trigger on_ucjoin. unless (defined $botchans{$svr}) { @{ $botchans{$svr} } = (substr($ex[2], 1)); } else { push(@{ $botchans{$svr} }, substr($ex[2], 1)); } + API::Std::event_run("on_ucjoin", (substr($ex[2], 1))); + } + else { + # It isn't. Trigger on_rcjoin. + API::Std::event_run("on_rcjoin", (%src, substr($ex[2], 1))); } } # Parse: NICK sub nick { - my ($svr, @ex) = @_; + my ($svr, ($uex, undef, $nex)) = @_; - my %src = API::IRC::usrc(substr($ex[0], 1)); + my %src = API::IRC::usrc(substr($uex, 1)); # Check if this is coming from ourselves. if ($src{nick} eq $botnick{$svr}) { - $botnick{$svr} = $ex[2]; + # It is. Update bot nick hash. + $botnick{$svr} = $nex; delete $botnick{$svr}{newnick} if (defined $botnick{$svr}{newnick}); + } + else { + # It isn't. Trigger on_nick. + API::Std::event_run("on_nick", (%src, $nex)); } }