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