route cache, wcy, wwv. ann caching
[spider.git] / perl / AnnTalk.pm
index 5a387d219ff30946138c720d92ce36ac058c68b0..ae3337f764e6b44d5aa5a2c54eeeaa33ce24e60f 100644 (file)
@@ -3,52 +3,74 @@
 #
 # Copyright (c) 2000 Dirk Koopman
 #
-# $Id$
+#
 #
 
 package AnnTalk;
 
 use strict;
 
+use DXVars;
 use DXUtil;
 use DXDebug;
 use DXDupe;
-use DXVars;
+use DXLog;
+use DXLogPrint;
 
 use vars qw(%dup $duplth $dupage $filterdef);
 
-$duplth = 60;                                  # the length of text to use in the deduping
-$dupage = 5*24*3600;                   # the length of time to hold spot dups
+$duplth = 30;                                  # the length of text to use in the deduping
+$dupage = 18*3600;                             # the length of time to hold ann dups
 $filterdef = bless ([
                          # tag, sort, field, priv, special parser 
                          ['by', 'c', 0],
                          ['dest', 'c', 1],
                          ['info', 't', 2],
                          ['group', 't', 3],
+                         ['origin', 'c', 4],
                          ['wx', 't', 5],
-                         ['origin', 'c', 7, 4],
-                         ['origin_dxcc', 'c', 10],
-                         ['origin_itu', 'c', 11],
-                         ['origin_itu', 'c', 12],
-                         ['by_dxcc', 'n', 7],
-                         ['by_itu', 'n', 8],
-                         ['by_zone', 'n', 9],
-                         ['channel', 'n', 6],
-                        ], 'Filter::Cmd');
+                         ['channel', 'c', 6],
+                         ['by_dxcc', 'nc', 7],
+                         ['by_itu', 'ni', 8],
+                         ['by_zone', 'nz', 9],
+                         ['origin_dxcc', 'nc', 10],
+                         ['origin_itu', 'ni', 11],
+                         ['origin_zone', 'nz', 12],
+                         ['by_state', 'nz', 13],
+                         ['origin_state', 'nz', 14],
+                  ], 'Filter::Cmd');
 
+our $maxcache = 30;
+our @anncache;
+
+sub init
+{
+       @anncache = DXLog::search(0, $maxcache, $main::systime, 'ann');
+       shift @anncache while @anncache > $maxcache;
+       my $l = @anncache;
+       dbg("AnnTalk: loaded last $l announcements into cache");
+}
+
+sub add_anncache
+{
+       push @anncache, [ $main::systime, @_ ];
+       shift @anncache while @anncache > $maxcache;
+}
 
 # enter the spot for dup checking and return true if it is already a dup
 sub dup
 {
-       my ($call, $to, $text) = @_; 
+       my ($call, $to, $text, $t) = @_; 
 
+       $t ||= $main::systime + $dupage;
        chomp $text;
        unpad($text);
-       $text =~ s/[\\\%]\d+//g;
-       $text =~ s/[^a-zA-Z0-9]//g;
+       $text =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg;
+#      $text = Encode::encode("iso-8859-1", $text) if $main::can_encode && Encode::is_utf8($text, 1);
+       $text =~ s/[^\#a-zA-Z0-9]//g;
        $text = substr($text, 0, $duplth) if length $text > $duplth; 
-       my $dupkey = "A$to|\L$text";
-       return DXDupe::check($dupkey, $main::systime + $dupage);
+       my $dupkey = "A$call|$to|\L$text";
+       return DXDupe::check($dupkey, $t);
 }
 
 sub listdups
@@ -56,6 +78,22 @@ sub listdups
        return DXDupe::listdups('A', $dupage, @_);
 }
 
+# is this text field a likely announce to talk substitution?
+# this may involve all sorts of language dependant heuristics, but 
+# then again, it might not
+sub is_talk_candidate
+{
+       my ($from, $text) = @_;
+       my $call;
 
+       ($call) = $text =~ /^\s*(?:[Xx]|[Tt][Oo]?:?)\s+([\w-]+)/;
+       ($call) = $text =~ /^\s*>\s*([\w-]+)\b/ unless $call;
+       ($call) = $text =~ /^\s*([\w-]+):?\b/ unless $call;
+       if ($call) {
+               $call = uc $call;
+               return is_callsign($call);
+       }
+    return undef;
+}
 1;