From e1adc011c39c0fe24f02ea440e52e028c5645c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Terje=20Ho=C3=A5s?= Date: Fri, 17 Aug 2012 17:16:26 +0200 Subject: [PATCH] Google: Stop output when there are no result. --- plugins/Google/plugin.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/Google/plugin.py b/plugins/Google/plugin.py index a45b8af85..7bb0aed21 100644 --- a/plugins/Google/plugin.py +++ b/plugins/Google/plugin.py @@ -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.*?(.*?)