2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
|
|
|
|
2019-04-25 19:18:13 +00:00
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
|
|
|
URL_DDG = "https://api.duckduckgo.com"
|
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
_name = "DDG"
|
|
|
|
|
|
|
|
@utils.hook("received.command.ddg", min_args=1)
|
|
|
|
def duckduckgo(self, event):
|
|
|
|
"""
|
2019-04-25 19:19:25 +00:00
|
|
|
:help: Get first DuckDuckGo result for a given search term
|
2019-04-25 19:18:13 +00:00
|
|
|
:usage: [search term]
|
|
|
|
"""
|
|
|
|
|
|
|
|
phrase = event["args"] or event["target"].buffer.get()
|
|
|
|
if phrase:
|
|
|
|
page = utils.http.request(URL_DDG, get_params={
|
|
|
|
"q": phrase, "format": "json", "no_html": "1",
|
2019-11-26 13:41:40 +00:00
|
|
|
"no_redirect": "1"}).json()
|
2019-04-25 19:18:13 +00:00
|
|
|
|
2019-11-26 13:41:40 +00:00
|
|
|
if page and page["AbstractURL"]:
|
|
|
|
event["stdout"].write(page["AbstractURL"])
|
2019-04-25 19:18:13 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("No results found")
|