changeset 156:a1f4c163e48c

weather: Add max results limit.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Jun 2014 18:47:36 +0300
parents f8571331003b
children c8fa73ba67da
files weather.tcl
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
 }