X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fforecast.rb;h=1095886f3b46ac28036f5d922b4131485137b83f;hb=1e841175468b3e0357ab278a226a237fe4d7687e;hp=8079072853084b5ed2d43747f6fad788dd8646dd;hpb=5cb051d0ba8e32f4e044c3c1a6e8d11a5a57e3d9;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/forecast.rb b/data/rbot/plugins/forecast.rb index 80790728..1095886f 100644 --- a/data/rbot/plugins/forecast.rb +++ b/data/rbot/plugins/forecast.rb @@ -107,41 +107,40 @@ class ForecastPlugin < Plugin end def get_forecast(m,loc) - Thread.new { - begin - @cache_mutex.synchronize do - if @forecast_cache.has_key?(loc) and - Time.new - @forecast_cache[loc][:date] < 3600 - forecast = @forecast_cache[loc][:forecast] - if forecast - m.reply forecast - Thread.exit - end + begin + @cache_mutex.synchronize do + if @forecast_cache.has_key?(loc) and + Time.new - @forecast_cache[loc][:date] < 3600 + forecast = @forecast_cache[loc][:forecast] + if forecast + m.reply forecast + return end end - begin - l = LatLong.new - f = Forecast.new(*l.get_lat_long(loc)) - forecast,forecast_date = f.forecast - rescue => err - m.reply err - end - if forecast - m.reply forecast - @cache_mutex.synchronize do - @forecast_cache[loc] = { - :forecast => forecast, - :date => forecast_date - } - end - else - m.reply "Couldn't find forecast for #{loc}" + end + begin + l = LatLong.new + f = Forecast.new(*l.get_lat_long(loc)) + forecast,forecast_date = f.forecast + rescue => err + m.reply err + end + if forecast + m.reply forecast + @cache_mutex.synchronize do + @forecast_cache[loc] = { + :forecast => forecast, + :date => forecast_date + } end - rescue => e - m.reply "ERROR: #{e}" + else + m.reply "Couldn't find forecast for #{loc}" end - } + rescue => e + m.reply "ERROR: #{e}" + end end end plugin = ForecastPlugin.new -plugin.map 'forecast *location', :defaults => {:location => false} +plugin.map 'forecast *location', + :defaults => {:location => false}, :thread => true