mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Added new getopt capability to google command.
This commit is contained in:
parent
e9e81227eb
commit
8d50d79e7a
@ -44,6 +44,7 @@ Commands include:
|
|||||||
from baseplugin import *
|
from baseplugin import *
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import getopt
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
import google
|
import google
|
||||||
@ -59,6 +60,17 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
key = anything('What is it?')
|
key = anything('What is it?')
|
||||||
onStart.append('load Google')
|
onStart.append('load Google')
|
||||||
onStart.append('googlelicensekey %s' % key)
|
onStart.append('googlelicensekey %s' % key)
|
||||||
|
if yn('Google depends on the Alias module for some commands. ' \
|
||||||
|
'Is the Alias module loaded?') == 'n':
|
||||||
|
if yn('Would you like to load the Alias module now?') == 'y':
|
||||||
|
onStart.append('load Alias')
|
||||||
|
else:
|
||||||
|
print 'You can still use the Google module, but you won\'t ' \
|
||||||
|
'be asked any further questions.'
|
||||||
|
return
|
||||||
|
onStart.append('alias googlelinux "google --restrict=linux $1"')
|
||||||
|
onStart.append('alias googlebsd "google --restrict=bsd $1"')
|
||||||
|
onStart.append('alias googlemac "google --restrict=mac $1"')
|
||||||
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 from http://www.google.com/apis/'
|
print 'You can apply for a key from http://www.google.com/apis/'
|
||||||
@ -90,12 +102,11 @@ class Google(callbacks.Privmsg):
|
|||||||
results.append('\x02%s\x02: %s' % (title, url))
|
results.append('\x02%s\x02: %s' % (title, url))
|
||||||
else:
|
else:
|
||||||
results.append(url)
|
results.append(url)
|
||||||
while reduce(operator.add, map((4).__add__,map(len, results)),0) > 400:
|
|
||||||
results.pop()
|
|
||||||
if not results:
|
if not results:
|
||||||
return 'No matches found %s' % time
|
return 'No matches found %s' % time
|
||||||
else:
|
else:
|
||||||
return '%s %s' % (' :: '.join(results), time)
|
response = ircutils.privmsgPayload(results, ' :: ', 400)
|
||||||
|
return '%s %s' % (response, time)
|
||||||
|
|
||||||
def googlelicensekey(self, irc, msg, args):
|
def googlelicensekey(self, irc, msg, args):
|
||||||
"""<key>
|
"""<key>
|
||||||
@ -109,51 +120,19 @@ class Google(callbacks.Privmsg):
|
|||||||
googlelicensekey = privmsgs.checkCapability(googlelicensekey, 'admin')
|
googlelicensekey = privmsgs.checkCapability(googlelicensekey, 'admin')
|
||||||
|
|
||||||
def google(self, irc, msg, args):
|
def google(self, irc, msg, args):
|
||||||
"""<search string>
|
"""<search string> [--{language,restrict,safe,filter}=<value>]
|
||||||
|
|
||||||
Searches google.com for the given string. As many results as can fit
|
Searches google.com for the given string. As many results as can fit
|
||||||
are included.
|
are included. Use options to set different values for the options
|
||||||
|
Google accepts.
|
||||||
"""
|
"""
|
||||||
searchString = privmsgs.getArgs(args)
|
(optlist, rest) = getopt.getopt(args, '', ['language=', 'restrict=',
|
||||||
data = google.doGoogleSearch(searchString,
|
'safe=', 'filter='])
|
||||||
language='lang_en',
|
kwargs = {'language': 'lang_en', 'safeSearch': 1}
|
||||||
safeSearch=1)
|
for (option, argument) in optlist:
|
||||||
irc.reply(msg, self.formatData(data))
|
kwargs[option[2:]] = argument
|
||||||
|
searchString = privmsgs.getArgs(rest)
|
||||||
def googlelinux(self, irc, msg, args):
|
data = google.doGoogleSearch(searchString, **kwargs)
|
||||||
"""<search string>
|
|
||||||
|
|
||||||
Searches Google's Linux repository.
|
|
||||||
"""
|
|
||||||
searchString = privmsgs.getArgs(args)
|
|
||||||
data=google.doGoogleSearch(searchString,
|
|
||||||
restrict='linux',
|
|
||||||
language='lang_en',
|
|
||||||
safeSearch=1)
|
|
||||||
irc.reply(msg, self.formatData(data))
|
|
||||||
|
|
||||||
def googlebsd(self, irc, msg, args):
|
|
||||||
"""<search string>
|
|
||||||
|
|
||||||
Searches Google's BSD repository.
|
|
||||||
"""
|
|
||||||
searchString = privmsgs.getArgs(args)
|
|
||||||
data = google.doGoogleSearch(searchString,
|
|
||||||
restrict='bsd',
|
|
||||||
language='lang_en',
|
|
||||||
safeSearch=1)
|
|
||||||
irc.reply(msg, self.formatData(data))
|
|
||||||
|
|
||||||
def googlemac(self, irc, msg, args):
|
|
||||||
"""<search string>
|
|
||||||
|
|
||||||
Searches Google's Mac repository.
|
|
||||||
"""
|
|
||||||
searchString = privmsgs.getArgs(args)
|
|
||||||
data = google.doGoogleSearch(searchString,
|
|
||||||
restrict='mac',
|
|
||||||
language='lang_en',
|
|
||||||
safeSearch=1)
|
|
||||||
irc.reply(msg, self.formatData(data))
|
irc.reply(msg, self.formatData(data))
|
||||||
|
|
||||||
def googlesite(self, irc, msg, args):
|
def googlesite(self, irc, msg, args):
|
||||||
@ -167,19 +146,6 @@ class Google(callbacks.Privmsg):
|
|||||||
safeSearch=1)
|
safeSearch=1)
|
||||||
irc.reply(msg, self.formatData(data))
|
irc.reply(msg, self.formatData(data))
|
||||||
|
|
||||||
def googleplex(self, irc, msg, args):
|
|
||||||
"""<search string> [language, restrict, safe, filter] keyword arguments
|
|
||||||
|
|
||||||
Search google, providing all your own options.
|
|
||||||
"""
|
|
||||||
(args, kwargs) = privmsgs.getKeywordArgs(irc, msg)
|
|
||||||
searchString = ' '.join(args)
|
|
||||||
if 'safe' in kwargs:
|
|
||||||
kwargs['safeSearch'] = int(kwargs['safe'])
|
|
||||||
del kwargs['safe']
|
|
||||||
data = google.doGoogleSearch(searchString, **kwargs)
|
|
||||||
irc.reply(msg, self.formatData(data))
|
|
||||||
|
|
||||||
def googlespell(self, irc, msg, args):
|
def googlespell(self, irc, msg, args):
|
||||||
"<word>"
|
"<word>"
|
||||||
word = privmsgs.getArgs(args)
|
word = privmsgs.getArgs(args)
|
||||||
|
Loading…
Reference in New Issue
Block a user