#!/usr/bin/perl use warnings; use strict; use IO::Socket::INET; my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 3009, Proto => 'tcp', ); print $socket "REG MSG\r\n"; while ($_ = <$socket>) { s/\r\n$// || s/\n$//; print "Received $_\n"; if (s/^MSG //) { my @line = split(/\t/); # MSGs should have exactly two fields, no? # Parse for positive karma. while ($line[0] =~ /(\w+) ftw/g) { print $socket "karma.add $1\t$line[1]\r\n"; } while ($line[0] =~ /(\w+)\+\+/g) { print $socket "karma.add $1\t$line[1]\r\n"; } # Parse for negative karma. while ($line[0] =~ /(\w+) ft[ls]/g) { print $socket "karma.subtract $1\t$line[1]\r\n"; } while ($line[0] =~ /(\w+)\-\-/g) { print $socket "karma.subtract $1\t$line[1]\r\n"; } # Parse $_ for lines beginning with ``-''. if ($line[0] =~ s/^-//) { $line[0] =~ s/\|\s*/\t/g; if ($line[0] =~ s/^quiet//) { $line[1] =~ s/([^ ]+) ([^ ]+)$/$2 $2/; } my $line = join("\t", @line); print "Calling ", $line, "\n"; print $socket "$line\r\n"; } } }