mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-27 20:54:33 +01:00
parent
94c582a4a0
commit
d26e8ff93d
10
config.py
10
config.py
@ -49,9 +49,13 @@ def configure(advanced):
|
|||||||
|
|
||||||
|
|
||||||
DDG = conf.registerPlugin('DDG')
|
DDG = conf.registerPlugin('DDG')
|
||||||
# This is where your configuration variables (if any) should go. For example:
|
conf.registerChannelValue(DDG, 'maxResults',
|
||||||
# conf.registerGlobalValue(DDG, 'someConfigVariableName',
|
registry.PositiveInteger(4, _("""Determines the maximum number of
|
||||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
results the bot will respond with.""")))
|
||||||
|
conf.registerChannelValue(DDG, 'showSnippet',
|
||||||
|
registry.Boolean(True, _("""Determines whether the bot will show a
|
||||||
|
snippet of each resulting link. If False, it will show the title
|
||||||
|
of the link instead.""")))
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
48
plugin.py
48
plugin.py
@ -69,27 +69,37 @@ class DDG(callbacks.Plugin):
|
|||||||
self.log.info(url)
|
self.log.info(url)
|
||||||
irc.error(str(e), Raise=True)
|
irc.error(str(e), Raise=True)
|
||||||
soup = BeautifulSoup(data)
|
soup = BeautifulSoup(data)
|
||||||
res = ''
|
replies = []
|
||||||
|
channel = msg.args[0]
|
||||||
for t in soup.find_all('td'):
|
for t in soup.find_all('td'):
|
||||||
if "1." in t.text:
|
maxr = self.registryValue("maxResults", channel)
|
||||||
res = t.next_sibling.next_sibling
|
for n in range(1, maxr):
|
||||||
if not res:
|
res = ''
|
||||||
continue
|
if ("%s." % n) in t.text:
|
||||||
try:
|
res = t.next_sibling.next_sibling
|
||||||
# 1) Get a result snippet.
|
if not res:
|
||||||
snippet = res.parent.next_sibling.next_sibling.\
|
continue
|
||||||
find_all("td")[-1]
|
try:
|
||||||
# 2) Fetch the result link.
|
snippet = ''
|
||||||
link = res.a.get('href')
|
# 1) Get a result snippet.
|
||||||
snippet = snippet.text.strip()
|
if self.registryValue("showsnippet", channel):
|
||||||
|
snippet = res.parent.next_sibling.next_sibling.\
|
||||||
s = format("%s - %u", snippet, link)
|
find_all("td")[-1]
|
||||||
irc.reply(s)
|
snippet = snippet.text.strip()
|
||||||
return
|
# 2) Fetch the link title.
|
||||||
except AttributeError:
|
title = res.a.text.strip()
|
||||||
continue
|
# 3) Fetch the result link.
|
||||||
|
link = res.a.get('href')
|
||||||
|
s = format("%s - %s %u", ircutils.bold(title), snippet,
|
||||||
|
link)
|
||||||
|
replies.append(s)
|
||||||
|
except AttributeError:
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
irc.error("No results found.")
|
if not replies:
|
||||||
|
irc.error("No results found.")
|
||||||
|
else:
|
||||||
|
irc.reply(', '.join(replies))
|
||||||
search = wrap(search, ['text'])
|
search = wrap(search, ['text'])
|
||||||
|
|
||||||
Class = DDG
|
Class = DDG
|
||||||
|
Loading…
Reference in New Issue
Block a user