diff --git a/plugins/Google/config.py b/plugins/Google/config.py index cd92d2d9a..2967c6ddf 100644 --- a/plugins/Google/config.py +++ b/plugins/Google/config.py @@ -111,6 +111,9 @@ conf.registerChannelValue(Google, 'colorfulFilter', bot's output will be made colorful (like Google's logo)."""))) conf.registerChannelValue(Google, 'bold', registry.Boolean(True, _("""Determines whether results are bolded."""))) +conf.registerChannelValue(Google, 'oneToOne', + registry.Boolean(False, _("""Determines whether results are sent in + different lines or all in the same one."""))) conf.registerChannelValue(Google, 'maximumResults', NumSearchResults(8, _("""Determines the maximum number of results returned from the google command."""))) diff --git a/plugins/Google/plugin.py b/plugins/Google/plugin.py index e67d5d4a4..8dfc35044 100644 --- a/plugins/Google/plugin.py +++ b/plugins/Google/plugin.py @@ -141,7 +141,7 @@ class Google(callbacks.PluginRegexp): raise callbacks.Error, _('We broke The Google!') return json - def formatData(self, data, bold=True, max=0): + def formatData(self, data, bold=True, max=0, onetoone=False): if isinstance(data, basestring): return data results = [] @@ -159,8 +159,10 @@ class Google(callbacks.PluginRegexp): results.append(url) if not results: return format(_('No matches found.')) + elif onetoone: + return results else: - return format('; '.join(results)) + return [format('; '.join(results))] @internationalizeDocstring def lucky(self, irc, msg, args, opts, text): @@ -201,8 +203,13 @@ class Google(callbacks.PluginRegexp): return bold = self.registryValue('bold', msg.args[0]) max = self.registryValue('maximumResults', msg.args[0]) - irc.reply(self.formatData(data['responseData']['results'], - bold=bold, max=max)) + # We don't use supybot.reply.oneToOne here, because you generally + # do not want @google to echo ~20 lines of results, even if you + # have reply.oneToOne enabled. + onetoone = self.registryValue('oneToOne', msg.args[0]) + for result in self.formatData(data['responseData']['results'], + bold=bold, max=max, onetoone=onetoone): + irc.reply(result) google = wrap(google, [getopts({'language':'something', 'filter':''}), 'text']) diff --git a/plugins/Google/test.py b/plugins/Google/test.py index 6357b0f9a..260b06bf2 100644 --- a/plugins/Google/test.py +++ b/plugins/Google/test.py @@ -31,7 +31,7 @@ from supybot.test import * class GoogleTestCase(ChannelPluginTestCase): - plugins = ('Google',) + plugins = ('Google', 'Config') if network: def testCalcHandlesMultiplicationSymbol(self): self.assertNotRegexp('google calc seconds in a century', r'215') @@ -54,6 +54,11 @@ class GoogleTestCase(ChannelPluginTestCase): # Unicode check self.assertNotError('google ae') + def testSearchOneToOne(self): + self.assertRegexp('google dupa', ';') + self.assertNotError('config plugins.Google.oneToOne True') + self.assertNotRegexp('google dupa', ';') + def testFight(self): self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+') self.assertNotError('fight ... !')