use strict;
use vars qw(%state @ssh $last $pipe $arg $slow);
-@ssh=("ssh","-a","-x","-oBatchmode=yes","-oSetupTimeOut=20");
+@ssh=("ssh","-a","-x","-oBatchmode=yes","-oSetupTimeOut=20","-qq");
$pipe = "/tmp/.away-tpope";
$arg=shift || "";
do_phone();
$slow=0;
}
+ eval_chat();
do_schedule();
do_decision();
save();
next unless /(\d\d):(\d\d)-(\d\d):(\d\d) (.*)/;
my ($hs,$ms,$he,$me,$ev) = ($1, $2, $3, $4, $5);
$ev =~ s/ *\[.*$//;
- $begin = $hs*60+$ms-25;
+ $begin = $hs*60+$ms-10;
$maxend = $he*60+$me+10;
- $end = ($begin+25)*3/4+($maxend-10)/4;
+ $end = ($begin+10)*3/4+($maxend-10)/4;
if($begin <= $now && $now < $end) {
$state{'class'} = $ev;
+ internal_out("School");
$familiar = 1;
last;
+ } elsif($begin-35<=$now && $now<$end && $state{'phone'} eq "absent") {
+ internal_out("School");
} elsif (($state{'class'}||'') eq $ev) {
$familiar = 1;
undef $state{'class'}
close(SCHEDULE);
undef $state{'class'} unless ($familiar);
-
open(SCHEDULE, "today --category='!school !private'|");
$familiar = 0;
while(<SCHEDULE>) {
}
}
+sub eval_chat {
+ if(($state{'chat'}||'') eq "jmwaller") {
+ internal_out("Work",3*60*60);
+ } elsif(($state{'chat'}||'') =~ /^tpope-\d+$/) {
+ internal_out("Work",3*60*60);
+ } elsif(($state{'chat'}||'') eq "accd") {
+ #internal_out("School",30*60);
+ }
+}
+
sub do_hosts {
- my (@check) = ("mona", "lisa", "homer", "sarah");
+ my (@check) = ("tobias", "lucille", "lindsay", "buster");
my (@uphosts, @livehosts, $host, $hostlist);
if(($_[0] || 0) == 1) {
$hostlist=$state{'hosts'};
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm(30);
- $ret=!(system(@ssh,shift, 'if pidof xscreensaver >/dev/null && DISPLAY=:0.0 xscreensaver-command -version >/dev/null 2>&1; then if DISPLAY=:0.0 xscreensaver-command -time 2>&1 |egrep "non-blanked|no saver status" >/dev/null; then true; else pid=`ps ax|egrep "[0-9]:[0-9][0-9] ssh marge .*(screen.*RR irc|Chat)"|sed -e "s/^ *//"|cut -d" " -f 1`; [ -f "$HOME/.irc.lock" -o -z "$pid" ] || kill $pid; false; fi; else false; fi') >> 8);
+ $ret=!(system(@ssh,shift, 'if pidof xscreensaver >/dev/null && DISPLAY=:0.0 xscreensaver-command -version >/dev/null 2>&1; then if DISPLAY=:0.0 xscreensaver-command -time 2>&1 |egrep "non-blanked|no saver status" >/dev/null; then true; else pid=`ps ax|egrep "[0-9]:[0-9][0-9] ssh michael .*(screen.*RR irc|Chat)"|sed -e "s/^ *//"|cut -d" " -f 1`; [ -f "$HOME/.irc.lock" -o -z "$pid" ] || kill $pid; false; fi; else false; fi') >> 8);
alarm(0);
};
if($@) {
sub do_phone {
my $phone;
- if(!ping('mona')) {
+ if(!ping('tobias')) {
$phone="unknown";
} else {
- my $last_slh=`@ssh mona cat .blue/last_slh 2>/dev/null`;
+ my $last_slh=`@ssh tobias cat .blue/last_slh 2>/dev/null`;
if(!$last_slh) {
$phone="unknown";
} elsif (time-$last_slh < 540) {
$phone="absent";
}
}
- if($state{'phone'} ne 'present' && $phone eq 'present') {
+ if(($state{'phone'}||"") ne 'present' && $phone eq 'present') {
custom_out("");
+ internal_out("");
}
$state{'phone'} = $phone;
}
sub do_power {
- open TMP, "upsc milhouse\@localhost|";
+ open TMP, "upsc milhouse\@localhost 2>/dev/null|";
my $ups='';
while(<TMP>) {
chomp;
if ($state{'customawayexp'} && $state{'customawayexp'}<time);
custom_out("")
if ($state{'customoutexp'} && $state{'customoutexp'}<time);
+ internal_out("")
+ if ($state{'internaloutexp'} && $state{'internaloutexp'}<time);
custom_activity("")
if ($state{'customactivityexp'} && $state{'customactivityexp'}<time);
- if ($state{'customactivity'}) {
+ if (exists($state{'customactivity'})) {
$state{'activity'}=$state{'customactivity'};
} elsif ($state{'ups'} eq 'OB' || $state{'ups'} eq 'LB') {
$state{'activity'}="Power outage";
$state{'away'}=$state{'schedule'};
} elsif ($state{'phone'} ne 'present' && $state{'class'}) {
$state{'away'}="Class: ".$state{'class'};
+ } elsif ($state{'internalout'} && $state{'phone'} eq 'absent') {
+ $state{'away'}=$state{'internalout'};
} elsif ($state{'alive'}) {
undef($state{'away'});
} elsif ($state{'phone'} eq 'absent') {
$state{'away'}="Out";
} elsif ($state{'phone'} ne 'absent') {
my @now=localtime;
- if (1 <= $now[2] && $now[2] < 9) {
+ if (0 <= $now[2] && $now[2] < 7) {
$state{'away'}="Sleeping";
} else {
$state{'away'}="Away from keyboard";
save();
}
+sub internal_out {
+ if($_[0]) {
+ $state{'internalout'} = $_[0];
+ $state{'internaloutexp'} = time+($_[1]||150*60);
+ } else {
+ undef $state{'internalout'};
+ undef $state{'internaloutexp'};
+ }
+ do_decision();
+ save();
+}
+
sub custom_activity {
if($_[0]) {
$state{'customactivity'} = $_[0];
$state{'status'}=$state{'activity'};
} elsif (defined($state{'away'})) {
$state{'status'}=$state{'away'};
- } elsif ($state{'alive'} eq "mona" || $state{'alive'} eq "homer") {
+ } elsif ($state{'alive'} eq "tobias" || $state{'alive'} eq "lucille") {
$state{'status'}="On desktop";
- } elsif ($state{'alive'} eq "lisa") {
+ } elsif ($state{'alive'} eq "lindsay") {
$state{'status'}="On laptop";
- } elsif ($state{'alive'} eq "sarah") {
+ } elsif ($state{'alive'} eq "buster") {
$state{'status'}="In bed";
}
open CONF, '>' . $ENV{'HOME'} . "/.away-tpope" || die $!;
sub load {
open CONF, '<' . $ENV{'HOME'} . "/.away-tpope" or return;
+ undef $state{'customactivity'};
+ undef $state{'customaway'};
+ undef $state{'customout'};
+ undef $state{'internalout'};
while(my $line=<CONF>) {
$line =~ s/\\n/\n/g;
$line =~ s/\\"/"/g;