From 28b697a3a5827c1c42b78d29b5a7df6d4a70fd39 Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Thu, 3 Feb 2011 21:45:48 -0700 Subject: [PATCH] Parse QUIT and added event on_quit. --- doc/CHANGELOG | 2 ++ src/Parser/IRC.pm | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/CHANGELOG b/doc/CHANGELOG index e1df9cb..d592007 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Added event on_quit. + * Parse QUIT. * Added event on_part. * Parse PART. * Update chanusers on JOIN. diff --git a/src/Parser/IRC.pm b/src/Parser/IRC.pm index 18ae1d2..c08a700 100644 --- a/src/Parser/IRC.pm +++ b/src/Parser/IRC.pm @@ -28,7 +28,8 @@ our %RAWC = ( 'NOTICE' => \¬ice, 'PART' => \&part, 'PRIVMSG' => \&privmsg, - 'TOPIC' => \&topic, + 'QUIT' => \&quit, + 'TOPIC' => \&topic, ); # Variables for various functions. @@ -42,6 +43,7 @@ API::Std::event_add("on_notice"); API::Std::event_add("on_nick"); API::Std::event_add("on_cprivmsg"); API::Std::event_add("on_uprivmsg"); +API::Std::event_add("on_quit"); API::Std::event_add("on_topic"); # Parse raw data. @@ -440,6 +442,34 @@ sub privmsg return 1; } +# Parse: QUIT +sub quit +{ + my ($svr, @ex) = @_; + my %src = API::IRC::usrc(substr($ex[0], 1)); + + # Delete the user from all channels. + foreach my $ccu (keys %{ $chanusers{$svr} }) { + delete $chanusers{$svr}{$ccu}{$src{nick}} if defined $chanusers{$svr}{$ccu}{$src{nick}}; + } + + # Set $msg to the quit message. + my $msg = 0; + if (defined $ex[2]) { + $msg = substr($ex[2], 1); + if (defined $ex[3]) { + for (my $i = 3; $i < scalar(@ex); $i++) { + $msg .= " ".$ex[$i]; + } + } + } + + # Trigger on_quit. + API::Std::event_run("on_quit", ($svr, %src, $msg)); + + return 1; +} + # Parse: TOPIC sub topic {