From bc1e27c970e004259fc93496bb343f1da39e9a8f Mon Sep 17 00:00:00 2001 From: RAKESH SEAL Date: Thu, 6 Oct 2022 15:18:46 +0530 Subject: [PATCH] plugin: add support for duckduckgo search. (#151) * Added support for duckduckgo search. * added pr comments fix. * added duck emoji --- README.md | 1 + .../plugins/downloaded/duckduckgo/__init__.py | 0 .../plugins/downloaded/duckduckgo/info.py | 11 ++++++ .../plugins/downloaded/duckduckgo/main.py | 37 +++++++++++++++++++ .../downloaded/duckduckgo/requirements.txt | 1 + 5 files changed, 50 insertions(+) create mode 100644 src/honeybot/plugins/downloaded/duckduckgo/__init__.py create mode 100644 src/honeybot/plugins/downloaded/duckduckgo/info.py create mode 100644 src/honeybot/plugins/downloaded/duckduckgo/main.py create mode 100644 src/honeybot/plugins/downloaded/duckduckgo/requirements.txt diff --git a/README.md b/README.md index fa74e67..2beb7b9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/honeybot/plugins/downloaded/duckduckgo/__init__.py b/src/honeybot/plugins/downloaded/duckduckgo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/honeybot/plugins/downloaded/duckduckgo/info.py b/src/honeybot/plugins/downloaded/duckduckgo/info.py new file mode 100644 index 0000000..ba90514 --- /dev/null +++ b/src/honeybot/plugins/downloaded/duckduckgo/info.py @@ -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 +returns abstrack from duckduckgo search +""" diff --git a/src/honeybot/plugins/downloaded/duckduckgo/main.py b/src/honeybot/plugins/downloaded/duckduckgo/main.py new file mode 100644 index 0000000..80674ab --- /dev/null +++ b/src/honeybot/plugins/downloaded/duckduckgo/main.py @@ -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 +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) diff --git a/src/honeybot/plugins/downloaded/duckduckgo/requirements.txt b/src/honeybot/plugins/downloaded/duckduckgo/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/src/honeybot/plugins/downloaded/duckduckgo/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file