mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Updated to use Configurable.
This commit is contained in:
parent
64e664e0bc
commit
3ed58d9115
@ -89,10 +89,10 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
print 'snarfing and a google search snarfer.\n'
|
print 'snarfing and a google search snarfer.\n'
|
||||||
if yn('Do you want the Google Groups link snarfer enabled by '\
|
if yn('Do you want the Google Groups link snarfer enabled by '\
|
||||||
'default?') == 'n':
|
'default?') == 'n':
|
||||||
onStart.append('Google toggle groups off')
|
onStart.append('Google config groups-snarfer off')
|
||||||
if yn('Do you want the Google search snarfer enabled by default?')\
|
if yn('Do you want the Google search snarfer enabled by default?')\
|
||||||
== 'y':
|
== 'y':
|
||||||
onStart.append('Google toggle search on')
|
onStart.append('Google config search-snarfer on')
|
||||||
else:
|
else:
|
||||||
print 'You\'ll need to get a key before you can use this plugin.'
|
print 'You\'ll need to get a key before you can use this plugin.'
|
||||||
print 'You can apply for a key at http://www.google.com/apis/'
|
print 'You can apply for a key at http://www.google.com/apis/'
|
||||||
@ -119,14 +119,21 @@ def search(*args, **kwargs):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
|
||||||
threaded = True
|
threaded = True
|
||||||
regexps = sets.Set(['googleSnarfer', 'googleGroups'])
|
regexps = sets.Set(['googleSnarfer', 'googleGroups'])
|
||||||
toggles = plugins.ToggleDictionary({'groups' : True,
|
configurables = plugins.ConfigurableDictionary(
|
||||||
'search' : False})
|
[('groups-snarfer', plugins.ConfigurableTypes.bool, True,
|
||||||
|
"""Determines whether the groups snarfer is enabled. If so, URLs at
|
||||||
|
groups.google.com will be snarfed and their group/title messaged to
|
||||||
|
the channel."""),
|
||||||
|
('search-snarfer', plugins.ConfigurableTypes.bool, False,
|
||||||
|
"""Determines whether the search snarfer is enabled. If so, messages
|
||||||
|
(even unaddressed ones) beginning with the word 'google' will result
|
||||||
|
in the first URL Google returns being sent to the channel.""")]
|
||||||
|
)
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(self.__class__, self).__init__()
|
super(Google, self).__init__()
|
||||||
plugins.Toggleable.__init__(self)
|
|
||||||
self.total = 0
|
self.total = 0
|
||||||
self.totalTime = 0
|
self.totalTime = 0
|
||||||
self.last24hours = structures.queue()
|
self.last24hours = structures.queue()
|
||||||
@ -260,7 +267,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
|
|
||||||
def googleSnarfer(self, irc, msg, match):
|
def googleSnarfer(self, irc, msg, match):
|
||||||
r"^google\s+(.*)$"
|
r"^google\s+(.*)$"
|
||||||
if not self.toggles.get('search', channel=msg.args[0]):
|
if not self.configurables.get('search-snarfer', channel=msg.args[0]):
|
||||||
return
|
return
|
||||||
searchString = match.group(1)
|
searchString = match.group(1)
|
||||||
try:
|
try:
|
||||||
@ -272,12 +279,13 @@ class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
irc.reply(msg, url)
|
irc.reply(msg, url)
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, 'No results for "%s"' % searchString)
|
irc.reply(msg, 'No results for "%s"' % searchString)
|
||||||
|
googleSnarfer = privmsgs.urlSnarfer(googleSnarfer)
|
||||||
|
|
||||||
_ggThread = re.compile(r'<br>Subject: ([^<]+)<br>')
|
_ggThread = re.compile(r'<br>Subject: ([^<]+)<br>')
|
||||||
_ggGroup = re.compile(r'Newsgroups: <a[^>]+>([^<]+)</a>')
|
_ggGroup = re.compile(r'Newsgroups: <a[^>]+>([^<]+)</a>')
|
||||||
def googleGroups(self, irc, msg, match):
|
def googleGroups(self, irc, msg, match):
|
||||||
r"http://groups.google.com/[^\s]+"
|
r"http://groups.google.com/[^\s]+"
|
||||||
if not self.toggles.get('groups', channel=msg.args[0]):
|
if not self.configurables.get('groups-snarfer', channel=msg.args[0]):
|
||||||
return
|
return
|
||||||
request = urllib2.Request(match.group(0), headers=\
|
request = urllib2.Request(match.group(0), headers=\
|
||||||
{'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'})
|
{'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'})
|
||||||
@ -303,6 +311,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
else:
|
else:
|
||||||
irc.error(msg, 'That doesn\'t appear to be a proper '\
|
irc.error(msg, 'That doesn\'t appear to be a proper '\
|
||||||
'Google Groups page. (%s)' % conf.replyPossibleBug)
|
'Google Groups page. (%s)' % conf.replyPossibleBug)
|
||||||
|
googleGroups = privmsgs.urlSnarfer(googleGroups)
|
||||||
|
|
||||||
|
|
||||||
Class = Google
|
Class = Google
|
||||||
|
Loading…
Reference in New Issue
Block a user