mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Can actually search with Google now that google.setLicense is being called.
Also, maxiumum-results -> maxiumumResults to prettify the function calls.
This commit is contained in:
parent
006909b909
commit
97eadb6feb
@ -73,7 +73,7 @@ def configure(onStart, afterConnect, advanced):
|
||||
break
|
||||
if key:
|
||||
onStart.append('load Google')
|
||||
conf.supybot.plugins.Google.licenseKey.set(key)
|
||||
conf.supybot.plugins.Google.licenseKey.setValue(key)
|
||||
print 'The Google plugin has the functionality to watch for URLs'
|
||||
print 'that match a specific pattern (we call this a snarfer).'
|
||||
print 'When supybot sees such a URL, he will parse the web page'
|
||||
@ -84,10 +84,10 @@ def configure(onStart, afterConnect, advanced):
|
||||
print
|
||||
if yn('Do you want the Google Groups link snarfer enabled by '
|
||||
'default?') == 'y':
|
||||
conf.supybot.plugins.Google.groupsSnarfer.set(True)
|
||||
conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
|
||||
if yn('Do you want the Google search snarfer enabled by default?') \
|
||||
== 'y':
|
||||
conf.supybot.plugins.Google.searchSnarfer.set(True)
|
||||
conf.supybot.plugins.Google.searchSnarfer.setValue(True)
|
||||
if 'load Alias' not in onStart:
|
||||
print 'Google depends on the Alias module for some extra commands.'
|
||||
if yn('Would you like to load the Alias module now?') == 'y':
|
||||
@ -132,6 +132,17 @@ def search(log, *args, **kwargs):
|
||||
raise callbacks.Error, 'Google returned an unparseable response. ' \
|
||||
'The full traceback has been logged.'
|
||||
|
||||
class LicenseKey(registry.String):
|
||||
def set(self, s):
|
||||
original = getattr(self, 'value', self.default)
|
||||
registry.String.set(self, s)
|
||||
if self.value and len(self.value) != 32:
|
||||
setattr(self, 'value', original)
|
||||
google.setLicense(self.value)
|
||||
raise registry.InvalidRegistryValue, 'Invalid Google license key.'
|
||||
if self.value:
|
||||
google.setLicense(self.value)
|
||||
|
||||
conf.registerPlugin('Google')
|
||||
conf.registerChannelValue(conf.supybot.plugins.Google, 'groupsSnarfer',
|
||||
registry.Boolean(False, """Determines whether the groups snarfer is
|
||||
@ -144,13 +155,14 @@ conf.registerChannelValue(conf.supybot.plugins.Google, 'searchSnarfer',
|
||||
channel."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Google, 'bold',
|
||||
registry.Boolean(True, """Determines whether results are bolded."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Google, 'maximum-results',
|
||||
conf.registerChannelValue(conf.supybot.plugins.Google, 'maximumResults',
|
||||
registry.PositiveInteger(10, """Determines the maximum number of results
|
||||
returned from the google command."""))
|
||||
conf.registerGlobalValue(conf.supybot.plugins.Google, 'licenseKey',
|
||||
registry.String('', """Sets the Google license key for using Google's Web
|
||||
LicenseKey('', """Sets the Google license key for using Google's Web
|
||||
Services API. This is necessary before you can do any searching with this
|
||||
module."""))
|
||||
|
||||
class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
threaded = True
|
||||
regexps = sets.Set(['googleSnarfer', 'googleGroups'])
|
||||
@ -210,7 +222,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||
irc.error(str(e))
|
||||
return
|
||||
bold = conf.supybot.plugins.Google.bold()
|
||||
max = conf.supybot.plugins.Google.get('maximum-results')
|
||||
max = conf.supybot.plugins.Google.maximumResults()
|
||||
irc.reply(self.formatData(data, bold=bold, max=max))
|
||||
|
||||
def metagoogle(self, irc, msg, args):
|
||||
|
@ -35,12 +35,12 @@ class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
plugins = ('Google',)
|
||||
if network:
|
||||
def testNoNoLicenseKeyError(self):
|
||||
conf.supybot.plugins.Google.groupsSnarfer.set('on')
|
||||
conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
|
||||
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))
|
||||
self.assertNoResponse(' ')
|
||||
|
||||
def testGroupsSnarfer(self):
|
||||
conf.supybot.plugins.Google.groupsSnarfer.set('on')
|
||||
conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
|
||||
self.assertRegexp('http://groups.google.com/groups?dq=&hl=en&'
|
||||
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
||||
'0310132012.738e22fc%40posting.google.com',
|
||||
@ -65,11 +65,11 @@ class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
r'comp\.lang\.python.*What exactly are bound')
|
||||
|
||||
def testConfig(self):
|
||||
conf.supybot.plugins.Google.groupsSnarfer.set('off')
|
||||
conf.supybot.plugins.Google.groupsSnarfer.setValue(False)
|
||||
self.assertNoResponse('http://groups.google.com/groups?dq=&hl=en&'
|
||||
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
||||
'0310132012.738e22fc%40posting.google.com')
|
||||
conf.supybot.plugins.Google.groupsSnarfer.set('on')
|
||||
conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
|
||||
self.assertNotError('http://groups.google.com/groups?dq=&hl=en&'
|
||||
'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.'
|
||||
'0310132012.738e22fc%40posting.google.com')
|
||||
|
Loading…
Reference in New Issue
Block a user