diff --git a/plugins/Google/plugin.py b/plugins/Google/plugin.py index 59660fc69..734a7b862 100644 --- a/plugins/Google/plugin.py +++ b/plugins/Google/plugin.py @@ -163,18 +163,27 @@ class Google(callbacks.PluginRegexp): return format('; '.join(results)) @internationalizeDocstring - def lucky(self, irc, msg, args, text): - """ + def lucky(self, irc, msg, args, opts, text): + """[--snippet] Does a google search, but only returns the first result. + If option --snippet is given, returns also the page text snippet. """ + opts = dict(opts) data = self.search(text, msg.args[0], {'smallsearch': True}) if data['responseData']['results']: url = data['responseData']['results'][0]['unescapedUrl'] - irc.reply(url.encode('utf-8')) + if opts.has_key('snippet'): + snippet = " | " + data['responseData']['results'][0]['content'] + snippet = snippet.replace('', '') + snippet = snippet.replace('', '') + else: + snippet = "" + result = url + snippet + irc.reply(result.encode('utf-8')) else: irc.reply(_('Google found nothing.')) - lucky = wrap(lucky, ['text']) + lucky = wrap(lucky, [getopts({'snippet':'',}), 'text']) @internationalizeDocstring def google(self, irc, msg, args, optlist, text):