dirkobot/lib/POE/Component/BukkitRestart.pm
2011-08-28 12:00:38 -04:00

33 lines
1,002 B
Perl

package POE::Component::BukkitRestart;
use strict;
use warnings;
use POE;
my $restarttime = 90 * 60;
sub spawn {
POE::Session->create(
inline_states => {
_start => sub {
$_[HEAP]->{todo} = [ qw( step1 step2 step2a ) ],
$_[KERNEL]->delay( restartwarning => $restarttime );
print "Starting ReBoot session\n";
},
restartwarning => sub {
my @messages = ("Incoming game! Prepare for ReBoot!",
"What's this bright light aimed at us? It's a ReBoot!",
"I'll get you next ReBoot, Gadget! Next TIME!");
$_[KERNEL]->post( 'bukkitdtach', 'queue_command', 'say '.$messages[rand(0+@messages)]);
$_[KERNEL]->delay( restart => 30 );
},
restart => sub {
$_[KERNEL]->post( 'bukkitdtach', 'queue_command', 'save-all' );
$_[KERNEL]->post( 'bukkitdtach', 'queue_command', 'stop' );
$_[KERNEL]->delay( restartwarning => $restarttime );
}
}
);
};
1;