Merge pull request #378 from jnaskali/feature/whois

whois plugin
This commit is contained in:
ned
2023-07-28 21:43:31 +02:00
committed by GitHub
3 changed files with 36 additions and 1 deletions

View File

@@ -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).

View File

@@ -12,6 +12,7 @@ from plugins.ddg_web_search import DDGWebSearchPlugin
from plugins.wolfram_alpha import WolframAlphaPlugin
from plugins.deepl import DeeplTranslatePlugin
from plugins.worldtimeapi import WorldTimeApiPlugin
from plugins.whois import WhoisPlugin
class PluginManager:
@@ -34,6 +35,7 @@ class PluginManager:
'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]
@@ -50,7 +52,7 @@ class PluginManager:
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:
"""

32
bot/plugins/whois.py Normal file
View File

@@ -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)}