put duplicate checking into respective modules and out of DXProt.
[spider.git] / perl / AnnTalk.pm
1 #
2 # Announce and Talk Handling routines
3 #
4 # Copyright (c) 2000 Dirk Koopman
5 #
6 # $Id$
7 #
8
9 package AnnTalk;
10
11 use strict;
12
13 use DXUtil;
14 use DXDebug;
15
16 use vars qw(%dup $duplth $dupage);
17
18 %dup = ();                                              # the duplicates hash
19 $duplth = 60;                                   # the length of text to use in the deduping
20 $dupage = 24*3600;               # the length of time to hold spot dups
21
22 # enter the spot for dup checking and return true if it is already a dup
23 sub dup
24 {
25         my ($call, $to, $text) = @_; 
26         my $d = $main::systime / 60;
27
28         chomp $text;
29         unpad($text);
30         $text = substr($text, 0, $duplth) if length $text > $duplth; 
31         my $dupkey = "$call|$to|$text";
32         return 1 if exists $dup{$dupkey};
33         $dup{$dupkey} = $d * 60;         # in seconds (to the nearest minute)
34         return 0; 
35 }
36
37 # called every hour and cleans out the dup cache
38 sub process
39 {
40         my $cutoff = $main::systime - $dupage;
41         while (my ($key, $val) = each %dup) {
42                 delete $dup{$key} if $val < $cutoff;
43         }
44 }
45
46 sub listdups
47 {
48         my @out;
49         for (sort { $dup{$a} <=> $dup{$b} } keys %dup) {
50                 my $val = $dup{$_};
51                 push @out, "$_ = $val (" . cldatetime($val) . ")";
52         }
53         return @out;
54 }
55
56 1; 
57