From 512c351577f5f4f1ed8d924c3d610bd7a5007973 Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Thu, 20 Jan 2011 21:46:43 -0700 Subject: [PATCH] * Parse NICK. * Do not import API::IRC subroutines to Parser::IRC, instead use the class. * Added usrc() to API::IRC for formatting a source. --- doc/CHANGELOG | 2 ++ src/API/IRC.pm | 18 +++++++++++++++++- src/Parser/IRC.pm | 34 +++++++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/doc/CHANGELOG b/doc/CHANGELOG index e371a38..dc73149 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Parse NICK. + * Added usrc() to API::IRC for formatting a source. * Added awarn() to API::Std for warnings. * Parse Numeric:432. * Parse Numeric:433. diff --git a/src/API/IRC.pm b/src/API/IRC.pm index 85c4773..b370ec1 100644 --- a/src/API/IRC.pm +++ b/src/API/IRC.pm @@ -9,7 +9,7 @@ use warnings; use Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(cjoin cpart cmode privmsg notice quit nick); +our @EXPORT_OK = qw(cjoin cpart cmode privmsg notice quit nick usrc); # Join a channel. @@ -91,3 +91,19 @@ sub quit delete $Parser::IRC::botnick{$svr} if (defined $Parser::IRC::botnick{$svr}); } + +# Get nick, ident and host from a !@ +sub usrc +{ + my ($ex) = @_; + + my @si = split('!', $ex); + my @sii = split('@', $si[1]); + + return ( + nick => $si[0], + ident => $si[1], + host => $sii[1] + ); +} + diff --git a/src/Parser/IRC.pm b/src/Parser/IRC.pm index d1b3a09..0b60821 100644 --- a/src/Parser/IRC.pm +++ b/src/Parser/IRC.pm @@ -6,14 +6,15 @@ package Parser::IRC; use strict; use warnings; -use API::Std qw(conf_get err); -use API::IRC qw(cjoin nick quit); +use API::Std qw(conf_get err awarn); +use API::IRC; # Raw parsing hash. our %RAWC = ( - '001' => \&num001, - '432' => \&num432, - '433' => \&num433, + '001' => \&num001, + '432' => \&num432, + '433' => \&num433, + 'NICK' => \&nick, ); # Variables for various functions. @@ -63,11 +64,11 @@ sub num001 # For single-line ajoins. my @sajoin = split(',', $cajoin[0]); - cjoin($svr, $_) foreach (@sajoin); + API::IRC::cjoin($svr, $_) foreach (@sajoin); } else { # For multi-line ajoins. - cjoin($svr, $_) foreach (@cajoin); + API::IRC::cjoin($svr, $_) foreach (@cajoin); } } @@ -82,7 +83,7 @@ sub num432 } else { err(2, "Got error from server[".$svr."] before 001: Erroneous nickname. Closing connection.", 0); - quit($svr, "An error occurred."); + API::IRC::quit($svr, "An error occurred."); } } @@ -93,8 +94,23 @@ sub num433 my ($svr, undef) = @_; if (defined $botnick{$svr}) { - nick($svr, $botnick{$svr}."_"); + API::IRC::nick($svr, $botnick{$svr}."_"); } } +# Parse: NICK +sub nick +{ + my ($svr, @ex) = @_; + + my %src = API::IRC::usrc(substr($ex[0], 1)); + + # Check if this is coming from ourselves, meaning a forced nick change. + if ($src{nick} eq $botnick{$svr}) { + # It is a forced nick change. + awarn(3, "Incoming NICK from myself?"); + $botnick{$svr} = $ex[2]; + } +} + 1;