Let's give the user the option to get only a Bender or Fry quote.

This commit is contained in:
James Vega 2004-09-07 14:30:35 +00:00
parent ac27c8e95a
commit b51f753b11

View File

@ -464,20 +464,29 @@ class Http(callbacks.PrivmsgCommandAndRegexp):
irc.reply('; '.join(resp)) irc.reply('; '.join(resp))
def futurama(self, irc, msg, args): def futurama(self, irc, msg, args):
"""takes no arguments """[{bender|fry}]
Returns a random Bender or Fry (from Futurama) quote from Slashdot's Returns a random Bender or Fry (from Futurama) quote from Slashdot's
HTTP headers. HTTP headers. If a name is specified, attempts to return a quote
specific to that character.
""" """
name = privmsgs.getArgs(args, required=0, optional=1)
fd = webutils.getUrlFd('http://slashdot.org/') fd = webutils.getUrlFd('http://slashdot.org/')
try: try:
if not name:
if 'X-Bender' in fd.headers: if 'X-Bender' in fd.headers:
irc.reply('<Bender> %s' % fd.headers['X-Bender']) return '<Bender> %s' % fd.headers['X-Bender']
elif 'X-Fry' in fd.headers: elif 'X-Fry' in fd.headers:
irc.reply('<Fry> %s' % fd.headers['X-Fry']) return '<Fry> %s' % fd.headers['X-Fry']
else: else:
irc.reply( return 'Slashdot seems to be running low on Futurama ' \
'Slashdot seems to be running low on Futurama quotes.') 'quotes.'
else:
try:
return '<%s> %s' % (name, fd.headers['X-%s' % name])
except KeyError:
return 'Slashdot seems to be running low on %s quotes' %\
name
finally: finally:
fd.close() fd.close()