diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 16:32:32 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 16:32:32 +0000 |
commit | 2a96c9198c1f6e13407d0999083f6ce5e0bc06fa (patch) | |
tree | b3b9247d275d9b554665bc22884104d266d2e757 /lib/rbot/plugins/weather.rb | |
parent | 21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (diff) |
move rbot into lib - still rearranging for packaging/installation
Diffstat (limited to 'lib/rbot/plugins/weather.rb')
-rw-r--r-- | lib/rbot/plugins/weather.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/rbot/plugins/weather.rb b/lib/rbot/plugins/weather.rb new file mode 100644 index 00000000..3e4134e4 --- /dev/null +++ b/lib/rbot/plugins/weather.rb @@ -0,0 +1,55 @@ +class WeatherPlugin < Plugin + + def help(plugin, topic="") + "weather <ICAO> => display the current weather at the location specified by the ICAO code [Lookup your ICAO code at http://www.nws.noaa.gov/oso/siteloc.shtml] - this will also store the ICAO against your nick, so you can later just say \"weather\", weather => display the current weather at the location you last asked for" + end + + def initialize + super + # this plugin only wants to store strings + class << @registry + def store(val) + val + end + def restore(val) + val + end + end + @metar_cache = Hash.new + end + + def describe(m, where) + if @metar_cache.has_key?(where) && + Time.now - @metar_cache[where].date < 3600 + met = @metar_cache[where] + else + met = Utils.get_metar(where) + end + + if met + m.reply met.pretty_print + @metar_cache[where] = met + else + m.reply "couldn't find weather data for #{where}" + end + end + + def privmsg(m) + case m.params + when nil + if @registry.has_key?(m.sourcenick) + where = @registry[m.sourcenick] + describe(m,where) + else + m.reply "I don't know where #{m.sourcenick} is!" + end + when (/^(\S{4})$/) + where = $1 + @registry[m.sourcenick] = where + describe(m,where) + end + end + +end +plugin = WeatherPlugin.new +plugin.register("weather") |