mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Google: Stop output when there are no result.
This commit is contained in:
parent
b5e965c48a
commit
e1adc011c3
@ -269,7 +269,7 @@ class Google(callbacks.PluginRegexp):
|
||||
"""
|
||||
urlig = self._googleUrlIG(expr)
|
||||
js = utils.web.getUrl(urlig).decode('utf8')
|
||||
# fix bad google json
|
||||
# Convert JavaScript to JSON. Ouch.
|
||||
js = js \
|
||||
.replace('lhs:','"lhs":') \
|
||||
.replace('rhs:','"rhs":') \
|
||||
@ -278,11 +278,6 @@ class Google(callbacks.PluginRegexp):
|
||||
.replace('\\', '\\\\')
|
||||
js = json.loads(js)
|
||||
|
||||
# Currency conversion
|
||||
if js['icc'] == True:
|
||||
irc.reply("%s = %s" % (js['lhs'], js['rhs'],))
|
||||
return
|
||||
|
||||
url = self._googleUrl(expr)
|
||||
html = utils.web.getUrl(url).decode('utf8')
|
||||
match = self._calcRe1.search(html)
|
||||
@ -294,10 +289,15 @@ class Google(callbacks.PluginRegexp):
|
||||
s = self._calcFontRe.sub(r',', s)
|
||||
s = self._calcTimesRe.sub(r'*', s)
|
||||
s = utils.web.htmlToText(s)
|
||||
irc.reply(s)
|
||||
else:
|
||||
irc.reply(_('Google says: Error: %s.') % (js['error'],))
|
||||
irc.reply('Google\'s calculator didn\'t come up with anything.')
|
||||
if ' = ' in s: # Extra check, since the regex seems to fail.
|
||||
irc.reply(s)
|
||||
return
|
||||
elif js['lhs'] and js['rhs']:
|
||||
# Outputs the original result. Might look ugly.
|
||||
irc.reply("%s = %s" % (js['lhs'], js['rhs'],))
|
||||
return
|
||||
irc.reply(_('Google says: Error: %s.') % (js['error'],))
|
||||
irc.reply('Google\'s calculator didn\'t come up with anything.')
|
||||
calc = wrap(calc, ['text'])
|
||||
|
||||
_phoneRe = re.compile(r'Phonebook.*?<font size=-1>(.*?)<a href')
|
||||
|
Loading…
Reference in New Issue
Block a user