source: trollforge/rucas/webchat.pl @ 467

Revision 368, 2.5 KB checked in by rucas, 3 years ago (diff)

gen troll

Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use WWW::Mechanize;
6use HTTP::Request::Common;
7use List::Util qw/shuffle/;
8use URI::Escape;
9
10require 'gen_nick.pl';
11require 'gen_troll.pl';
12
13my $proxyfile = "proxies.txt";
14our $channel = "#wikia";
15
16our $troll = "DEMOLISHED";
17our $random = 1;  #1 will use trolldb, 0 will use message above
18our $baseurl = "http://irc.wikia.com/";
19
20
21my @proxies;
22if (-e $proxyfile) {
23    print "Loading proxies from $proxyfile\n";
24    my $fh; open $fh, $proxyfile or die $!;
25    local $/;
26    my $proxies = <$fh>;
27    close $fh;
28    @proxies = split("\n", $proxies);
29}
30
31while (1) {
32    if (fork) {
33        sleep 1;
34    } else {
35        h8();
36        exit;
37    }
38}
39
40sub pick_proxy {
41    return unless @proxies;
42    my @p = shuffle @proxies;
43    return shift @p;
44}
45
46sub h8 {
47    my $nick = gen_nick();
48        my $count = 0;
49        my $randomseed = 0;
50    my $mech = new WWW::Mechanize(
51        stack_depth => 0,
52        agent => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8',
53    );
54
55    my $proxy = pick_proxy();
56    if ($proxy) {
57        $proxy = "http://$proxy" unless $proxy =~ /^\w+:\/\//;
58        $mech->proxy('http', $proxy);
59    }
60
61    print "Connecting with nick $nick";
62    print " and proxy $proxy" if $proxy;
63    print "...\n";
64
65    $mech->get($baseurl."irc.cgi");
66        $mech->form_name('loginform');
67        $mech->field('interface' => "mozilla");
68        $mech->field('Nickname' => $nick);
69        $mech->field('Channel' => $channel);
70        $mech->field('Server' => "irc.freenode.net");
71        $mech->click();
72        my $content = $mech->response()->content();
73        if($content =~ /&R=(\S+)&item/) { $randomseed = $1 } else { die "RANDOM SEED NOT RECOVERED"; } 
74
75        if(fork){$mech->get($baseurl."nph-irc.cgi?style=default&R=".$randomseed."&interface=mozilla&chan=".uri_escape($channel)."&nick=".$nick."&serv=irc.freenode.net");}
76
77    my $post_req = sub {
78        my (@params) = @_;
79                push @params, 'R' => $randomseed;
80                push @params, 'cmd' => "say";
81                push @params, 'item' => "say";
82                push @params, 'xmlhttp' => "0";
83        my $req_url = $baseurl."client-perl.cgi";       
84        my $req = POST $req_url, \@params;
85        $mech->add_header( 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' );
86        $mech->add_header( Encoding => 'application/x-www-form-urlencoded; charset=UTF-8' );
87        $mech->request($req);
88        return 1;
89    };
90    while (1) {
91            if($random==1) {
92                        $troll=gen_troll();             
93                }
94                $post_req->(target=>$channel,say=>$troll);
95    }
96}
Note: See TracBrowser for help on using the repository browser.