Add duckduckgo.py
This commit is contained in:
parent
bdcb4b5db2
commit
789787b866
1 changed files with 24 additions and 0 deletions
24
modules/duckduckgo.py
Normal file
24
modules/duckduckgo.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
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):
|
||||
"""
|
||||
:help: Get first Google result for a given search term
|
||||
: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",
|
||||
"no_redirect": "1"}, json=True)
|
||||
|
||||
if page:
|
||||
event["stdout"].write(page.data["AbstractURL"])
|
||||
else:
|
||||
event["stderr"].write("No results found")
|
Loading…
Reference in a new issue