mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Better error message and make sure an int is provided when we need it
This commit is contained in:
parent
47817f8ea3
commit
f7e44d8f50
@ -62,7 +62,7 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
print 'supybot sees such a URL, he will parse the web page for'
|
print 'supybot sees such a URL, he will parse the web page for'
|
||||||
print 'information and reply with the results.\n'
|
print 'information and reply with the results.\n'
|
||||||
if yn('Do you want the Ebay snarfer enabled by default?') == 'n':
|
if yn('Do you want the Ebay snarfer enabled by default?') == 'n':
|
||||||
onStart.append('Ebay toggle auction off')
|
onStart.append('Ebay config auction-snarfer off')
|
||||||
|
|
||||||
class Ebay(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
class Ebay(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
||||||
"""
|
"""
|
||||||
@ -119,11 +119,19 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
|||||||
if option == 'link':
|
if option == 'link':
|
||||||
link = True
|
link = True
|
||||||
item = privmsgs.getArgs(rest)
|
item = privmsgs.getArgs(rest)
|
||||||
|
try:
|
||||||
|
int(item)
|
||||||
|
except ValueError:
|
||||||
|
irc.error(msg, '<item> must be an integer value.')
|
||||||
|
return
|
||||||
url = 'http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=%s' % item
|
url = 'http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=%s' % item
|
||||||
if link:
|
if link:
|
||||||
irc.reply(msg, url)
|
irc.reply(msg, url)
|
||||||
return
|
return
|
||||||
self._getResponse(irc, msg, url)
|
try:
|
||||||
|
self._getResponse(irc, msg, url)
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
irc.error(msg, 'Error while fetching the web page: %s' % e.msg)
|
||||||
|
|
||||||
def ebaySnarfer(self, irc, msg, match):
|
def ebaySnarfer(self, irc, msg, match):
|
||||||
r"http://cgi\.ebay\.(?:com(?:.au)?|ca|co.uk)/(?:.*?/)?(?:ws/)?" \
|
r"http://cgi\.ebay\.(?:com(?:.au)?|ca|co.uk)/(?:.*?/)?(?:ws/)?" \
|
||||||
@ -132,7 +140,10 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
|||||||
return
|
return
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
#debug.printf(url)
|
#debug.printf(url)
|
||||||
self._getResponse(irc, msg, url, snarf=True)
|
try:
|
||||||
|
self._getResponse(irc, msg, url, snarf=True)
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
debug.msg('Error while fetching the web page: %s' % e.msg)
|
||||||
ebaySnarfer = privmsgs.urlSnarfer(ebaySnarfer)
|
ebaySnarfer = privmsgs.urlSnarfer(ebaySnarfer)
|
||||||
|
|
||||||
def _getResponse(self, irc, msg, url, snarf=False):
|
def _getResponse(self, irc, msg, url, snarf=False):
|
||||||
|
@ -39,6 +39,7 @@ class EbayTest(PluginTestCase, PluginDocumentation):
|
|||||||
'ViewItem&item=3053641570')
|
'ViewItem&item=3053641570')
|
||||||
# test 'Invalid Item' checking
|
# test 'Invalid Item' checking
|
||||||
self.assertRegexp('ebay 2357056673', 'That auction is invalid')
|
self.assertRegexp('ebay 2357056673', 'That auction is invalid')
|
||||||
|
self.assertError('ebay foobar')
|
||||||
|
|
||||||
def testSnarfer(self):
|
def testSnarfer(self):
|
||||||
self.assertRegexp('http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem'
|
self.assertRegexp('http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem'
|
||||||
|
Loading…
Reference in New Issue
Block a user