package Bot::BasicBot::Pluggable::Module::RssPromote; use strict; use warnings; use Data::Dumper; use base qw(Bot::BasicBot::Pluggable::Module); use HTML::TreeBuilder; use LWP::UserAgent; use POE qw(Component::BukkitDtach); my $regurl = "http://www.dirkocraft.com/regbackend"; my $donatorurl = "http://www.dirkocraft.com/donationsview"; my $command = ".c groupset %s Resident"; my $doncommand = ".c groupset %s Citizen"; my $adminchan = "#dirkocraft"; my $welcomemsg = "Welcome to &9Dirkocraft&4, &6%s"; my $ua = LWP::UserAgent->new(); my $dtach = POE::Component::BukkitDtach->spawn("dtach"); # change this for production sub run_command { local $\ = " :: "; my $ret = POE::Kernel->post($dtach, "queue_command", @_); print "RUNNING COMMAND $ret = @_\n"; } sub help {return ""} sub is_resident { my $self = shift; my $resident = shift; $self->get("resident_". lc $resident); } sub make_resident { my $self = shift; my $resident = shift; $self->set("resident_". lc $resident, 1); } sub is_donator { my $self = shift; my $resident = shift; $self->get("donator_". lc $resident); } sub make_donator { my $self = shift; my $resident = shift; $self->set("donator_". lc $resident, 1); } sub check_resident { my $self = shift; my $res = $ua->get($regurl); if ($res->is_success()) { my $cont = $res->content(); my $root = HTML::TreeBuilder->new_from_content($cont); my $users_elem = $root->look_down(_tag => "div", class => qr/view-registrationbackendstupid/); my $ulist = $users_elem->format(); my @users = ($ulist =~ m/\*\s*(\w+)/g); for my $user (@users) { if (!$self->is_resident($user)) { $self->make_resident($user); my $cmd = sprintf($command, $user); my $welcome = sprintf($welcomemsg, $user); run_command($cmd); # $self->say({body => $cmd, channel => $adminchan }); $self->say({body => $welcome, channel => $adminchan }); } } } else { printf "Damn: %s\n",$res->status_line(); } } sub check_donator { my $self = shift; my $res = $ua->get($donatorurl); print "DONATOR\n"; if ($res->is_success()) { my $cont = $res->content(); my $root = HTML::TreeBuilder->new_from_content($cont); my $users_elem = $root->look_down(_tag => "div", class => qr/view-id-donationsview/); my $ulist = $users_elem->format(); my @users = ($ulist =~ m/Completed\s+(\w+)/g); print Dumper(\@users, $ulist); for my $user (@users) { print "$user\n"; if (!$self->is_donator($user)) { print "$user 2\n"; $self->make_donator($user); my $cmd = sprintf($doncommand, $user); #$self->say({body => $cmd, channel => $adminchan }); run_command($cmd); } } } else { printf "Damn: %s\n",$res->status_line(); } } our $counter = 0; sub tick { # called every 5 seconds my $self = shift; # get ourself, duh $counter++; # every 15 seconds, 3 * 5 seconds, check the feed $self->check_resident() unless ($counter % 3); # every 3 minutes, 36 * 5 seconds, check the feed $self->check_donator() unless ($counter % 36); run_command("ECHO!"); } 1;