diff weather.tcl @ 543:a513b98f2a37

weather: Improve alias handling and do some work on stations listing.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 08 Jul 2020 00:42:05 +0300
parents 8e02d736bcc3
children 3b363fd0a60b
line wrap: on
line diff
--- a/weather.tcl	Tue Jul 07 23:17:02 2020 +0300
+++ b/weather.tcl	Wed Jul 08 00:42:05 2020 +0300
@@ -347,7 +347,15 @@
       }
     }
 
-    set res [join $result " ; "]
+    if {[llength $result] > 0} {
+      set res ""
+      if {[llength $result] > 10} {
+        set res [weather_qm "stations_limit"]
+      }
+      append res [join [lrange $result 0 10] " ; "]
+    } else {
+      set res [weather_qm "stations_no_matches"]
+    }
     weather_msg $upublic $unick $uchan "stations_list" [list $res]
     return 0
   } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} {
@@ -434,8 +442,14 @@
 
     set ualias [lindex $nlist 0]
     set uname [lindex $nlist 1]
+
+    if {[info exists weather_aliases($ualias)]} {
+      weather_msg $upublic $unick $uchan "alias_updated" [list $ualias $weather_aliases($ualias) $uname]
+    } else {
+      weather_msg $upublic $unick $uchan "alias_set" [list $ualias $uname]
+    }
+
     set weather_aliases($ualias) $uname
-    weather_msg $upublic $unick $uchan "alias_set" [list $ualias $uname]
 
     weather_save_aliases
     return 0
@@ -452,18 +466,29 @@
     }
 
     set ualias [lindex $rarglist 1]
+
+    if {![info exists weather_aliases($ualias)]} {
+      weather_msg $upublic $unick $uchan "alias_not_exist" [list $ualias]
+      return 0
+    }
+
     weather_msg $upublic $unick $uchan "alias_unset" [list $ualias $weather_aliases($ualias)]
     unset weather_aliases($ualias)
+    weather_save_aliases
 
     weather_save_aliases
     return 0
   } elseif {$rcmd == "list"} {
     # List all currently defined aliases
     set ulist {}
+    set ulistitem [weather_qm "alias_item"]
+    set ulistsep [weather_qm "alias_list_sep"]
+
     foreach {ukey uvalue} [array get weather_aliases] {
-      lappend ulist "\002'$ukey' = '$uvalue'\002"
+      lappend ulist [utl_str_map_values $ulistitem [list $ukey $uvalue]]
     }
-    weather_msg $upublic $unick $uchan "alias_list" [list [join $ulist ", "]]
+
+    weather_msg $upublic $unick $uchan "alias_list" [list [join $ulist $ulistsep]]
     return 0
   }