Added weather command.

This commit is contained in:
Jeremy Fincher 2004-02-23 09:05:12 +00:00
parent a8554a0ea3
commit 295eafcb37
1 changed files with 21 additions and 10 deletions

View File

@ -30,14 +30,15 @@
### ###
""" """
This plugin does weather-related stuff. This plugin does weather-related stuff. It can't change the weather, though,
so don't get your hopes up. We just report it.
""" """
import urllib
import plugins import plugins
import re import re
import sets import sets
import urllib
import conf import conf
import utils import utils
@ -55,19 +56,20 @@ class WeatherUnit(registry.String):
s = s.lower() s = s.lower()
if s not in unitAbbrevs: if s not in unitAbbrevs:
raise registry.InvalidRegistryValue,\ raise registry.InvalidRegistryValue,\
'Unit must be one of fahrenheit, celsius, or kelvin.' 'Unit must be one of Fahrenheit, Celsius, or Kelvin.'
s = unitAbbrevs[s].capitalize() s = unitAbbrevs[s].capitalize()
registry.String.setValue(self, s) registry.String.setValue(self, s)
class WeatherCommand(registry.String): class WeatherCommand(registry.String):
def set(self, s): def setValue(self, s):
original = getattr(self, 'value', self.default) m = Weather.weatherCommands
registry.String.set(self, s) if s not in m:
m = Weather.commands
if self.value not in m:
setattr(self, 'value', original)
raise registry.InvalidRegistryValue,\ raise registry.InvalidRegistryValue,\
'Command must be one of %s' % utils.commaAndify(m) 'Command must be one of %s' % utils.commaAndify(m)
else:
method = getattr(Weather, s)
Weather.weather.__doc__ = method.__doc__
registry.String.setValue(self, s)
conf.registerPlugin('Weather') conf.registerPlugin('Weather')
conf.registerChannelValue(conf.supybot.plugins.Weather, 'preferredUnit', conf.registerChannelValue(conf.supybot.plugins.Weather, 'preferredUnit',
@ -78,7 +80,7 @@ conf.registerChannelValue(conf.supybot.plugins.Weather, 'weatherCommand',
the weather.""")) the weather."""))
class Weather(callbacks.Privmsg): class Weather(callbacks.Privmsg):
commands = ['ham', 'cnn'] weatherCommands = ['ham', 'cnn']
threaded = True threaded = True
def callCommand(self, method, irc, msg, *L): def callCommand(self, method, irc, msg, *L):
try: try:
@ -86,6 +88,15 @@ class Weather(callbacks.Privmsg):
except webutils.WebError, e: except webutils.WebError, e:
irc.error(str(e)) irc.error(str(e))
def weather(self, irc, msg, args):
# This specifically does not have a docstring.
channel = None
if ircutils.isChannel(msg.args[0]):
channel = msg.args[0]
realCommandName = self.registryValue('weatherCommand', channel)
realCommand = getattr(self, realCommandName)
realCommand(irc, msg, args)
def _getTemp(self, temp, deg, unit, chan): def _getTemp(self, temp, deg, unit, chan):
default = self.registryValue('preferredUnit', chan).lower() default = self.registryValue('preferredUnit', chan).lower()
default = unitAbbrevs[default] default = unitAbbrevs[default]