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 @anncache = DXLog::search(0, $maxcache, $main::systime, 'ann');
51 shift @anncache while @anncache > $maxcache;
53 dbg("AnnTalk: loaded last $l announcements into cache in " . _diffms($t0) . "mS");
58 push @anncache, [ $main::systime, @_ ];
59 shift @anncache while @anncache > $maxcache;
62 # enter the spot for dup checking and return true if it is already a dup
65 my ($call, $to, $text, $t) = @_;
67 $t ||= $main::systime + $dupage;
70 $text =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg;
71 # $text = Encode::encode("iso-8859-1", $text) if $main::can_encode && Encode::is_utf8($text, 1);
72 $text =~ s/[^\#a-zA-Z0-9]//g;
73 $text = substr($text, 0, $duplth) if length $text > $duplth;
74 my $dupkey = "A$call|$to|\L$text";
75 return DXDupe::check($dupkey, $t);
80 return DXDupe::listdups('A', $dupage, @_);
83 # is this text field a likely announce to talk substitution?
84 # this may involve all sorts of language dependant heuristics, but
85 # then again, it might not
88 my ($from, $text) = @_;
91 ($call) = $text =~ /^\s*(?:[Xx]|[Tt][Oo]?:?)\s+([\w-]+)/;
92 ($call) = $text =~ /^\s*>\s*([\w-]+)\b/ unless $call;
93 ($call) = $text =~ /^\s*([\w-]+):?\b/ unless $call;
96 return is_callsign($call);