mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Google: Add supybot.plugins.Google.oneToOne.
This commit is contained in:
parent
6ccfe95751
commit
d5f3e1844f
@ -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.""")))
|
||||
|
@ -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'])
|
||||
|
@ -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 ... !')
|
||||
|
Loading…
Reference in New Issue
Block a user