-------------------------------- start whatbot.pl -------------------------------- #!/usr/local/bin/perl # code by Timm (http://timjoh.com/) use strict; use IO::Socket; my $server = 'irc.what.cd'; my $nick = 'Timm'; my $login = 'Timm'; my $channel = '#what.cd-announce'; my $logfile = 'whatlog'; print 'Opening socket', "\n"; my $sock = new IO::Socket::INET(PeerAddr => $server, PeerPort => 6667, Proto => 'tcp') or die "Can't connect\n"; print 'Connecting to server ', $server, "\n"; print $sock "NICK $nick\r\n"; print $sock "USER $login 8 * :Joti\r\n"; while (<$sock>) { if (/004/) { print 'Logged in', "\n"; last; } elsif (/433/) { die "Nickname is already in use."; } elsif (/PING :(.*)$/) { print $sock "PONG $1\r\n"; } } print 'Sending password', "\n"; print $sock "PRIVMSG nickserv :identify *****\r\n"; print 'Joining channel ', $channel, "\n"; print $sock "JOIN $channel\r\n"; while (<$sock>) { chop; print $_, "\n"; if (/^PING(.*)$/i) { print $sock "PONG $1\r\n"; } elsif ( m/^:Bot\![^\ ]+\ PRIVMSG $channel :(.*)$/i ) { open( LOG, '>>', $logfile ) or die $!; printf LOG "%d\t%s\n", time, $1; close( LOG ); } } -------------------------------- end whatbot.pl -------------------------------- -------------------------------- start whatrss.pl -------------------------------- #!/usr/bin/perl # code by Timm (http://timjoh.com/) use strict; use CGI::Carp qw(fatalsToBrowser); use POSIX qw(strftime); print "Content-type: text/xml\n\n"; print '', "\n"; print '', "\n"; print "\t", '', "\n"; print "\t\t", 'what.cd?', "\n"; print "\t\t", 'http://what.cd/', "\n"; print "\t\t", 'Latest torrents from what.cd', "\n"; for ( reverse `tail -20 whatlog` ) { m/^(\d+)[\t\ ]*\cB\[(.*?)\]\cB\ (.*?)\[([^\]]*)\]\ -\ (http:.*?)\r?$/; &item( $3, $5, sprintf( '%s [%s]', $2, $4 ), $1 ); } print "\t", '', "\n"; print ''; sub item { my ( $title, $link, $desc, $time ) = @_; $link =~ /(\d+)$/; my $id = $1; print "\t\t", '', "\n"; print "\t\t\t", '', $title, '', "\n"; print "\t\t\t", 'http://what.cd/download.php/', $id, '/torrent.torrent', "\n"; print "\t\t\t", '', $id, '', "\n"; print "\t\t\t", '', $desc, ' ', $link, '', "\n"; print "\t\t\t", '', strftime( '%Y-%m-%dT%H:%M:%S+01:00', localtime($time) ), '', "\n"; print "\t\t", '', "\n"; } -------------------------------- end whatrss.pl --------------------------------