chiark / gitweb /
yoweb-scrape: wip new flag and ocean functionality - do_embargoes
[ypp-sc-tools.main.git] / ypp-chatlog-alerter
index 2f6d86ef2fa934cd7659f472065445a8f15c51d6..05a9c2001c7e516b8a8292db51ac0d11313c9194 100755 (executable)
@@ -74,12 +74,15 @@ proc hidenotice {} {
 }
 
 proc newfile {} {
-    global currentfile defaultfile
+    global currentfile defaultfile logfile
     
     set newfile [tk_getOpenFile -multiple 0 -initialfile $currentfile \
                     -title "Select YPP log to track"]
     if {![string length $newfile]} return
 
+    catch { close $logfile }
+    catch { unset logfile }
+
     set currentfile $newfile
     set newdefaults [open $defaultfile.new w]
     puts $newdefaults "[list set currentfile $currentfile]"
@@ -103,6 +106,7 @@ proc for_lw {args} {
 
 set e_life 120
 set tint_switch 90
+set bell_again 60
 set tint_switched [expr { exp( -($tint_switch+0.0) / $e_life ) }]
 
 proc retint {} {
@@ -116,14 +120,16 @@ proc retint {} {
        set age [expr {$now-$time}]
        if {!$time} {
            lappend newprtimes {}
-       } elseif {$age < 120} {
+       } elseif {$age < 60} {
            lappend newprtimes [format "%3ds" $age]
+       } elseif {$age < 3600} {
+           lappend newprtimes [format "%3dm" [expr {$age/60}]]
        } else {
-           lappend newprtimes [format "%3dm" [expr {$age/120}]]
+           lappend newprtimes [format "%3dh" [expr {$age/3600}]]
        }
        set latest [expr { $time > $latest ? $time : $latest }]
        set tint [expr { exp( (-($age >= 0 ? $age : 0) + 0.0) / $e_life ) }]
-puts "AGE $age LA $latest TI $tint"
+#puts "AGE $age LA $latest TI $tint"
        tintentries .msg $i $tint
        incr i
     }
@@ -212,7 +218,7 @@ proc file-read-lines {lvar body} {
            set l "$bufdata$lhs"
            set bufdata {}
            set got $rhs
-puts ">>$l<<"
+#puts ">>$l<<"
            uplevel 1 $body
        }
        append bufdata $got
@@ -256,7 +262,7 @@ proc pollfile {} {
     file-read-lines l {
        hidenotice
        if {[regexp {^\[\d+:\d+:\d+\] (.*)} $l dummy rhs]} {
-puts PROCLINE
+#puts PROCLINE
            process-line $rhs
        }
     }
@@ -264,17 +270,22 @@ puts PROCLINE
 
 proc process-line {l} {
     if {[regexp {^(\w+) tells ye, \"(.*)\"$} $l dummy pirate msg]} {
-puts "MESSAGE $l"
+#puts "MESSAGE $l"
        message $pirate $msg
     }
 }
 
 proc message {pirate msg} {
     global times pirates messages height
-    global lw_ls lw_ws
+    global lw_ls lw_ws bell_again
     
     set ix [lsearch -exact $pirates $pirate]
     set now [clock seconds]
+    
+    if {$bell_again > -2 &&
+       ($ix<0 || [lindex $times $ix] < $now-$bell_again)} {
+       bell -nice
+    }
     if {$ix < 0} {
        set cix 0
        set oldest $now
@@ -298,7 +309,7 @@ proc message {pirate msg} {
        $w delete $ix
        $w insert $ix $new
     }
-puts "TIMES $times"
+#puts "TIMES $times"
     .pirate itemconfigure $ix -foreground white
     retint
 }
@@ -308,6 +319,8 @@ proc parseargs {} {
     foreach arg $argv {
        if {![string compare $arg --test-tints]} {
            showtints
+       } elseif {![string compare $arg --no-bell]} {
+           set bell_again -2
        } else {
            error "unknown option $arg"
        }