Make Weather.weather actually work as a wrapped command calling wrapped

commands and using the user registry.
This commit is contained in:
James Vega 2004-10-25 08:30:04 +00:00
parent de711b5bab
commit 2adef7c265
1 changed files with 12 additions and 11 deletions

View File

@ -112,29 +112,30 @@ class Weather(callbacks.Privmsg):
channel = None channel = None
if ircutils.isChannel(msg.args[0]): if ircutils.isChannel(msg.args[0]):
channel = msg.args[0] channel = msg.args[0]
if not args: if not location:
s = self.userValue('lastLocation', msg.prefix) location = self.userValue('lastLocation', msg.prefix)
if s: if location is None:
args = [s] raise callbacks.ArgumentError
self.setUserValue('lastLocation', msg.prefix, self.setUserValue('lastLocation', msg.prefix,
location, ignoreNoUser=True) location, ignoreNoUser=True)
args = [location]
realCommandName = self.registryValue('command', channel) realCommandName = self.registryValue('command', channel)
realCommand = getattr(self, realCommandName) realCommand = getattr(self, realCommandName)
try: try:
realCommand(irc, msg, args) realCommand(irc, msg, args[:])
except NoLocation: except NoLocation:
self.log.info('%s lookup failed, Trying others.', realCommandName) self.log.info('%s lookup failed, Trying others.', realCommandName)
for command in self.weatherCommands: for command in self.weatherCommands:
if command != realCommandName: if command != realCommandName:
self.log.info('Trying %s.', command) self.log.info('Trying %s.', command)
try: try:
getattr(self, command)(irc, msg, args) getattr(self, command)(irc, msg, args[:])
self.log.info('%s lookup succeeded.', command) self.log.info('%s lookup succeeded.', command)
break break
except NoLocation: except NoLocation:
self.log.info('%s lookup failed as backup.', command) self.log.info('%s lookup failed as backup.', command)
weather = wrap(weather, ['text']) weather = wrap(weather, [additional('text')])
def _toCelsius(self, temp, unit): def _toCelsius(self, temp, unit):
if unit == 'K': if unit == 'K':
@ -304,7 +305,7 @@ class Weather(callbacks.Privmsg):
irc.reply(s) irc.reply(s)
else: else:
irc.errorPossibleBug('The format of the page was odd.') irc.errorPossibleBug('The format of the page was odd.')
ham = commands.wrap(ham, ['something']) ham = commands.wrap(ham, ['text'])
_cnnUrl = 'http://weather.cnn.com/weather/search?wsearch=' _cnnUrl = 'http://weather.cnn.com/weather/search?wsearch='
_cnnFTemp = re.compile(r'(-?\d+)(&deg;)(F)</span>', re.I | re.S) _cnnFTemp = re.compile(r'(-?\d+)(&deg;)(F)</span>', re.I | re.S)
@ -372,7 +373,7 @@ class Weather(callbacks.Privmsg):
irc.reply(' '.join(resp)) irc.reply(' '.join(resp))
else: else:
irc.errorPossibleBug('Could not find weather information.') irc.errorPossibleBug('Could not find weather information.')
cnn = commands.wrap(cnn, ['something']) cnn = commands.wrap(cnn, ['text'])
_wunderUrl = 'http://mobile.wunderground.com/cgi-bin/' \ _wunderUrl = 'http://mobile.wunderground.com/cgi-bin/' \
'findweather/getForecast?query=' 'findweather/getForecast?query='
@ -466,7 +467,7 @@ class Weather(callbacks.Privmsg):
irc.reply(' '.join(resp)) irc.reply(' '.join(resp))
else: else:
irc.error('Could not find weather information.') irc.error('Could not find weather information.')
wunder = commands.wrap(wunder, ['something']) wunder = commands.wrap(wunder, ['text'])
conf.registerPlugin('Weather') conf.registerPlugin('Weather')
conf.registerChannelValue(conf.supybot.plugins.Weather, 'temperatureUnit', conf.registerChannelValue(conf.supybot.plugins.Weather, 'temperatureUnit',