Intervals in ping messages are abbreviated.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 18 Feb 2001 15:11:19 +0000 (15:11 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 18 Feb 2001 15:11:19 +0000 (15:11 +0000)
bot.tcl

diff --git a/bot.tcl b/bot.tcl
index 0733d2c..45af865 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -275,11 +275,11 @@ proc prefix_nick {} {
     }
 }
 
-proc showintervalsecs {howlong} {
-    return [showintervalsecs/[opt timeformat] $howlong]
+proc showintervalsecs {howlong abbrev} {
+    return [showintervalsecs/[opt timeformat] $howlong $abbrev]
 }
 
-proc showintervalsecs/ks {howlong} {
+proc showintervalsecs/ks {howlong abbrev} {
     if {$howlong < 1000} {
        return "${howlong}s"
     } else {
@@ -298,15 +298,19 @@ proc showintervalsecs/ks {howlong} {
     }
 }
 
-proc format_qty {qty unit} {
+proc format_qty {qty unit abbrev} {
     set o $qty
-    append o " "
-    append o $unit
-    if {$qty != 1} { append o s }
+    if {$abbrev} {
+       append o [string range $unit 0 0]
+    } else {
+       append o " "
+       append o $unit
+       if {$qty != 1} { append o s }
+    }
     return $o
 }
 
-proc showintervalsecs/hms {qty} {
+proc showintervalsecs/hms {qty abbrev} {
     set ul {second 60 minute 60 hour 24 day 7 week}
     set remainv 0
     while {[llength $ul] > 1 && $qty >= [set uv [lindex $ul 1]]} {
@@ -315,10 +319,10 @@ proc showintervalsecs/hms {qty} {
        set qty [expr {($qty-$remainv)/$uv}]
        set ul [lreplace $ul 0 1]
     }
-    set o [format_qty $qty [lindex $ul 0]]
+    set o [format_qty $qty [lindex $ul 0] $abbrev]
     if {$remainv} {
-       append o " "
-       append o [format_qty $remainv $remainu]
+       if {!$abbrev} { append o " " }
+       append o [format_qty $remainv $remainu $abbrev]
     }
     return $o
 }
@@ -327,7 +331,7 @@ proc showinterval {howlong} {
     if {$howlong <= 0} {
        return {just now}
     } else {
-       return "[showintervalsecs $howlong] ago"
+       return "[showintervalsecs $howlong 0] ago"
     }
 }
 
@@ -1406,7 +1410,7 @@ proc marktime_desc {mt} {
     } elseif {"$mt" == "once"} {
        return "I will send you one informational message when I see you."
     } else {
-       return "I'll send you a message every [showintervalsecs $mt]."
+       return "I'll send you a message every [showintervalsecs $mt 0]."
     }
 }
 
@@ -1530,7 +1534,7 @@ def_ucmd summon {
        set idletime [expr {$now - $idlesince}]
        set ls $now
        ucmdr {} {} {} "invites $target ($tty[expr {
-           $idletime > 10 ? ", idle for [showintervalsecs $idletime]" : ""
+           $idletime > 10 ? ", idle for [showintervalsecs $idletime 0]" : ""
        }]) to [expr {
            [ischan $dest] ? "join us here" : "talk to you"
        }]."
@@ -1628,7 +1632,8 @@ proc lnick_pingstring {why oc apstring} {
            upvar #0 chan_lastactivity($ch) la
            if {![info exists la]} continue
            if {$la <= $best_la} continue
-           set activity "$ch [showintervalsecs [expr {[clock seconds]-$la}]]"
+           set since [showintervalsecs [expr {[clock seconds]-$la}] 1]
+           set activity "$ch $since"
            set best_la $la
        }
     } else {