diff --git a/bin/auto b/bin/auto index cad888f..8994579 100755 --- a/bin/auto +++ b/bin/auto @@ -114,6 +114,9 @@ foreach my $cskey (keys %cservers) { chomp $data; # Debug. dbug "$cskey -> You: $data"; + + # Parse data. + Parser::IRC::_parse($cskey, $data); } }) or err(2, "Failed to create process for ".$cskey, 0) and next; # Success! diff --git a/doc/CHANGELOG b/doc/CHANGELOG index f763f82..483ffdd 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Parse PING and Numeric:001. * Begin on the IRC parser. * Added sockets, support for multiple asynchronous sockets. * Bug fix: conf_get() now returns correct data by checking diff --git a/src/Parser/IRC.pm b/src/Parser/IRC.pm index 925eb70..44209fa 100644 --- a/src/Parser/IRC.pm +++ b/src/Parser/IRC.pm @@ -6,5 +6,66 @@ package Parser::IRC; use strict; use warnings; +use API::Std qw(conf_get); +use Data::Dumper; +# Raw parsing hash. +our %RAWC = ( + '001' => \&num001, +); + +# Parse raw data. +sub _parse +{ + my ($svr, $data) = @_; + + # Split spaces into @ex. + my @ex = split(' ', $data); + + # Make sure there is enough data. + if (defined $ex[0] and defined $ex[1]) { + # If it's a ping... + if ($ex[0] eq 'PING') { + # send a PONG. + Auto::socksnd($svr, "PONG ".$ex[1]); + } + else { + # otherwise, check %RAWC for ex[1]. + if (defined $RAWC{$ex[1]}) { + &{ $RAWC{$ex[1]} }($svr, @ex); + } + } + } +} + +########################### +# Raw parsing subroutines # +########################### + +# Parse: Numeric:001 +sub num001 +{ + my ($svr, @ex) = @_; + + # Get the auto-join from the config. + my @cajoin = @{ (conf_get("server:$svr:ajoin"))[0] }; + + # Join the channels. + unless (defined $cajoin[1]) { + # For single-line ajoins. + my @sajoin = split(',', $cajoin[0]); + + foreach my $sjoin (@sajoin) { + Auto::socksnd($svr, "JOIN $sjoin"); + } + } + else { + # For multi-line ajoins. + foreach my $sjoin (@cajoin) { + Auto::socksnd($svr, "JOIN $sjoin"); + } + } +} + +1;