-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin: add support for duckduckgo search. (#151)
* Added support for duckduckgo search. * added pr comments fix. * added duck emoji
- Loading branch information
1 parent
00a75fc
commit bc1e27c
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAME = "duck.py" | ||
ORIGINAL_AUTHORS = ["Rakesh Seal"] | ||
|
||
ABOUT = """ | ||
Returns a abstract of the search query from a duckduckgo Search. Return empty if no abstract found. | ||
""" | ||
|
||
COMMANDS = """ | ||
>>> .duck <query> | ||
returns abstrack from duckduckgo search | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
[duckduckgo.py] | ||
Duckduckgo Plugin | ||
[Author] | ||
Rakesh Seal | ||
[About] | ||
Returns a abstract of the search query from a duckduckgo Search. Return empty if no abstract found. | ||
[Website] | ||
[Commands] | ||
>>> .duck <query> | ||
returns abstrack from duckduckgo search | ||
""" | ||
|
||
import requests | ||
|
||
|
||
class Plugin: | ||
def __init__(self): | ||
pass | ||
|
||
def __gen_url_from_query(self, query): | ||
return "https://duckduckgo.com/?q=" + query + "&format=json&pretty=1" | ||
|
||
def run(self, incoming, methods, info, bot_info): | ||
try: | ||
msgs = info["args"][1:][0].split() | ||
if info['command'] == 'PRIVMSG' and msgs[0] == '.duck': | ||
query = ' '.join(msg for msg in msgs[1:]) | ||
duck_abstract = requests.get(self.__gen_url_from_query(query)).json()["Abstract"] | ||
methods['send'](info['address'], duck_abstract) | ||
except Exception as e: | ||
print("quack quack!", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests |