# HG changeset patch # User Matti Hamalainen # Date 1422025199 -7200 # Node ID 259f093c95030a12045644ecb57bf8751fb4bf92 # Parent 4ca3b5e39ca29250445dc2409c6e00022f2636bb weather: Make some more messages configurable. diff -r 4ca3b5e39ca2 -r 259f093c9503 config.weather.example --- a/config.weather.example Fri Jan 23 13:20:28 2015 +0200 +++ b/config.weather.example Fri Jan 23 16:59:59 2015 +0200 @@ -35,14 +35,13 @@ ### ### Messages ### -set weather_msg_result_base "\002@0@\002, mitattu klo @2@: \002@3@C\002" -set weather_msg_result_1_opt_5 ", @@" -set weather_msg_result_1_opt_6 ", keli @@" -set weather_msg_result_1_opt_4 ", tien pinta @@C" - -set weather_msg_result_2_opt_4 ", kosteus \002@@\002" -set weather_msg_result_2_opt_5 ", tuuli \002@@\002 m/s" -set weather_msg_result_2_opt_6 ", pilvipeite @@" +set weather_msg_result [list "\002@station@\002, mitattu klo @ctime@: \002@temp@°C\002"] +lappend weather_msg_result ", @weather1@" +lappend weather_msg_result ", keli @weather2@" +lappend weather_msg_result ", tien pinta @road_temp@°C" +lappend weather_msg_result ", kosteus \002@humidity@%\002" +lappend weather_msg_result ", tuuli \002@wind_speed@\002 m/s" +lappend weather_msg_result ", pilvipeite \002@cloud_cover@\002" set weather_msg_usage_prefix_1 "Käyttö: !sää " diff -r 4ca3b5e39ca2 -r 259f093c9503 weather.tcl --- a/weather.tcl Fri Jan 23 13:20:28 2015 +0200 +++ b/weather.tcl Fri Jan 23 16:59:59 2015 +0200 @@ -48,6 +48,16 @@ } +proc weather_msg {apublic anick achan amsg {aargs {}}} { + set narg 1 + foreach marg $aargs { + set amsg [string map [list "%$narg" $marg] $amsg] + incr narg + } + weather_msg_do $apublic $anick $achan $amsg +} + + proc weather_usage {apublic anick achan amsg} { global weather_msg_usage_prefix_1 weather_msg_usage_prefix_2 set nline 0 @@ -64,13 +74,18 @@ } -proc weather_msg {apublic anick achan amsg {aargs {}}} { - set narg 1 - foreach marg $aargs { - set amsg [string map [list "%$narg" $marg] $amsg] - incr narg +proc weather_translate_msg {amsg aargs} { + set aresult "" + foreach aitem $amsg { + set atmp $aitem + foreach {akey aval} [array get aargs] { + set atmp [string map [list "@${akey}@" $aval] $atmp] + } + if {$atmp != $aitem} { + append aresult $atmp + } } - weather_msg_do $apublic $anick $achan $amsg + return $amsg } @@ -148,17 +163,31 @@ # Produce one location of weather data as a string proc weather_get_data {udata ukey} { - set str "\002[lindex $udata 0]\002, mitattu klo [weather_ctime [lindex $udata 2]]: \002[lindex $udata 3]°C\002" + global weather_msg_result + + array unset uvals + array set uvals { + station [lindex udata 0] + vtime [lindex udata 2] + ctime [weather_ctime [lindex udata 2]] + temp [lindex udata 3] + } + if {[lindex $udata 1] == 0} { - append str [weather_item $udata 5 ", @@"] - append str [weather_item $udata 6 ", keli @@"] - append str [weather_item $udata 4 ", tien pinta @@°C"] + array set uvals { + weather1 [lindex udata 5] + weather2 [lindex udata 6] + road_temp [lindex udata 4] + } } else { - append str [weather_item $udata 4 ", kosteus \002@@%\002"] - append str [weather_item $udata 5 ", tuuli \002@@\002 m/s"] - append str [weather_item $udata 6 ", pilvipeite \002@@\002"] + array set uvals { + humidity [lindex udata 4] + wind_speed [lindex udata 5] + cloud_cover [lindex udata 6] + } } - return "${str}." + + return "[weather_translate_msg $weather_msg_result $uvals]." }