# HG changeset patch # User Matti Hamalainen # Date 1401637656 -10800 # Node ID a1f4c163e48c127d58cac6b8987ab1897ec47f36 # Parent f8571331003b266c34b5ace0efba32a3fd1b8435 weather: Add max results limit. diff -r f8571331003b -r a1f4c163e48c weather.tcl --- a/weather.tcl Sun Jun 01 18:46:56 2014 +0300 +++ b/weather.tcl Sun Jun 01 18:47:36 2014 +0300 @@ -14,6 +14,8 @@ set weather_datafile "/home/niinuska/bot/data.weather" set weather_check_period 5 +set weather_max_results 3 + set weather_logmsg 1 set weather_preferredmsg "PRIVMSG" @@ -155,7 +157,7 @@ #------------------------------------------------------------------------- proc weather_cmd {unick uhand uchan uargs upublic} { - global weather_default_locations weather_data + global weather_default_locations weather_data weather_max_results global weather_msg_usage_1 weather_msg_usage_2 weather_msg_user_not_known global weather_msg_no_results weather_msg_no_data_for_location @@ -200,21 +202,25 @@ } # Handle argument list + set nresults 0 set rarglist [::textutil::split::splitx $rargs "\s*\;\s*"] foreach rarg $rarglist { if {$rarg == "min"} { # Min temp set umin [weather_get_key "w_min"] weather_msg $upublic $unick $uchan "Min: $umin" + incr nresults } elseif {$rarg == "max"} { # Max temp set umax [weather_get_key "w_max"] weather_msg $upublic $unick $uchan "Max: $umax" + incr nresults } elseif {$rarg == "minmax" || $rarg == "min max" || $rarg == "maxmin" || $rarg == "max min"} { # Min & Max temps set umin [weather_get_key "w_min"] set umax [weather_get_key "w_max"] weather_msg $upublic $unick $uchan "Min: $umin | Max: $umax" + incr nresults } else { # Location match set ufound 0 @@ -222,6 +228,7 @@ if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { if {[llength $uvalue] > 0} { weather_msg $upublic $unick $uchan [weather_get_data $ukey $uvalue] + incr nresults } else { weather_msg $upublic $unick $uchan "\002${ukey}\002: $weather_msg_no_results" } @@ -233,6 +240,9 @@ weather_msg $upublic $unick $uchan "\002${rarg}\002: $weather_msg_no_data_for_location" } } + if {$nresults >= $weather_max_results} { + return 0 + } } return 0 }