-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathseen.pl
63 lines (54 loc) · 1.23 KB
/
seen.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;
my ($who, $nick) = @ARGV;
my $DAT_FILE = "seen.dat";
$| = 1;
unless (open SEEN, "<$DAT_FILE") {
print STDERR "$DAT_FILE: $!\n";
print "Pole siin kedagi.\n";
exit 1
}
our %seen;
while (<SEEN>) {
my @r = split /\t/s;
unless ($#r) {
$_->[1] =~ s/^\+//s for values %seen;
next
}
our $k = lc $r[0];
if (length $r[2] <= 1 and exists $seen{$k}) {
$_ = $seen{$k}->[2];
$r[2] = $_ if $_;
}
$seen{$k} = \@r;
}
# write compacted seen.dat
# this is because the main bot just appends to the seen.dat
open TMP, ">$DAT_FILE.tmp" or die "Cannot create temp";
print TMP join("\t", @{$_}) for values %seen;
close TMP;
rename "$DAT_FILE.tmp", $DAT_FILE or print STDERR "$DAT_FILE: $!\n";
close SEEN;
if (lc $who eq lc $nick) {
print "$nick: Paraku oled sa ikka veel siin";
exit
}
my $r = $seen{lc $nick};
if ($r) {
$r->[1] =~ /^(\+?)(.*)/s;
my $alive = $1;
if ($alive) {
print "$r->[0] on praegu kanalil"
} else {
my $t = time - $2;
my $s = $t % 60;
my $t = int($t / 60);
my $m = $t % 60;
my $t = int($t / 60);
my $h = $t % 24;
my $t = int($t / 24);
print ("$r->[0] oli siin ${t}d ${h}h ${m}m ${s}s tagasi" .
($r->[2] =~ /\S/ ? " ja ütles: $r->[2]" : "\n"))
}
} else {
print "Ei tea midagi ${nick}'st\n"
}