2 # Announce and Talk Handling routines
4 # Copyright (c) 2000 Dirk Koopman
19 use Time::HiRes qw(gettimeofday tv_interval);
21 use vars qw(%dup $duplth $dupage $filterdef);
23 $duplth = 30; # the length of text to use in the deduping
24 $dupage = 18*3600; # the length of time to hold ann dups
26 # tag, sort, field, priv, special parser
37 ['origin_dxcc', 'nc', 10],
38 ['origin_itu', 'ni', 11],
39 ['origin_zone', 'nz', 12],
40 ['by_state', 'nz', 13],
41 ['origin_state', 'nz', 14],
49 my $t0 = [gettimeofday];
50 dbg("AnnTalk: loading up to $maxcache announcements into cache");
51 @anncache = DXLog::search(0, $maxcache, $main::systime, 'ann');
52 shift @anncache while @anncache > $maxcache;
54 dbg("AnnTalk: loaded last $l announcements into cache in " . _diffms($t0) . "mS");
59 push @anncache, [ $main::systime, @_ ];
60 shift @anncache while @anncache > $maxcache;
63 # enter the spot for dup checking and return true if it is already a dup
66 my ($call, $to, $text, $t) = @_;
68 $t ||= $main::systime + $dupage;
71 $text =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg;
72 # $text = Encode::encode("iso-8859-1", $text) if $main::can_encode && Encode::is_utf8($text, 1);
73 $text =~ s/[^\#a-zA-Z0-9]//g;
74 $text = substr($text, 0, $duplth) if length $text > $duplth;
75 my $dupkey = "A$call|$to|\L$text";
76 return DXDupe::check($dupkey, $t);
81 return DXDupe::listdups('A', $dupage, @_);
84 # is this text field a likely announce to talk substitution?
85 # this may involve all sorts of language dependant heuristics, but
86 # then again, it might not
89 my ($from, $text) = @_;
92 ($call) = $text =~ /^\s*(?:[Xx]|[Tt][Oo]?:?)\s+([\w-]+)/;
93 ($call) = $text =~ /^\s*>\s*([\w-]+)\b/ unless $call;
94 ($call) = $text =~ /^\s*([\w-]+):?\b/ unless $call;
97 return is_callsign($call);