Skip to content

Commit

Permalink
plugin: add support for duckduckgo search. (#151)
Browse files Browse the repository at this point in the history
* Added support for duckduckgo search.

* added pr comments fix.

* added duck emoji
  • Loading branch information
rakeshseal0 authored Oct 6, 2022
1 parent 00a75fc commit bc1e27c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ GUI clients are used to manage plugins, launch bot as well as specify credential
| :page_with_curl: comic | Returns a random comic | [@mboekhold](https://github.com/mboekhold) |
| 📝 todo | Makes a to do list | [@h-ranjan1110](https://github.com/h-ranjan1110) |
| 🎱 Magic 8 Ball | Answer questions using magic 8 ball | [@ZakariaTalhami](https://github.com/ZakariaTalhami) |
| 🦆 DuckDuckGo Search | Search queries in duckduckgo and return abstract. | [@rakeshseal0](https://github.com/rakeshseal0) |

## ⚡ Quickstart

Expand Down
Empty file.
11 changes: 11 additions & 0 deletions src/honeybot/plugins/downloaded/duckduckgo/info.py
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
"""
37 changes: 37 additions & 0 deletions src/honeybot/plugins/downloaded/duckduckgo/main.py
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests

0 comments on commit bc1e27c

Please sign in to comment.