I was in some random irc channel and they had a bot spit out the latest forum threads so I decided to code my own and then after it was done I thought it would be cool to make one for active forum users and here is the code.
Usage:
Code:
<tgo> !users
<Forums> Currently Logged in Users: john, Niels, tgo
<tgo> !forum
<Forums> Latest Forum Post: Forums irc bot -> http://www.anomalous-security.org/forum/viewtopic.php?t=1261
Code:
Code:
#!/usr/bin/perl -w
# Bot that reads the last forum post coded by Niels and tgo
# http://www.anomalous-security.org
use IO::Socket;
$server = "snake.zq1.de";
$nick = "Forums";
$ircport = 6667;
$httpport = 80;
$channel = "#aso";
Start();
sub Start {
$CONNECTION = IO::Socket::INET->new (
PeerAddr => $server,
PeerPort => $ircport,
Proto => 'tcp'
) or die;
print $CONNECTION "USER $nick 0 0 :$nick\n";
print $CONNECTION "NICK $nick\n";
print $CONNECTION "JOIN $channel\n";
while (my $input = <$CONNECTION>) {
if ($input =~ /:tgo!tgo\@je.to.jne/)
{
if ($input =~ /:!forum/)
{
getpage("/","rss_feeds2");
lastpost();
}
elsif ($input =~ /:!users/)
{
getpage("/forum/index.php","Registered Users:");
getuser();
}
}
print $CONNECTION "PONG $1\n" if $input =~ /PING (.*)/;
}
}
sub getpage {
my ($page,$keyword) = @_;
print "page is $page\n";
print "keyword is $keyword\n";
$CON = IO::Socket::INET->new (
PeerAddr => $server,
PeerPort => $httpport,
Proto => 'tcp'
) or die;
$request = "GET $page HTTP/1.1\r\n";
$request .= "Host: www.anomalous-security.org\r\n";
$request .= "User-Agent: Forums Bot\r\n";
$request .= "Connection: close\r\n\r\n";
print $CON $request;
while (my $text = <$CON>)
{
$all .= $text;
if ($text =~ /$keyword/)
{
$spot = length($all);
$s = $spot - length($text);
}
if ($text =~ /This data is based/)
{
$end = ($s - length($all)) * -1;
}
}
}
sub lastpost {
$chunk = substr($all,$spot+94,100);
$chunk =~ /(.*)">(.*)<\/a\>/;
print $CONNECTION "PRIVMSG $channel :Latest Forum Post: $2 -> http://www.anomalous-security.org/$1\n";
close($CON);
}
sub getuser {
$chunk = substr($all,$s,$end);
if ($chunk =~ /Registered Users: None/)
{
$names = "None";
}
else
{
$chunk =~ s/<([^>]*)>//g;
$chunk =~ /Registered Users: (.*)\s+/;
$names = $1;
}
print $CONNECTION "PRIVMSG $channel :Currently Logged in Users: $names\n";
}