Limnoria/plugins/Google/config.py
2009-03-11 13:37:25 -04:00

107 lines
5.1 KiB
Python

###
# Copyright (c) 2005, Jeremiah Fincher
# Copyright (c) 2008, James Vega
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import supybot.conf as conf
import supybot.registry as registry
def configure(advanced):
from supybot.questions import output, yn
conf.registerPlugin('Google', True)
output("""The Google plugin has the functionality to watch for URLs
that match a specific pattern. (We call this a snarfer)
When supybot sees such a URL, it will parse the web page
for information and reply with the results.
Google has two available snarfers: Google Groups link
snarfing and a google search snarfer.""")
if yn('Do you want the Google Groups link snarfer enabled by '
'default?'):
conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
if yn('Do you want the Google search snarfer enabled by default?'):
conf.supybot.plugins.Google.searchSnarfer.setValue(True)
class Language(registry.OnlySomeStrings):
validStrings = ['lang_' + s for s in 'ar bg ca zh-CN zh-TW hr cs da nl en '
'et fi fr de el iw hu is id it ja ko '
'lv lt no pl pt ro ru sr sk sl es sv '
'tr'.split()]
validStrings.append('')
def normalize(self, s):
if not s.startswith('lang_'):
s = 'lang_' + s
if not s.endswith('CN') or s.endswith('TW'):
s = s.lower()
else:
s = s.lower()[:-2] + s[-2:]
return s
class NumSearchResults(registry.PositiveInteger):
"""Value must be 1 <= n <= 8"""
def setValue(self, v):
if v > 8:
self.error()
super(NumSearchResults, self).setValue(v)
class SafeSearch(registry.OnlySomeStrings):
validStrings = ['active', 'moderate', 'off']
Google = conf.registerPlugin('Google')
conf.registerGlobalValue(Google, 'referer',
registry.String('', """Determines the URL that will be sent to Google for
the Referer field of the search requests. If this value is empty, a
Referer will be generated in the following format:
http://$server/$botName"""))
conf.registerChannelValue(Google, 'groupsSnarfer',
registry.Boolean(False, """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."""))
conf.registerChannelValue(Google, 'searchSnarfer',
registry.Boolean(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."""))
conf.registerChannelValue(Google, 'colorfulFilter',
registry.Boolean(False, """Determines whether the word 'google' in the
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, 'maximumResults',
NumSearchResults(8, """Determines the maximum number of results returned
from the google command."""))
conf.registerChannelValue(Google, 'defaultLanguage',
Language('lang_en', """Determines what default language is used in
searches. If left empty, no specific language will be requested."""))
conf.registerChannelValue(Google, 'safeSearch',
SafeSearch('moderate', """Determines what level of safeSearch to use by
default. 'active' - most filtering, 'moderate' - default filtering, 'off'
- no filtering"""))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: