rendered paste body#!/usr/bin/perl
#
# HORSENEWS.PL 2.0
#
# http://www.horsehater.org/
#
use strict;
use Net::IRC;
use XML::RSS::Parser;
use HTML::Entities;
use Text::LevenshteinXS qw(distance);
use POSIX;
my $time = time();
my @horsestories;
my @horseurls;
my @horsecache;
my @newhorses;
my @channels = ('#chirp', '#anus');
my %lasthorsehash = ();
my $basenick = 'HorseNews';
my $mynick = $basenick;
my $trigger = '!horse';
foreach (@channels)
{
$lasthorsehash{lc($_)} = time() - 31;
}
my $irc = new Net::IRC;
my $conn =
$irc->newconn(
Nick => $mynick,
Server => 'irc.horsehater.org',
Port => 6667,
Username => 'penisbird',
Ircname => 'HorseNews',
SSL => 0
);
sub Horse
{
print "Horse() call: size of the horsecache:". scalar @horsecache."\n";
$time = time();
my $parser = XML::RSS::Parser->new;
my @feeds = ();
push @feeds,
$parser->parse_uri('http://news.google.com/news?hl=en&ned=us&ie=UTF-8&q=HORSE+-trojan+-%22dark horse%22&output=rss');
print $parser->errstr;
@horsestories = ();
@horseurls = ();
@newhorses = ();
my $i = 0;
foreach my $feed (@feeds)
{
foreach ($feed->query('//item'))
{
my $horsestory = decode_entities($_->query('title')->text_content);
$horsestory =~ s/ -.+$//;
push @horsestories, $horsestory;
my $url = $_->query('link')->text_content;
#jewgle news niggers up the URLs with their tracker exit script
if ($url =~ /url=.+$/)
{
$url =~ /url=(.+)$/;
$url = $1;
}
$url =~ s/%3F/?/gi;
$url =~ s/%3D/=/gi;
$url =~ s/%26/&/gi;
$url =~ s/\&cid=.+$//;
push @horseurls, $url;
my $iscached = 0;
foreach (@horsecache)
{
if ($_ eq $horsestory || distance($_, $horsestory) < 20)
{
$iscached = 1;
last;
}
}
unless ($iscached)
{
push(@horsecache, $horsestory);
push(@newhorses, "$i. $horsestory");
}
$i++;
}
}
while (@horsecache > 50)
{
shift(@horsecache);
}
}
sub HorseUpdates
{
if (@newhorses > 0)
{
foreach my $channel (@channels)
{
$conn->privmsg($channel, '7,5/!!!!\ BREAKING HORSE NEWS /!!!!\');
}
}
foreach my $newhorse (@newhorses)
{
$newhorse =~ /^(\d+)/;
my $i = $1;
$newhorse =~ s/^\d+\. //;
foreach my $channel (@channels)
{
if (lc($channel) eq "#buttes" && int(rand(15)) == 4)
{
$conn->privmsg($channel, "tcl aim $newhorse -> $horseurls[$i]");
}
else
{
$conn->privmsg($channel, "$newhorse -> $horseurls[$i]");
}
}
}
}
sub nicktaken
{
my ($self) = shift;
$mynick = $basenick . int(rand(9999));
$self->nick($mynick);
}
sub connected
{
my $self = shift;
foreach (@channels)
{
unless(lc($_) eq '#anus')
{
$self->join($_);
}
}
}
sub joined
{
my ($self, $event) = @_;
my ($channel) = ($event->to)[0];
my $valid = 0;
foreach (@channels)
{
if ($channel =~ /$_/i)
{
$valid = 1;
$self->sl("MODE $channel +oq $mynick $mynick");
last;
}
}
if (!$valid)
{
$self->part($channel);
}
}
sub public
{
my ($self, $event) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick);
my ($arg) = ($event->args);
if ($arg =~ /^$trigger$/i && ((time() - $lasthorsehash{lc($to[0])}) > 30))
{
if ((time() - $time) >= 300 || @horsestories == 0)
{
Horse();
}
my $i = 0;
foreach (@horsestories)
{
$self->privmsg([@to], "$i. " . $_);
$i++;
}
$lasthorsehash{lc($to[0])} = time();
}
elsif ($arg =~ /^$trigger (\d+)$/i
&& (time() - $lasthorsehash{lc($to[0])} > 2))
{
my $url = $horseurls[$1];
$self->privmsg([@to], $url);
$lasthorsehash{lc($to[0])} = time();
}
}
sub cversion
{
my ($self, $event) = @_;
my @unamed = POSIX::uname();
my $uname = "$unamed[0] $unamed[2] $unamed[4]";
my $nick = $event->nick;
$self->sl("NOTICE $nick :VERSION HorseNews 2.0 series running on $uname");
}
sub disconnect
{
my ($self, $event) = @_;
print "Disconnected from ", $event->from(), " (", ($event->args())[0],
"). Attempting to reconnect...\n";
$self->connect();
}
$conn->add_global_handler('376', \&connected);
$conn->add_global_handler('disconnect', \&disconnect);
$conn->add_global_handler('public', \&public);
$conn->add_global_handler('cversion', \&cversion);
$conn->add_global_handler(433, \&nicktaken);
$conn->add_global_handler('join', \&joined);
while (1)
{
$irc->do_one_loop();
if ((time() - $time) >= 300)
{
Horse();
HorseUpdates();
}
}