added whois plugin

This commit is contained in:
Juhani Naskali
2023-07-15 19:52:00 +03:00
parent 2e9f742c17
commit 0b8317fca3
2 changed files with 34 additions and 0 deletions

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]

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.whois(kwargs['domain'])
return whois_result
except whois.parser.PywhoisError as e:
return {'result': 'No such domain found'}
except Exception as e:
return {'error': 'An unexpected error occurred: ' + str(e)}