* Parse the data.

* Parse PING and Numeric:001.
This commit is contained in:
Elijah Perrault committed 2011-01-19 15:11:05 -07:00
1 parent cff3b8662d
commit 3573c7339b
3 files changed
+65

No files matched your search

+61
View File
@@ -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;