Posted by Don Juan Tue 13th Mar 2007 18:54 - Syntax is Perl - 136 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
dion@titan:~$ cat deoxy_bot/Carlo.pl
-
#!/usr/bin/perl -w
-
-
use Digest::MD5 (md5 md5_hex md5_base64);
-
-
# Create a user agent object
-
use LWP::UserAgent;
-
use HTTP::Cookies;
-
-
$ua = LWP::UserAgent->new;
-
$ua->agent("MyApp/0.1 ");
-
-
# setup a ua cookie-jar
-
$ua->cookie_jar(HTTP::Cookies->new(file => "Carlo_cookies.txt",
-
autosave => 1));
-
-
# log on deoxy.org
-
-
my $req = HTTP::Request->new(POST => 'http://deoxy.org/forum/start_page.pl');
-
$req->content_type('application/x-www-form-urlencoded');
-
$req->content("Username=Carlo&Password=XHvkdq&option=Login");
-
my $res = $ua->request($req);
-
-
"\nrequest:". $res->content if ($res->is_success);
-
-
# Create a display request
-
my $req = HTTP::Request->new(GET => 'http://deoxy.org/forum/chat.pl?show=body');
-
my $loop_cnt;
-
my @prev_msg_hashes;
-
-
while(1) {
-
# Pass request to the user agent and get a response back
-
my $res = $ua->request($req);
-
-
if ($res->is_success) {
-
# Get the actual chat messages
-
-
-
#print "loop #$loop_cnt\n". join ',', @prev_msg_hashes;
-
#print "$messages\n";
-
-
#print "extracted messages:\n";
-
-
my @messages;
-
-
@messages, {sign=>$1, msg=>$2, hash=>md5_hex($1.$2)};
-
}
-
-
# print join "\n", map "md5: $_->{hash}\n<$_->{sign}> $_->{msg}", @messages;
-
-
my @new_msgs;
-
-
foreach $message (@messages) {
-
@new_msgs, $message if( ! (/$message->{hash}/, @prev_msg_hashes));
-
}
-
-
"\n", "md5: $_->{hash}\n<$_->{sign}> $_->{msg}", @new_msgs;
-
-
foreach $message (@new_msgs) {
-
say("Hi $message->{sign}, Im a bot") if ($message->{msg} =~ /Hi Carlo ?/i);
-
}
-
-
@prev_msg_hashes = $_->{hash}, @messages;
-
}
-
$loop_cnt++;
-
8;
-
}
-
-
sub say {
-
my $message = ;
-
"posting message: $message";
-
# Create a talk post request
-
my $req = HTTP::Request->new(POST => 'http://deoxy.org/forum/chat.pl?show=form');
-
$req->content_type('application/x-www-form-urlencoded');
-
$req->content("message=$message&submit=talk");
-
my $res = $ua->request($req);
-
# print "\nrequest:". $res->content if ($res->is_success);
-
}
-
PermaLink to this entry https://pastebin.co.uk/11835
Posted by Don Juan Tue 13th Mar 2007 18:54 - Syntax is Perl - 136 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0