From c6ae00f1299e5b13f221f07f7be8c6bf3445d8e1 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 4 Dec 2014 13:14:42 +0100 Subject: Implemented timeout handling --- Avalon.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Avalon.pm b/Avalon.pm index 8fd76d8..cd6d874 100644 --- a/Avalon.pm +++ b/Avalon.pm @@ -7,9 +7,28 @@ use strict; use warnings; use v5.12; use experimental qw(switch); +use POE; +use Time::HiRes qw(time); use base qw(Bot::BasicBot::Pluggable::Module); +### Game logic ############################################################### +sub set_timeout { + my ( $self, $value) = @_; + $poe_kernel->alarm( avalon_timeout => time() + $value ); +} + +sub timeout_occurred { + my $self = shift; + $self->say( channel => $self->{avalon}->{config}->{'game.channel'}, body => "timeout" ); +} + +### IRC methods override ###################################################### +sub connected { + my $self = shift; + $poe_kernel->state( 'avalon_timeout', $self, 'timeout_occurred' ); +} + sub init { my $self = shift; $self->{avalon} = {}; -- cgit v1.2.3