New module: ddg: search on internet through Duckduckgo and Wolfram|Alpha
This commit is contained in:
parent
cf18e7c2e7
commit
16f6cefc59
3 changed files with 187 additions and 0 deletions
50
modules/ddg/__init__.py
Normal file
50
modules/ddg/__init__.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# coding=utf-8
|
||||
|
||||
nemubotversion = 3.0
|
||||
|
||||
from .DDGSearch import DDGSearch
|
||||
from . import WFASearch
|
||||
|
||||
lastSearch = dict()
|
||||
|
||||
def load():
|
||||
global CONF
|
||||
WFASearch.CONF = CONF
|
||||
|
||||
def parseanswer(msg):
|
||||
global lastSearch
|
||||
req = None
|
||||
if msg.cmd[0] == "def" or msg.cmd[0] == "d" or msg.cmd[0] == "define" or msg.cmd[0] == "defini" or msg.cmd[0] == "definit" or msg.cmd[0] == "definition":
|
||||
req = "def"
|
||||
elif msg.cmd[0] == "g" or msg.cmd[0] == "ddg" or msg.cmd[0] == "d":
|
||||
req = "link"
|
||||
elif msg.cmd[0] == "wfa" or msg.cmd[0] == "calc" or msg.cmd[0] == "wa":
|
||||
req = "wfa"
|
||||
|
||||
if msg.cmd[0] == "more" or msg.cmd[0] == "plus":
|
||||
if msg.channel in lastSearch and lastSearch[msg.channel] is not None:
|
||||
msg.send_chn(lastSearch[msg.channel].nextRes)
|
||||
else:
|
||||
msg.send_chn("There is no ongoing research.")
|
||||
elif req is not None:
|
||||
if len(msg.cmd) > 1:
|
||||
if req == "wfa":
|
||||
s = WFASearch.WFASearch(' '.join(msg.cmd[1:]))
|
||||
if not s.success:
|
||||
msg.send_chn("An error occurs during computation")
|
||||
return True
|
||||
else:
|
||||
s = DDGSearch(' '.join(msg.cmd[1:]))
|
||||
|
||||
if req == "def":
|
||||
msg.send_chn(s.definition)
|
||||
else:
|
||||
msg.send_chn(s.nextRes)
|
||||
lastSearch[msg.channel] = s
|
||||
else:
|
||||
msg.send_chn("What are you looking for?")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue