mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Added bold and maximum-results configurable.
This commit is contained in:
parent
83995296b7
commit
2f55345012
@ -1,4 +1,4 @@
|
|||||||
#re!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
###
|
###
|
||||||
# Copyright (c) 2002, Jeremiah Fincher
|
# Copyright (c) 2002, Jeremiah Fincher
|
||||||
@ -142,7 +142,12 @@ class Google(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
('search-snarfer', configurable.BoolType, False,
|
('search-snarfer', configurable.BoolType, False,
|
||||||
"""Determines whether the search snarfer is enabled. If so, messages
|
"""Determines whether the search snarfer is enabled. If so, messages
|
||||||
(even unaddressed ones) beginning with the word 'google' will result
|
(even unaddressed ones) beginning with the word 'google' will result
|
||||||
in the first URL Google returns being sent to the channel.""")]
|
in the first URL Google returns being sent to the channel."""),
|
||||||
|
('bold', configurable.BoolType, True,
|
||||||
|
"""Determines whether results are bolded."""),
|
||||||
|
('maximum-results', configurable.PositiveIntType, 10,
|
||||||
|
"""Determines the maximum number of results returned from the
|
||||||
|
google command."""),]
|
||||||
)
|
)
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
configurable.Mixin.__init__(self)
|
configurable.Mixin.__init__(self)
|
||||||
@ -155,16 +160,20 @@ class Google(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
configurable.Mixin.die(self)
|
configurable.Mixin.die(self)
|
||||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||||
|
|
||||||
def formatData(self, data):
|
def formatData(self, data, bold=True, max=0):
|
||||||
if isinstance(data, basestring):
|
if isinstance(data, basestring):
|
||||||
return data
|
return data
|
||||||
time = 'Search took %s seconds' % data.meta.searchTime
|
time = 'Search took %s seconds' % data.meta.searchTime
|
||||||
results = []
|
results = []
|
||||||
|
if max:
|
||||||
|
data.results = data.results[:max]
|
||||||
for result in data.results:
|
for result in data.results:
|
||||||
title = utils.htmlToText(result.title.encode('utf-8'))
|
title = utils.htmlToText(result.title.encode('utf-8'))
|
||||||
url = result.URL
|
url = result.URL
|
||||||
if title:
|
if title:
|
||||||
results.append('%s: <%s>' % (ircutils.bold(title), url))
|
if bold:
|
||||||
|
title = ircutils.bold(title)
|
||||||
|
results.append('%s: <%s>' % (title, url))
|
||||||
else:
|
else:
|
||||||
results.append(url)
|
results.append(url)
|
||||||
if not results:
|
if not results:
|
||||||
@ -207,7 +216,9 @@ class Google(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
kwargs[option[2:]] = argument
|
kwargs[option[2:]] = argument
|
||||||
searchString = privmsgs.getArgs(rest)
|
searchString = privmsgs.getArgs(rest)
|
||||||
data = search(self.log, searchString, **kwargs)
|
data = search(self.log, searchString, **kwargs)
|
||||||
irc.reply(msg, self.formatData(data))
|
bold = self.configurables.get('bold', msg.args[0])
|
||||||
|
max = self.configurables.get('maximum-results', msg.args[0])
|
||||||
|
irc.reply(msg, self.formatData(data, bold=bold, max=max))
|
||||||
|
|
||||||
def metagoogle(self, irc, msg, args):
|
def metagoogle(self, irc, msg, args):
|
||||||
"""<search> [--(language,restrict)=<value>] [--{similar,notsafe}]
|
"""<search> [--(language,restrict)=<value>] [--{similar,notsafe}]
|
||||||
|
@ -33,7 +33,9 @@ from testsupport import *
|
|||||||
|
|
||||||
class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
|
class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||||
plugins = ('Google',)
|
plugins = ('Google',)
|
||||||
|
if network:
|
||||||
def testNoNoLicenseKeyError(self):
|
def testNoNoLicenseKeyError(self):
|
||||||
|
self.assertNotError('google config groups-snarfer on')
|
||||||
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))
|
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))
|
||||||
self.assertNoResponse(' ')
|
self.assertNoResponse(' ')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user