mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05: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).""")))
|
bot's output will be made colorful (like Google's logo).""")))
|
||||||
conf.registerChannelValue(Google, 'bold',
|
conf.registerChannelValue(Google, 'bold',
|
||||||
registry.Boolean(True, _("""Determines whether results are bolded.""")))
|
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',
|
conf.registerChannelValue(Google, 'maximumResults',
|
||||||
NumSearchResults(8, _("""Determines the maximum number of results returned
|
NumSearchResults(8, _("""Determines the maximum number of results returned
|
||||||
from the google command.""")))
|
from the google command.""")))
|
||||||
|
@ -141,7 +141,7 @@ class Google(callbacks.PluginRegexp):
|
|||||||
raise callbacks.Error, _('We broke The Google!')
|
raise callbacks.Error, _('We broke The Google!')
|
||||||
return json
|
return json
|
||||||
|
|
||||||
def formatData(self, data, bold=True, max=0):
|
def formatData(self, data, bold=True, max=0, onetoone=False):
|
||||||
if isinstance(data, basestring):
|
if isinstance(data, basestring):
|
||||||
return data
|
return data
|
||||||
results = []
|
results = []
|
||||||
@ -159,8 +159,10 @@ class Google(callbacks.PluginRegexp):
|
|||||||
results.append(url)
|
results.append(url)
|
||||||
if not results:
|
if not results:
|
||||||
return format(_('No matches found.'))
|
return format(_('No matches found.'))
|
||||||
|
elif onetoone:
|
||||||
|
return results
|
||||||
else:
|
else:
|
||||||
return format('; '.join(results))
|
return [format('; '.join(results))]
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def lucky(self, irc, msg, args, opts, text):
|
def lucky(self, irc, msg, args, opts, text):
|
||||||
@ -201,8 +203,13 @@ class Google(callbacks.PluginRegexp):
|
|||||||
return
|
return
|
||||||
bold = self.registryValue('bold', msg.args[0])
|
bold = self.registryValue('bold', msg.args[0])
|
||||||
max = self.registryValue('maximumResults', msg.args[0])
|
max = self.registryValue('maximumResults', msg.args[0])
|
||||||
irc.reply(self.formatData(data['responseData']['results'],
|
# We don't use supybot.reply.oneToOne here, because you generally
|
||||||
bold=bold, max=max))
|
# 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',
|
google = wrap(google, [getopts({'language':'something',
|
||||||
'filter':''}),
|
'filter':''}),
|
||||||
'text'])
|
'text'])
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
|
|
||||||
class GoogleTestCase(ChannelPluginTestCase):
|
class GoogleTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('Google',)
|
plugins = ('Google', 'Config')
|
||||||
if network:
|
if network:
|
||||||
def testCalcHandlesMultiplicationSymbol(self):
|
def testCalcHandlesMultiplicationSymbol(self):
|
||||||
self.assertNotRegexp('google calc seconds in a century', r'215')
|
self.assertNotRegexp('google calc seconds in a century', r'215')
|
||||||
@ -54,6 +54,11 @@ class GoogleTestCase(ChannelPluginTestCase):
|
|||||||
# Unicode check
|
# Unicode check
|
||||||
self.assertNotError('google ae')
|
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):
|
def testFight(self):
|
||||||
self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+')
|
self.assertRegexp('fight supybot moobot', r'.*supybot.*: \d+')
|
||||||
self.assertNotError('fight ... !')
|
self.assertNotError('fight ... !')
|
||||||
|
Loading…
Reference in New Issue
Block a user