Skip to content

Commit

Permalink
Merge pull request #378 from jnaskali/feature/whois
Browse files Browse the repository at this point in the history
whois plugin
  • Loading branch information
n3d1117 committed Jul 28, 2023
2 parents 2e9f742 + d64859d commit c277df4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Check out the [official API reference](https://platform.openai.com/docs/api-refe
| `youtube_audio_extractor` | Extract audio from YouTube videos | - | `pip install pytube~=15.0.0` |
| `deepl_translate` | Translate text to any language (powered by [DeepL](https://deepl.com)) - by [@LedyBacer](https://github.com/LedyBacer) | `DEEPL_API_KEY` | |
| `gtts_text_to_speech` | Text to speech (powered by Google Translate APIs) | - | `pip install gtts~=2.3.2` |
| `whois` | Query the whois domain database | - | `pip install whois~=0.9.27` |

**Note**: some plugins have additional dependencies that are not listed in the `requirements.txt` file. If you plan on using these plugins, you can install them manually using the command above (see the `Dependency` column).

Expand Down
4 changes: 3 additions & 1 deletion bot/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from plugins.wolfram_alpha import WolframAlphaPlugin
from plugins.deepl import DeeplTranslatePlugin
from plugins.worldtimeapi import WorldTimeApiPlugin
from plugins.whois import WhoisPlugin


class PluginManager:
Expand All @@ -34,6 +35,7 @@ def __init__(self, config):
'dice': DicePlugin,
'deepl_translate': DeeplTranslatePlugin,
'gtts_text_to_speech': GTTSTextToSpeech,
'whois': WhoisPlugin,
}
self.plugins = [plugin_mapping[plugin]() for plugin in enabled_plugins if plugin in plugin_mapping]

Expand All @@ -50,7 +52,7 @@ async def call_function(self, function_name, arguments):
plugin = self.__get_plugin_by_function_name(function_name)
if not plugin:
return json.dumps({'error': f'Function {function_name} not found'})
return json.dumps(await plugin.execute(function_name, **json.loads(arguments)))
return json.dumps(await plugin.execute(function_name, **json.loads(arguments)), default=str)

def get_plugin_source_name(self, function_name) -> str:
"""
Expand Down
32 changes: 32 additions & 0 deletions bot/plugins/whois.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Dict
from .plugin import Plugin
import whois

class WhoisPlugin(Plugin):
"""
A plugin to query whois database
"""
def get_source_name(self) -> str:
return "Whois"

def get_spec(self) -> [Dict]:
return [{
"name": "get_whois",
"description": "Get whois registration and expiry information for a domain",
"parameters": {
"type": "object",
"properties": {
"domain": {"type": "string", "description": "Domain name"}
},
"required": ["domain"],
},
}]

async def execute(self, function_name, **kwargs) -> Dict:
try:
whois_result = whois.query(kwargs['domain'])
if whois_result is None:
return {'result': 'No such domain found'}
return whois_result.__dict__
except Exception as e:
return {'error': 'An unexpected error occurred: ' + str(e)}

0 comments on commit c277df4

Please sign in to comment.